[OpenLayers-Users] control.SelectFeature

Sarah Schuessler sarah_flip at yahoo.de
Tue Apr 20 10:10:30 EDT 2010


Hi Alexandre,

thanks for examples.
I went ahead with wfs-getfeature example selecting from a WFS.fromWMSLayer layer (changed this to simple wfs layer because I haven´t got a wms layer at my map right now)- but I get only a response at firebug not at my map because of different projection.


I have a viewport loading my layers:
xtype: "gx_mappanel",
map: map,
layers: [...,wfs2],
...
If I use map.addLayers(wfs2) after defining my layer my map is empty (no layers were loaded).

You said:
"unless you add all the vector layers to the SelectFeature control.

Also, you could use only one layer (wfs2) for feature selection instead 
of two."
Can I use only one vector layer or more than one?

best regards
Sarah



________________________________


Hi Sarah,

Have you tried to put your wfs2 layer on top of your layers (as the last 
one added to the map) ? Only the top-most layer can have its features 
selected, unless you add all the vector layers to the SelectFeature control.

Also, you could use only one layer (wfs2) for feature selection instead 
of two. It seems kinda odd to copy features from one layer to an other 
for the purpose of "selection". Check the first example about that 
matter (the other is just to let you know of the cool 'highlight' 
feature you might be interested into ):
http://www.openlayers.org/dev/examples/select-feature.html
http://www.openlayers.org/dev/examples/highlight-feature.html

Best regards,

Alexandre


Sarah Schuessler wrote:
> Hi list,
> I try to select a feature from a wfs layer but it didn´t work.
>
> var select = new OpenLayers.Layer.Vector("Selection", {
>
> styleMap: new
>
> OpenLayers.StyleMap({strokeColor: "blue",
>
> strokeWidth: 5 , strokeOpacity: 0.5, fillOpacity: 0.4}),
>
> displayInLayerSwitcher: true, visibility: true});
>
> var wfs2 = new OpenLayers.Layer.Vector("WFS_",
>
> { styleMap: styleMap,
>
> strategies: [new OpenLayers.Strategy.Fixed()],
>
> projection: destproj,
>
> protocol: new OpenLayers.Protocol.WFS({
>
> url: "http://myserver:81/geoserver/wfs",
>
> featureNS: http://mycomp.org,
>
> featureType: "mylayer",
>
> geometryName: "SHAPE",
>
> srsName: "EPSG:4326",
>
> version: "1.1.0"
>
> }),
>
> projection: new OpenLayers.Projection("EPSG:4326")
>
> });
>
> var selectFeature = new OpenLayers.Control.SelectFeature(wfs2,{box:true});
>
> //map.addControl(selectFeature);
>
> selectFeature.events.register("featureselected", this, function(e){
>
> select.addFeatures([e.feature]); });
>
> selectFeature.events.register("featureunselected", this, 
> function(e){select.removeFeatures([e.feature]);});
>
>  
>
> map.addControl(selectFeature);
>
> I can cover my feature with a box but then nothing happens. At firebug 
> I can see that my code never reach "select.addFeatures([e.feature]);".
>
> If I use:
>
> selectControl = new OpenLayers.Control.GetFeature({
>
> protocol: OpenLayers.Protocol.WFS({
>
> url: "http://myserver:81/geoserver/wfs?service=wfs",
>
> featureNS: "http://mycomp.org",
>
> featureType: "mylayer",
>
> geometryName: "SHAPE",
>
> srsName: "EPSG:4326",
>
> version: "1.0.0",
>
> }),
>
> box: true,
>
> multipleKey: "shiftKey",
>
> toggleKey: "ctrlKey"
>
> }, {projection: new OpenLayers.Projection("EPSG:4326")}
>
> );
>
> selectControl.events.register("featureselected", this, function(e){
>
> //select.addFeatures(Proj4js.transform(sourceproj,destproj,[e.feature.geometry])); 
>
>
> //Proj4js.reportError = 
> function(msg){alert(msg);}//[e.feature.transform(sourceproj,destproj)]);
>
> select.addFeatures([e.feature])
>
> });
>
> selectControl.events.register("featureunselected", this, 
> function(e){select.removeFeatures([e.feature]);});
>
> map.addControl(selectControl);
>
> I get a response at firebug (but feature has different projection). If 
> I want to transform my response then I get a message saying "Latitude 
> failed to converge".
>
> Features are multipolygon if that does matter.
>
> What did I wrong?
>
> Thanks for any hint.
>
> best regards
>
> Sarah
>
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> Users mailing list
> Users at openlayers.org
> http://openlayers.org/mailman/listinfo/users
>  


-- 
Alexandre Dubé
Mapgears
www.mapgears.com

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/openlayers-users/attachments/20100420/523573d5/attachment.html


More information about the Users mailing list