-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
62 lines (59 loc) · 1.72 KB
/
index.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
<!DOCTYPE html>
<html lang='en'>
<head>
<meta charset='utf-8' />
<title>Points on a map</title>
<meta name='viewport' content='width=device-width, initial-scale=1' />
<script src='https://api.tiles.mapbox.com/mapbox-gl-js/v2.4.1/mapbox-gl.js'></script>
<link href='https://api.tiles.mapbox.com/mapbox-gl-js/v2.4.1/mapbox-gl.css' rel='stylesheet' />
<style>
body {
margin: 0;
padding: 0;
}
#map {
position: absolute;
top: 0;
bottom: 0;
width: 100%;
}
</style>
</head>
<body>
<div id='map'></div>
<script>
// The value for 'accessToken' begins with 'pk...'
mapboxgl.accessToken = 'pk.eyJ1IjoidGhpc2lzbWV4cCIsImEiOiJja3RvaThnb2IwMG12MnZucXAyN25xMHh1In0.By4bJOVk-QclkrVwh8rgeA';
const map = new mapboxgl.Map({
container: 'map',
style: 'mapbox://styles/thisismexp/cktoofcef1gaf18nwpl9h6eum',
center: [16.3320, 48.2202],
zoom: 16
});
/*
Add an event listener that runs
when a user clicks on the map element.
*/
map.on('click', ({ point }) => {
// If the user clicked on one of your markers, get its information.
const features = map.queryRenderedFeatures(point, {
layers: ['trees']
});
if (!features.length) {
return;
}
const feature = features[0];
/*
Create a popup, specify its options
and properties, and add it to the map.
*/
const popup = new mapboxgl.Popup({ offset: [0, -15] })
.setLngLat(feature.geometry.coordinates)
.setHTML(
`<h3 style="color:black; padding:0; margin:0">${feature.properties.title}</h3><p style="color:black;padding:0;margin:0">${feature.properties.description}</p>`
)
.addTo(map);
});
</script>
</body>
</html>