mirror of
https://github.com/Leaflet/Leaflet.git
synced 2025-12-08 21:26:14 +00:00
80 lines
2.4 KiB
HTML
80 lines
2.4 KiB
HTML
<!doctype html>
|
|
<html>
|
|
<head>
|
|
<meta charset="utf-8" />
|
|
<title>Leaflet debug page - Vector Bounds</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.esm.js"
|
|
}
|
|
}
|
|
</script>
|
|
</head>
|
|
<body>
|
|
<div id="map"></div>
|
|
<button id="zoomToPath" type="button">Zoom to path</button>
|
|
<button id="zoomToPolygon" type="button">Zoom to polygon</button>
|
|
<script type="module">
|
|
import {TileLayer, Polyline, LatLng, Polygon, Map} from 'leaflet';
|
|
|
|
const osm = new TileLayer('https://tile.openstreetmap.org/{z}/{x}/{y}.png', {maxZoom: 18});
|
|
|
|
/* eslint-disable no-loss-of-precision */
|
|
const polyPoints = [
|
|
[39.70348880963439, -104.98603820800781],
|
|
[39.69926245589766, -104.95582580566406],
|
|
[39.67918374111695, -104.94483947753906],
|
|
[39.663856582926165, -104.95307922363281],
|
|
[39.66279941218785, -104.98672485351562],
|
|
[39.70348880963439, -104.98603820800781]
|
|
];
|
|
|
|
const pathPoints = [
|
|
[39.72567292003209, -104.98672485351562],
|
|
[39.717222671644635, -104.96612548828124],
|
|
[39.71405356154611, -104.95513916015625],
|
|
[39.70982785491674, -104.94758605957031],
|
|
[39.70454535762547, -104.93247985839844],
|
|
[39.696092520737224, -104.91874694824217],
|
|
[39.687638648548635, -104.90432739257812],
|
|
[39.67759833072648, -104.89471435546875]
|
|
];
|
|
|
|
const latlngs = [];
|
|
|
|
for (let i = 0, len = pathPoints.length; i < len; i++) {
|
|
latlngs.push(new LatLng(pathPoints[i][0], pathPoints[i][1]));
|
|
}
|
|
|
|
const path = new Polyline(latlngs);
|
|
const latlngs2 = [];
|
|
|
|
for (let i = 0, len = polyPoints.length; i < len; i++) {
|
|
latlngs2.push(new LatLng(polyPoints[i][0], polyPoints[i][1]));
|
|
}
|
|
|
|
const poly = new Polygon(latlngs2);
|
|
const map = new Map('map', {
|
|
layers: [osm],
|
|
center: new LatLng(39.69596043694606, -104.95084762573242),
|
|
zoom: 12
|
|
});
|
|
|
|
map.addLayer(path);
|
|
map.addLayer(poly);
|
|
|
|
path.bindPopup('Hello world');
|
|
|
|
const zoomToPathBtn = document.getElementById('zoomToPath');
|
|
const zoomToPolygonBtn = document.getElementById('zoomToPolygon');
|
|
|
|
zoomToPathBtn.addEventListener('click', () => map.fitBounds(path.getBounds()));
|
|
zoomToPolygonBtn.addEventListener('click', () => map.fitBounds(poly.getBounds()));
|
|
</script>
|
|
</body>
|
|
</html>
|