[OpenLayers-Users] SelectFeature

Stephen Woodbridge woodbri at swoodbridge.com
Tue Oct 9 13:17:53 EDT 2007


Lourens Veen wrote:
> On Tuesday 09 October 2007 14:10:49 Christopher Schmidt wrote:
>> On Tue, Oct 09, 2007 at 01:24:27PM +0200, Stefano Bonnin wrote:
>>> hi all,
>>>
>>> I have to define a popup for every vector feature but I notice that
>>> SelectFeature has some problem when there is more than 1 layer. The
>>> SelectFeature control seems to work only when there is 1 layer
>>> active. This (critical, for me) SelectFeature bug will be pathed
>>> only in the 2.6 release of OpenLayers ... so ...
>> Actually, it's not expected, as far as I know, to be fixed then
>> either. (It might be, with some recent work we're doing, but it's not
>> high on the priority list). This is a limitation of browser event
>> handling with SVG.
> 
> The same limitation causes trouble if you have multiple features on top 
> of each other in the same layer. The browser will render them in some 
> order, and one of them will end up on top. That one can then be 
> selected, but the other ones can't be.
> 
> The problem is that the event handler uses the source of the event, as 
> passed by the browser in the Event object, to determine which feature 
> was clicked. The browser chooses one feature to attach the event to, 
> and so only one feature can be selected.
> 
> The solution to this is to find out where the user clicked, transform 
> the screen coordinates into LatLon, and then search through the 
> features to find out which features are at that location. It's not very 
> fast, but it works. The problem is that selection isn't precise, 
> because OpenLayers.Geometry.atPoint() uses a bounding box test (and 
> I've got polygons in my WFS layer). That would be quite hard to fix.
> 
> Also, you still have no intuitive way of selecting only a small polygon 
> lying completely inside a larger one: you have to select both of them 
> first by clicking inside the small one, and then deselect the large one 
> by clicking somewhere inside it where the small one is not.
> 
> Another possibility I'm considering trying is to use the Box handler, 
> and then only select a feature if one (all?) point is within the 
> dragged box.

Lourens,

Another idea that might work it to take the item attached to the event 
and hide it, then re-issue the event and see if you get another object, 
and continue until you do not get an object. I'm not sure if this is 
possible, but it would allow you to collect the objects into an array 
which could be returned. You might want to differentiate single-select 
from multiple-select?

Also isn't there a way to allow an event to propagate to other layers 
below the one currently being handled. If this happened would you not 
get a series of events for all the overlapping features?

-Steve



More information about the Users mailing list