So, here's the thing: I want to draw a circle on my map in OL3 and then save it to a JSON file. As I understood you can't write circular geometry to JSON (https://github.com/openlayers/ol3/issues/3552). I used the OL3 example to draw shapes and changed it to use ol.geom.Polygon.circular method to avoid using circle geometry. When I try to save it I get "TypeError: cyclic object value".
if (value) {
var geometryFunction, maxPoints;
if (value === 'Circle') {
value='Circle';
maxPoints=2;
geometryFunction = function (coordinates, geometry) {
if (!geometry) {
geometry = new ol.geom.Polygon(null);
}
var center = coordinates[0];
var last = coordinates[1];
var dx = center[0] - last[0];
var dy = center[1] - last[1];
var radius = Math.sqrt(dx * dx + dy * dy);
geometry = ol.geom.Polygon.circular(wgs84Sphere, center, radius);
return geometry;
};
draw = new ol.interaction.Draw({
features:features,
type: value,
geometryFunction: geometryFunction,
maxPoints: maxPoints
});
map.addInteraction(draw);
That's how I save JSON:
var writer = new ol.format.GeoJSON();
var geojsonStr = writer.writeFeatures(source.getFeatures());
alert(geojsonStr);
I'm pretty sure there must be a way to draw and save circles to JSON using ol.geom.Polygon.fromCircle or ol.geom.Polygon.circular. Any ideas?