-
Notifications
You must be signed in to change notification settings - Fork 1
/
Demo.html
91 lines (86 loc) · 2.16 KB
/
Demo.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
<!DOCTYPE html>
<html>
<head>
<title>MarkerPreCluster - Demo</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.7.1/dist/leaflet.css"/>
<script src="https://unpkg.com/leaflet@1.7.1/dist/leaflet.js"></script>
<script src="https://unpkg.com/leaflet.markercluster@1.4.1/dist/leaflet.markercluster.js"></script>
<script src="https://unpkg.com/leaflet.markerprecluster@1.0.0/markerprecluster-min.js"></script>
<style>
body {
padding: 0;
margin: 0;
}
html, body, #map {
height: 100%;
width: 100%;
background: white;
}
#map .leaflet-div-icon {
width:0;
height:0;
border: 0;
padding: 0;
}
#map .leaflet-div-icon div {
display:inline-block;
padding: 3px;
border: 1px solid #666;
border-radius: 3px;
background:#fff;
transform:translate(-50%, -50%);
text-align: center;
}
</style>
</head>
<body>
<div id='map'></div>
<script>
const dNode = {
1: "You",
2: "ok?",
0: "Hi!",
};
const lLeaf = [
[[0,1], [2, -2], "Hope"],
[[0,1], [1, -1], "you"],
[[0,1], [0, 0], "like"],
[[0,2], [-1, 1], "that"],
[[0,2], [-2, 2], "Plugin :-)"],
];
const maxDepth = 2;
const bounds = [[-2, -2], [2, 2]];
var map = L.map('map', {
zoom: 0,
center: [0,0],
crs: L.CRS.Simple,
});
map.fitBounds(bounds);
var zoomOffset = map.getZoom();
map.options.minZoom = zoomOffset-maxDepth;
map.options.maxZoom = zoomOffset;
console.error(map.options.minZoom, zoomOffset, map.options.maxZoom)
map.options.zoom = zoomOffset;
var leafs = L.markerClusterGroup({
spiderfyOnMaxZoom: false,
showCoverageOnHover: false,
zoomToBoundsOnClick: true,
singleMarkerMode: false,
iconCreateFunction: function(cluster) {
return L.divIcon({ html: "<div><b>"+ dNode[cluster.nodeID] + '</b><br>(' + cluster.getChildCount() + "children)</div>", iconSize: "auto"});
},
});
for (var info of lLeaf) {
var hierarchy = info[0];
var position = info[1];
var popup = info[2];
var leaf = L.leaf(position, hierarchy).bindTooltip(popup, {permanent: true});
leafs.addLayer(leaf);
}
map.addLayer(leafs);
map.setView([0,0],map.options.minZoom);
</script>
</body>
</html>