Leaflet/debug/vector/rectangle.html
Jon Koops 7ac98758d4
Drop UMD and make ESM the default entrypoint (#8826)
Signed-off-by: Jon Koops <jonkoops@gmail.com>
Co-authored-by: Florian Bischof <design.falke@gmail.com>
2025-03-17 15:59:00 +01:00

61 lines
1.7 KiB
HTML

<!doctype html>
<html>
<head>
<meta charset="utf-8" />
<title>Leaflet debug page - Rectangle</title>
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=0" />
<link rel="stylesheet" href="../../dist/leaflet.css" />
<link rel="stylesheet" href="../css/screen.css" />
<script type="importmap">
{
"imports": {
"leaflet": "../../dist/leaflet-src.js"
}
}
</script>
</head>
<body>
<div id="map"></div>
<button id="resetBounds" type="button">
Set blue rectangle bounds as current map extent.
</button>
<script type="module">
import {TileLayer, LatLngBounds, LatLng, Rectangle, Map} from 'leaflet';
const osm = new TileLayer('https://tile.openstreetmap.org/{z}/{x}/{y}.png', {maxZoom: 18});
const bounds = new LatLngBounds(new LatLng(54.559322, -5.767822), new LatLng(56.1210604, -3.021240));
const bounds2 = new LatLngBounds(new LatLng(56.2124322195806, -3.427734375), new LatLng(56.307776937156945, -3.2560729980468746));
const rectangle = new Rectangle(bounds);
const styledRectangle = new Rectangle(bounds2, {
fillColor: '#ff7800',
color: '#000000',
opacity: 1,
weight: 2
});
rectangle.on('click', () => {
alert('you clicked a rectangle.');
});
rectangle.bindPopup('I\'m a rectangle!');
const map = new Map('map', {
center: bounds.getCenter(),
zoom: 7,
layers: [osm]
});
map.addLayer(rectangle).addLayer(styledRectangle);
const resetBoundsBtn = document.getElementById('resetBounds');
resetBoundsBtn.addEventListener('click', resetBounds);
function resetBounds() {
rectangle.setBounds(map.getBounds());
}
</script>
</body>
</html>