<html><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><br><div><div>On Aug 18, 2009, at 12:38 AM, Eric Lemoine wrote:</div><br><blockquote type="cite"><div>Hi John<br><br>Actually the to-be-added feature is already in the layer when<br>beforefeatureadded triggers, so calling destroyFeatures() in a<br>beforefeatureadded listener also destroys the to-be-added feature .<br>This looks like a bug to me, so I think a ticket should be open for<br>this. In the mean time you can do this:<br><br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;function clearPreviousFeatures(evt) {<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;var i, len, toDestroy = []<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;for(i=0,len=vectors.features.length; i&lt;len; i++) {<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if(vectors.features[i] != evt.feature) {<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;toDestroy.push(vectors.features[i]);<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;vectors.removeFeatures(toDestroy);<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;for(i=toDestroy.length-1; i&gt;=0; i--) {<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;toDestroy[i].destroy();<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br><br><br>Hope this helps,<br><br><br>PS: thanks for the example you provided.<br></div></blockquote></div><br><div>Thanks Eric, this works great!</div><div><br></div><div>I notice that there doesn't seem to be any difference between this:</div><div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 13px/normal Monaco; color: rgb(0, 128, 0); "><span class="Apple-tab-span" style="white-space:pre"><font class="Apple-style-span" color="#000000">        </font></span>vectors.removeFeatures(toDestroy);</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 13px/normal Monaco; color: rgb(0, 128, 0); "><span class="Apple-tab-span" style="white-space:pre"><font class="Apple-style-span" color="#000000">        </font></span>for(i=toDestroy.length-1; i&gt;=0; i--) {</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 13px/normal Monaco; color: rgb(0, 128, 0); "><span class="Apple-tab-span" style="white-space:pre"><font class="Apple-style-span" color="#000000">        <span class="Apple-tab-span" style="white-space:pre">        </span></font></span>toDestroy[i].destroy();</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 13px/normal Monaco; "><span style="color: #008000"><span class="Apple-tab-span" style="white-space:pre"><font class="Apple-style-span" color="#000000">        </font></span>}</span></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 13px/normal Monaco; "><font class="Apple-style-span" color="#008000"><br></font></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 13px/normal Monaco; "><font class="Apple-style-span" color="#008000">and this:</font></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 13px/normal Monaco; "><br></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 13px/normal Monaco; "><span class="Apple-tab-span" style="white-space:pre">        </span>vectors<span style="color: #5c5c5c">.</span>destroyFeatures<span style="color: #5c5c5c">(</span>toDestroy<span style="color: #5c5c5c">);</span></div></div><div><br></div><div>Is that what you'd expect?</div><div><br></div><div>--john</div><div><br></div><div>&nbsp;</div></body></html>