My task is to draw a polygon on an OpenLayers map. The code I am using for this purpose is as follows:
draw = new Draw({
source: this.vectorSource,
type: 'Polygon'
})
draw.on('drawend', e => {
// Solution 1, the result is not what I need
let coords = e.feature.getGeometry().getCoordinates()
// Solution 2 gives correct results, but the drawn polygon disappears
let coords = e.feature.getGeometry().transform('EPSG:3857', 'EPSG:4326').getCoordinates()
}
this.olmap.addInteraction(draw)
I need to store the transformed coordinates in a database, but Solution #2 does not maintain the visibility of the drawn polygon. With Solution #1, it does not provide the required formatted coordinates if I try to transform them later using
transform(coords, 'EPSG:3857', 'EPSG:4326')
Please advise me on how to correct the issue with maintaining the visibility of the polygon and obtaining the transformed coordinates.