4

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?

2
  • 3
    loop array from last to first ? Commented Oct 30, 2012 at 8:27
  • do you have any code?
    – CaptDragon
    Commented Oct 30, 2012 at 13:06

1 Answer 1

0

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; 
while(i--)
{
    ...
        graphicZIndex: i,
    ...
}
1
  • 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 :) Commented Oct 31, 2012 at 3:51

Your Answer

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

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