如何在 mapbox 中获取圆的 wkt

How to get the wkt of circle in mapbox

我试图在 mapbox 中获取圆的 wkt。但不确定如何在 mapbox 中获取 circle 的 geojson。 我想我可以使用以下示例顺便说一句,问题是 geojson。

var bounds = turf.bbox(markers);

请帮帮我!

GeoJSON 不支持圆圈。您可以查看规范,但不支持 Circles,因此 Mapbox 也不支持它们。

来源:http://geojson.org/geojson-spec.html

我使用 geojson 创建了绘制圆的函数。

var createGeoJSONCircle = function(center, radiusInKm, points) {
if(!points) points = 64;

var coords = {
    latitude: center[1],
    longitude: center[0]
};

var km = radiusInKm;

var ret = [];
var distanceX = km/(111.320*Math.cos(coords.latitude*Math.PI/180));
var distanceY = km/110.574;

var theta, x, y;
for(var i=0; i<points; i++) {
    theta = (i/points)*(2*Math.PI);
    x = distanceX*Math.cos(theta);
    y = distanceY*Math.sin(theta);

    ret.push([coords.longitude+x, coords.latitude+y]);
}
ret.push(ret[0]);

return {
    "type": "geojson",
    "data": {
        "type": "FeatureCollection",
        "features": [{
            "type": "Feature",
            "geometry": {
                "type": "Polygon",
                "coordinates": [ret]
            }
        }]
    }
};
};

以上函数重要的是points变量

函数的使用

var c = createGeoJSONCircle([-93.6248586, 41.58527859], 50);
map.addSource("polygon", createGeoJSONCircle([-93.6248586, 41.58527859], 50));
var cc = map.addLayer({
    "id": "polygon",
    "type": "fill",
    "source": "polygon",
    "layout": {},
    "paint": {
        "fill-color": "blue",
        "fill-opacity": 0.6
    }
});

并且可以使用 wellknown 获取 wkt。

wellknown.stringify(c.data.features[0].geometry)

也许效果不错。