首页 > 解决方案 > Mapbox如何编写带有停止的图层绘制属性以便它可以支持特征状态?

问题描述

我正在使用 mapbox gl js 0.46.0。我利用了 setFeatureState API(>=0.46.0) 的优势,它对于像用例这样的“悬停在功能上”具有更好的性能。

我决定对具有两种状态的功能使用单层,一种是“无”,另一种是“选择”。不幸的是,由于文档和示例不足,我无法完全同步这两种状态的视觉效果。

例如,如果我想拥有一个基于缩放级别的带有停止的线宽属性,我该如何为相应的“选定”和“无”状态编写这种表达式?

 "paint": {
            "line-color": [
                "match",[ "string", [ "feature-state", "line_color" ], "none" ],
                    "selected", "hsl(189, 87%, 37%)",
                    "none", "hsl(189, 87%, 37%)",
                    "hsl(189, 87%, 37%)"
                ],
            "line-width":  [
                "match",[ "string", [ "feature-state", "line_width" ], "none" ],
                    "selected", 4,
                    "none", 3,
                    3
                ],
            "line-opacity": [
                "match",[ "string", [ "feature-state", "line_opacity" ], "none" ],
                    "selected", 0.68,
                    "none", 0.38,
                    0.38
                ]
        }

标签: mapboxmapbox-gl-js

解决方案


推荐阅读