7

I'm rendering map with OSM and I have some serious problem with setting zIndex for page elements.

Part of JS looks like this:

var userRoute = new OpenLayers.Layer.Vector( "KML", {
    sphericalMercator : true,
    styleMap: styleMap,
    rendererOptions: { zIndexing: true }
} );

var markers = new OpenLayers.Layer.Markers( "Markers", {
    sphericalMercator : true,
    rendererOptions: { zIndexing: true }
} );

markers.setZIndex( 500 );
userRoute.setZIndex( 200 );

Now while parsing KML file for first element I set

var startFlag = new OpenLayers.Icon( '/start_flag_2.png', new OpenLayers.Size( 23, 22 ) );
markers.addMarker( new OpenLayers.Marker( latlon, startFlag ) )

Same goes for last elem. :

var stopFlag = new OpenLayers.Icon( '/stop_flag_2.png', new OpenLayers.Size( 23, 22 ) );
markers.addMarker( new OpenLayers.Marker( latlon, stopFlag ) )

Setting zIndex is simply ignored by script, any idea why?

Joel
  • 7,401
  • 4
  • 52
  • 58
kamil
  • 3,482
  • 1
  • 40
  • 64
  • 1
    If anyone is intrested, you need to specify zIndex AFTER adding layers to map map.addLayers( [userRoute, markers] ); markers.setZIndex( 1001 ); userRoute.setZIndex( 1000 ); and it works just fine :) – kamil Oct 28 '11 at 12:44
  • Great that you found the solution. :-) Place it as an answer and mark it as solution for other to easily see that it's solved. – Niklas Wulff Oct 31 '11 at 11:44
  • i just couldn't do it earlier cause i cant answer own questions for 8hrs ;) – kamil Oct 31 '11 at 13:44

1 Answers1

19

If anyone is intrested, you need to specify zIndex AFTER adding layers to map

map.addLayers( [userRoute, markers] ); 
markers.setZIndex( 1001 ); 
userRoute.setZIndex( 1000 ); 

and it works just fine :)

kamil
  • 3,482
  • 1
  • 40
  • 64
  • As you have said "you need to specify zIndex AFTER adding layers to map" did the trick! Thank you! – wondim May 28 '15 at 08:22