/
githubmirror
/
Leaflet
Обзор
Документация
Войти
/
githubmirror
/
Leaflet
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
debug/tests/event-perf-2.html
74 строки
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 - Event Perf 2</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> <script type="module"> import {LeafletMap, TileLayer, FeatureGroup, LatLng, Marker} from 'leaflet'; /* * Can be used to profile performance of event system. * Start the test, start CPU profiler. Slowly move the * mouse around over the map for 20 seconds or so, stop * profiler and examine times for _on, _off and fire. */ const map = new LeafletMap('map').setView([50.5, 30.51], 15); new TileLayer('https://tile.openstreetmap.org/{z}/{x}/{y}.png', {maxZoom: 18}).addTo(map); const markers = new FeatureGroup().addTo(map); const markerArr = []; function getRandomLatLng(llbounds) { const s = llbounds.getSouth(); const n = llbounds.getNorth(); const w = llbounds.getWest(); const e = llbounds.getEast(); return new LatLng( s + Math.random() * (n - s), w + Math.random() * (e - w) ); } function shuffleMarkers() { let marker; if (markerArr.length > 2000) { const i = Math.floor(Math.random() * markerArr.length); marker = markerArr.splice(i, 1)[0]; markers.removeLayer(marker); } else { marker = new Marker(getRandomLatLng(map.getBounds())) .on('pointerover', () => { marker.setZIndexOffset(10000); }) .on('pointerout', () => { marker.setZIndexOffset(0); }) .addTo(markers); markerArr.push(marker); } } while (markerArr.length < 2000) { shuffleMarkers(); } setInterval(shuffleMarkers, 20); </script> </body> </html>