Giorgi Moniava Giorgi Moniava -4 years ago 118
Javascript Question

Which is base layer out of two tile layers

I can't find docs about it, consider:

// base map
L.tileLayer('http://tiles.mapc.org/basemap/{z}/{x}/{y}.png',
{
attribution: 'Tiles by <a href="http://mapc.org">MAPC</a>,
Data by <a href="http://mass.gov/mgis">MassGIS</a>',
maxZoom: 17,
minZoom: 9
}).addTo(map);

// bike lanes
L.tileLayer('http://tiles.mapc.org/trailmap-onroad/{z}/{x}/{y}.png',
{
maxZoom: 17,
minZoom: 9
}).addTo(map);



  • So we added two tile layers to the map right? But which of the above two is set as a base layer now?
    Can a map have multiple base layers at once? (because I read somewhere base layers normally should be mutually exclusive).

  • Extra: Can I change a base layer without using the layer control mechanism? (e.g. only programatically).


Answer Source

So we added two tile layers to the map right? But which of the above two is set as a base layer now? Can a map have multiple base layers at once? (because I read somewhere base layers normally should be mutually exclusive).

Yes they are mutually exclusive in display so that means you can display only one layer at a time. It's not documented but the last layer added will become the base layer which is being displayed.

Extra: Can I change a base layer without using the layer control mechanism? (e.g. only programatically).

Yes you can using addLayer/removeLayer method.

map.removeLayer(base map layer name here);
map.addLayer(bike lane layer name here);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download