[OpenLayers-Users] limiting a Vector layer to the last feature
added
Eric Lemoine
eric.lemoine at camptocamp.com
Sat Aug 15 03:26:02 EDT 2009
On Friday, August 14, 2009, John Cartwright
<john.c.cartwright at comcast.net> wrote:
> Hello All,
>
> I'm using OL 2.8 and trying to implement the behavior where the user can
> digitize points, lines, or polygons, but only the last created feature
> will be kept and displayed. I've attempted this via a handler on the
> Layer's "beforefeatureadded" event like:
>
> function clearPreviousFeatures(evt) {
> dojo.forEach(vectorLayer.features, function(f) {
> if (http://f.id != http://evt.feature.id) {
> vectorLayer.removeFeatures([f], {silent:true});
> }
> });
> vectorLayer.redraw();
removing objects within a dojo.forEach loop may not be safe.
why don't you have you beforefeatureadded listener destroy all
features (with layer.destroyFeature)?
Cheers,
> }
>
>
> However, I find that the previous drawn features remain until the
> DrawFeature control is changed. Also as soon as the second feature is
> added, the code above complains that "f is undefined". Finally, any
> features added subsequent to the first do not display in the style
> defined for the layer.
>
> I feel like this should be a simple task and that I'm missing something
> fundamental here. Can someone show me what's wrong or suggest a better
> strategy for accomplishing this goal?
>
> Thanks!
>
> --john
>
> _______________________________________________
> Users mailing list
> Users at openlayers.org
> http://openlayers.org/mailman/listinfo/users
>
--
Eric Lemoine
Camptocamp France SAS
Savoie Technolac, BP 352
73377 Le Bourget du Lac, Cedex
Tel : 00 33 4 79 44 44 96
Mail : eric.lemoine at camptocamp.com
http://www.camptocamp.com
More information about the Users
mailing list