-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmaplibre.html
More file actions
114 lines (99 loc) · 3.92 KB
/
maplibre.html
File metadata and controls
114 lines (99 loc) · 3.92 KB
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
<!DOCTYPE html>
<html lang="de">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>MapLibre Karte mit GeoJSON</title>
<link href="https://unpkg.com/maplibre-gl@2.4.0/dist/maplibre-gl.css" rel="stylesheet" />
<style>
body {
margin: 0;
padding: 0;
}
#map {
width: 100%;
height: 100vh;
}
.popup {
background-color: white;
border: 1px solid black;
border-radius: 5px;
padding: 10px;
max-width: 300px;
}
.popup img {
max-width: 100%;
height: auto;
border-radius: 5px;
}
</style>
</head>
<body>
<div id="map"></div>
<script src="https://unpkg.com/maplibre-gl@2.4.0/dist/maplibre-gl.js"></script>
<script>
// Map initialisieren
const map = new maplibregl.Map({
container: 'map', // ID des Containers
style: 'https://demotiles.maplibre.org/style.json', // Standard-MapLibre-Stil
center: [0.0, 0.0], // Startposition (Europa)
zoom: 2 // Startzoom
});
// GeoJSON-Daten laden
fetch('geojson_results.json')
.then(response => response.json())
.then(data => {
// GeoJSON-Daten zur Karte hinzufügen
map.on('load', () => {
map.addSource('geojson-data', {
type: 'geojson',
data: data
});
map.addLayer({
id: 'geojson-layer',
type: 'circle',
source: 'geojson-data',
paint: {
'circle-radius': 8,
'circle-color': '#FF0000',
'circle-stroke-width': 2,
'circle-stroke-color': '#000000'
}
});
// Popup für Objektinformationen
const popup = new maplibregl.Popup({
closeButton: true,
closeOnClick: true
});
// Klick-Event für Features
map.on('click', 'geojson-layer', (e) => {
const feature = e.features[0];
const properties = feature.properties;
// Popup-Inhalt
const popupContent = `
<div class="popup">
<strong>${properties.name || 'Unbekannt'}</strong><br>
<img src="${properties.thumbnail}" alt="${properties.name}" /><br>
Lizenz: <a href="${properties.license}" target="_blank">${properties.license || 'Keine Lizenz'}</a><br>
Ersteller: ${properties.creator || 'Unbekannt'}<br>
Webseite: <a href="${properties.url}" target="_blank">${properties.url || 'Keine Webseite'}</a>
</div>
`;
// Popup anzeigen
popup.setLngLat(e.lngLat)
.setHTML(popupContent)
.addTo(map);
});
// Mauszeiger ändern, wenn über ein Feature gefahren wird
map.on('mouseenter', 'geojson-layer', () => {
map.getCanvas().style.cursor = 'pointer';
});
map.on('mouseleave', 'geojson-layer', () => {
map.getCanvas().style.cursor = '';
});
});
})
.catch(error => console.error('Fehler beim Laden des GeoJSON:', error));
</script>
</body>
</html>