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

[Android] Layer symbol changes with the zoom #9975

Closed
paulVulog opened this issue Sep 12, 2017 · 8 comments
Closed

[Android] Layer symbol changes with the zoom #9975

paulVulog opened this issue Sep 12, 2017 · 8 comments
Labels
Android Mapbox Maps SDK for Android needs information support

Comments

@paulVulog
Copy link

paulVulog commented Sep 12, 2017

Hi,
from time to time, I have issue with my symbol layers.
When I change the zoom from one level to another, my layer display either the current state or the old state. (The big marker is one unique layer. I only change the marker icon. The blue direction is another layer)

Below are two captures taken with the same application state but at a slightly different zoom level :

Is it a known issue ? I am not able to find any comments about it. I can explain my code as needed.
(Mapbox 5.1.3)
Thanks.

@tobrun
Copy link
Member

tobrun commented Sep 12, 2017

@paulVulog could you share some code how you are changing the icon?
Changing icons like this should be done with zoom functions, an example of this can be found here.

@tobrun tobrun added Android Mapbox Maps SDK for Android support labels Sep 12, 2017
@paulVulog
Copy link
Author

Hi @tobrun , I use the same kind of code :

List<Stop> stops = new ArrayList<>();
stops.add(Stop.stop(true, iconImage(selectedIcon)));
stops.add(Stop.stop(false, iconImage(unselectedIcon)));
map.getLayer(layerName).setProperties(
        iconImage(Function.property("is_selected", 
                     Stops.categorical(stops.toArray(new Stop[stops.size()]))
        ).withDefaultValue(iconImage(unselectedIcon)))
);

Then I just change the "is_selected" property and I reload the layer. E.G:

List<Feature> updatedList = new ArrayList<>();
for(Feature f : geoJsonSource.querySourceFeatures(null)) {
         if(f.getId().contentEquals(feature.getId())) {
		 f.addBooleanProperty("is_selected", true);
          }
	  updatedList.add(f);
}

//reload the LayerSource
geoJsonSource.setGeoJson(FeatureCollection.fromFeatures(updatedList));

However, I notice the same issue on a simple symbol layer.
I have create a user position layer that display a single icon.
I change the icon position on every GPS fix. From time to times, the icon is not displayed at the right position and changing the zoom display either the current or previous position.
E.G:

map.addSource(new GeoJsonSource(USER_POSITION_SOURCE));
SymbolLayer userPositionLayer = new SymbolLayer(USER_POSITION_LAYER, USER_POSITION_SOURCE).withProperties(iconImage(MARKER_USER_POSITION));
map.addLayer(userPositionLayer);

and updated by

Feature featureUserPos = Feature.fromGeometry(Point.fromCoordinates(Position.fromCoordinates(location.getLongitude(), location.getLatitude())));
updateSource(USER_POSITION_SOURCE, FeatureCollection.fromFeatures(new Feature[]{featureUserPos}));

In addition, let me know if you have a better way to achieve what I want to do :

  • For a given layer, have a different icon regarding the selection status.
  • Have different icon images in a single layer.

@tobrun
Copy link
Member

tobrun commented Sep 13, 2017

Have different icon images in a single layer.

The best way to achieve this is using a token that refers to a key in your geojson (eg. {keyFromGeojson}). You use the same key to add images to the map with mapboxMap#addImage("keyFromGeojson", bitmap).

An example of this can be found in the mapbox-android-demo app:

  • adding layer with construct mentioned above here
  • adding images with the key to the map here

eg. the images shown in gif below are being shown with a single layer: (the cluster items are seperate):

ezgif com-video-to-gif 77

For a given layer, have a different icon regarding the selection status.

I will work on adding an example of this to the mentioned example here

@tobrun
Copy link
Member

tobrun commented Sep 13, 2017

I updated our zoom function example #9987 with UX requested. Didn't run into any of the mentioned issues. So I'm going to close this as non-reproducible. Feel free to add more context or create any follow up issues.

re. showing user location, feel free to check out our locaiton layer plugin that uses layers/sources to do the same. You might find the code there usefull to 👀. See here.

@tobrun tobrun closed this as completed Sep 13, 2017
@paulVulog
Copy link
Author

Thanks for all the information and links. I will have a look and perhaps have a try with simple Markers too.

@adieldev82
Copy link

The same issue
img-20171227-wa0001
could be seen in the demo app also.

@mpuchala
Copy link

Guys,

I have an issue related to this topic. I'm trying to prepare an Activity with Symbols dependent of zoom but it seems to be a problem with Expression. I have also tried your example (https://github.com/mapbox/mapbox-gl-native/blob/master/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/style/ZoomFunctionSymbolLayerActivity.java#L104)

but in both cases I have an error like:

Error setting property: icon-image Type string is not interpolatable.

Thanks for help!
CC: @tobrun

@LukasPaczos
Copy link
Contributor

@mpuchala Per documentation, "The output type must be number, array<number>, or color".
That said, we need to fix the example, thanks for pointing this out!

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

No branches or pull requests

6 participants