Debian Codegraph @

example/marker-clustering-custom.html

raw ◀ ▶
1 Debian patch touch this file
1 <!DOCTYPE html>
2 <html>
3 <head>
4 <title>Leaflet debug page</title>
5
•6 <link rel="stylesheet" href="/usr/share/javascript/leafletleaflet.css" integrity="sha512-07I2e+7D8p6he1SIM+1twR5TIrhUQn9+I6yjqD53JQjFiMf8EtC93ty0/5vJTZGF8aAocvHYNEDJajGdNx1IsQ==" crossorigin="" />
7 <script src="/usr/share/javascript/leafletleaflet-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="/usr/share/javascript/leaflet/MarkerCluster.css" />
12 <script src="/usr/share/javascript/leaflet/leaflet.markercluster-src.js"></script>
13
14 <style>
15 .mycluster {
16 width: 40px;
17 height: 40px;
18 background-color: greenyellow;
19 text-align: center;
20 font-size: 24px;
21 }
22
23 </style>
24 </head>
25 <body>
26
27 <div id="map"></div>
28
29 <script type="text/javascript">
30
31 var tiles = L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
32 maxZoom: 18,
33 attribution: '&copy; <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'
34 }),
35 latlng = L.latLng(50.5, 30.51);
36
37 var map = L.map('map', {center: latlng, zoom: 15, layers: [tiles]});
38
39
40 //Custom radius and icon create function
41 var markers = L.markerClusterGroup({
42 maxClusterRadius: 120,
43 iconCreateFunction: function (cluster) {
44 var markers = cluster.getAllChildMarkers();
45 var n = 0;
46 for (var i = 0; i < markers.length; i++) {
47 n += markers[i].number;
48 }
49 return L.divIcon({ html: n, className: 'mycluster', iconSize: L.point(40, 40) });
50 },
51 //Disable all of the defaults:
52 spiderfyOnMaxZoom: false, showCoverageOnHover: false, zoomToBoundsOnClick: false
53 });
54
55
56 function populate() {
57 for (var i = 0; i < 100; i++) {
58 var m = L.marker(getRandomLatLng(map), { title: i });
59 m.number = i;
60 markers.addLayer(m);
61 }
62 return false;
63 }
64 function populateRandomVector() {
65 for (var i = 0, latlngs = [], len = 20; i < len; i++) {
66 latlngs.push(getRandomLatLng(map));
67 }
68 var path = L.polyline(latlngs);
69 map.addLayer(path);
70 }
71 function getRandomLatLng(map) {
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
78 return L.latLng(
79 southWest.lat + latSpan * Math.random(),
80 southWest.lng + lngSpan * Math.random());
81 }
82
83 populate();
84 map.addLayer(markers);
85
86
87
88 var shownLayer, polygon;
89
90 function removePolygon() {
91 if (shownLayer) {
92 shownLayer.setOpacity(1);
93 shownLayer = null;
94 }
95 if (polygon) {
96 map.removeLayer(polygon);
97 polygon = null;
98 }
99 };
100
101 markers.on('clustermouseover', function (a) {
102 removePolygon();
103
104 a.layer.setOpacity(0.2);
105 shownLayer = a.layer;
106 polygon = L.polygon(a.layer.getConvexHull());
107 map.addLayer(polygon);
108 });
109 markers.on('clustermouseout', removePolygon);
110 map.on('zoomend', removePolygon);
111
112 </script>
113 </body>
114 </html>