Search code examples
androidkotlinmapsmapboxmapbox-android

Hide mapbox POI in runtime


I'm making a "navigation" like app, and I want to display a lot of POI like food_and_drink and others (Hotels, Historical) and when the user starts the "navigation" I would like to hide some of this POI to avoid an extra "load" and "noise" in the map, I can't find the way to this with the default POI, I'm using mapbox studio and I can show/hide some POI but I want them to be visible and then later "hide" and when the navigation is over "show" them again, is possible this? I tried loading the style

retrieveMap()?.getStyle {
                    it.getLayer("food_and_drink")?.let { layer ->
                        if (VISIBLE == layer.visibility.value) {
                            layer.setProperties(PropertyFactory.visibility(NONE))
                        }else{
                            layer.setProperties(PropertyFactory.visibility(VISIBLE))
                        }
                    }
                }

But that does not work. Thanks a lot


Solution

  • After a lot of research and try/error i solve my issue, the solution is partialy the one I proposed and @Moritz too, however there is an extra steps, I want to display only some POI like restaurants or bars, removing the whole poi-label will cause all the POI (hospital, gas station, museums and so on) to dissapear, what I did, is copy/clone the poi-label from mapbox studio, and then inside "select data" i filter the items I want to display so I will have 2 layers, one with all the POI and a second layer with all the filter POI (let's ay only displaying gas stations) and then I can use something like this

    layers.find { it.id == "poi-label" }?.setProperties(
                    PropertyFactory.visibility(Property.NONE)
                )
    
    layers.find { it.id == "poi-copy-with-gas-station-only" }?.setProperties(
                    PropertyFactory.visibility(Property.VISIBLE)
                )
    

    With this code, i can hide/display specific layers here is more information how to filter places with mapbox https://www.mapbox.com/videos/how-to/filter-what-data-appears-on-your-map-in-mapbox-studio/