UNPKG

@maplibre/maplibre-gl-leaflet

Version:

Supports adding Maplibre GL Web to a Leaflet Map as a layer

52 lines (42 loc) 1.43 kB
<!DOCTYPE html> <html> <head> <title>WebGL</title> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <style> html, body, #map { width: 100%; height: 100%; margin: 0; } </style> <!-- Leaflet --> <link rel="stylesheet" href="https://unpkg.com/leaflet@1.9.3/dist/leaflet.css" /> <script src="https://unpkg.com/leaflet@1.9.3/dist/leaflet.js"></script> <!-- Maplibre GL --> <link href="https://unpkg.com/maplibre-gl@5/dist/maplibre-gl.css" rel='stylesheet' /> <script src="https://unpkg.com/maplibre-gl@5/dist/maplibre-gl.js"></script> </head> <body> <div id="map"></div> <script src="../leaflet-maplibre-gl.js"></script> <script> var map = L.map('map', { maxBounds: [[180, -Infinity], [-180, Infinity]], // restrict bounds to avoid max latitude issues with MapLibre GL maxBoundsViscosity: 1, // make the max bounds "solid" so users cannot pan past them minZoom: 1 // prevent sync issues at zoom 0 }).setView([38.912753, -77.032194], 2); L.marker([38.912753, -77.032194]) .bindPopup("Hello <b>Leaflet GL</b>!<br>Whoa, it works!") .addTo(map) .openPopup(); var gl = L.maplibreGL({ // get your own MapTiler token at https://cloud.maptiler.com/ or use MapBox style style: 'https://demotiles.maplibre.org/style.json' }).addTo(map); </script> </body> </html>