hey guys,

i like to draw polygons on a map, but it is important that i have several
levels. So my idea was to add a vector layer for each level. to change
between the layers i use the " map.removeControl(controls[key]);"  function
to remove all controls needed for drawing and re-add the controls with the
new selected layer. So my problem is now, that all works fine with the
initalized layer, but when i change to annother layer it the drawing feature
behaves strange and it is not possible to draw new polygons. So please help
me how i can use the drawfeature Control with multiple layers.

My pseudo Code:
//create multiple layers: one for each level
        var styleMapL1 = new OpenLayers.StyleMap({fillColor: "green"});
        vlayer1 = new OpenLayers.Layer.Vector("Layer 1", {styleMap: 
styleMapL1});
        layerArray[1] = vlayer1;
        var styleMapL2 = new OpenLayers.StyleMap({fillColor: "red"});
        vlayer2 = new OpenLayers.Layer.Vector("Layer 2", {styleMap: 
styleMapL2});
        layerArray[2] = vlayer2;
        var styleMapL3 = new OpenLayers.StyleMap({fillColor: "blue"});
        vlayer3 = new OpenLayers.Layer.Vector("Layer 3", {styleMap: 
styleMapL3});
        layerArray[3] = vlayer3;

        map.addLayers([vlayer1, vlayer2, vlayer3]);

        this.addControls(3);

//this method is called when i want to change the layers 
function switchControls(layerIndex)
                {
                        this.removeControls();
                        this.addControls(layerIndex);
                }
                
                function addControls(layerIndex)
                {
                        if(layerIndex != null)
                        {
                                var layer = layerArray[layerIndex];
                                controls = {
                                            polygon: new 
OpenLayers.Control.DrawFeature(layer,
OpenLayers.Handler.Polygon)      
                                        };

                                        for(var key in controls) {
                                                                        
                                            map.addControl(controls[key]);
                                            controls[key].activate();   
                                                                                
    
                                        }
                                
                        }
                }
                function removeControls()
                {
                        for(var key in controls) {
                                
                            map.removeControl(controls[key]);                   
                            
                        }
                        
                }


Greetings Peter


--
View this message in context: 
http://osgeo-org.1803224.n2.nabble.com/Drawfeature-with-multiple-vector-layers-tp7184326p7184326.html
Sent from the OpenLayers Users mailing list archive at Nabble.com.
_______________________________________________
Users mailing list
[email protected]
http://lists.osgeo.org/mailman/listinfo/openlayers-users

Reply via email to