I am trying to remove the last point in a polygon draw feature on esc key.
The following code do not work. It seems to remove it when it draw the area part, but the vertex is stil there.
var geom :ol.geom.Polygon = null;
draw.on("drawstart",(event) => {
console.log(event);
var feature :ol.Feature= event.feature;
console.log(feature);
geom = feature.getGeometry<ol.geom.Polygon>();
});
$(document).keyup((e)=> {
if (e.keyCode === 27) {
var coords = geom.getCoordinates()[0];
if(coords.length>1)
geom.setCoordinates([coords.slice(0, coords.length - 2)]);
}
});
OpenLayers 3 has a new solution to this with the Draw.removeLastPoint() method. Works like a charm!
draw = new ol.interaction.Draw({
source:source,
type: /** @type (ol.geom.GeometryType) */ ('Polygon')
})
draw.on('drawstart',
function(evt){
$(document).on('keyup', function(event){
if(event.keyCode === 27){
draw.removeLastPoint();
}
});
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With