[OpenLayers-Users] Using only one set of modify feature controls for different layers?

Arnd Wippermann arnd.wippermann at web.de
Wed Jan 6 16:56:26 EST 2010


Hi,

It is possible to work with one control set for all vector layers. I have an
application, where i use this.

When changing from one vectorlayer to another, I destroy the controls and
declare them then for the next vectorlayer. But i have my controls set in a
OpenLayers panel. So there is no need for registering events, that's part of
the panel. Perhaps there is the cause, that your approach doesn't work.

Arnd
http://gis.ibbeck.de/OLClient/OLClient.asp?MAPNR=900913&LAYERS=100000,100020
,100630,100641&CENTER=798470.75198434,6669045.919625&ZOOM=17

-----Ursprüngliche Nachricht-----
Von: users-bounces at openlayers.org [mailto:users-bounces at openlayers.org] Im
Auftrag von cgp
Gesendet: Dienstag, 5. Januar 2010 18:16
An: users at openlayers.org
Betreff: [OpenLayers-Users] Using only one set of modify feature controls
for different layers?


I added 3 different WFS polygon overlays to the map like this:

        var wfs_poly_1 = new OpenLayers.Layer.Vector("WFS POLY 1", {
            strategies: [new OpenLayers.Strategy.BBOX()],
            protocol: new OpenLayers.Protocol.WFS({
                version: "1.1.0",
                url:  "/geoserver/wfs",
                featureType: 'LAYER_PREFIX.WFS_POLY_1',
                featureNS: "http://geoserver.sf.net",
                featurePrefix: "sde",
                srsName: "EPSG:900913",
                geometryName: "SHAPE"
            })
        });
        wfs_poly_1.setVisibility(false);

        var wfs_poly_2 = new OpenLayers.Layer.Vector("WFS POLY 2", {
            strategies: [new OpenLayers.Strategy.BBOX()],
            protocol: new OpenLayers.Protocol.WFS({
                version: "1.1.0",
                url:  "/geoserver/wfs",
                featureType: 'LAYER_PREFIX.WFS_POLY_2',
                featureNS: "http://geoserver.sf.net",
                featurePrefix: "sde",
                srsName: "EPSG:900913",
                geometryName: "SHAPE"
            })
        });
        wfs_poly_2.setVisibility(false);

        var wfs_poly_3 = new OpenLayers.Layer.Vector("WFS POLY 3", {
            strategies: [new OpenLayers.Strategy.BBOX()],
            protocol: new OpenLayers.Protocol.WFS({
                version: "1.1.0",
                url:  "/geoserver/wfs",
                featureType: 'LAYER_PREFIX.WFS_POLY_3',
                featureNS: "http://geoserver.sf.net",
                featurePrefix: "sde",
                srsName: "EPSG:900913",
                geometryName: "SHAPE"
            })
        });
        wfs_poly_3.setVisibility(false);

        map.addLayers( [ wfs_poly_1, wfs_poly_2, wfs_poly_3 ]);

Then I added the modify controls like this: (by default, wfs_poly_1 is
selected)

			modifyControls = {
				select: new
OpenLayers.Control.SelectFeature(wfs_poly_1,{
							onSelect:
onFeatureSelect,
							onUnselect:
onFeatureUnselect,
							toggle: true,
							clickout:true,
							multipleKey:
"ctrlKey"}),
				drag: new
OpenLayers.Control.ModifyFeature(wfs_poly_1,{mode:OpenLayers.Control.ModifyF
eature.DRAG,displayClass:"olControlModifyFeatureDrag"}),
				resize: new
OpenLayers.Control.ModifyFeature(wfs_poly_1,{mode:OpenLayers.Control.ModifyF
eature.RESIZE,displayClass:"olControlModifyFeatureResize"}),
				rotate: new
OpenLayers.Control.ModifyFeature(wfs_poly_1,{mode:OpenLayers.Control.ModifyF
eature.ROTATE,displayClass:"olControlModifyFeatureRotate"}),
				reshape: new
OpenLayers.Control.ModifyFeature(wfs_poly_1,{mode:OpenLayers.Control.ModifyF
eature.RESHAPE,displayClass:"olControlModifyFeatureReshape"}),
				delete_f: new
OpenLayers.Control.SelectFeature(wfs_poly_1,{onSelect:function(feature){vect
or1.destroyFeatures([feature])}})	
			};

        	for (var key in modifyControls) {
        		map.addControl(modifyControls[key]);
        	}

I also made my own layer switcher that only allows modification of one layer
at a time. When I toggle between the layers, I assign the layer to each of
the modify feature controls:

            for(var modify_key in modifyControls) {
                var control = modifyControls[modify_key];
                control.layer = layer;
            }

The following HTML displays the controls:

					< div id="modifyControls">MODIFY
CONTROLS<br/>
						< img id="select"
class="modify_functions"
src="./js/img/select-enabled.png" alt="Select"/>
						< img id="drag"
class="modify_functions"
src="./js/img/drag-enabled.png" alt="Drag"/>
						< img id="resize"
class="modify_functions"
src="./js/img/resize-enabled.png" alt="Resize"/>
						< img id="reshape"
class="modify_functions"
src="./js/img/reshape-enabled.png" alt="Reshape"/>
						< img id="rotate"
class="modify_functions"
src="./js/img/rotate-enabled.png" alt="Rotate"/>
						< img id="delete_f"
class="modify_functions"
src="./js/img/delete_f-enabled.png" alt="Delete"/>
					</ div>

My main function assigns events on $(document).ready:

		$("#select").click(function(){
			toggleModifyControls("select");
		});
		$("#drag").click(function(){
			toggleModifyControls("drag");
		});
		$("#resize").click(function(){
			toggleModifyControls("resize");
		});
		$("#reshape").click(function(){
			toggleModifyControls("reshape");
		});
		$("#rotate").click(function(){
			toggleModifyControls("rotate");
		});
		$("#delete_f").click(function(){
			toggleModifyControls("delete_f");
		});

Here is the function:

        function toggleModifyControls(control_name) {       
			for(var key in modifyControls) {
            	var control = modifyControls[key];
	            if (control_name.toLowerCase()==key.toLowerCase()) {
	
$("#"+key).attr("src","./js/img/"+key+"-activated.png");
	                control.activate();
                	console.log("control: "+control.id+", layer:
"+control.layer.name+", active: "+control.active);
	                }
	            } else {
	
$("#"+key).attr("src","./js/img/"+key+"-enabled.png");
	            	control.deactivate();
	            }
			}
        }

So if I want to modify wfs_poly_2, I'll assign that layer to all of the
modify controls. The Firebug console indicates that the layer is being
properly assigned and the appropriate control is being activated; but it
doesn't do anything. I try to click on a feature to drag it or resize etc
but all it does is try to pan the map.

I'm not sure if I explained my problem well. But what I'm trying to ask is,
how can I just use one set of these modify feature controls for many
different overlays? I think I've got the right idea with my code, but I
don't know why it's not working.

Thanks in advance for your help.

--
View this message in context:
http://n2.nabble.com/Using-only-one-set-of-modify-feature-controls-for-diffe
rent-layers-tp4256234p4256234.html
Sent from the OpenLayers Users mailing list archive at Nabble.com.
_______________________________________________
Users mailing list
Users at openlayers.org
http://openlayers.org/mailman/listinfo/users




More information about the Users mailing list