OpenLayers OpenLayers

Ticket #434 (reopened bug)

Opened 2 years ago

Last modified 1 month ago

Only top vector layer is queried

Reported by: camerons Assigned to:
Priority: minor Milestone: 2.7 Release
Component: Control.SelectFeature Version:
Keywords: Cc:
State:

Description

Currently when you use the Control/EditAttributes tool to query a map with multiple layers, only the last layer added is queried. Ie, you will only get an AttributeList if you click on a feature from the top layer.

You should be able to query all layers.

Attachments

MultiLayerFeature.js (13.3 kB) - added by openlayers on 06/16/08 13:36:34.
OpenLayers/Handler/MultiLayerFeature.js
mulafese001.patch (11.5 kB) - added by openlayers on 06/16/08 13:39:55.
A patch enabling selecting features on multiple layers, using geometry intersection tests. Requires the Handler/MultiLayerFeature.js file.

Change History

12/05/06 02:05:36 changed by camerons

Degginging information: Tracing the call stack from the mouseEvent

When clicking on a feature the bottom layer (water bodies) evt.target=<path> ... </path> (a child of <svg id=...4597>)

When clicking on other features, evt.target=<svg id=...4597>...<path/><path/> ...<svg>

-- So we have something like the following: <svg id="layer1">

<path id="path1"/>

</svg> <svg id="layer2">

<path id="path2/> <path id="path3/>

</svg>

When a key a user clicks on the mapPane, if it is not caught by path1, it goes up the tree to layer1. IT DOESN'T GO BACK DOWN THE TREE to path2.

One solution is to move all geometries into the one svg container. Ie: <svg>

<path class="layer1" id="path1"/> <path class="layer2" id="path2/> <path class="layer2" id="path3/>

</svg>

The class attribute is introduced to allow an entire layer to be hidden. This page suggests that we can change the style for all the CLASS elements for a layer: http://developer.apple.com/internet/webcontent/styles.html

For reference, here is the mouse click Call stack:

#0: function anonymous(evt=MouseEvent:{4}) in <file:/C:/Documents%20and%20Settings/shorterc/My%20Documents/work/svn.openlayers.org/sandbox/vector/lib/OpenLayers/Renderer/Svg.js> line 106 #1: function anonymous(evt=MouseEvent:{4}) in <file:/C:/Documents%20and%20Settings/shorterc/My%20Documents/work/svn.openlayers.org/sandbox/vector/lib/OpenLayers/Control/EditingTool.js> line 141 #2: function anonymous(evt=MouseEvent:{4}) in <file:/C:/Documents%20and%20Settings/shorterc/My%20Documents/work/svn.openlayers.org/sandbox/vector/lib/OpenLayers/Control/EditingTool.js> line 175

#4: function anonymous(evt=MouseEvent:{4}) in <file:/C:/Documents%20and%20Settings/shorterc/My%20Documents/work/svn.openlayers.org/sandbox/vector/lib/OpenLayers/Control/EditingAttributes.js> line 124

#6: function anonymous(event=MouseEvent:{4}) in <file:/C:/Documents%20and%20Settings/shorterc/My%20Documents/work/svn.openlayers.org/sandbox/vector/lib/OpenLayers/BaseTypes.js> line 886

#10: function anonymous(type=string:"mousedown", evt=MouseEvent:{4}) in <file:/C:/Documents%20and%20Settings/shorterc/My%20Documents/work/svn.openlayers.org/sandbox/vector/lib/OpenLayers/Events.js> line 286 #11: function anonymous(evt=MouseEvent:{4}) in <file:/C:/Documents%20and%20Settings/shorterc/My%20Documents/work/svn.openlayers.org/sandbox/vector/lib/OpenLayers/Events.js> line 314

#13: function anonymous(event=MouseEvent:{4}) in <file:/C:/Documents%20and%20Settings/shorterc/My%20Documents/work/svn.openlayers.org/sandbox/vector/lib/OpenLayers/BaseTypes.js> line 886

Event is attached to the the HTMLDiv element, currentTarget=

<HTMLDivElement>

12/05/06 04:04:04 changed by camerons

Stated again with formatting:

<svg id="layer1">
    <path id="path1"/>
</svg>
<svg id="layer2">
    <path id="path2/>
    <path id="path3/>
</svg>

One solution is to move all geometries into the one svg container. Ie:

<svg>
    <path class="layer1" id="path1"/>
    <path class="layer2" id="path2"/>
    <path class="layer2" id="path3"/>
</svg>

12/05/06 05:55:26 changed by camerons

Mmm, downside with option above is that you cannot insert a <div id=WMS> layer between 2 SVG layers. You could create an SVG image, but that would have a major impact on the code.

Option 2: We might be able to simulate a mouse event in the non-visible layers. Use:

document.createEvent('MouseEvents')
event.initMouseEvent()
element.dispatchEvent(event); // use fireEvent() in IE

12/05/06 19:04:50 changed by camerons

Option 2 above doesn't seem to work. In firefox I can trigger an event for a <div> or svg/path, but the event is always fired and doesn't seem to be distinguishable if the x,y position is over a svg feature or not.

IE has elementFromPoint which might help, but I suspect it doesn't work if the element is hidden. I haven't tested yet: http://msdn.microsoft.com/workshop/author/dhtml/reference/methods/elementfrompoint.asp

12/06/06 02:02:34 changed by camerons

Option 3: This is a bit of a hack. If a feature is not found in the top layer, then loop through the features in the layers below and check if the point fits in the feature's bounding box.

12/06/06 22:59:26 changed by camerons

  • priority changed from major to minor.

Option 3 addressed by r2020. Still needs to address selecting a points layer (you need a tollerance around the point) and multiple geometries doesn't have a bbox for each geometry. Might be a few other things too. Changed priority to minor.

04/05/07 14:32:33 changed by sderle

  • milestone changed from Vector RC1 to 2.5 Release.

06/29/07 15:27:45 changed by crschmidt

  • status changed from new to closed.
  • resolution set to duplicate.

#791 is a duplicate of this:

I found out that the SelectFeature control only works for one layer. I looked at the code, but I did not find a reason why.

I made an example to show this behaviour at

http://dev.openlayers.org/sandbox/ahocevar/selectFeature/examples/gml-layer.html

By default, SelectFeature controls are active on both the MultiPoint and the MultiPolygon layer. To see if it works just hover over the vector features. As you can see, only the MultiPolygon control works. It was added after MultiPoint. If you use the MultiPolygon button to deactivate the MultiPolygon control, then the MultiPoint control works.

If you deactivate the MultiPoint control too, there is also an interesting behaviour: the mouse cursor changes when hovering over MultiPolygon features.

Feel free to play around in the sandbox. I would really be glad if this could be fixed. Unfortunately, I do not have a clue what might be wrong and so I cannot do it myself.

Thank you! Andreas Hocevar.

06/29/07 15:28:09 changed by crschmidt

  • status changed from closed to reopened.
  • resolution deleted.

Argh, closed wrong ticket

08/03/07 11:17:52 changed by crschmidt

  • milestone changed from 2.5 Release to 2.6 Release.

01/16/08 10:33:16 changed by crschmidt

  • state changed.
  • component changed from general to Control.SelectFeature.
  • milestone changed from 2.6 Release to 2.7 Release.

With the geometry intersection code, it should be possible to modify SelectFeature to take a list of layers, and if passed a list, then on click, create a small bounding box and query through all the selectable layers looking for a feature which intersects. However, there has been no one actively pursuing coding this for 2.6, so I'm bumping it.

If you are interested in this task, I would be willing to mentor you through the development of the functionality. It would likely be a half dozen hours or less to write the code and some tests -- possibly a bit more to get it complete for trunk. If you are interested, please contact me either on IRC or via the dev mailing list.

06/16/08 13:36:34 changed by openlayers

  • attachment MultiLayerFeature.js added.

OpenLayers/Handler/MultiLayerFeature.js

06/16/08 13:39:55 changed by openlayers

  • attachment mulafese001.patch added.

A patch enabling selecting features on multiple layers, using geometry intersection tests. Requires the Handler/MultiLayerFeature.js file.

06/16/08 13:42:24 changed by openlayers

I created a patch + file (OpenLayers/Handler/MultiLayerFeatureHandler.js) that make it possible to select features on multiple layers. They use the geometry intersection tests similarly to what crschmidt suggested.

I descriped some of the problems/questions with this solution in the mailing list.

You can try the selecting on multiple layers thing here.

Thoughts & ideas are welcome.