@maplibre/maplibre-gl-leaflet
Version:
Supports adding Maplibre GL Web to a Leaflet Map as a layer
53 lines (40 loc) • 1.77 kB
HTML
<html>
<head>
<title>WebGL</title>
<meta charset="utf-8">
<style>#map { width: 800px; height: 600px; }</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.0.1/dist/maplibre-gl.css" rel='stylesheet' />
<script src="https://unpkg.com/maplibre-gl@5.0.1/dist/maplibre-gl.js"></script>
<!-- Leaflet.MarkerCluster -->
<script src='https://cdnjs.cloudflare.com/ajax/libs/leaflet.markercluster/1.5.3/leaflet.markercluster.js'></script>
<link href='https://cdnjs.cloudflare.com/ajax/libs/leaflet.markercluster/1.5.3/MarkerCluster.css' rel='stylesheet' />
<link href='https://cdnjs.cloudflare.com/ajax/libs/leaflet.markercluster/1.5.3/MarkerCluster.Default.css' rel='stylesheet' />
<!-- test data -->
<script src="https://www.mapbox.com/mapbox.js/assets/data/realworld.388.js"></script>
</head>
<body>
<div id="map"></div>
<script src="../leaflet-maplibre-gl.js"></script>
<script>
var map = L.map('map', {maxZoom: 17}).setView([-37.821, 175.219], 16);
var gl = L.maplibreGL({
// get your own MapTiler token at https://cloud.maptiler.com/ or use MapBox style
style: 'https://api.maptiler.com/maps/basic/style.json?key=get_your_own_OpIi9ZULNHzrESv6T2vL'
}).addTo(map);
var markers = L.markerClusterGroup();
for (var i = 0; i < addressPoints.length; i++) {
var a = addressPoints[i];
var title = a[2];
var marker = L.marker(new L.LatLng(a[0], a[1]), { title: title });
marker.bindPopup(title);
markers.addLayer(marker);
}
map.addLayer(markers);
</script>
</body>
</html>