I followed the example on how to implement a drag and drop interaction with openLayers.

I now want to read the coordinate of every features like the following

this.dragAndDropInteraction.on('addfeatures', (event: DragAndDropEvent) => {
      const features: Feature<Geometry>[] = event.features

      features.forEach((feature, index) => {
        const properties = feature.getProperties()
        const coordinates = properties?.geometry


But I get [799785.5152789096,...] and I wanted to have it with the EPSG:4326 format.

I did try to change the projections when I initialized the map like this

 const dragAndDropInteraction = new DragAndDrop({
    formatConstructors: [<any>GPX, KML],
    projections: 'EPSG:4326',

this.map = new Map({
  projections: 'EPSG:4326',
  interactions: defaultInteractions().extend([this.dragAndDropInteraction]),
  target: target,
  layers: [
    new TileLayer({
      source: new OSM(),
  view: this.view,

But I keep get the wrong coordinate.

Is it normal?

I'm importing a KML file
Here is his content

<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2"
    <name>Traces du passé</name>
    <Style id="default0">
    <StyleMap id="default">
    <Style id="hl">
    <Folder id="kml_ft_Sentier">
        <description>La porte de Fully</description>

1 Answer 1


The features are displayed in the view projection, to get the EPSG:4326 coordinates the geometry must be cloned and transformed back to EPSG:4326

  features.forEach((feature, index) => {
    const geometry = feature.getGeometry().clone().transform(map.getView().getProjection(), 'EPSG:4326');

  • Well, it did work. I understand that it take the default view projection, but why does it didn't had the right projection from the beginning ? Commented Apr 29, 2021 at 9:42
  • If your view uses meters as projection units and the feature was in EPSG:4326 the feature would appear very small near point [0, 0] in the projection.
    – Mike
    Commented Apr 29, 2021 at 9:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.