Platform: Nexus 5x running Nougat
Mapbox SDK version: 4.2.0-beta.3
Updated source shows up instantly when added to map
new Source won't show up till after zooming map in or out (invalidating the map?)
cc: @ivovandongen @zugaldia
Might be the same issue as I had with iOS, see https://github.com/mapbox/mapbox-gl-native/issues/6177#issuecomment-251378211
This sounds different than #6177. As of beta 3, we鈥檙e 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鈥檝e been fixed by #6201, or is it another special case?
@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?
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:
@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.
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);
My current workaround is mapboxMap.moveCamera(CameraUpdateFactory.zoomBy(0.0001f));
@sddamico That's #5906, and should be fixed in v4.2.0-beta.3.
@jfirebaugh I'm using v4.2.0-beta.3 and the issue as I described is present.
Ok, please open a fresh issue.
@jfirebaugh done: https://github.com/mapbox/mapbox-gl-native/issues/6744
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
@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.
@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.
@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.
Ah, now works perfectly. Thank you @ivovandongen :)