【获取特定的】
前提:明确矢量图形的feature
//WKT
var wktshape = new ol.format.WKT().writeFeature(editorSource.getFeatures()[0]);
//GeoJSON
var jsonshape = new ol.format.GeoJSON().writeFeature(editorSource.getFeatures()[0]);
【获取刚刚画完的】
//新建draw对象
var draw = new ol.interaction.Draw({
source: editorSource, //图层的source
Type: 'LineString' //图层类型'Point'/'LineString'/'Polygon'
});
draw.on('drawend', function(event) {
if (event.feature) {
vectorSource.addFeature(event.feature);
console.log((event.feature.getGeometry().getCoordinates()).toString())
var Coordinates = new ol.format.GeoJSON().writeFeature(event.feature);
var positionList = new ol.format.WKT().writeFeature(event.feature);
}
map.removeInteraction(draw);
});
// 将Draw绘图控件加入Map对象
map.addInteraction(draw);