2011-10-14 02:31:50 +08:00
|
|
|
<!DOCTYPE html>
|
|
|
|
<html>
|
|
|
|
<head>
|
|
|
|
<title>Leaflet Layers Control Example</title>
|
|
|
|
<meta charset="utf-8" />
|
2012-02-14 23:02:29 +08:00
|
|
|
|
|
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
|
|
|
2015-10-26 18:16:47 +08:00
|
|
|
<link rel="stylesheet" href="http://cdn.leafletjs.com/leaflet/v0.7.7/leaflet.css" />
|
2011-10-14 02:31:50 +08:00
|
|
|
</head>
|
|
|
|
<body>
|
|
|
|
<div id="map" style="width: 600px; height: 400px"></div>
|
|
|
|
|
2015-10-26 18:16:47 +08:00
|
|
|
<script src="http://cdn.leafletjs.com/leaflet/v0.7.7/leaflet.js"></script>
|
2011-10-27 21:37:48 +08:00
|
|
|
<script>
|
2012-07-26 17:17:40 +08:00
|
|
|
var cities = new L.LayerGroup();
|
2011-10-27 21:37:48 +08:00
|
|
|
|
2015-07-08 08:20:26 +08:00
|
|
|
L.marker([39.61, -105.02]).bindPopup('This is Littleton, CO.').addTo(cities),
|
2012-07-26 17:17:40 +08:00
|
|
|
L.marker([39.74, -104.99]).bindPopup('This is Denver, CO.').addTo(cities),
|
|
|
|
L.marker([39.73, -104.8]).bindPopup('This is Aurora, CO.').addTo(cities),
|
|
|
|
L.marker([39.77, -105.23]).bindPopup('This is Golden, CO.').addTo(cities);
|
2011-10-27 21:37:48 +08:00
|
|
|
|
|
|
|
|
2014-04-28 19:16:15 +08:00
|
|
|
var mbAttr = 'Map data © <a href="http://openstreetmap.org">OpenStreetMap</a> contributors, ' +
|
|
|
|
'<a href="http://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>, ' +
|
|
|
|
'Imagery © <a href="http://mapbox.com">Mapbox</a>',
|
2015-07-08 08:20:26 +08:00
|
|
|
mbUrl = 'https://api.tiles.mapbox.com/v4/{id}/{z}/{x}/{y}.png?access_token=pk.eyJ1IjoibWFwYm94IiwiYSI6IjZjNmRjNzk3ZmE2MTcwOTEwMGY0MzU3YjUzOWFmNWZhIn0.Y8bhBaUMqFiPrDRW9hieoQ';
|
2011-10-27 21:37:48 +08:00
|
|
|
|
2015-07-08 08:20:26 +08:00
|
|
|
var grayscale = L.tileLayer(mbUrl, {id: 'mapbox.light', attribution: mbAttr}),
|
|
|
|
streets = L.tileLayer(mbUrl, {id: 'mapbox.streets', attribution: mbAttr});
|
2011-10-27 21:37:48 +08:00
|
|
|
|
2012-07-26 17:17:40 +08:00
|
|
|
var map = L.map('map', {
|
|
|
|
center: [39.73, -104.99],
|
|
|
|
zoom: 10,
|
2014-04-28 19:16:15 +08:00
|
|
|
layers: [grayscale, cities]
|
2012-07-26 17:17:40 +08:00
|
|
|
});
|
2011-10-27 21:37:48 +08:00
|
|
|
|
2012-07-26 17:17:40 +08:00
|
|
|
var baseLayers = {
|
2014-04-28 19:16:15 +08:00
|
|
|
"Grayscale": grayscale,
|
|
|
|
"Streets": streets
|
2011-10-27 21:37:48 +08:00
|
|
|
};
|
|
|
|
|
2012-07-26 17:17:40 +08:00
|
|
|
var overlays = {
|
|
|
|
"Cities": cities
|
2011-10-27 21:37:48 +08:00
|
|
|
};
|
|
|
|
|
2012-07-26 17:17:40 +08:00
|
|
|
L.control.layers(baseLayers, overlays).addTo(map);
|
2011-10-14 02:31:50 +08:00
|
|
|
</script>
|
|
|
|
</body>
|
2012-02-14 23:02:29 +08:00
|
|
|
</html>
|