Leaflet/examples/layers-control-example.html

52 lines
1.6 KiB
HTML
Raw Normal View History

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">
2011-10-14 02:31:50 +08:00
<link rel="stylesheet" href="../dist/leaflet.css" />
<!--[if lte IE 8]><link rel="stylesheet" href="../dist/leaflet.ie.css" /><![endif]-->
</head>
<body>
<div id="map" style="width: 600px; height: 400px"></div>
<script src="../dist/leaflet.js"></script>
<script>
2012-07-26 17:17:40 +08:00
var cities = new L.LayerGroup();
2012-07-26 17:17:40 +08:00
L.marker([39.61, -105.02]).bindPopup('This is Littleton, CO.').addTo(cities),
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);
2012-07-26 17:17:40 +08:00
var cmAttr = 'Map data &copy; 2011 OpenStreetMap contributors, Imagery &copy; 2011 CloudMade',
cmUrl = 'http://{s}.tile.cloudmade.com/BC9A493B41014CAABB98F0471D759707/{styleId}/256/{z}/{x}/{y}.png';
2012-07-26 17:17:40 +08:00
var minimal = L.tileLayer(cmUrl, {styleId: 22677, attribution: cmAttr}),
midnight = L.tileLayer(cmUrl, {styleId: 999, attribution: cmAttr}),
motorways = L.tileLayer(cmUrl, {styleId: 46561, attribution: cmAttr});
2012-07-26 17:17:40 +08:00
var map = L.map('map', {
center: [39.73, -104.99],
zoom: 10,
layers: [minimal, motorways, cities]
});
2012-07-26 17:17:40 +08:00
var baseLayers = {
"Minimal": minimal,
2012-07-26 17:17:40 +08:00
"Night View": midnight
};
2012-07-26 17:17:40 +08:00
var overlays = {
"Motorways": motorways,
2012-07-26 17:17:40 +08:00
"Cities": cities
};
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>