5

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!!

JGH
  • 15,928
  • 4
  • 31
  • 48
Funn_Bobby
  • 647
  • 1
  • 20
  • 57
  • 3
    The ol.geom.Polygon.circular parameters have changed from (sphere, center, radius, opt_n) to (center, radius, opt_n, opt_sphereRadius) so there's no longer any necessity for ol.Sphere. http://openlayers.org/en/v4.6.5/apidoc/ol.geom.Polygon.html https://openlayers.org/en/latest/apidoc/module-ol_geom_Polygon.html – Mike Nov 02 '18 at 11:55

0 Answers0