Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Document exclusive layer group functionality
- Update example and readme.
- Loading branch information
Showing
3 changed files
with
43 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,72 +1,77 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<title>Basic example</title> | ||
<title>Basic Example</title> | ||
<meta charset="utf-8" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
|
||
<link rel="stylesheet" href="http://cdn.leafletjs.com/leaflet-0.7.2/leaflet.css" /> | ||
<!--[if lte IE 8]><link rel="stylesheet" href="http://cdn.leafletjs.com/leaflet-0.7.2/leaflet.ie.css" /><![endif]--> | ||
<link rel="stylesheet" href="http://cdn.leafletjs.com/leaflet-0.7.3/leaflet.css" /> | ||
<link rel="stylesheet" href="../src/leaflet.groupedlayercontrol.css" /> | ||
|
||
<script src="http://cdn.leafletjs.com/leaflet-0.7.2/leaflet.js"></script> | ||
<script src="../src/leaflet.groupedlayercontrol.js"></script> | ||
</head> | ||
<body> | ||
<div id="map" style="width: 600px; height: 400px"></div> | ||
|
||
<div id="map" style="position:absolute;width:80%;height:50%;"></div> | ||
|
||
<script type="text/javascript"> | ||
|
||
var cities = new L.LayerGroup(); | ||
|
||
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), | ||
<script src="http://cdn.leafletjs.com/leaflet-0.7.3/leaflet.js"></script> | ||
<script src="../src/leaflet.groupedlayercontrol.js"></script> | ||
<script> | ||
var cities = new L.LayerGroup(); | ||
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); | ||
|
||
var restaurants = new L.LayerGroup(); | ||
|
||
L.marker([39.69, -104.85]).bindPopup('A fake restaurant').addTo(restaurants); | ||
L.marker([39.69, -105.12]).bindPopup('A fake restaurant').addTo(restaurants); | ||
|
||
var dogs = new L.LayerGroup(); | ||
L.marker([39.79, -104.95]).bindPopup('A fake restaurant').addTo(dogs); | ||
L.marker([39.79, -105.22]).bindPopup('A fake restaurant').addTo(dogs); | ||
|
||
var cats = new L.LayerGroup(); | ||
L.marker([39.59, -104.75]).bindPopup('A fake restaurant').addTo(cats); | ||
L.marker([39.59, -105.02]).bindPopup('A fake restaurant').addTo(cats); | ||
|
||
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>', | ||
mbUrl = 'https://{s}.tiles.mapbox.com/v3/{id}/{z}/{x}/{y}.png'; | ||
|
||
var cmAttr = 'Map data © 2011 OpenStreetMap contributors, Imagery © 2011 CloudMade', | ||
cmUrl = 'http://{s}.tile.cloudmade.com/BC9A493B41014CAABB98F0471D759707/{styleId}/256/{z}/{x}/{y}.png'; | ||
|
||
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}); | ||
var grayscale = L.tileLayer(mbUrl, {id: 'examples.map-20v6611k', attribution: mbAttr}), | ||
streets = L.tileLayer(mbUrl, {id: 'examples.map-i875mjb7', attribution: mbAttr}); | ||
|
||
var map = L.map('map', { | ||
center: [39.73, -104.99], | ||
zoom: 10, | ||
layers: [minimal, motorways, cities] | ||
layers: [grayscale, cities] | ||
}); | ||
|
||
var baseLayers = { | ||
"Minimal": minimal, | ||
"Night View": midnight | ||
"Grayscale": grayscale, | ||
"Streets": streets | ||
}; | ||
|
||
// Overlay layers are grouped | ||
var groupedOverlays = { | ||
"Landmarks": { | ||
"Motorways": motorways, | ||
"Cities": cities | ||
}, | ||
"Points of Interest": { | ||
"Cities": cities, | ||
"Restaurants": restaurants | ||
}, | ||
"Random": { | ||
"Dogs": dogs, | ||
"Cats": cats | ||
} | ||
}; | ||
|
||
// Make the "Landmarks" group exclusive (use radio inputs) | ||
var options = { exclusiveGroups: ["Landmarks"] }; | ||
|
||
// Use the custom grouped layer control, not "L.control.layers" | ||
var layerControl = L.control.groupedLayers(baseLayers, groupedOverlays); | ||
var layerControl = L.control.groupedLayers(baseLayers, groupedOverlays, options); | ||
map.addControl(layerControl); | ||
|
||
// Remove and add a layer | ||
//layerControl.removeLayer(cities); | ||
//layerControl.addOverlay(cities, "Cities", "New Category"); | ||
|
||
</script> | ||
</body> | ||
</html> |
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.