Skip to content

Instantly share code, notes, and snippets.

@d3noob d3noob/index.html

Last active Oct 8, 2019
What would you like to do?
Multiple tile layers in leaflet.js

An example of using leaflet.js with multiple tile layers.

<!DOCTYPE html>
<title>Simple Leaflet Map</title>
<meta charset="utf-8" />
<div id="map" style="width: 600px; height: 400px"></div>
var osmLink = '<a href="">OpenStreetMap</a>',
thunLink = '<a href="">Thunderforest</a>';
var osmUrl = 'http://{s}{z}/{x}/{y}.png',
osmAttrib = '&copy; ' + osmLink + ' Contributors',
landUrl = 'http://{s}{z}/{x}/{y}.png',
thunAttrib = '&copy; '+osmLink+' Contributors & '+thunLink;
var osmMap = L.tileLayer(osmUrl, {attribution: osmAttrib}),
landMap = L.tileLayer(landUrl, {attribution: thunAttrib});
var map ='map', {
layers: [osmMap] // only add one!
.setView([-41.2858, 174.78682], 14);
var baseLayers = {
"OSM Mapnik": osmMap,
"Landscape": landMap
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.