forked from gn00672312/leaflet-image
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
71 lines (66 loc) · 1.75 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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8 />
<title>Leaflet Image</title>
<meta name='viewport' content='initial-scale=1,maximum-scale=1,user-scalable=no' />
<script src='https://api.tiles.mapbox.com/mapbox.js/v2.4.0/mapbox.js'></script>
<link href='https://api.tiles.mapbox.com/mapbox.js/v2.4.0/mapbox.css' rel='stylesheet' />
<style>
body { margin:0; padding:0; }
#map { position:absolute; top:0; bottom:0; width:100%; }
</style>
</head>
<body>
<style>
.ui-button {
position:absolute;
top:10px;
right:10px;
z-index:1000;
}
#map {
width:50%;
}
#snapshot {
position:absolute;
top:0;bottom:0;right:0;
width:50%;
}
</style>
<button id='snap' class='ui-button'>Take a snapshot</button>
<div id='snapshot'></div>
<div id='map'></div>
<script src='https://api.tiles.mapbox.com/mapbox.js/plugins/leaflet-heat/v0.1.0/leaflet-heat.js'></script>
<script src='leaflet-image.js'></script>
<script>
var snapshot = document.getElementById('snapshot');
var map = L.mapbox.map('map')
.setView([38.88995, -77.00906], 15);
document.getElementById('snap').addEventListener('click', function() {
leafletImage(map, doImage);
});
function doImage(err, canvas) {
var img = document.createElement('img');
var dimensions = map.getSize();
img.width = dimensions.x;
img.height = dimensions.y;
img.src = canvas.toDataURL();
snapshot.innerHTML = '';
snapshot.appendChild(img);
}
var heat = L.heatLayer([], {maxZoom: 18}).addTo(map);
var draw = true;
// add points on mouse move (except when interacting with the map)
map.on({
movestart: function () { draw = false; },
moveend: function () { draw = true; },
mousemove: function (e) {
if (draw) {
heat.addLatLng(e.latlng);
}
}
})
</script>
</body>
</html>