[OpenLayers-Dev] Canvas + SelectFeature = Bug (OL 2.11/2.12)

Mike Ryan mr at mry4n.net
Tue Jul 3 14:14:19 PDT 2012

When I render a layer as a Canvas it no longer respects the layer index.

In my case, the Canvas layer is made up of polygons and a separate layer 
above it is made up of points. Any points within polygons cannot be 
selected -- only the surrounding polygon gets selected.

I do not have this problem if the polygon layer is rendered as something 
other than a Canvas.

This problem is caused by the order of the layers in the array sent to 
OpenLayers.Control.SelectFeature. The workaround is ordering the layers 
array so that the Canvas layer comes after layers that are above it in 
the layer index.

In other words, even though I add layers to the map like this:
map.addLayers([canvas_layer, point_layer])

I have to add layers to the control like this:
map.addControl(new OpenLayers.Control.SelectFeature([point_layer, 

To reproduce this problem do the following.

1. Go to: 

2. Swap the order of vectors1, vectors2 in lines 62 & 65 so they look 
like this:

(line 62) map.addLayers([wmsLayer, vectors2, vectors1]);
(line 65) selectControl = new OpenLayers.Control.SelectFeature(
                 [vectors2, vectors1],

Changing addLayers puts the markers above the squares. Changing 
SelectFeature disallows markers within squares to be selected, even 
though they are above the squares. You will only see this problem if you 
render the layers as Canvases (i.e. include "?renderer=Canvas" in the url).

Considering that layer order in SelectFeature has no effect on layers 
not rendered as Canvases, this is either a bug or requires some 
documentation for SelectFeature.

This was also an issue in OL 2.11, but 2.12 improved the situation. In 
2.11 if you turned off the Canvas layer it persisted even though you 
could not see the layer! If you panned the map, it would finally go away 
and you could click the  layers below.



OpenLayers Select Feature on Multiple Layers Example

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/openlayers-dev/attachments/20120703/ffb5fd07/attachment.html>

More information about the Dev mailing list