[OpenLayers-Users] control.SelectFeature

Alexandre Dube adube at mapgears.com
Tue Apr 20 08:57:21 EDT 2010


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




More information about the Users mailing list