[GIS] Openlayers – Problem with selecting features from overlapping vector layers

openlayers-2vector

I face the following problem.
I have two vector layers. One has linestring and the other point geometry.

When I add this line to my point geometry vector layer:

          pointLayer.setZIndex( 1001 );

I get the point layer on top and then I am unable to select any feature from the linestring vector layer.

How can I solve this problem so all the features are clickable? I wouldn't expect this behavior as the point vector layer just has some points.

Best Answer

To solve this problem, you have to look under the hood of the library. The SelectFeature control can be applied on a single layer or multiple layers.

  • Single layer: The control's layer and handler properties receives the layer object, then you can select features from that layer.
  • Multiple layers: The library creates a new Vector.RootContainer layer, which basically a vector layer group containing the layers. The control is then applied to that RootContainer layer.

This way if you modify the Z index of the original layer, you just block the mouse event from the created layer group. I have two ideas which would help you solve this problem in theory:

  1. Get the RootContainer layer and modify its position to be on top. You can set the Z-index, but the more convenient way is to use the map's raiseLayer function.
  2. Define the pointer-events CSS property of your layers' DOM elements. You can set it to none, to get your mouse clicks fall through completely.