[OpenLayers-Users] SelectFeature control/Feature Handler interaction on programmatic feature selection

Eric Lemoine eric.c2c at gmail.com
Tue Sep 2 02:04:23 EDT 2008


Hi Justin.

I haven't checked but I'm pretty sure my app suffers the same issue.
You made me realize that. Thanks :)

I tend to think that this problem must be dealt with at the
application level. OpenLayers isn't responsible for us calling the
select feature control's select method. One possible solution would be
to use a click handler in our app code and do the unselect/close popup
there if it couldn't be achieved through the select feature control. I
haven't tested this myself but it should work.

What do you think?

Eric

2008/9/2, Justin Stern <jstern81 at gmail.com>:
> The background: my goal is to make vector features which open a popup
> when clicked, or when their name is clicked in a list.  The popup
> should close when the features are 'unselected'.  To do this I add a
> SelectFeature control, similar to one of the OpenLayers demo examples,
> and when I want to open the popup programmatically , I invoke the
> 'select' method on the SelectFeature control.
>
> The issue: this works well, except for when the very first action is
> the user clicking the feature name to open the popup.  In this case,
> clicking outside the popup (the map area) does not cause the popup to
> close.  It must be closed via the 'x' or by clicking that or another
> feature to open a new popup, at which point future programmatically
> opened popups behave the same as those from clicking a feature.
>
> I tracked this down to the Handler not being informed of features
> selected via the control 'select' method (which makes sense, the
> Handler handles mouse events, which calling 'select' is not), which
> causes certain checks to fail in the Handler when the user then clicks
> outside the popup.  To the Handler nothing appears to be selected, so
> it doesn't know to tell the feature control to 'unselect' the feature.
>
> Now I seem to be able to work around this issue by faking out the
> Handler when I detect the first programmatic select:
>
> if(!selectFeatureControl.handlers.feature.lastFeature) {
>     selectFeatureControl.handlers.feature.lastFeature =
> selectFeatureControl.handlers.feature.feature = theFeature;
>     selectFeatureControl.handlers.feature.handled = true;
> }
>
> But it makes me wonder if my approach is wrong to have to go through
> this sort of thing...  Any suggestions?
> _______________________________________________
> Users mailing list
> Users at openlayers.org
> http://openlayers.org/mailman/listinfo/users
>



More information about the Users mailing list