Skip to content

Add a Popup

Use bindPopup() to attach a popup to a marker, and openPopup() to show it immediately.

import * as maplibregl from 'https://cdn.jsdelivr.net/npm/[email protected]/dist/maplibre-gl.mjs';
import { MaptoolkitLogoControl } from 'https://cdn.jsdelivr.net/npm/@maptoolkit/leaflet-logo/+esm';

// maplibre-gl-leaflet is UMD with no ESM build and reads the global when it
// loads, so the assignment has to happen first - hence the dynamic import
// instead of a <script> tag, whose order we could not control here.
window.maplibregl = maplibregl;
await import('https://cdn.jsdelivr.net/npm/@maplibre/[email protected]/leaflet-maplibre-gl.js');
const map = L.map('map').setView([52.52, 13.405], 13);
L.maplibreGL({ style: 'https://styles.maptoolkit.org/summer.json'}).addTo(map);

// Arabic/Hebrew: MapLibre has no right-to-left support built in, this plugin adds it
maplibregl.setRTLTextPlugin('https://cdn.jsdelivr.net/npm/@mapbox/[email protected]/dist/mapbox-gl-rtl-text.js', false);
L.marker([52.52, 13.405]).addTo(map).bindPopup('<strong>Berlin</strong>').openPopup();
new MaptoolkitLogoControl().addTo(map);
map.attributionControl.setPrefix(false);
<!DOCTYPE html>
<html>
<head>
  <meta charset="UTF-8" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/leaflet.css" />
  <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/leaflet.js"></script>
  <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/maplibre-gl.css" />
  <style>
    html, body { width: 100%; height: 100%; margin: 0; padding: 0; }
    #map { width: 100%; height: 100%; }
  </style>
</head>
<body>
  <div id="map"></div>
  <script type="module">
import * as maplibregl from 'https://cdn.jsdelivr.net/npm/[email protected]/dist/maplibre-gl.mjs';
import { MaptoolkitLogoControl } from 'https://cdn.jsdelivr.net/npm/@maptoolkit/leaflet-logo/+esm';

// maplibre-gl-leaflet is UMD with no ESM build and reads the global when it
// loads, so the assignment has to happen first - hence the dynamic import
// instead of a <script> tag, whose order we could not control here.
window.maplibregl = maplibregl;
await import('https://cdn.jsdelivr.net/npm/@maplibre/[email protected]/leaflet-maplibre-gl.js');
const map = L.map('map').setView([52.52, 13.405], 13);
L.maplibreGL({ style: 'https://styles.maptoolkit.org/summer.json'}).addTo(map);

// Arabic/Hebrew: MapLibre has no right-to-left support built in, this plugin adds it
maplibregl.setRTLTextPlugin('https://cdn.jsdelivr.net/npm/@mapbox/[email protected]/dist/mapbox-gl-rtl-text.js', false);
L.marker([52.52, 13.405]).addTo(map).bindPopup('<strong>Berlin</strong>').openPopup();
new MaptoolkitLogoControl().addTo(map);
map.attributionControl.setPrefix(false);
  </script>
</body>
</html>