英文:
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)
            ));
I need to hide this Symbol when my statusValue = 0 and appears again when statusValue = 1. Please help
答案1
得分: 0
将可见性属性更改为 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
                ));
            }
        }
    });
}
英文:
Change visibilty propery to 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
                ));
            }
        }
    });
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。


评论