-2

How can I get a collection of latitude/longitude pairs for a given LineString which may be in raw or compressed format in OpenLayers 6?

var draw; 
function addInteraction() {
var value ='LineString';
if (value !== 'None') {
draw = new Draw({
  source: source,
  type: 'LineString'
});
map.addInteraction(draw);
  }
}


 addInteraction();

1 Answers1

1

You can read it on drawend event, something like this:

draw.on('drawend', function (e) {
  let format = new ol.format.WKT();
  let wktRepresenation = format.writeGeometry(e.getGeometry(), {
    dataProjection: "EPSG:4326",
    featureProjection: "EPSG:3857",
  });
  console.log(wktRepresenation);
});

Change dataProjection and featureProjection depending on your needs.

ivom
  • 51
  • 4