Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Adding/removing a GeoJSON source doesn't show in layer till map is zoomed in/out #6612

Closed
cammace opened this issue Oct 6, 2016 · 16 comments
Labels
Android Mapbox Maps SDK for Android bug

Comments

@cammace
Copy link
Contributor

cammace commented Oct 6, 2016

Platform: Nexus 5x running Nougat
Mapbox SDK version: 4.2.0-beta.3

Steps to trigger behavior

  1. Have a map style with a GeoJSON source that is visible.
  2. Replace the GeoJSON source with a new one.
  3. The layer won't show update till you zoom in/out

Expected behavior

Updated source shows up instantly when added to map

Actual behavior

new Source won't show up till after zooming map in or out (invalidating the map?)

cc: @ivovandongen @zugaldia

@cammace cammace added bug Android Mapbox Maps SDK for Android labels Oct 6, 2016
@cammace cammace added this to the android-v4.2.0 milestone Oct 6, 2016
@rmnblm
Copy link

rmnblm commented Oct 7, 2016

Might be the same issue as I had with iOS, see #6177 (comment)

@1ec5
Copy link
Contributor

1ec5 commented Oct 7, 2016

This sounds different than #6177. As of beta 3, we’re correctly invalidating the map when a layout or paint property or filter is set; however, swapping out a source is probably distinct from changing a filter.

@jfirebaugh, does this sound like something that should’ve been fixed by #6201, or is it another special case?

@ivovandongen
Copy link
Contributor

@cammace Just to clarify, this issue is not about updating a GeoJsonSource (like the title suggests), but replacing it all together with add/removeSource right?

@jfirebaugh
Copy link
Contributor

jfirebaugh commented Oct 7, 2016

This is exposing some lax behavior in our runtime styling APIs -- it's not actually intended to be possible to remove a source that's currently in use by one or more layers, add another source with the same ID but different data, and have the layers update to the new data. (Doing so potentially violates numerous invariants that the style attempts to enforce.)

Instead, removing an in-use source should either:

  • Produce an error indicating that the layers that use it need to be removed first, or
  • Automatically remove those layers

@ivovandongen ivovandongen changed the title Updated GeoJSON source changes don't show in layer till map is zoomed in/out Adding/removing a GeoJSON source doesn't show in layer till map is zoomed in/out Oct 11, 2016
@ivovandongen ivovandongen removed this from the android-v4.2.0 milestone Oct 11, 2016
@ivovandongen
Copy link
Contributor

@jfirebaugh Agreed. I would prefer an error in this situation to make it abundantly clear that this is an unsupported operation.

I removed this from the upcoming release milestone as it is not a blocker.

@sddamico
Copy link

It should be noted that the same behavior is seen if one changes the backing data in a geojson source
(e.g. layers not not invalidating until the map is invalidated by zoom or some other event)

String serializedGeoJsonData = getNewGeoJsonData();
final GeoJsonSource source = mapboxMap.getSourceAs("geoJsonData");
source.setGeoJson(serializedGeoJsonData);

@sddamico
Copy link

My current workaround is mapboxMap.moveCamera(CameraUpdateFactory.zoomBy(0.0001f));

@jfirebaugh
Copy link
Contributor

@sddamico That's #5906, and should be fixed in v4.2.0-beta.3.

@sddamico
Copy link

@jfirebaugh I'm using v4.2.0-beta.3 and the issue as I described is present.

@jfirebaugh
Copy link
Contributor

Ok, please open a fresh issue.

@sddamico
Copy link

@jfirebaugh done: #6744

@damianflannery
Copy link

I am also facing this issue with beta4. I call removeLayer(layerId) before adding a new layer (with different id).

I recorded a short recording here (glitch happens at 11 seconds from start)
https://dl.dropboxusercontent.com/u/27007357/mapbox_geojsonsource_glitch.mp4

@ivovandongen
Copy link
Contributor

@damianflannery Could you share some code (minimal case) so we can see how you're doing this? The original issue was about removing/adding a source to get layers updated, you seem to be doing something else.

@damianflannery
Copy link

@ivovandongen Sure, I created a sample project here:
https://github.com/damianflannery/MapboxGlitch

I also created another recording of the issue using this sample and log output below (Nexus 5X, Adnroid 6.0.1):
https://dl.dropboxusercontent.com/u/27007357/navenio/glitch.mp4

11-10 11:29:58.703 14144-14144/glitch.com.glitch D/Glitch: in showPolygon old:outer_polygon.geojson, new:floor_0.geojson
11-10 11:29:58.720 14144-14144/glitch.com.glitch D/Glitch: read polygons in floor_0.geojson
11-10 11:29:58.721 14144-14144/glitch.com.glitch D/Glitch: removing old polygons / polylines outer_polygon.geojson
11-10 11:29:58.744 14144-14144/glitch.com.glitch W/art: Attempt to remove non-JNI local reference, dumping thread
11-10 11:29:58.758 14144-14144/glitch.com.glitch W/art: Attempt to remove non-JNI local reference, dumping thread
11-10 11:29:58.759 14144-14144/glitch.com.glitch W/art: Attempt to remove non-JNI local reference, dumping thread
11-10 11:29:58.759 14144-14144/glitch.com.glitch D/Glitch: adding fillLayer floor_0.geojson_venue
11-10 11:29:58.760 14144-14144/glitch.com.glitch D/Glitch: adding linesLayer floor_0.geojson_lines
11-10 11:29:58.760 14144-14144/glitch.com.glitch D/Glitch: --------
11-10 11:30:03.561 14144-14144/glitch.com.glitch D/Glitch: in showPolygon old:floor_0.geojson, new:floor_1.geojson
11-10 11:30:03.583 14144-14144/glitch.com.glitch D/Glitch: read polygons in floor_1.geojson
11-10 11:30:03.584 14144-14144/glitch.com.glitch D/Glitch: removing old polygons / polylines floor_0.geojson
11-10 11:30:03.602 14144-14144/glitch.com.glitch W/art: Attempt to remove non-JNI local reference, dumping thread
11-10 11:30:03.612 14144-14144/glitch.com.glitch W/art: Attempt to remove non-JNI local reference, dumping thread
11-10 11:30:03.612 14144-14144/glitch.com.glitch W/art: Attempt to remove non-JNI local reference, dumping thread
11-10 11:30:03.613 14144-14144/glitch.com.glitch D/Glitch: adding fillLayer floor_1.geojson_venue
11-10 11:30:03.613 14144-14144/glitch.com.glitch D/Glitch: adding linesLayer floor_1.geojson_lines
11-10 11:30:03.614 14144-14144/glitch.com.glitch D/Glitch: --------
11-10 11:30:06.649 14144-14144/glitch.com.glitch D/Glitch: in showPolygon old:floor_1.geojson, new:floor_0.geojson
11-10 11:30:06.672 14144-14144/glitch.com.glitch D/Glitch: read polygons in floor_0.geojson
11-10 11:30:06.673 14144-14144/glitch.com.glitch D/Glitch: removing old polygons / polylines floor_1.geojson
11-10 11:30:06.698 14144-14144/glitch.com.glitch W/art: Attempt to remove non-JNI local reference, dumping thread
11-10 11:30:06.712 14144-14144/glitch.com.glitch W/art: Attempt to remove non-JNI local reference, dumping thread
11-10 11:30:06.713 14144-14144/glitch.com.glitch W/art: Attempt to remove non-JNI local reference, dumping thread
11-10 11:30:06.713 14144-14144/glitch.com.glitch D/Glitch: adding fillLayer floor_0.geojson_venue
11-10 11:30:06.714 14144-14144/glitch.com.glitch D/Glitch: adding linesLayer floor_0.geojson_lines
11-10 11:30:06.714 14144-14144/glitch.com.glitch D/Glitch: --------
11-10 11:30:13.162 14144-17317/glitch.com.glitch W/com.mapbox.mapboxsdk.http.HTTPRequest: Request failed due to a permanent error: Canceled
11-10 11:30:13.340 14144-17317/glitch.com.glitch W/com.mapbox.mapboxsdk.http.HTTPRequest: Request failed due to a permanent error: Canceled
11-10 11:30:13.526 14144-17317/glitch.com.glitch W/com.mapbox.mapboxsdk.http.HTTPRequest: Request failed due to a permanent error: Canceled
11-10 11:30:13.555 14144-17318/glitch.com.glitch W/com.mapbox.mapboxsdk.http.HTTPRequest: Request failed due to a permanent error: Canceled
11-10 11:30:20.011 14144-14144/glitch.com.glitch D/Glitch: in showPolygon old:floor_0.geojson, new:floor_1.geojson
11-10 11:30:20.029 14144-14144/glitch.com.glitch D/Glitch: read polygons in floor_1.geojson
11-10 11:30:20.029 14144-14144/glitch.com.glitch D/Glitch: removing old polygons / polylines floor_0.geojson
11-10 11:30:20.048 14144-14144/glitch.com.glitch W/art: Attempt to remove non-JNI local reference, dumping thread
11-10 11:30:20.058 14144-14144/glitch.com.glitch W/art: Attempt to remove non-JNI local reference, dumping thread
11-10 11:30:20.058 14144-14144/glitch.com.glitch W/art: Attempt to remove non-JNI local reference, dumping thread
11-10 11:30:20.059 14144-14144/glitch.com.glitch D/Glitch: adding fillLayer floor_1.geojson_venue
11-10 11:30:20.059 14144-14144/glitch.com.glitch D/Glitch: adding linesLayer floor_1.geojson_lines
11-10 11:30:20.059 14144-14144/glitch.com.glitch D/Glitch: --------
11-10 11:30:26.626 14144-20203/glitch.com.glitch D/GzipRequestInterceptor: Compressing
11-10 11:30:26.882 14144-20203/glitch.com.glitch D/MapboxEventManager: response code = 204 for events 97
11-10 11:30:29.023 14144-14144/glitch.com.glitch D/Glitch: in showPolygon old:floor_1.geojson, new:floor_0.geojson
11-10 11:30:29.046 14144-14144/glitch.com.glitch D/Glitch: read polygons in floor_0.geojson
11-10 11:30:29.046 14144-14144/glitch.com.glitch D/Glitch: removing old polygons / polylines floor_1.geojson
11-10 11:30:29.071 14144-14144/glitch.com.glitch W/art: Attempt to remove non-JNI local reference, dumping thread
11-10 11:30:29.086 14144-14144/glitch.com.glitch W/art: Attempt to remove non-JNI local reference, dumping thread
11-10 11:30:29.086 14144-14144/glitch.com.glitch W/art: Attempt to remove non-JNI local reference, dumping thread
11-10 11:30:29.087 14144-14144/glitch.com.glitch D/Glitch: adding fillLayer floor_0.geojson_venue
11-10 11:30:29.087 14144-14144/glitch.com.glitch D/Glitch: adding linesLayer floor_0.geojson_lines
11-10 11:30:29.087 14144-14144/glitch.com.glitch D/Glitch: --------

Thanks for taking a look.

@ivovandongen
Copy link
Contributor

@damianflannery Thanks for the example code. That cleared things up a lot.

There is a slight issue in your code that triggers this behaviour. You add sources, but never remove them. The issues start appearing when a source is added twice for the same id it seems. If your remove your source, just as the layers. It works as expected. See this patch for details.

If you want to get the most out of it in your real application btw, it might be worth toggling the opacity or visibility on layers instead of remove/adding them. This often gives a smoother transition.

@damianflannery
Copy link

Ah, now works perfectly. Thank you @ivovandongen :)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Android Mapbox Maps SDK for Android bug
Projects
None yet
Development

No branches or pull requests

7 participants