/
githubmirror
/
Leaflet
Обзор
Документация
Войти
/
githubmirror
/
Leaflet
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
debug/vector/rectangle.html
60 строк
2 KB
Simon Legner
Rename `Map` to `LeafletMap` and keep `Map` as alias (#9892)
11 ноя 2025, 21:28
Не верифицирован
11 ноя 2025, 21:28
2e9b617
Код
Авторство
О чём код?
<!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, LeafletMap} 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 LeafletMap('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>