javascript - How can I retrieve and remove a shape that has been drawn through interaction -


using openlayers 3. have:

var geometrytype = 'circle'; var interactiondraw = new ol.interaction.draw({   source: source,   type: /** @type {ol.geom.geometrytype} */ (geometrytype) }); $scope.map.addinteraction(interactiondraw); 

we catch 'drawend' event , things doesn't matter here, worth mentionning returns false eliminate click effect.

interactiondraw.on('drawend', function(event){  //event code   return false; }; 

how can access added shape , remove it, or prevent appear @ all?

it simple, add collection destination on interaction constructor , remove @ drawend.

var collection = new ol.collection();  draw = new ol.interaction.draw({     source: source,     features: collection,     //... draw.on('drawend', function(evt){     console.info(collection.getlength());     collection.pop(); }); 

update - try these modifications:

var collection = new ol.collection();  draw = new ol.interaction.draw({     source: source,     features: collection,     //... });  vectorsource.on('addfeature', function(){     var feature = collection.item(collection.getlength() - 1);     source.removefeature(feature);     collection.pop(); }); 

Comments

Popular posts from this blog

twig - Using Twigbridge in a Laravel 5.1 Package -

jdbc - Not able to establish database connection in eclipse -

firemonkey - How do I make a beep sound in Android using Delphi and the API? -