UNPKG

2.83 kBHTMLView Raw
1<!DOCTYPE html>
2<html>
3<head>
4 <title>Leaflet debug page</title>
5
6 <link rel="stylesheet" href="https://unpkg.com/leaflet@1.0.3/dist/leaflet.css" integrity="sha512-07I2e+7D8p6he1SIM+1twR5TIrhUQn9+I6yjqD53JQjFiMf8EtC93ty0/5vJTZGF8aAocvHYNEDJajGdNx1IsQ==" crossorigin="" />
7 <script src="https://unpkg.com/leaflet@1.0.3/dist/leaflet-src.js" integrity="sha512-WXoSHqw/t26DszhdMhOXOkI7qCiv5QWXhH9R7CgvgZMHz1ImlkVQ3uNsiQKu5wwbbxtPzFXd1hK4tzno2VqhpA==" crossorigin=""></script>
8 <meta name="viewport" content="width=device-width, initial-scale=1.0">
9 <link rel="stylesheet" href="screen.css" />
10
11 <link rel="stylesheet" href="../dist/MarkerCluster.css" />
12 <link rel="stylesheet" href="../dist/MarkerCluster.Default.css" />
13 <script src="../dist/leaflet.markercluster-src.js"></script>
14</head>
15<body>
16
17 <div id="map"></div>
18 <button id="moveone">Move a random marker</button>
19
20 <script type="text/javascript">
21
22 var tiles = L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
23 maxZoom: 18,
24 attribution: '&copy; <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'
25 }),
26 latlng = new L.LatLng(50.5, 30.51);
27
28 var map = new L.Map('map', {center: latlng, zoom: 15, layers: [tiles]});
29
30 var markers = new L.MarkerClusterGroup();
31 var markersList = [];
32
33 function populate() {
34 for (var i = 0; i < 100; i++) {
35 var m = new L.Marker(getRandomLatLng(map), { draggable: true });
36 markersList.push(m);
37 markers.addLayer(m);
38 }
39 return false;
40 }
41 function populateRandomVector() {
42 for (var i = 0, latlngs = [], len = 20; i < len; i++) {
43 latlngs.push(getRandomLatLng(map));
44 }
45 var path = new L.Polyline(latlngs);
46 map.addLayer(path);
47 }
48 function getRandomLatLng(map) {
49 var bounds = map.getBounds(),
50 southWest = bounds.getSouthWest(),
51 northEast = bounds.getNorthEast(),
52 lngSpan = northEast.lng - southWest.lng,
53 latSpan = northEast.lat - southWest.lat;
54
55 return new L.LatLng(
56 southWest.lat + latSpan * Math.random(),
57 southWest.lng + lngSpan * Math.random());
58 }
59
60 markers.on('clusterclick', function (a) {
61 alert('cluster ' + a.layer.getAllChildMarkers().length);
62 });
63 markers.on('click', function (a) {
64 alert('marker ' + a.layer);
65 });
66
67 populate();
68 map.addLayer(markers);
69
70 L.DomUtil.get('moveone').onclick = function () {
71 var m = markersList[Math.floor(Math.random() * markersList.length)];
72 var bounds = map.getBounds(),
73 southWest = bounds.getSouthWest(),
74 northEast = bounds.getNorthEast(),
75 lngSpan = northEast.lng - southWest.lng,
76 latSpan = northEast.lat - southWest.lat;
77 m.setLatLng(new L.LatLng(
78 southWest.lat + latSpan * 0.5,
79 southWest.lng + lngSpan * 0.5));
80 };
81 </script>
82</body>
83</html>