简体   繁体   中英

LineString to latitude/longitude pairs OpenLayers

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();

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM