如何获得给定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。