mapbox-maps-android icon indicating copy to clipboard operation
mapbox-maps-android copied to clipboard

setFeatureState not updating SymbolLayer

Open BryanJonesRichardson opened this issue 3 years ago • 1 comments

I'm trying to have map icons that change color when they are clicked. When I use setFeatureState and subsequently call getFeatureState the output in my log shows that the state map for the Feature has been updated correctly. However, the map icons on SymbolLayer never get updated. However, circles on CircleLayer respond to featureState changes and update as expected. I followed this code example: https://github.com/mapbox/mapbox-maps-android/blob/main/app/src/main/java/com/mapbox/maps/testapp/examples/featurestate/FeatureStateActivity.kt

My call to setFeatureState

featureId?.let { id ->
                        map?.setFeatureState(
                            SOURCE_ID, UNCLUSTERED_LAYER_ID, id,
                            Value(hashMapOf(ICON_SELECTED to Value(!assetSelected)))
                        )

                        map?.getFeatureState(SOURCE_ID, UNCLUSTERED_LAYER_ID, id) { stateMap ->
                            Timber.d("getFeatureState: ${stateMap.value!!}")
                        }

                        lastFeatureId = id
                    }

How i add icon to SymbolLayer. This is not responding to featureState updates.

val unclustered = SymbolLayer(UNCLUSTERED_LAYER_ID, SOURCE_ID)
        unclustered.iconImage(
         switchCase {
                boolean {
                    featureState {
                        literal(ICON_SELECTED)
                    }
                    literal(false)
                }
                get(ICON_IMAGE_SELECTED) //true
                get(ICON_IMAGE) // false
            }
        )
        loadedMapStyle.addLayer(unclustered)

How i add circle to CircleLayer. This is responding to featureState updates.

val unclustered2 = CircleLayer(UNCLUSTERED_LAYER_ID, SOURCE_ID)
        unclustered2.circleRadius(
         switchCase {
                boolean {
                    featureState {
                        literal(ICON_SELECTED)
                    }
                    literal(false)
                }
                literal(2.0) //true
                literal(1.0) // false
            }
        )
        loadedMapStyle.addLayer(unclustered2)

What am i missing?

BryanJonesRichardson avatar Sep 01 '22 17:09 BryanJonesRichardson

@BryanJonesRichardson , the symbol layer icon-image does not support feature state, but circle-radius of circleLayer does supports feature state property, and that's why you can see the result with circle-radius but not with icon-image. In order to achieve the result, the property needs to support feature-state.

Please see the documentation icon-image : https://docs.mapbox.com/mapbox-gl-js/style-spec/layers/#layout-symbol-icon-image and circle-radius : https://docs.mapbox.com/mapbox-gl-js/style-spec/layers/#paint-circle-circle-radius.

ank27 avatar Sep 26 '22 10:09 ank27

@BryanJonesRichardson , the symbol layer icon-image does not support feature state, but circle-radius of circleLayer does supports feature state property, and that's why you can see the result with circle-radius but not with icon-image. In order to achieve the result, the property needs to support feature-state.

Please see the documentation icon-image : https://docs.mapbox.com/mapbox-gl-js/style-spec/layers/#layout-symbol-icon-image and circle-radius : https://docs.mapbox.com/mapbox-gl-js/style-spec/layers/#paint-circle-circle-radius.

In order to achieve the result, the property needs to support feature-state. @ank27 How to do this in Android code? Can you share an example? The link you provided does not tell what to do next. Thanks

iadcialim avatar Nov 14 '22 08:11 iadcialim