<html><body><div style="color:#000; background-color:#fff; font-family:arial, helvetica, sans-serif;font-size:10pt"><div style="font-family: arial, helvetica, sans-serif; font-size: 10pt; ">Hi,</div><div style="font-family: arial, helvetica, sans-serif; font-size: 10pt; "><br></div><div style="font-family: arial, helvetica, sans-serif; font-size: 13px; color: rgb(0, 0, 0); background-color: transparent; font-style: normal; ">I have some code which creates drawing tools for a map in openlayers 2.12. The code works, but what I don´t understand is that I can only modify the drawing if I add the drawing-vector layer to the map <span style="background-color: transparent; ">with a handler in the code for each drawing action - (point,polygon,line)</span><span style="background-color: transparent; ">. If I add the drawing-layer to the map before an action is triggered and remove the "add vector layer" handler in each tool, I can still draw, but I can´t
modify the drawings!?!</span></div><div style="background-color: transparent; "><div style="background-color: transparent; color: rgb(0, 0, 0); font-size: 13px; font-family: arial, helvetica, sans-serif; font-style: normal; "><span style="font-family: arial, helvetica, sans-serif; font-size: 13px;"><br></span></div><div style="background-color: transparent; color: rgb(0, 0, 0); font-size: 13px; font-family: arial, helvetica, sans-serif; font-style: normal; "><span style="font-family: arial, helvetica, sans-serif; font-size: 13px;">Here is the code showing a working version where the modify tool works. For every action, the vector layer gets adds again via the handler. At the beginning, the commented out line will allow the layer to be added to the map before the drawing-actions starts, but I won´t be able to modify them.</span></div><div style="background-color: transparent; color: rgb(0, 0, 0); font-size: 13px; font-family: arial, helvetica,
sans-serif; font-style: normal; "><br></div><div style="background-color: transparent; color: rgb(0, 0, 0); font-size: 13px; font-family: arial, helvetica, sans-serif; font-style: normal; ">Is there a better way to do this? It seems a very unlogical way to to this.</div><div style="background-color: transparent; color: rgb(0, 0, 0); font-size: 13px; font-family: arial, helvetica, sans-serif; font-style: normal; "><br></div><div style="background-color: transparent; color: rgb(0, 0, 0); font-size: 13px; font-family: arial, helvetica, sans-serif; font-style: normal; ">Thanks,</div><div style="background-color: transparent; color: rgb(0, 0, 0); font-size: 13px; font-family: arial, helvetica, sans-serif; font-style: normal; "><br></div><div style="background-color: transparent; color: rgb(0, 0, 0); font-size: 13px; font-family: arial, helvetica, sans-serif; font-style: normal; ">Rob</div><div style="background-color: transparent; color: rgb(0, 0, 0);
font-size: 13px; font-family: arial, helvetica, sans-serif; font-style: normal; "><span style="font-family: arial, helvetica, sans-serif; font-size: 13px;"><br></span></div><div style="background-color: transparent; "><span style="font-family: arial, helvetica, sans-serif; font-size: 13px;"><span class="Apple-tab-span" style="white-space:pre">        </span>var vector = new OpenLayers.Layer.Vector("vector",{styleMap: styleMap2});</span></div><div style="background-color: transparent; "><span style="font-family: arial, helvetica, sans-serif; font-size: 13px;"> //<span class="Apple-tab-span" style="white-space:pre">        </span>map.addLayers([vector]); // this adds the layer to the map before the tool actions are started.</span></div><div style="background-color: transparent; "><span style="font-family: arial, helvetica, sans-serif; font-size: 13px;"><br></span></div><div style="background-color: transparent; "><span style="font-family: arial, helvetica,
sans-serif; font-size: 13px;"><span class="Apple-tab-span" style="white-space:pre">        </span>action = new GeoExt.Action({</span></div><div style="background-color: transparent; "><span style="font-family: arial, helvetica, sans-serif; font-size: 13px;"> text: "Fläche",</span></div><div style="background-color: transparent; "><span style="font-family: arial, helvetica, sans-serif; font-size: 13px;"> icon:"images/edit_poly.png",</span></div><div style="background-color: transparent; "><span style="font-family: arial, helvetica, sans-serif; font-size: 13px;"> control: new OpenLayers.Control.DrawFeature(vector, OpenLayers.Handler.Polygon,{</span></div><div style="background-color: transparent; "><span style="font-family: arial, helvetica, sans-serif; font-size: 13px;"> <span class="Apple-tab-span" style="white-space:pre">        </span>handlerOptions:
{</span></div><div style="background-color: transparent; "><span style="font-family: arial, helvetica, sans-serif; font-size: 13px;"> layerOptions: {</span></div><div style="background-color: transparent; "><span style="font-family: arial, helvetica, sans-serif; font-size: 13px;"> styleMap: styleMap2</span></div><div style="background-color: transparent; "><span style="font-family: arial, helvetica, sans-serif; font-size: 13px;"> }</span></div><div style="background-color: transparent; "><span style="font-family: arial, helvetica, sans-serif; font-size: 13px;"> }}</span></div><div style="background-color: transparent; "><span style="font-family: arial, helvetica, sans-serif; font-size: 13px;">
),</span></div><div style="background-color: transparent; "><span style="font-family: arial, helvetica, sans-serif; font-size: 13px;"> map: map,</span></div><div style="background-color: transparent; "><span style="font-family: arial, helvetica, sans-serif; font-size: 13px;"> toggleGroup: "mapTools",</span></div><div style="background-color: transparent; "><span style="font-family: arial, helvetica, sans-serif; font-size: 13px;"> allowDepress: false,</span></div><div style="background-color: transparent; "><span style="font-family: arial, helvetica, sans-serif; font-size: 13px;"> handler: function(){</span></div><div style="background-color: transparent; "><span style="font-family: arial, helvetica, sans-serif; font-size: 13px;"> <span class="Apple-tab-span" style="white-space:pre">
        </span>map.addLayers([vector]);</span></div><div style="background-color: transparent; "><span style="font-family: arial, helvetica, sans-serif; font-size: 13px;"> },</span></div><div style="background-color: transparent; "><span style="font-family: arial, helvetica, sans-serif; font-size: 13px;"> tooltip: "<b>Fläche zeichnen",</span></div><div style="background-color: transparent; "><span style="font-family: arial, helvetica, sans-serif; font-size: 13px;"> group: "mapTools"</span></div><div style="background-color: transparent; "><span style="font-family: arial, helvetica, sans-serif; font-size: 13px;"> });</span></div><div style="background-color: transparent; "><span style="font-family: arial, helvetica, sans-serif; font-size: 13px;"> actions["draw_poly"] = action;</span></div><div style="background-color: transparent; "><span
style="font-family: arial, helvetica, sans-serif; font-size: 13px;"><span class="Apple-tab-span" style="white-space:pre">        </span>toolbarItems_edit.push(action);</span></div><div style="background-color: transparent; "><span style="font-family: arial, helvetica, sans-serif; font-size: 13px;"><span class="Apple-tab-span" style="white-space:pre">        </span>toolbarItems_edit.push('-',' ' );</span></div><div style="background-color: transparent; "><span class="Apple-tab-span" style="white-space: pre; font-family: arial, helvetica, sans-serif; font-size: 13px;">        </span></div><div style="background-color: transparent; "><span style="font-family: arial, helvetica, sans-serif; font-size: 13px;"> action = new GeoExt.Action({</span></div><div style="background-color: transparent; "><span style="font-family: arial, helvetica, sans-serif; font-size: 13px;"> text: "Linie",</span></div><div style="background-color: transparent;
"><span style="font-family: arial, helvetica, sans-serif; font-size: 13px;"> icon:"images/edit_line.png",</span></div><div style="background-color: transparent; "><span style="font-family: arial, helvetica, sans-serif; font-size: 13px;"> control: new OpenLayers.Control.DrawFeature(vector, OpenLayers.Handler.Path,{</span></div><div style="background-color: transparent; "><span style="font-family: arial, helvetica, sans-serif; font-size: 13px;"> <span class="Apple-tab-span" style="white-space:pre">        </span>handlerOptions: {</span></div><div style="background-color: transparent; "><span style="font-family: arial, helvetica, sans-serif; font-size: 13px;"> layerOptions: {</span></div><div style="background-color: transparent; "><span style="font-family: arial, helvetica, sans-serif; font-size: 13px;">
styleMap: styleMap2</span></div><div style="background-color: transparent; "><span style="font-family: arial, helvetica, sans-serif; font-size: 13px;"> }</span></div><div style="background-color: transparent; "><span style="font-family: arial, helvetica, sans-serif; font-size: 13px;"> }}</span></div><div style="background-color: transparent; "><span style="font-family: arial, helvetica, sans-serif; font-size: 13px;"> ),</span></div><div style="background-color: transparent; "><span style="font-family: arial, helvetica, sans-serif; font-size: 13px;"> map: map,</span></div><div style="background-color: transparent; "><span style="font-family: arial, helvetica, sans-serif; font-size: 13px;"> toggleGroup: "mapTools",</span></div><div
style="background-color: transparent; "><span style="font-family: arial, helvetica, sans-serif; font-size: 13px;"> allowDepress: false,</span></div><div style="background-color: transparent; "><span style="font-family: arial, helvetica, sans-serif; font-size: 13px;"> handler: function(){</span></div><div style="background-color: transparent; "><span style="font-family: arial, helvetica, sans-serif; font-size: 13px;"> <span class="Apple-tab-span" style="white-space:pre">        </span>map.addLayers([vector]);</span></div><div style="background-color: transparent; "><span style="font-family: arial, helvetica, sans-serif; font-size: 13px;"> },</span></div><div style="background-color: transparent; "><span style="font-family: arial, helvetica, sans-serif; font-size: 13px;"> tooltip: "<b>Linie zeichnen",</span></div><div
style="background-color: transparent; "><span style="font-family: arial, helvetica, sans-serif; font-size: 13px;"> group: "mapTools"</span></div><div style="background-color: transparent; "><span style="font-family: arial, helvetica, sans-serif; font-size: 13px;"> });</span></div><div style="background-color: transparent; "><span style="font-family: arial, helvetica, sans-serif; font-size: 13px;"> actions["draw_line"] = action;</span></div><div style="background-color: transparent; "><span style="font-family: arial, helvetica, sans-serif; font-size: 13px;"><span class="Apple-tab-span" style="white-space:pre">        </span>toolbarItems_edit.push(action);</span></div><div style="background-color: transparent; "><span style="font-family: arial, helvetica, sans-serif; font-size: 13px;"><span class="Apple-tab-span" style="white-space:pre">        </span>toolbarItems_edit.push('-',' ' );</span></div><div
style="background-color: transparent; "><span class="Apple-tab-span" style="white-space: pre; font-family: arial, helvetica, sans-serif; font-size: 13px;">        </span></div><div style="background-color: transparent; "><span class="Apple-tab-span" style="white-space: pre; font-family: arial, helvetica, sans-serif; font-size: 13px;">        </span></div><div style="background-color: transparent; "><span style="font-family: arial, helvetica, sans-serif; font-size: 13px;"><span class="Apple-tab-span" style="white-space:pre">        </span>action = new GeoExt.Action({</span></div><div style="background-color: transparent; "><span style="font-family: arial, helvetica, sans-serif; font-size: 13px;"><span class="Apple-tab-span" style="white-space:pre">        </span> text: "Überarbeiten",</span></div><div style="background-color: transparent; "><span style="font-family: arial, helvetica, sans-serif; font-size: 13px;"><span class="Apple-tab-span"
style="white-space:pre">        </span> icon:"images/edit_modify.png",</span></div><div style="background-color: transparent; "><span style="font-family: arial, helvetica, sans-serif; font-size: 13px;"><span class="Apple-tab-span" style="white-space:pre">        </span> control: new OpenLayers.Control.ModifyFeature(</span></div><div style="background-color: transparent; "><span style="font-family: arial, helvetica, sans-serif; font-size: 13px;"><span class="Apple-tab-span" style="white-space:pre">        </span> vector,{}</span></div><div style="background-color: transparent; "><span style="font-family: arial, helvetica, sans-serif; font-size: 13px;"><span class="Apple-tab-span" style="white-space:pre">        </span> ),</span></div><div style="background-color: transparent; "><span style="font-family: arial, helvetica, sans-serif; font-size: 13px;"><span
class="Apple-tab-span" style="white-space:pre">        </span> map: map,<span class="Apple-tab-span" style="white-space:pre">        </span> </span></div><div style="background-color: transparent; "><span style="font-family: arial, helvetica, sans-serif; font-size: 13px;"><span class="Apple-tab-span" style="white-space:pre">        </span> toggleGroup: "mapTools",</span></div><div style="background-color: transparent; "><span style="font-family: arial, helvetica, sans-serif; font-size: 13px;"><span class="Apple-tab-span" style="white-space:pre">        </span> enableToggle: true,</span></div><div style="background-color: transparent; "><span style="font-family: arial, helvetica, sans-serif; font-size: 13px;"><span class="Apple-tab-span" style="white-space:pre">        </span> tooltip: "<b>Elemente verschieben",</span></div><div
style="background-color: transparent; "><span style="font-family: arial, helvetica, sans-serif; font-size: 13px;"><span class="Apple-tab-span" style="white-space:pre">        </span> group: "mapTools"</span></div><div style="background-color: transparent; "><span style="font-family: arial, helvetica, sans-serif; font-size: 13px;"><span class="Apple-tab-span" style="white-space:pre">        </span> });</span></div><div style="background-color: transparent; "><span style="font-family: arial, helvetica, sans-serif; font-size: 13px;"><span class="Apple-tab-span" style="white-space:pre">        </span> actions["modify_features"] = action;</span></div><div style="background-color: transparent; "><span style="font-family: arial, helvetica, sans-serif; font-size: 13px;"><span class="Apple-tab-span" style="white-space:pre">        </span> toolbarItems_edit.push(action);</span></div><div style="background-color: transparent;
"><span style="font-family: arial, helvetica, sans-serif; font-size: 13px;"> toolbarItems_edit.push('-',' ' );</span></div></div></div></body></html>