-
Notifications
You must be signed in to change notification settings - Fork 25
/
demo.html
94 lines (71 loc) · 3.09 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
92
93
94
<!DOCTYPE html>
<html>
<head>
<title>Leaflet debug page</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<!-- <script src="./node_modules/leaflet/dist/leaflet-src.js"></script>
<link rel="stylesheet" href="./node_modules/leaflet/dist/leaflet.css" />-->
<link rel="stylesheet" href="https://unpkg.com/[email protected]/dist/leaflet.css"
integrity="sha512-Rksm5RenBEKSKFjgI3a41vrjkw4EVPlJ3+OiI65vTjIdo9brlAacEuKOiQ5OFh7cOI1bkDwLqdLw3Zg0cRJAAQ=="
crossorigin=""/>
<script src="https://unpkg.com/[email protected]/dist/leaflet.js"
integrity="sha512-/Nsx9X4HebavoBvEBuyp3I7od5tA0UzAxs+j83KgC8PU0kgB4XiK4Lfe4y4cgBtaRJQEIFCW+oC506aPT2L1zw=="
crossorigin=""></script>
<script src="./Leaflet.ImageOverlay.Rotated.js"></script>
</head>
<body>
<div id="map" style='width:800px; height:600px;'></div>
<div>
Overlay opacity:
<button onclick='setOverlayOpacity(0.1)'>10%</button>
<button onclick='setOverlayOpacity(0.2)'>20%</button>
<button onclick='setOverlayOpacity(0.3)'>30%</button>
<button onclick='setOverlayOpacity(0.4)'>40%</button>
<button onclick='setOverlayOpacity(0.5)'>50%</button>
<button onclick='setOverlayOpacity(0.6)'>60%</button>
<button onclick='setOverlayOpacity(0.7)'>70%</button>
<button onclick='setOverlayOpacity(0.8)'>80%</button>
<button onclick='setOverlayOpacity(0.9)'>90%</button>
</div>
<script type="text/javascript">
var map = new L.Map('map');
var positron = L.tileLayer('http://{s}.basemaps.cartocdn.com/light_all/{z}/{x}/{y}.png', {
attribution: '© <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors, © <a href="http://cartodb.com/attributions">CartoDB</a>',
maxNativeZoom: 18,
maxZoom:24
}).addTo(map);
var point1 = L.latLng(40.52256691873593, -3.7743186950683594),
point2 = L.latLng(40.5210255066156, -3.7734764814376835),
point3 = L.latLng(40.52180437272552, -3.7768453359603886);
var marker1 = L.marker(point1, {draggable: true} ).addTo(map),
marker2 = L.marker(point2, {draggable: true} ).addTo(map),
marker3 = L.marker(point3, {draggable: true} ).addTo(map);
var bounds = new L.LatLngBounds(point1, point2).extend(point3);
map.fitBounds(bounds);
var overlay = L.imageOverlay.rotated("./palacio-de-el-pardo-821175.jpg", point1, point2, point3, {
opacity: 0.4,
interactive: true,
attribution: "Historical building plan © <a href='http://www.ign.es'>Instituto Geográfico Nacional de España</a>"
});
function repositionImage() {
overlay.reposition(marker1.getLatLng(), marker2.getLatLng(), marker3.getLatLng());
};
marker1.on('drag dragend', repositionImage);
marker2.on('drag dragend', repositionImage);
marker3.on('drag dragend', repositionImage);
// var c = overlay.getCanvas2DContext()
map.addLayer(overlay);
overlay.on('dblclick',function (e) {
console.log('Double click on image.');
e.stop();
});
overlay.on('click',function (e) {
console.log('Click on image.');
});
function setOverlayOpacity(opacity) {
overlay.setOpacity(opacity);
}
</script>
</body>
</html>