Files
leaflet/docs/examples/quick-start/example.md
chcederquist 9b89ab4eb5 Updated title and descriptions of docs (#9692)
Co-authored-by: Florian Bischof <design.falke@gmail.com>
2025-05-09 18:47:17 +02:00

1.4 KiB

layout, title, customMapContainer
layout title customMapContainer
tutorial_frame Full Example true
<script type="module"> import L, {Map, TileLayer, Marker, Circle, Polygon, Popup} from 'leaflet';
const map = new Map('map').setView([51.505, -0.09], 13);

const tiles = new TileLayer('https://tile.openstreetmap.org/{z}/{x}/{y}.png', {
	maxZoom: 19,
	attribution: '&copy; <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a>'
}).addTo(map);

const marker = new Marker([51.5, -0.09]).addTo(map)
	.bindPopup('<b>Hello world!</b><br />I am a popup.').openPopup();

const circle = new Circle([51.508, -0.11], {
	color: 'red',
	fillColor: '#f03',
	fillOpacity: 0.5,
	radius: 500
}).addTo(map).bindPopup('I am a circle.');

const polygon = new Polygon([
	[51.509, -0.08],
	[51.503, -0.06],
	[51.51, -0.047]
]).addTo(map).bindPopup('I am a polygon.');


const popup = new Popup()
	.setLatLng([51.513, -0.09])
	.setContent('I am a standalone popup.')
	.openOn(map);

function onMapClick(e) {
	popup
		.setLatLng(e.latlng)
		.setContent(`You clicked the map at ${e.latlng.toString()}`)
		.openOn(map);
}

map.on('click', onMapClick);

globalThis.L = L; // only for debugging in the developer console
globalThis.map = map; // only for debugging in the developer console

</script>