What is the best method for getting the radius of a circle in Openlayers 3 in epsg 4326 (geodesic)? I'm using this example for a base and trying to draw a circle while getting the radius, but using proj 4326 is proving difficult.
Here's my code:
var pointerMoveHandler = function(evt) {
if (evt.dragging) {
return;
}
var tooltipCoord = evt.coordinate;
if (sketch) {
var output;
var geom = (sketch.getGeometry());
if (geom instanceof ol.geom.Cirlce) {
output = formatCircle(/** @type {ol.geom.Circle} */ (geom));
tooltipCoord = geom.getCenter().getRadius();
measureTooltipElement.innerHTML = output;
measureTooltip.setPosition(tooltipCoord);
}
};
var sourceProj = map.getView().getProjection();
var geom = /** @type {ol.geom.Circle} */(Circle.clone().transform(
sourceProj, 'EPSG:4326'));
var center= geom.getRadius;
radius = Math.abs(wgs84Sphere.geodesicArea(center));
var output;
if (area > 10000) {
output = (Math.round(area / 1000000 * 100) / 100) +
' ' + 'km<sup>2</sup>';
} else {
output = (Math.round(area * 100) / 100) +
' ' + 'm<sup>2</sup>';
}
return output;
};
radius = Math.abs(wgs84Sphere.geodesicArea(center)); isn't right, but I'm not sure what to put there….
Best Answer
Found it..