Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I saw this example which demonstrates how ordering can be controlled with markers added using styling options (graphicZIndex) applied to a vector layer. Due to the limitations in the combination of event listeners that I can apply using this method, I am forced to use the markers layer instead.

There are 100 points with associated data that I need to present both on the map (as markers) and listed below it (as detailed data). The data is sorted with the most important data appearing first. It makes sense that the corresponding marker is also on top of the heap. But by looping through the array, and calling the addMarkers function while appending data to the bottom of the map, the most important marker would be buried under the heap.

Is there a way to reverse the ordering of the markers without having to loop through the data twice?

share|improve this question
loop array from last to first ? – simplexio Oct 30 '12 at 8:27
do you have any code? – CaptDragon Oct 30 '12 at 13:06
up vote 0 down vote accepted

myFeatures.length - i should give you descending ZIndex.

for (var i=0;i<myFeatures.length;i++)
        graphicZIndex: myFeatures.length - i,

Or this will be faster:

var i = myFeatures.length; 
        graphicZIndex: i,
share|improve this answer
Err, I am not sure the more primitive Markers class allow the use of Features class and Style class. But you got the general idea there. I solved it by tackling the z-index in marker.icon.imageDiv instead. Thanks for your help :) – Question Overflow Oct 31 '12 at 3:51

Your Answer


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.