LineString至纬度/经度对OpenLayers

问题描述 投票:-2回答:1

如何获得给定LineString的纬度/经度对的集合,在OpenLayers 6中可能是原始格式或压缩格式?

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


 addInteraction();
javascript openlayers openlayers-3 openlayers-5
1个回答
0
投票

您可以在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。

© www.soinside.com 2019 - 2024. All rights reserved.