Skip to content

Instantly share code, notes, and snippets.



Last active Sep 1, 2018
What would you like to do?
Overlay example for leaflet.js

An example of using leaflet.js with multiple tile layers and an overlay.

<!DOCTYPE html>
<title>Simple Leaflet Map</title>
<meta charset="utf-8" />
<div id="map" style="width: 600px; height: 400px"></div>
var coolPlaces = new L.LayerGroup();
L.marker([-41.29042, 174.78219])
.bindPopup('Te Papa').addTo(coolPlaces),
L.marker([-41.29437, 174.78405])
.bindPopup('Embassy Theatre').addTo(coolPlaces),
L.marker([-41.2895, 174.77803])
.bindPopup('Michael Fowler Centre').addTo(coolPlaces),
L.marker([-41.28313, 174.77736])
.bindPopup('Leuven Belgin Beer Cafe').addTo(coolPlaces),
[-41.28313, 174.77736],
[-41.2895, 174.77803],
[-41.29042, 174.78219],
[-41.29437, 174.78405]
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
var overlays = {
"Interesting places": coolPlaces

This comment has been minimized.

Copy link

@pachecoder pachecoder commented Mar 11, 2014

Thanks, this really help me.


This comment has been minimized.

Copy link

@viniciusmaeda viniciusmaeda commented Oct 7, 2016

Excellent!!! Thanks!


This comment has been minimized.

Copy link

@danhillcode danhillcode commented Jun 30, 2017

Do you know how to add an icon or colour within this box? thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment