Debian Codegraph @

example/old-bugs/doesnt-update-cluster-on-bottom-level.html

raw
1 <!DOCTYPE html>
2 <html>
3 <head>
4 <title>Leaflet debug page</title>
5
6 <link rel="stylesheet" href="https://unpkg.com/[email protected]/dist/leaflet.css" integrity="sha512-07I2e+7D8p6he1SIM+1twR5TIrhUQn9+I6yjqD53JQjFiMf8EtC93ty0/5vJTZGF8aAocvHYNEDJajGdNx1IsQ==" crossorigin="" />
7 <script src="https://unpkg.com/[email protected]/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="../../src/DistanceGrid.js"></script>
14 <script src="../../src/MarkerCluster.js"></script>
15 <script src="../../src/MarkerClusterGroup.js"></script>
16 <script src="../../src/MarkerCluster.QuickHull.js"></script>
17 <script src="../../src/MarkerCluster.Spiderfier.js"></script>
18 </head>
19 <body>
20
21 <div id="map"></div>
22 <button id="doit">AddMarker</button><button id="doit2">Add by Timer</button><br/>
23 <span>Bug <a href="https://github.com/danzel/Leaflet.markercluster/issues/114">#114</a>. Markers are added to the map periodically using addLayers. Bug was that after becoming a cluster (size 2 or 3 usually) they would never change again even if more markers were added to them.</span><br/>
24
25 <script type="text/javascript">
26
27 var tiles = L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
28 maxZoom: 18,
29 attribution: '&copy; <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'
30 }),
31 latlng = new L.LatLng(40.782982, -73.969452);
32
33 var map = new L.Map('map', {
34 center: latlng,
35 zoom: 12,
36 maxZoom: 12,
37 layers: [tiles]
38 });
39
40 var markerCluster = new L.MarkerClusterGroup();
41 map.addLayer(markerCluster);
42
43 function getRandomLatLng() {
44 return [
45 40.782982 + (Math.random() > 0.5 ? 0.5 : -0.5) * Math.random(),
46 -73.969452 + (Math.random() > 0.5 ? 0.5 : -0.5) * Math.random()
47 ];
48 }
49
50 document.getElementById('doit').onclick = function () {
51 markerCluster.addLayers([new L.Marker(map.getCenter())]);
52 };
53 document.getElementById('doit2').onclick = function () {
54 setInterval(function () {
55 var n = 100;
56 var markers = new Array();
57
58 for (var i = 0; i < n; i++) {
59 markers.push(L.marker(getRandomLatLng()));
60 }
61
62 markerCluster.addLayers(markers);
63
64 }, 1000);
65 };
66
67 </script>
68 </body>
69 </html>