如何在 mapbox android 中隐藏图层?
How to hide layer in mapbox android?
private void AddSanciangkoStreet(@NonNull Style style) {
style.addImage("sanciangko-street",
BitmapUtils.getBitmapFromDrawable(getResources().getDrawable(R.drawable.floodicon)));
style.addSource(new GeoJsonSource("sanciangkoFlood1-source-id"));
style.addLayer(new SymbolLayer("sanciangkoFlood1-layer-id", "sanciangkoFlood1-source-id").withProperties(
iconImage("sanciangko-street"),
iconIgnorePlacement(true),
iconAllowOverlap(true),
iconSize(1f)
));
我需要在我的 statusValue = 0 时隐藏此符号,并在 statusValue = 1 时再次出现。请帮忙
将可见性 属性 更改为 NONE/VISIBLE
:
public void updateLayer(final int statusValue) {
mapboxMap.getStyle(new Style.OnStyleLoaded() {
@Override
public void onStyleLoaded(@NonNull Style style) {
Layer layer = style.getLayer("sanciangkoFlood1-layer-id");
if (layer != null) {
layer.setProperties(PropertyFactory.visibility(
statusValue == 0 ? Property.NONE : Property.VISIBLE
));
}
}
});
}
private void AddSanciangkoStreet(@NonNull Style style) {
style.addImage("sanciangko-street",
BitmapUtils.getBitmapFromDrawable(getResources().getDrawable(R.drawable.floodicon)));
style.addSource(new GeoJsonSource("sanciangkoFlood1-source-id"));
style.addLayer(new SymbolLayer("sanciangkoFlood1-layer-id", "sanciangkoFlood1-source-id").withProperties(
iconImage("sanciangko-street"),
iconIgnorePlacement(true),
iconAllowOverlap(true),
iconSize(1f)
));
我需要在我的 statusValue = 0 时隐藏此符号,并在 statusValue = 1 时再次出现。请帮忙
将可见性 属性 更改为 NONE/VISIBLE
:
public void updateLayer(final int statusValue) {
mapboxMap.getStyle(new Style.OnStyleLoaded() {
@Override
public void onStyleLoaded(@NonNull Style style) {
Layer layer = style.getLayer("sanciangkoFlood1-layer-id");
if (layer != null) {
layer.setProperties(PropertyFactory.visibility(
statusValue == 0 ? Property.NONE : Property.VISIBLE
));
}
}
});
}