Thanks everyone for this bug report and patch suggestions. I have codified this in the OL trac:<br>
<a href="http://trac.openlayers.org/ticket/761">http://trac.openlayers.org/ticket/761</a><br>
<br>
<br><br><div><span class="gmail_quote">On 5/30/07, <b class="gmail_sendername">Mike Quentel</b> &lt;<a href="mailto:mikequentel@yahoo.com">mikequentel@yahoo.com</a>&gt; wrote:</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Also, add the following to OpenLayers.Layer.Vector:<br><br>&nbsp;&nbsp;&nbsp;&nbsp;destroySelectedFeatures: function () {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;for (var i = (this.selectedFeatures.length - 1); i &gt;= 0; i--) {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;var selectedFeature = this.selectedFeatures
[i];<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;this.selectedFeatures
= OpenLayers.Util.removeItem(this.selectedFeatures, selectedFeature);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;this.renderer.eraseGeometry(selectedFeature.geometry);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br>&nbsp;&nbsp;&nbsp;&nbsp;},<br><br>Mike Quentel<br><br>----- Original Message ----<br>
From: Mike Quentel &lt;<a href="mailto:mikequentel@yahoo.com">mikequentel@yahoo.com</a>&gt;<br>To: Roger Kunkel &lt;<a href="mailto:rakunkel@ucdavis.edu">rakunkel@ucdavis.edu</a>&gt;<br>Cc: <a href="mailto:users@openlayers.org">
users@openlayers.org</a><br>Sent: Wednesday, 30 May, 2007 5:22:48 PM<br>Subject: Re: [OpenLayers-Users] how to cleanly remove a vector layer<br><br>This might be of help to you...<br><br>OpenLayers.Control.EraseFeatures = 
OpenLayers.Class.create();<br>OpenLayers.Control.EraseFeatures.prototype =<br>&nbsp;&nbsp;OpenLayers.Class.inherit( OpenLayers.Control, {<br>&nbsp;&nbsp;&nbsp;&nbsp;/** @type OpenLayers.Control.TYPES */<br>&nbsp;&nbsp;&nbsp;&nbsp;type: OpenLayers.Control.TYPE_BUTTON,<br>
&nbsp;&nbsp;&nbsp;&nbsp;trigger: function () {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (this.map) {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;var map = this.map;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;for(i = 0; i &lt; map.layers.length; i++) {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;var currentLayer = map.layers[i];<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (currentLayer.isVector
) {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (currentLayer.selectedFeatures.length &gt; 0) {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;currentLayer.destroySelectedFeatures();<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;} else {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;currentLayer.destroyFeatures();<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;} //if (currentLayer.selectedFeatures..
.<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;} //if (currentLayer.isVector...<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;} // for (i = 0...<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;} //if (this.map...<br>&nbsp;&nbsp;&nbsp;&nbsp;},<br>/** @final @type String */<br>CLASS_NAME: &quot;OpenLayers.Control.EraseFeatures&quot;<br>});<br><br>
<br>Mike Quentel<br><br>----- Original Message ----<br>From: Roger Kunkel &lt;<a href="mailto:rakunkel@ucdavis.edu">rakunkel@ucdavis.edu</a>&gt;<br>To: Christopher Schmidt &lt;<a href="mailto:crschmidt@metacarta.com">crschmidt@metacarta.com
</a>&gt;<br>Cc: <a href="mailto:users@openlayers.org">users@openlayers.org</a><br>Sent: Wednesday, 30 May, 2007 3:35:07 PM<br>Subject: Re: [OpenLayers-Users] how to cleanly remove a vector layer<br><br>Thanks for your reply.
<br>I was using the removeFeatures incorrectly.<br><br><br>On May 30, 2007, at 1:53 PM, Christopher Schmidt wrote:<br><br>&gt; On Wed, May 30, 2007 at 01:36:41PM -0700, Roger Kunkel wrote:<br>&gt;&gt;<br>&gt;&gt; I&#39;m having trouble using and then removing a vector layer.
<br>&gt;&gt; removeFeatures() - produces errors saying that the feature is not<br>&gt;&gt; defined when feature.geometry is referenced.<br>&gt;<br>&gt; map.layers[1].removeFeatures(map.layers[1].features); works for me on
<br>&gt; <a href="http://openlayers.org/dev/examples/vector-features.html">http://openlayers.org/dev/examples/vector-features.html</a> .<br>&gt;<br>&gt;&gt; calling destroy on the layer causes continuous mouse event errors
<br>&gt;&gt; - it seems that the getFeatureFromEvent method keeps getting called<br>&gt;&gt; even though I&#39;ve destroyed the layer.<br>&gt;<br>&gt; Yep. That&#39;s a bug. The only piece of advice I have for that is to not
<br>&gt; destroy a layer if you have selectefatures handler on it :) I&#39;ll<br>&gt; file it<br>&gt; as a bug.<br>&gt;<br>&gt; Regards,<br>&gt; --<br>&gt; Christopher Schmidt<br>&gt; MetaCarta<br><br>Roger Kunkel<br>CERES Program
<br>Dept. of Land Air &amp; Water Resources<br>UC Davis<br><a href="mailto:rakunkel@ucdavis.edu">rakunkel@ucdavis.edu</a><br><br><br>_______________________________________________<br>Users mailing list<br><a href="mailto:Users@openlayers.org">
Users@openlayers.org</a><br><a href="http://openlayers.org/mailman/listinfo/users">http://openlayers.org/mailman/listinfo/users</a><br><br><br><br><br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;___________________________________________________________<br>
Yahoo! Answers - Got a question? Someone out there knows the answer. Try it<br>now.<br><a href="http://uk.answers.yahoo.com/">http://uk.answers.yahoo.com/</a><br><br><br><br><br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;___________________________________________________________
<br>Yahoo! Mail is the world&#39;s favourite email. Don&#39;t settle for less, sign up for<br>your free account today <a href="http://uk.rd.yahoo.com/evt=44106/*http://uk.docs.yahoo.com/mail/winter07.html">http://uk.rd.yahoo.com/evt=44106/*http://uk.docs.yahoo.com/mail/winter07.html
</a><br>_______________________________________________<br>Users mailing list<br><a href="mailto:Users@openlayers.org">Users@openlayers.org</a><br><a href="http://openlayers.org/mailman/listinfo/users">http://openlayers.org/mailman/listinfo/users
</a><br></blockquote></div><br>