Leaflet/debug/tests/opacity.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

67 lines
1.7 KiB
HTML

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Leaflet debug page - Opacity</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" />
<style>
.mybox {
background-color: red;
}
</style>
<script type="importmap">
{
"imports": {
"leaflet": "../../dist/leaflet-src.js"
}
}
</script>
</head>
<body>
<div id="map"></div>
<script type="module">
import {TileLayer, LatLng, Map, DivIcon, Point, Marker} from 'leaflet';
const osm = new TileLayer('https://tile.openstreetmap.org/{z}/{x}/{y}.png', {maxZoom: 18});
const latlng = new LatLng(50.5, 30.51);
const map = new Map('map', {center: latlng, zoom: 15, layers: [osm]});
// Create a marker, clicking it toggles opacity
const opaqueIcon = new DivIcon({
className: 'mybox',
iconSize: new Point(100, 100),
html: 'opaque. click to toggle',
});
const transparentIcon = new DivIcon({
className: 'mybox',
iconSize: new Point(100, 100),
html: 'transparent',
});
const marker = new Marker(latlng, {icon: opaqueIcon});
map.addLayer(marker);
let visible = true;
marker.on('click', () => {
if (visible) {
marker.setOpacity(0.3);
marker.setIcon(transparentIcon);
} else {
marker.setOpacity(1);
marker.setIcon(opaqueIcon);
}
visible = !visible;
});
const marker2 = new Marker(new LatLng(50.5, 30.52));
map.addLayer(marker2);
marker2.bindPopup(
'This is an amazing message. I shouldn\'t of deleted the Ipsum text'
);
</script>
</body>
</html>