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

[Android] Layer symbol changes with the zoom  #9975

Closed

Description

@paulVulog

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.

Activity

  1. tobrun commented on Sep 12, 2017

    @tobrun
    Member

    @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.

  2. added
    Android
    on Sep 12, 2017
  3. paulVulog commented on Sep 13, 2017

    @paulVulog
    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.
  4. tobrun commented on Sep 13, 2017

    @tobrun
    Member

    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

  5. tobrun commented on Sep 13, 2017

    @tobrun
    Member

    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.

  6. paulVulog commented on Sep 13, 2017

    @paulVulog
    Author

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

  7. adieldev82 commented on Dec 27, 2017

    @adieldev82

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

  8. mpuchala commented on Apr 27, 2018

    @mpuchala

    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

  9. LukasPaczos commented on Apr 30, 2018

    @LukasPaczos
    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 join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Androidneeds informationsupport

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions