LineString 到 latitude/longitude 对 OpenLayers

LineString to latitude/longitude pairs OpenLayers

如何为给定的 LineString 获取 latitude/longitude 对的集合,这些 LineString 在 OpenLayers 6 中可能是原始格式或压缩格式?

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


 addInteraction();

你可以在 drawend 事件上阅读它,像这样:

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

根据需要更改 dataProjection 和 featureProjection。