OpenLayers 5 v5.2.0 draw circle as polygon

Viewed 1543

I'm trying to upgrade to OpenLayers v5.2.0 and I can't see that there is a clear path to drawing a circle as a polygon (which I need so that I can store it in our data base)

This is what I was doing...

if (webMapValues.activeDrawControl == "Circle") {
    var wgs84Sphere = new ol.Sphere(6378138);
    webMapValues.drawObj = new ol.interaction.Draw({
        features: webMapValues.features,
        type: /** @type {ol.geom.GeometryType} */ (webMapValues.drawType),
        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);
            var circle = ol.geom.Polygon.circular(wgs84Sphere, ol.proj.toLonLat(center), radius);
            circle.transform('EPSG:4326', 'EPSG:3857');
            geometry.setCoordinates(circle.getCoordinates());
            return geometry;
        }

    });

}

...but ol.Sphere is not even a thing in this version of OpenLayers and ol.sphere which is in this version of OpenLayers doesn't like this...

Any help is greatly appreciated!!

0 Answers
Related