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

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -