簡體   English   中英

如何將標簽添加到地圖框中的多邊形

[英]How to add the label to the polygon in the mapbox

我要在地圖框中的多邊形上添加標簽,順便說一句,我找不到解決方案如何添加標簽。

我找到了將標簽添加到點的方法。

map.addLayer({
    "id": "points",
    "type": "symbol",
    "source": {
        "type": "geojson",
        "data": {
            "type": "FeatureCollection",
            "features": [{
                "type": "Feature",
                "geometry": {
                    "type": "Point",
                    "coordinates": [-77.03238901390978, 38.913188059745586]
                },
                "properties": {
                    "title": "Mapbox DC",
                    "icon": "monument"
                }
            }, {
                "type": "Feature",
                "geometry": {
                    "type": "Point",
                    "coordinates": [-122.414, 37.776]
                },
                "properties": {
                    "title": "Mapbox SF",
                    "icon": "harbor"
                }
            }]
        }
    },
    "layout": {
        "icon-image": "{icon}-15",
        "text-field": "{title}",
        "text-font": ["Open Sans Semibold", "Arial Unicode MS Bold"],
        "text-offset": [0, 0.6],
        "text-anchor": "top"
    }
});

因此,我嘗試使用上述解決方案將標簽添加到地圖框中的多邊形,但失敗了。

請幫我!

您最有可能要將多邊形轉換成點並將其用作標簽源。

您可以直接在您的應用做到這一點https://github.com/mapbox/polylabel或手之前https://github.com/andrewharvey/geojson-polygon-labels

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM