androidmapboxmapbox-androidcountry

Highlight a country in Mapbox Android


Below is my code for highlighting a country .But no changes in the map . What i missed it in this code.

mapboxMap.loadStyleUri(Style.TRAFFIC_NIGHT) { style ->

    style.addSource(
        VectorSource.Builder("countries").apply {
            url("mapbox://mapbox.country-boundaries-v1")

        }.build()
    )
    style.addLayer(
        fillLayer("country-layer","country-source") {
            fillColor(Color.parseColor("#4469f7"))
            fillOpacity(4.5)
            filter(
                eq {
                    literal("iso_3166_1_alpha_3")
                    literal("IND")
                }
            )
        }
    )
}

Solution

  • I missed the sourceLayer Below is my updated code.

            mapboxMap.loadStyleUri(Style.TRAFFIC_NIGHT) { style ->
           
            style.addSource(
                VectorSource.Builder("countries").apply {
                    url("mapbox://mapbox.country-boundaries-v1")
    
                }.build()
            )
            val layer=FillLayer("country-layer","countries").apply{
                sourceLayer("country_boundaries")
                fillColor(Color.parseColor("#4469f7"))
                fillOpacity(0.5)
                filter(com.mapbox.maps.extension.style.expressions.generated.Expression.eq(
                    com.mapbox.maps.extension.style.expressions.generated.Expression.get("iso_3166_1_alpha_3"),
                    com.mapbox.maps.extension.style.expressions.generated.Expression.literal("IND")))
            }
            style.addLayer(layer)
        }