0
我有一個openlayers 3地圖,我可以繪製多邊形。OpenLayers 3獲得WKT多邊形字符串
我會返回提取繪製的多邊形的WKT字符串。
我該怎麼做?
的jsfiddle代碼http://jsfiddle.net/michelejs/3zawt33b/7/
這裏我的地圖:
map = new ol.Map({
target: 'map',
layers: [raster,vector],
view: new ol.View({
center: ol.proj.fromLonLat([11.249367, 43.774298]),
zoom: 15
})
});
這裏說的幫我繪製多邊形的intaractions:
function addInteraction() {
var ct = 0;
draw = new ol.interaction.Draw({
source: source,
type: 'Polygon',
geometryFunction: function (c, g) {
if (goog.isDef(g)) {
g.setCoordinates(c);
} else {
g = new ol.geom.Polygon(c);
}
if (c[0].length > ct) {
console.log('click coord : ' + c[0][c[0].length - 1]);
var coord = c[0][c[0].length - 1];
$('div#coordinate').html($('div#coordinate').html() + "<p>" + (Number(coord[0]).toFixed(2)) + " - " + (Number(coord[1]).toFixed(2)) + "</p>");
coordinates.push(coord);
ct = c[0].length;
} else {
console.log('move coord : ' + c[0][c[0].length - 1]);
}
return g;
}
});
draw.on('drawend', function(e) {
isin = e;
checkIfIn();
lastFeature = e.feature;
//write WKT Polygon Code in div#getAsWK
})
draw.on('drawstart', function (e) {
source.clear();
});
map.addInteraction(draw);
}
map.addInteraction(draw);