File: rectangle.html

package info (click to toggle)
leaflet 1.7.1~dfsg-7
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 16,996 kB
  • sloc: javascript: 16,627; makefile: 48; xml: 23; sh: 21
file content (54 lines) | stat: -rw-r--r-- 1,483 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
<!DOCTYPE html>
<html>
<head>
	<title>Leaflet debug page</title>

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

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

	<script src="../leaflet-include.js"></script>
</head>
<body>

	<div id="map" style="width: 500px; height: 500px;"></div>
	<input type="button" value="Set blue rectangle bounds as current map extent." onclick="resetBounds();" />

	<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});

		var bounds = new L.LatLngBounds(new L.LatLng(54.559322, -5.767822), new L.LatLng(56.1210604, -3.021240));
		var bounds2 = new L.LatLngBounds(new L.LatLng(56.2124322195806, -3.427734375), new L.LatLng(56.307776937156945, -3.2560729980468746));

		var rectangle = new L.Rectangle(bounds);
		var styledRectangle = new L.Rectangle(bounds2, {
			fillColor: "#ff7800",
			color: "#000000",
			opacity: 1,
			weight: 2
		});

		rectangle.on("click", function () {
			alert("you clicked a rectangle.")
		});

		rectangle.bindPopup('I\'m a rectangle!');

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

		map.addLayer(rectangle).addLayer(styledRectangle);

		function resetBounds() {
			rectangle.setBounds(map.getBounds());
		}

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