Leaflet/debug/map/svg-overlay.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

45 lines
1.4 KiB
HTML

<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>Leaflet debug page - SVG Overlay</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" style='width:750px; height: 450px;'></div>
<svg id="image" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 200 200"><rect width="200" height="200"/><rect x="75" y="23" width="50" height="50" style="fill:red"/><rect x="75" y="123" width="50" height="50" style="fill:#0013ff"/></svg>
<script type="module">
import {Map, TileLayer, LatLngBounds, SVGOverlay} from 'leaflet';
const map = new Map('map');
new TileLayer('https://tile.openstreetmap.org/{z}/{x}/{y}.png', {maxZoom: 19}).addTo(map);
const svgElement = document.querySelector('#image');
const bounds = new LatLngBounds([[32, -130], [13, -100]]);
map.fitBounds(bounds);
const overlay = new SVGOverlay(svgElement, bounds, {
opacity: 0.7,
interactive: true
});
map.addLayer(overlay);
const element = overlay.getElement();
element.addEventListener('click', () => console.log('click!'));
</script>
</body>
</html>