<!DOCTYPE html>
<html>
<head>
<title>Leaflet</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link type="text/css" rel="stylesheet" href="https://unpkg.com/leaflet@1.3.1/dist/leaflet.css" />
<style>
html,
body,
#leaflet {
height: 90%
}
</style>
</head>
<body>
<button id="hidem">Hide</button>
<button id="showm">Show</button>
<div id="leaflet"></div>
<script src="https://unpkg.com/leaflet@1.3.1/dist/leaflet-src.js"></script>
<script>
var map = L.map('leaflet', {
layers: [
L.tileLayer('//{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
'attribution': 'Map data © <a href="http://openstreetmap.org">OpenStreetMap</a> contributors'
})
],
center: [48.85, 2.35],
zoom: 12
});
// Example adapted from http://jsfiddle.net/b7LgG/3/
// provided by @danzel https://github.com/Leaflet/Leaflet/issues/4#issuecomment-35025365
// Images from Leaflet Custom Icons tutorial http://leafletjs.com/examples/custom-icons/
//We don't use shadows as you can't currently specify what pane shadows end up in
//Create panes for each of the sets of markers
var pane1 = map.createPane('markers1');
var pane2 = map.createPane('markers2');
populate();
function hide() {
pane2.style.display = 'none';
}
function show() {
pane2.style.display = '';
}
L.DomUtil.get('hidem').onclick = hide;
L.DomUtil.get('showm').onclick = show;
//Add 200 markers to each of the groups/layers
function populate() {
for (var i = 0; i < 200; i++) {
L.circleMarker(getRandomLatLng(), {
pane: 'markers1',
"radius": 5,
"fillColor": "#ff7800",
"color": "#ff7800",
"weight": 1,
"opacity": 1
}).addTo(map);
L.circleMarker(getRandomLatLng(), {
pane: 'markers2',
"radius": 5,
"fillColor": "#012999",
"color": "#012999",
"weight": 1,
"opacity": 1
}).addTo(map);
}
return false;
}
function getRandomLatLng() {
return [
48.8 + 0.1 * Math.random(),
2.25 + 0.2 * Math.random()
];
}
</script>
</body>
</html>