Search code examples
androidmapboxmapbox-android

Android Mapxox - Change icon style for feature id


I have some pois showing on the MapView and a RecyclerView list that shows the same pois. When a list row is clicked I want to make all poi icons smaller and transparent except the one that was clicked from the list. This is what I have so far but it fails. It applies the changes to ALL icons including the clicked one. I guess I'm missing something related to the switchCase logic. Some help please?

private fun updateLayer(layer: Layer, opacity: Float, scale: Float, excludeFeatureId: Int) {
    layer.setProperties(
        PropertyFactory.iconOpacity(
            switchCase(
                eq(get("featureId"), literal(excludeFeatureId)),
                literal(1),
                neq(get("featureId"), literal(excludeFeatureId)),
                literal(opacity),
                literal(1)
            )
        ),
        PropertyFactory.iconSize(
            switchCase(
                eq(get("featureId"), literal(excludeFeatureId)),
                literal(1),
                neq(get("featureId"), literal(excludeFeatureId)),
                literal(scale),
                literal(1)
            )
        )
    )
}

I also need to change the icon for that specific featureId as well. Info on that would also be helpful.


Solution

  • Turns out the only correction my code needed was to not use integer value in the expression. excludeFeatureId needed to be provided as a String.

    private fun updateLayer(layer: Layer, opacity: Float, scale: Float, excludeFeatureId: Int) {
        layer.setProperties(
            PropertyFactory.iconOpacity(
                switchCase(
                    eq(get("featureId"), literal(excludeFeatureId.toString())),
                    literal(1),
                    neq(get("featureId"), literal(excludeFeatureId.toString())),
                    literal(opacity),
                    literal(1)
                )
            ),
            PropertyFactory.iconSize(
                switchCase(
                    eq(get("featureId"), literal(excludeFeatureId.toString())),
                    literal(1),
                    neq(get("featureId"), literal(excludeFeatureId.toString())),
                    literal(scale),
                    literal(1)
                )
            )
        )
    }