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

cgp carina_palanca at forcorp.com
Thu Jan 7 12:05:39 EST 2010


Thanks Arnd. The earlier version of my application had the same thing as
yours, but we discovered that the OpenLayers panel is not as flexible as we
wanted it to be, so we switched to <div> elements. For example, we wanted
the panel to be draggable and collapsible by using jquery but there were
some obstacles to doing that, due to the fact that it's an
OpenLayers.Control.Panel object, and not just a plain old <div> element.




Arnd Wippermann wrote:
> 
> 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
> 
> _______________________________________________
> Users mailing list
> Users at openlayers.org
> http://openlayers.org/mailman/listinfo/users
> 
> 

-- 
View this message in context: http://n2.nabble.com/Using-only-one-set-of-modify-feature-controls-for-different-layers-tp4256234p4267549.html
Sent from the OpenLayers Users mailing list archive at Nabble.com.



More information about the Users mailing list