-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathindex.html
55 lines (47 loc) · 1.76 KB
/
index.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
<html lang="en">
<head>
<meta charset="UTF-8"></meta>
<title>index</title>
<link rel="stylesheet" href="static/lib/leaflet.css" />
<script src="static/lib/leaflet-src.js"></script>
<script src="Leaflet.Canvas-Marker-layer.js"></script>
</head>
<body>
<div id='map' style="width: 100%;height: 100%;"></div>
<script>
const map = L.map('map').setView([59.9578,30.2987], 10);
const tiles = L.tileLayer('http://{s}.tile.osm.org/{z}/{x}/{y}.png', {
attribution: '© <a href="http://osm.org/copyright">OpenStreetMap</a> contributors',
preferCanvas: true
}).addTo(map);
const ciLayer = L.canvasMarkerLayer({
userDrawFunc: function(layer, marker, pointPos, size){
const ctx = layer._context;
const number = marker.properties.number;
ctx.beginPath();
ctx.fillStyle = 'rgba(255,0,0,0.8)';
ctx.fillRect(pointPos.x-size[0]/2, pointPos.y-size[1]/2, size[0], size[1]);
ctx.font = '12px Helvetica Neue';
ctx.fillStyle = '#000';
ctx.fillText(number, pointPos.x, pointPos.y+size[1]/4);
ctx.textAlign='center';
ctx.closePath();
}
}).addTo(map);
ciLayer.addOnClickListener(function (e,data) {console.log(data)});
ciLayer.addOnHoverListener(function (e,data) {console.log(data[0].data._leaflet_id)});
const markers = [];
for (let i = 0; i < 10000; i++) {
let marker = L.marker([58.5578 + Math.random()*1.8, 29.0087 + Math.random()*3.6],
{
icon: L.icon({
iconSize: [40, 20]
})
}).bindPopup("I Am "+i);
marker.properties = { number: i };
markers.push(marker);
}
ciLayer.addLayers(markers);
</script>
</body>
</html>