[OpenLayers-Dev] Selecting features on multiple layers
Antti Nieminen
ahn at iki.fi
Tue Jun 10 05:56:49 EDT 2008
Hello,
I've worked a bit with the feature event issue for multiple layers,
described in ticket #434.
http://trac.openlayers.org/ticket/434
I did pretty much what crschmidt suggested in the ticket. I modified
SelectFeature and Handler.Feature to accept a list of layers instead
of a single layer. Now, when the handler receives an event, it creates
a small square-shaped geometry with its center at mouse position,
transformed to LonLat coordinates. Then all the visible layers are
queried for features intersecting the "mouse position geometry".
There are some issues/questions though:
* Selecting Point-like features
Using the intersection test, features whose geometry is Point have a
very small "selection area" although they may be a lot bigger on the
screen, shown as a externalGraphic image or something else. So
selecting them doesn't work like it's supposed to. I tried to get
around this problem by using the style properties of the feature
(graphicWidth etc.) to construct a "view geometry" to be used in the
intersection tests.
* Different coordinates in event
For some reason, the event.xy Pixel seems to be a bit (9 pixels) off.
The (layerX,layerY) seemed to right...
* Not messing with map navigation
When navigating the map by holding down the mouse button, the features
shouldn't get selected. In original implementation (that got the
features id straight from the event) this was not a problem since no
events with features id in it were generated during navigation (?).
Using the coordinates however, during/at the end of navigation the
browser sends events whose coordinates may be on top of a feature. I
got around this by ignoring all the events between "mousedown" event
and a "click" event if the "mousedown" didn't happen on top of any
feature.
If nobody is working on this issue, I could develop this further and
maybe even get something ready for the trunk if somebody can convince
me that this is the right (or only) way to do it. I'd appreciate if
somebody has any suggestions or a better idea how to do this. All this
geometry selection thing seems a bit too much for this kind of issue.
I think somebody suggested something like moving all the layer
rendering to a single SVG element (I don't have any idea how to do
that). At least that would get rid of this geometry intersection mess.
With geometries however, it would be possible to implement something
like area selection tools etc...
- antti
More information about the Dev
mailing list