[OpenLayers-Users] Multiple selectfeature on one layer

Eric Lemoine eric.c2c at gmail.com
Fri May 16 17:48:26 EDT 2008


On Mon, May 5, 2008 at 12:51 PM, Lid Sjur Ringheim
<sjur.ringheim.lid at imr.no> wrote:
> Hello,
>
>
>
> This was working in OpenLayers 2.5 but I can't get it to work in 2.6.
>
>
>
> I'm having a GML layer with point features that I want to put a hover and a
> click selectFeature control on but only the hover one seems to be working.
>
> This is the code I'm using which were working in 2.5
>
>
>
>     selfeature = new OpenLayers.Control.SelectFeature(pointlayer, { hover :
> true, onSelect : onFeatureSelect, onUnselect :onFeatureUnselect});
>
>     clickfeature = new OpenLayers.Control.SelectFeature(pointlayer,
> {onSelect : updateStationsFeature, onUnselect : updateStationsFeature});
>
>
>
>     map.addControl(clickfeature);
>
>     map.addControl(selfeature);
>
>
>
>     clickfeature.activate();
>
>     selfeature.activate();
>
>
>
> In 2.6 only the first method is working the second is never used for some
> reason. I have checked the DOM tree and both are part of the controls array
> of the map object.
>
>
>
> Do anyone know a workaround for this? Maybe making two layers and having one
> of them use the hover version and one the click version?

I did some investigation, and having one "click" select feature
control and one "hover" select feature control on the same layer
works. The simplest way is to activate the click control after that
with hover control. If done the other way around, then
hoverControl.handler.stopClick = false must be done.

This might still not work as you expect it to work because onSelect()
of the click control won't be called when you go over a feature and
click on it. But in fact it makes sense that onSelect() isn't called.
You move over the feature, it gets selectetd, so clicking on it does
trigger onSelect() because the feature is already selected.

If you tell me more on what you want to achieve, I may be able to help
you further. Sorry for taking so long to go back to you on this issue,
but I was busy with other stuff.

Cheers,
--
Eric



More information about the Users mailing list