7

I'd like my map to display a few layers in a particular order. Some of these layers are Vectors, others are XYZs, and some of my Vector layers display attribution.

Initial layer ordering works fine until I attempt to provide attribution for some of my vector layers. The problem comes when I use the SelectFeature control to handle vector attribution. Those layers that are added to this control are then rendered on top of the map's other layers (preventing the layers from being ordering in a meaningful manner).

I'm seeking a solution that allows the attribution of some vector layers while also allowing control over the layer rendering order.

I've filed an OpenLayers bug report: https://github.com/openlayers/openlayers/issues/661

Sample code can be found here: https://gist.github.com/3537881

And an example of that same code can be viewed here: http://labs.ecotrust.org/selectfeature/selectfeatureanomaly.html

This example demonstrates the re-ordering that occurs when the SelectFeature control is activated and deactivated (click on the Activate Control link under the map).

Again, I'm looking for a solution that allows me to maintain control over layer ordering while providing attribution for a subset of the rendered vector layers.

-Scott

2 Answers 2

1

I understood the problem wrong, tried to jsfiddle this for a change. I assume you need a workaround, hence I'm going this road. Getting this to work on jsfiddle but had to do some things differently to make it work but I see your issue now.

bugreport you opened has got it right, best solution is:

beforefeaturehighlighted: function(e) {
            if (e.feature.layer.name === "green_vector") { return false;}              
        } 

its only logic by design, in order to select a layer you need to see it. it has to be brought to the front. But you still have a problem with the ordering I see... perhaps this really leans towards a bug.

1
  • lol, my initial idea was already worked out in the bug report you opened.
    – Glenn Plas
    Nov 1, 2012 at 2:19
0

I've found a solution.

Rather than use the SelectFeature control to manage my vector attribution I'm using an OpenLayers branch created by Andreas Hocevar.

This branch uses an Event Listener strategy rather than the SelectFeature control to manage mouse events on vector layers.

ASIDE:

This event listener strategy actually solves 3 problems I was having.

It solves my original layer re-ordering problem in which the SelectFetaure control had the unwanted side effect of overriding the zIndex of my newly controlled vector layers (causing these vector layers to be displayed on top of my other vector and XYZ layers, regardless of their original ordering). Using the event listeners strategy from ahocevar's feature-events branch leaves the zIndex values unchanged thus preserving the original/intended layer ordering.

Even better, this strategy also solves a problem in which the user is unable to pan the map with the cursor inside an attributed (SelectFeature control-managed) vector layer.

And even more awesome (but wait there's more!), it enables my application to capture and display attribution from all of the layers under a mouse click or hover event rather than just the top most layer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.