For people that will search this in the future, I hope that It will help.
Working code for creating an ellipse in open layer V5.3:
// this works for a static image (pixels) but the idea can be on any coordinate system
addEllipseFeature(center, semiMajor, semiMinor) {
let coordinates = [] ;
const radinas = Math.PI / 180 ;
for (let angle = 1; angle <= 360; angle ++) {
const px = center[0] + semiMajor * Math.cos(radinas * angle);
const py = center[0] + semiMinor * Math.sin(radinas * angle);
coordinates.push([px, py]);
}
const geoJson = {
'type': 'Feature',
'geometry': {
'type': 'Polygon',
'coordinates': []
}
};
const featureId = source.getFeatures().length;
coordinates = this.convertCoordinates('Polygon', [coordinates]);
geoJson.geometry.coordinates = coordinates ;
const polygonFeature = (new GeoJSON()).readFeature(geoJson);
polygonFeature.setId(featureId );
const layerStyle = [ new Style({
stroke: new Stroke({
color: 'blue',
width: 3
}),
fill: new Fill({
color: 'rgba(0, 0, 255, 0.1)'
})
})];
polygonFeature.setStyle(layerStyle);
source.addFeature(polygonFeature);
return featureId;
}
