[OpenLayers-Users] delete feature & vertexes

Robert Sanson SansonR at asurequality.com
Wed Oct 15 23:38:05 EDT 2008


I have found a similar problem to Adorian using OL2.7. When I click on the feature to delete it, the polygon disappears, but not the vertices. In the code below, crops is a Vector polygon layer loaded from a geoJSON file:
 
var delf =  new OpenLayers.Control.SelectFeature(crops, {onSelect: function(feature) {crops.destroyFeatures([feature])}});
map.addControl(delf);
delf.activate();
 
Robert Sanson

>>> Tim Schaub <tschaub at opengeo.org> 5/08/2008 12:13 a.m. >>>
Hey-

Adorian Ardelean wrote:
> Hi,
> 
> After upgrading to OL 2.6, delete feature function does not work correctly:
> when a polygon or polyline is removed, the lines that define the 
> disappear, but the vertexes not (the vertexes appear as the entity is 
> selected). The code worked flawlessly in previous version. Is something 
> that I have to be aware and/or modify?
> 
> declaration of control
> deletefeature: new 
> OpenLayers.Control.SelectFeature(vectors,{onSelect:deleteFeature})
> 
> delete function
> function deleteFeature(geometry)
> {
>   this.layer.removeFeatures(geometry);
> }
> 
> Any hint that may solve this issue is appreciated,

I just tried the following and confirmed that the above works.

1) open http://openlayers.org/dev/examples/draw-feature.html 
2) draw a polygon (note freehand is true here)
3) in the firebug console, run this code:

var del = new OpenLayers.Control.SelectFeature(
     map.layers[3], {
         onSelect: function(feature) {
             map.layers[3].removeFeatures([feature]);
         }
     }
);
map.addControl(del);
del.activate();

4) click on your polygon to see it removed

I suspect you really want to be calling destroyFeatures instead of 
removeFeatures - unless you call feature.destroy elsewhere.

Tim

> Adorian
> 
> -- 
> Dr. Adorian Ardelean
> coordinator of myNature Project
> 
> proiectul myNature
> str. Rascoala din 1907 nr 12
> Timisoara 300523
> Romania
> 
> http://mybiosis.info/nature/portal.php?pagename=firstpage [a Romanian 
> biodiversity-database]
> http://mybiosis.info/nature/portal.php?pagename=adorian [CV]
> 
> 
> ------------------------------------------------------------------------
> 
> _______________________________________________
> Users mailing list
> Users at openlayers.org 
> http://openlayers.org/mailman/listinfo/users 

_______________________________________________
Users mailing list
Users at openlayers.org 
http://openlayers.org/mailman/listinfo/users 

------------------------------------------------------------------
The contents of this email are confidential to AsureQuality. If you have received this communication in error please notify the sender immediately and delete the message and any attachments. The opinions expressed in this email are not necessarily those of AsureQuality. This message has been scanned for known viruses before delivery. AsureQuality supports the Unsolicited Electronic Messages Act 2007. If you do not wish to receive similar communications in future, please notify the sender of this message.
------------------------------------------------------------------


This message has been scanned for malware by SurfControl plc. www.surfcontrol.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/openlayers-users/attachments/20081016/f454433b/attachment.html


More information about the Users mailing list