2

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

Javier
  • 1,469
  • 2
  • 20
  • 38

2 Answers2

0

Can you change your solution to take Property.NONE instead of NONE as value for the visibility?

For me the below works fine:

override fun onMapReady(mapboxMap: MapboxMap) {

        this.mapboxMap = mapboxMap 

        mapboxMap.setStyle(
            "<YOUR_STYLE_ID>" 
        ) { style: Style -> 

            //Find all layers in this style

            val layers: MutableList<Layer> = style.layers
           
            var iterator: Int = 0
            for (layer in layers){

                layer?.setProperties(
                    PropertyFactory.visibility(
                        Property.NONE
                    )
                )

                
            }
            }
Moritz
  • 1,710
  • 1
  • 8
  • 13
  • Unfortunately does not work, seemd that `it.getLayer` does not even contain any of this layers :/ – Javier Nov 20 '20 at 15:40
  • this will hide all the "poi-label" but is possible only to hide `food_and_drink` only? – Javier Nov 20 '20 at 16:40
  • Sure, this was just an example on how to hide layers. You need to compare the layer id with the id you want to hide, and only hide the one with the `food_and_drink` ID. – Moritz Nov 21 '20 at 18:52
  • sadly the only layer is `poi-label` and that will hid all the POI (restaurants, gas, hospitals and so on) I can't find the way to only hide specific POI :( – Javier Nov 24 '20 at 10:39
0

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/

Javier
  • 1,469
  • 2
  • 20
  • 38