我要在地图框中的多边形上添加标签,顺便说一下我找不到解决方法如何添加标签。
我找到了将标签添加到点的方法。
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"
}
});
所以我尝试使用上面的解决方案将标签添加到地图框中的多边形但是失败了。
请帮助我!
答案 0 :(得分:2)
您最有可能希望将多边形转换为点数并将其用作标签来源。
您可以使用https://github.com/mapbox/polylabel直接在您的应用中执行此操作,也可以在https://github.com/andrewharvey/geojson-polygon-labels
之前执行此操作