-2

I tried to get the wkt of circle in the mapbox. but not sure how to get the geojson of circle in the mapbox. I thought I can use following sample btw the problem is geojson.

var bounds = turf.bbox(markers);

Please help me!

Steve Bennett
  • 114,604
  • 39
  • 168
  • 219
Christian Soto
  • 2,540
  • 2
  • 15
  • 33
  • Can you post the geojson. Since you are saying the geojson is the problem – MatejMecka Feb 28 '18 at 20:30
  • 1
    Yeah, geojson is the problem. It means I can't get the geojson of circle. If I get the geojson of circle, to get the wkt will be easy. Do you know how to get the geojson of circle in mapbox? – Christian Soto Mar 03 '18 at 08:54
  • GeoJSON doesn't support circles. So we don't know how are you trying to emulate a circle. – MatejMecka Mar 03 '18 at 09:39

2 Answers2

1

I made the function to draw the circle using 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]
            }
        }]
    }
};
};

The important thing of above function is points variable.

The usage of function.

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
    }
});

And can get the wkt using wellknown.

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

Maybe it works well.

Christian Soto
  • 2,540
  • 2
  • 15
  • 33
0

GeoJSON doesn't support Circles. You can look up the specs but there isn't support for Circles so Mapbox doesn't support them too.

Source: http://geojson.org/geojson-spec.html

MatejMecka
  • 1,448
  • 2
  • 24
  • 37