-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmaplibre-leaflet.html
47 lines (42 loc) · 1.65 KB
/
maplibre-leaflet.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>MapLibre with Leaflet Integration</title>
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.9.4/dist/leaflet.css">
<script src="https://unpkg.com/leaflet@1.9.4/dist/leaflet.js"></script>
<script src="https://unpkg.com/maplibre-gl@^5.0.1/dist/maplibre-gl.js"></script>
<link href="https://unpkg.com/maplibre-gl@^5.0.1/dist/maplibre-gl.css" rel="stylesheet" />
<style>
#map {
height: 100vh;
margin: 0;
}
</style>
</head>
<body>
<div id="map"></div>
<script>
// Initialize Leaflet map
const map = L.map('map').setView([37.7749, -122.4194], 13); // Centered on San Francisco, USA
// Add a Leaflet tile layer (OpenStreetMap)
L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
attribution: '© OpenStreetMap contributors'
}).addTo(map);
// Add MapLibre layer manually using its API
const mapLibreContainer = L.DomUtil.create('div', 'leaflet-maplibre-container');
mapLibreContainer.style.height = '100%';
mapLibreContainer.style.width = '100%';
const mapLibreMap = new maplibregl.Map({
container: mapLibreContainer,
style: 'https://demotiles.maplibre.org/style.json',
center: [ -122.4194, 37.7749 ],
zoom: 13,
attributionControl: false
});
const mapLibrePane = map.createPane('maplibrePane');
mapLibrePane.appendChild(mapLibreContainer);
</script>
</body>
</html>