<html><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div>Thanks for your suggestion Eric. &nbsp;That was the first thing I tried, but it doesn't clear the map, even with an explicit redraw()</div><div><br></div><div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 13px/normal Monaco; ">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;vectorLayer<span style="color: #5c5c5c">.</span>events<span style="color: #5c5c5c">.</span>on<span style="color: #5c5c5c">({</span></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, 92, 0); "><span class="Apple-style-span" style="color: rgb(0, 0, 0); "><span class="Apple-tab-span" style="white-space:pre">        </span>&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #005c00">"featuremodified"</span><span style="color: #5c5c5c">:</span> mapUpdated<span style="color: #5c5c5c">,</span></span></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, 92, 0); "><span class="Apple-style-span" style="color: rgb(0, 0, 0); "><span class="Apple-tab-span" style="white-space:pre">        </span>&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #005c00">"beforefeatureadded"</span><span style="color: #5c5c5c">:</span> clearPreviousFeatures<span style="color: #5c5c5c">,</span></span></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-style-span" style="color: rgb(0, 0, 0); "><span class="Apple-tab-span" style="white-space:pre">        </span>&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #005c00">"featureadded"</span><span style="color: #5c5c5c">:</span> mapUpdated</span></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, 92, 0); "><span class="Apple-style-span" style="color: rgb(0, 0, 0); ">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #5c5c5c">});</span></span></div><div><font class="Apple-style-span" color="#5C5C5C" face="Monaco" size="3"><span class="Apple-style-span" style="font-size: 13px;"><br></span></font></div></div><div><br></div><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><span style="color: #0000c0">function</span> clearPreviousFeatures<span style="color: #5c5c5c">(</span>evt<span style="color: #5c5c5c">)</span> <span style="color: #5c5c5c">{</span></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, 92, 0); "><span class="Apple-style-span" style="color: rgb(0, 0, 0); "><span class="Apple-tab-span" style="white-space:pre">                </span>vectorLayer<span style="color: #5c5c5c">.</span>destroyFeatures<span style="color: #5c5c5c">();</span></span></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, 92, 0); "><font class="Apple-style-span" color="#5C5C5C"><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>vectorLayer<span style="color: #5c5c5c">.</span>redraw<span style="color: #5c5c5c">();</span></div></font></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><span style="color: #5c5c5c">}</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="#5C5C5C"><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="#5C5C5C"><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><span style="color: #0000c0">function</span> mapUpdated<span style="color: #5c5c5c">(</span>evt<span style="color: #5c5c5c">)</span> <span style="color: #5c5c5c">{</span></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, 92, 0); "><span class="Apple-style-span" style="color: rgb(92, 92, 92); "><span class="Apple-tab-span" style="white-space:pre">                </span>console<span style="color: #5c5c5c">.</span>log<span style="color: #5c5c5c">(</span><span style="color: #005c00">'Vector layer has '</span><span style="color: #5c5c5c">+</span>vectorLayer<span style="color: #5c5c5c">.</span>features<span style="color: #5c5c5c">.</span>length<span style="color: #5c5c5c">+</span><span style="color: #005c00">' features'</span><span style="color: #5c5c5c">);</span></span></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>dojo<span style="color: #5c5c5c">.</span>publish<span style="color: #5c5c5c">(</span><span style="color: #005c00">'mapUpdated'</span><span style="color: #5c5c5c">,[</span>evt<span style="color: #5c5c5c">.</span>feature<span style="color: #5c5c5c">.</span>geometry<span style="color: #5c5c5c">]);</span></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><span style="color: #5c5c5c">}</span></div><div><br></div></font></div><div><font class="Apple-style-span" color="#5C5C5C" face="Monaco" size="3"><span class="Apple-style-span" style="font-size: 13px; "><br></span></font></div></div><div>Setting it up this way also seems to clear the newly added feature as well - when the featureadded handler runs, it reports no features in the layer.</div><div><br></div>Is this what you had in mind?<div><br></div><div>I really appreciate your help with this.</div><div><br></div><div>--john<br><div><br></div><div><br><div><div>On Aug 15, 2009, at 1:26 AM, Eric Lemoine wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div>On Friday, August 14, 2009, John Cartwright<br>&lt;<a href="mailto:john.c.cartwright@comcast.net">john.c.cartwright@comcast.net</a>&gt; wrote:<br><blockquote type="cite">Hello All,<br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">I'm using OL 2.8 and trying to implement the behavior where the user can<br></blockquote><blockquote type="cite">digitize points, lines, or polygons, but only the last created feature<br></blockquote><blockquote type="cite">will be kept and displayed. &nbsp;I've attempted this via a handler on the<br></blockquote><blockquote type="cite">Layer's "beforefeatureadded" event like:<br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">function clearPreviousFeatures(evt) {<br></blockquote><blockquote type="cite"> &nbsp; &nbsp;dojo.forEach(vectorLayer.features, function(f) {<br></blockquote><blockquote type="cite"> &nbsp; &nbsp; &nbsp; if (<a href="http://f.id">http://f.id</a> != <a href="http://evt.feature.id">http://evt.feature.id</a>) {<br></blockquote><blockquote type="cite"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;vectorLayer.removeFeatures([f], {silent:true});<br></blockquote><blockquote type="cite"> &nbsp; &nbsp; &nbsp; }<br></blockquote><blockquote type="cite"> &nbsp; &nbsp;});<br></blockquote><blockquote type="cite"> &nbsp; &nbsp;vectorLayer.redraw();<br></blockquote><br>removing objects within a dojo.forEach loop may not be safe.<br><br>why don't you have you beforefeatureadded listener destroy all<br>features (with layer.destroyFeature)?<br><br>Cheers,<br><br><br><blockquote type="cite">}<br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">However, &nbsp;I find that the previous drawn features remain until the<br></blockquote><blockquote type="cite">DrawFeature control is changed. &nbsp;Also as soon as the second feature is<br></blockquote><blockquote type="cite">added, the code above complains that "f is undefined". &nbsp;Finally, any<br></blockquote><blockquote type="cite">features added subsequent to the first do not display in the style<br></blockquote><blockquote type="cite">defined for the layer.<br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">I feel like this should be a simple task and that I'm missing something<br></blockquote><blockquote type="cite">fundamental here. &nbsp;Can someone show me what's wrong or suggest a better<br></blockquote><blockquote type="cite">strategy for accomplishing this goal?<br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">Thanks!<br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">--john<br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">_______________________________________________<br></blockquote><blockquote type="cite">Users mailing list<br></blockquote><blockquote type="cite"><a href="mailto:Users@openlayers.org">Users@openlayers.org</a><br></blockquote><blockquote type="cite"><a href="http://openlayers.org/mailman/listinfo/users">http://openlayers.org/mailman/listinfo/users</a><br></blockquote><blockquote type="cite"><br></blockquote><br>-- <br>Eric Lemoine<br><br>Camptocamp France SAS<br>Savoie Technolac, BP 352<br>73377 Le Bourget du Lac, Cedex<br><br>Tel : 00 33 4 79 44 44 96<br>Mail : <a href="mailto:eric.lemoine@camptocamp.com">eric.lemoine@camptocamp.com</a><br><a href="http://www.camptocamp.com">http://www.camptocamp.com</a><br></div></blockquote></div><br></div></div></body></html>