在运行时隐藏 mapbox POI
Hide mapbox POI in runtime
我正在制作类似应用程序的“导航”,我想显示很多 POI,例如 food_and_drink
和其他(酒店、历史),当用户启动“导航”时,我希望要隐藏一些 POI 以避免地图中出现额外的“负载”和“噪音”,我无法使用默认 POI 找到解决此问题的方法,我正在使用 mapbox studio,我可以 show/hide 一些POI,但我希望它们可见,然后再“隐藏”,当导航结束时再次“显示”它们,这可能吗?
我尝试加载样式
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))
}
}
}
但这不起作用。
非常感谢
您能否更改您的解决方案以将 Property.NONE
而不是 NONE
作为可见性值?
对我来说,下面的工作正常:
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
)
)
}
}
经过大量研究 try/error 我解决了我的问题,该解决方案部分是我提出的,@Moritz 也是,但是还有一个额外的步骤,我只想显示一些 POI,比如餐馆或酒吧,删除整个 poi-label
将导致所有 POI(医院,加油站,博物馆等)消失,我所做的是 copy/clone 来自 mapbox studio 的 poi-label,然后在“select 数据”中,我过滤了我想要显示的项目,所以我将有 2 层,一层包含所有 POI,第二层包含所有过滤 POI(让我们只显示加油站)然后我可以使用类似这样的东西
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)
)
使用此代码,我可以 hide/display 特定图层
这里有更多信息如何使用 mapbox 过滤地点
https://www.mapbox.com/videos/how-to/filter-what-data-appears-on-your-map-in-mapbox-studio/
我正在制作类似应用程序的“导航”,我想显示很多 POI,例如 food_and_drink
和其他(酒店、历史),当用户启动“导航”时,我希望要隐藏一些 POI 以避免地图中出现额外的“负载”和“噪音”,我无法使用默认 POI 找到解决此问题的方法,我正在使用 mapbox studio,我可以 show/hide 一些POI,但我希望它们可见,然后再“隐藏”,当导航结束时再次“显示”它们,这可能吗?
我尝试加载样式
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))
}
}
}
但这不起作用。 非常感谢
您能否更改您的解决方案以将 Property.NONE
而不是 NONE
作为可见性值?
对我来说,下面的工作正常:
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
)
)
}
}
经过大量研究 try/error 我解决了我的问题,该解决方案部分是我提出的,@Moritz 也是,但是还有一个额外的步骤,我只想显示一些 POI,比如餐馆或酒吧,删除整个 poi-label
将导致所有 POI(医院,加油站,博物馆等)消失,我所做的是 copy/clone 来自 mapbox studio 的 poi-label,然后在“select 数据”中,我过滤了我想要显示的项目,所以我将有 2 层,一层包含所有 POI,第二层包含所有过滤 POI(让我们只显示加油站)然后我可以使用类似这样的东西
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)
)
使用此代码,我可以 hide/display 特定图层 这里有更多信息如何使用 mapbox 过滤地点 https://www.mapbox.com/videos/how-to/filter-what-data-appears-on-your-map-in-mapbox-studio/