Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Leaflet layer ordering

Tags:

leaflet

I'm having problems about the layer ordering in leaflet. I've followed this page http://leafletjs.com/examples/layers-control.html

exact question would be... how can I reorder the layers (foreground background etc).

Lets say, one of my "base layers" is made of semi transparent tiles, and I want to see the "overlay layers" through my base layer (it should be at the foreground)

Depending on the page example, here is a snippet to explain more about the issue:

var baseMaps = {
    "Minimal": minimal,
    "Night View": midnight,
    "My Custom Layer": customlayer
};

var overlayMaps = {
    "Motorways": motorways,
    "Cities": cities
};

In other words, I would like to know how to set "My Custom Layer" as the layer that will be at the foreground (above overlayMaps).

I've tried setting zindex values of layers, didn't help.

Thanks.

like image 598
Mia Avatar asked Jan 22 '13 18:01

Mia


2 Answers

The layers control has two sets of layers, the set of base layers and the set of overlay layers. The overlay layers will be drawn on top of the base layers. So generally, you'll want to add your transparent layer to the overlay layers.

The autoZIndex option, which is by default On, specifies that the control must assign z indices to each of its layers in the order in which they are added, and that means they'll be drawn in that order.

See http://leafletjs.com/reference.html#control-layers

like image 109
flup Avatar answered Nov 12 '22 09:11

flup


Sets the zIndex of the tile layer.

setZIndex( <Number> zIndex )

myLayer1.setZIndex(4);
myLayer2.setZIndex(5);

Layer 2 over Layer 1

like image 37
Kenyo Joel Avatar answered Nov 12 '22 10:11

Kenyo Joel