[OpenLayers-Users] Selectfeature not firing

Chris Green chris.green at ibstv.co.uk
Fri Feb 26 06:48:24 EST 2010


Hi Alex

I finally figured out what seems to be happening. When I create a vector layer and populate it with features as follows...

var wfs = new OpenLayers.Layer.Vector("Countries WFS", {
	styleMap: styleMap2,
	strategies: [new OpenLayers.Strategy.BBOX()],
	protocol: new OpenLayers.Protocol.WFS({
	url:"http://localhost/cgi-bin/mapserv.exe?map=c:/ms4w/apps/OLFurtherTest/htdocs/wfsVectorGetFeature.map",
	featureType: "France",
	featureNS: "http://mapserver.gis.umn.edu/mapserver"})
	});
map.addLayer(wfs)

....then any features which are added are not selectable by SelectFeature. If on the other hand I create a blank vector layer and add features to it by making a separate WFS call and using Vector.addFeatures(WFSfeatures); then those features can be selected by the SelectFeature control.

I can make my map using this second method but it seems more cumbersome and I wonder if I am missing something in the first method....it seems that when I create a vector layer with in-built WFS call as above then the resulting layer is not editable. Does this make sense and do you have any suggestions?

Best regards,



Chris 


-----Original Message-----
From: Alexandre Dube [mailto:adube at mapgears.com] 
Sent: 24 February 2010 21:55
To: chris.green at ibstv.co.uk
Cc: Users at openlayers.org
Subject: Re: [OpenLayers-Users] Selectfeature not firing

Chris,

What you're describing is a normal behavior when the Navigation and 
SelectFeature control are both activated, yes. To resolve this, you could :

* have a toolbar with your controls as buttons and only one is active at 
a time
* have your SelectFeature control clicks work only while pressing a 
specific key (ctrl for example). This could be done by defining a 
'keymask' to the Handler.Feature object of your SF control.
* make the "select" on "hover" instead of "click", see an example [1]

Hope this helps,

Alexandre

[1] http://openlayers.org/dev/examples/highlight-feature.html


Chris Green wrote:
> Alex
>
> Can't really offer much more except that I observe that if I comment out
> selectCtrl.activate(); then I can drag the map to a new position when the
> cursor is over the feature on the vector layer delivered by WFS, but if the
> selectctrl is activated then dragging the map does not work when the cursor
> is in that position (but it does work if the cursor is anywhere else on the
> map). So there seems to be some kind of conflict caused by this control.
> Does this help?
>
>
> Regards,
>
>
>
> Chris 
>
>
> -----Original Message-----
> From: Alexandre Dube [mailto:adube at mapgears.com] 
> Sent: 24 February 2010 15:47
> To: chris.green at ibstv.co.uk
> Cc: Users at openlayers.org
> Subject: Re: [OpenLayers-Users] Selectfeature not firing
>
> Chris,
>
> Could you share a live example or more code demonstrating your problem ? 
> The code you pasted below doesn't seem to have any issue.
>
> Kind regards,
>
> Alexandre
>
>
> Chris Green wrote:
>   
>> Hello all
>>
>> Hope someone can help with what is probably a simple problem that I 
>> don’t seem to be able to solve. I have created a vector layer which 
>> has features taken from a wms layer:
>>
>> var wfs = new OpenLayers.Layer.Vector("Countries WFS", {
>>
>> styleMap: styleMap2,
>>
>> strategies: [new OpenLayers.Strategy.BBOX()],
>>
>> protocol: new OpenLayers.Protocol.WFS({
>>
>> url: 
>>
>>     
> "http://localhost/cgi-bin/mapserv.exe?map=c:/ms4w/apps/OLFurtherTest/htdocs/
> wfsVectorGetFeature.map",
>   
>> featureType: "France",
>>
>> featureNS: "http://mapserver.gis.umn.edu/mapserver"
>>
>> })
>>
>> });
>>
>> map.addLayer(wfs);
>>
>> This works OK, but I want to be able to click to select an individual 
>> feature so I added:
>>
>> var selectCtrl = new OpenLayers.Control.SelectFeature(wfs,
>>
>> {clickout: true}
>>
>> );
>>
>> map.addControl(selectCtrl);
>>
>> selectCtrl.activate();
>>
>> However the selectfeature control does not fire in response to any map 
>> clicks. Can anyone suggest what I am missing?
>>
>> Chris
>>
>> ------------------------------------------------------------------------
>>
>> _______________________________________________
>> 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