I was able to get this working as intended (in browsers that support it) by
1) omitting the calls to moveLayerToTop() in the OpenLayers code; and
2) setting $(layer.div).css("pointer-events", "none").
I also tested an approach using the relatively recently added map events featureover, featureout, and featureclick i.e.
var mapOptions =
{
.
.
.
eventListeners:
{
featureover: function(e)
{
e.feature.renderIntent = "temporary";
e.feature.layer.drawFeature(e.feature);
},
featureout: function(e)
{
e.feature.renderIntent = "default";
e.feature.layer.drawFeature(e.feature);
},
featureclick: function(e)
{
e.feature.renderIntent = "select";
e.feature.layer.drawFeature(e.feature);
}
}
};
map = new OpenLayers.Map(mapOptions);
It worked, but proved to be slower than the first approach to change feature states; probably because there's many hundreds of features on my map for the code to sift through. For my intended use, the response could be sped up quite a bit if it stopped firing events once the top-most feature was hit, rather than reporting for every feature under the cursor. I still had to set the image layer's pointer-events to none to get it to work.
For my work, it's common to have sparse or semi-transparent image layers above vector layers that still need to respond to mouse events. I'm surprised that OpenLayers doesn't include an option to turn off the layer re-ordering when the select control is added; or maybe it does and I just don't see it in the code.
Best Answer
Assuming you use an
ol.layer.Vector
with anol.source.GeoJSON
you can use something like this:This shows how to get a notification when the vector source is loaded. It only works with sources inheriting from
ol.source.StaticVector
. Examples includeol.source.GeoJSON
andol.source.KML
.Also, note that this code may no longer work in the future when ol3 will provide a consistent way to know if/when a source is loaded.