File: mousemove_on_polygons.html

package info (click to toggle)
leaflet 1.7.1~dfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 16,972 kB
  • sloc: javascript: 16,627; makefile: 49; sh: 26; xml: 23
file content (106 lines) | stat: -rw-r--r-- 2,890 bytes parent folder | download | duplicates (3)
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
95
96
97
98
99
100
101
102
103
104
105
106
<!DOCTYPE html>
<html>
<head>
	<title>Leaflet debug page</title>

	<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">

	<link rel="stylesheet" href="../../dist/leaflet.css" />

	<link rel="stylesheet" href="../css/screen.css" />
	<style>
		.mybox {
			background-color: red;
		}
		td {
			border: transparent solid 2px;
		}
		td.red {
			border: red solid 2px;
		}
		td.updated {
			border: transparent solid 2px;
			animation-name: borderfade;
			animation-duration: 0.5s;
		}
		
		@keyframes borderfade {
			from {
				border: red solid 2px;
			}
			to {
				border: transparent solid 2px;
			}
		}
	</style>
	<script src="../leaflet-include.js"></script>
	<table>
	<tr><td>           </td><td>Enter       </td><td>Move       </td><td>Exit       </td><td>Click       </td></tr>
	<tr><td>Triangle 1:</td><td id='enter1'></td><td id='move1'></td><td id='exit1'></td><td id='click1'></td></tr>
	<tr><td>Triangle 2:</td><td id='enter2'></td><td id='move2'></td><td id='exit2'></td><td id='click2'></td></tr>
	<tr><td>Map:       </td><td id='enter3'></td><td id='move3'></td><td id='exit3'></td><td id='click3'></td></tr>
	</table>
</head>
<body>

	<div id="map"></div>

	<script>

		var osmUrl = 'https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png',
			osmAttrib = '&copy; <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors',
			osm = L.tileLayer(osmUrl, {maxZoom: 18, attribution: osmAttrib}),
			latlng = new L.LatLng(39.05, 8.40);

		var map = new L.Map('map', {center: latlng, zoom: 12, layers: [osm]});

		function update(domid) {
			return function(){
				document.getElementById(domid).innerHTML = Date.now();
				document.getElementById(domid).className = 'red';
				window.setTimeout(function(){
					document.getElementById(domid).className = 'updated';
				},1);
			}
		}
		
		var polygon = (new L.Polygon([
			[39, 8.40],
			[39.10, 8.50],
			[39.05, 8.30]
		])).addTo(map).on('mouseover',update('enter1'))
			.on('mousemove',update('move1'))
			.on('mouseout',update('exit1'))
			.on('click',update('click1'))
			.bindPopup('Triangle 1');
		
		var polygon2 = (new L.Polygon([
			[39.03, 8.30],
			[39.10, 8.40],
			[39.00, 8.30]
		])).addTo(map).on('mouseover',update('enter2'))
			.on('mousemove',update('move2'))
			.on('mouseout',update('exit2'))
			.on('click',update('click2'))
			.bindPopup('Triangle 2');

		
		var marker = new L.Marker(latlng, {draggable: true})
			.bindPopup('Marker');;
		map.addLayer(marker);
		

// 		map.on('mousemove', function (e) {
// 			marker.setLatLng(e.latlng);
// 		});
		map.on('mouseover',update('enter3'))
			.on('mousemove',update('move3'))
			.on('mouseout',update('exit3'))
			.on('click',update('click3'));
		
		// We should be able to move marker around in a fluid way,
		// plus going over the polygon with no issue.

	</script>
</body>
</html>