Leaflet/debug/map/control-layers.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

62 lines
1.7 KiB
HTML

<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>Leaflet debug page - Control Layers</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>
<style>
.grayscale-tile {
filter: grayscale(1);
}
</style>
<script type="module">
import {Map, TileLayer, Control, Circle, Polygon, GeoJSON} from 'leaflet';
const GrayscaleTileLayer = TileLayer.extend({
createTile(...args) {
const element = TileLayer.prototype.createTile.call(this, ...args);
element.classList.add('grayscale-tile');
return element;
}
});
const map = new Map('map').setView([50.5, 0], 5);
const tileUrl = 'https://tile.openstreetmap.org/{z}/{x}/{y}.png';
const regularTiles = new TileLayer(tileUrl).addTo(map);
const blackAndWhiteTiles = new GrayscaleTileLayer(tileUrl);
new Control.Layers({
'OSM': regularTiles,
'OSM BW': blackAndWhiteTiles
}, {
'Circle': new Circle([53, 4], 111111).addTo(map),
'Polygon': new Polygon([[48, -3], [50, -4], [52, 4]]),
'GeoJSON': new GeoJSON({
type: 'Polygon',
coordinates: [[
[5.4931640625, 51.781435604431195],
[0.9008789062499999, 53.35710874569601],
[-2.30712890625, 51.795027225829145],
[2.8125, 49.109837790524416],
[5.4931640625, 51.781435604431195]
]]
}),
}, {
collapsed: false
}).addTo(map);
</script>
</body>
</html>