mirror of
https://github.com/Leaflet/Leaflet.git
synced 2025-12-08 21:26:14 +00:00
Signed-off-by: Jon Koops <jonkoops@gmail.com> Co-authored-by: Florian Bischof <design.falke@gmail.com>
67 lines
1.7 KiB
HTML
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>
|