Reputation: 97
When I finish drawing with the draw interaction, the feature is displayed on the map.
I don't want the feature to be displayed on the map.
I want to remove the feature when drawing is completed.
I removed the feature from the drawend event, but it still shows up on the map.
When should the feature be removed?
var draw = new ol.interaction.Draw({
source: source,
type: 'LineString',
style: style,
freehandCondition: function freehandCondition(e) {
return false;
}
});
map.addInteraction(draw);
drawInteraction.on('drawend', function (e) {
source.removeFeature(e.feature); // not work
});
Upvotes: 0
Views: 1986
Reputation: 17907
Draw features are only added if you specify a source to add them to, if you don't want to save them you don't need a source
var draw = new ol.interaction.Draw({
type: 'LineString',
style: style,
freehandCondition: function freehandCondition(e) {
return false;
}
});
map.addInteraction(draw);
Upvotes: 2
Reputation: 97
I solved it with addFeature event.
source.on("addfeature", function(e){
if(e.feature == global_feature)
{
source.removeFeature(e.feature);
}
});
Upvotes: 0