mirror of
https://github.com/Leaflet/Leaflet.git
synced 2025-08-16 16:45:22 +00:00

Signed-off-by: Jon Koops <jonkoops@gmail.com> Co-authored-by: Florian Bischof <design.falke@gmail.com>
66 lines
3.6 KiB
HTML
66 lines
3.6 KiB
HTML
<!doctype html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="utf-8" />
|
|
<title>Leaflet debug page - Tooltip</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>
|
|
<style type="text/css">
|
|
.my-div-icon {
|
|
background-color: goldenrod;
|
|
text-align: center;
|
|
}
|
|
#map {
|
|
width: 100%;
|
|
}
|
|
</style>
|
|
<div id="map"></div>
|
|
<script type="module">
|
|
import {Map, TileLayer, Polygon, Marker, CircleMarker, DivIcon, FeatureGroup, Polyline} from 'leaflet';
|
|
|
|
const center = [41.2058, 9.4307];
|
|
const map = new Map('map').setView(center, 13);
|
|
|
|
new TileLayer('https://tile.openstreetmap.org/{z}/{x}/{y}.png').addTo(map);
|
|
|
|
new Polygon([[41.21, 9.42], [41.22, 9.40], [41.23, 9.40]]).addTo(map).bindTooltip('Default centered polygon tooltip');
|
|
new Polygon([[41.20, 9.41], [41.20, 9.39], [41.21, 9.40]]).addTo(map).bindTooltip('Polygon tooltip following mouse', {sticky: true});
|
|
new Polygon([[41.18, 9.42], [41.17, 9.40], [41.19, 9.38]]).addTo(map).bindTooltip('Permanent polygon tooltip', {permanent: true});
|
|
new Marker([41.20, 9.4307]).addTo(map).bindTooltip('tooltip on the left', {direction: 'left'});
|
|
new Marker([41.206, 9.44]).addTo(map).bindTooltip('click me, I have a popup', {permanent: true, interactive: true}).bindPopup('See?');
|
|
new CircleMarker([41.206, 9.48], {color: 'Chocolate', radius: 12}).addTo(map).bindTooltip('Hello Left World', {direction: 'left'});
|
|
new CircleMarker([41.20, 9.50], {color: 'Chocolate', radius: 12}).addTo(map).bindTooltip('Hello top World', {direction: 'top', permanent: true});
|
|
new CircleMarker([41.20, 9.47], {color: 'Tomato', radius: 10}).addTo(map).bindTooltip('Seems I am centered', {direction: 'center', permanent: true, interactive: true}).bindPopup('Yeah');
|
|
new CircleMarker([41.195, 9.47], {color: 'Tomato', radius: 10}).addTo(map).bindTooltip('Me too', {direction: 'center'}).bindPopup('Yeah');
|
|
const icon = new DivIcon({
|
|
className: 'my-div-icon',
|
|
html: '<p>A div icon</p>',
|
|
iconSize: [50, 50]
|
|
});
|
|
new Marker([41.22, 9.48], {icon}).addTo(map).bindTooltip('A div icon tooltip following mouse', {sticky: true, direction: 'auto'});
|
|
new Marker([41.23, 9.47], {icon}).addTo(map).bindTooltip('A div icon tooltip with custom offset', {direction: 'top', offset: [-25, -25]});
|
|
new Marker([41.23, 9.42], {draggable: true}).addTo(map).bindTooltip('Draggable marker tooltip', {permanent: true, direction: 'auto'});
|
|
new Marker([41.19, 9.43]).addTo(map).bindTooltip('Clickable marker tooltip', {permanent: true, interactive: true}).on('click', () => { alert('clicked!'); });
|
|
|
|
const marker1 = new Marker([41.18, 9.45], {description: 'Marker 1'});
|
|
const marker2 = new Marker([41.18, 9.46], {description: 'Marker 2'});
|
|
const group = new FeatureGroup([marker1, marker2]).addTo(map);
|
|
group.bindTooltip(layer => `Group tooltip: ${layer.options.description}`, {opacity: 0.7});
|
|
new Marker([41.18, 9.35]).addTo(map).bindTooltip('Top tooltip is top', {permanent: true, direction: 'top'});
|
|
new Marker([41.173, 9.37]).addTo(map).bindTooltip('Bottom tooltip is weird but ok', {permanent: true, direction: 'bottom'});
|
|
new Polyline([[41.20, 9.36], [41.205, 9.35], [41.19, 9.34]]).bindTooltip('Polyline tooltip', {permanent: true, direction: 'top'}).addTo(map);
|
|
new Polygon([[41.21, 9.36], [41.24, 9.35], [41.23, 9.34]]).addTo(map).bindTooltip('Top tooltip following mouse', {sticky: true, direction: 'top'});
|
|
</script>
|
|
</body>
|
|
</html>
|