Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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

share|improve this question
add comment

2 Answers

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.

share|improve this answer
    
lol, my initial idea was already worked out in the bug report you opened. –  Glenn Plas Nov 1 '12 at 2:19
add comment
up vote 0 down vote accepted

I've found a solution to the problem outlined in my original question above.

Rather than use the SelectFeature control to manage my vector attribution I've employed a branch of openlayers (currently in the pull-request queue) created by Andreas Hocevar, an active openlayers contributor.

This branch uses an event listener strategy rather than the SelectFeature control to manage mouse events on vector layers. I've created an example to show how this strategy might be employed to capture and display vector attribution from hover and click events.
(The code for this example can also be found here.)

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.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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