-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUNESCO_mapBox.html
More file actions
57 lines (56 loc) · 1.73 KB
/
Copy pathUNESCO_mapBox.html
File metadata and controls
57 lines (56 loc) · 1.73 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
<!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.9.2/mapbox-gl.js'></script>
<link href='https://api.tiles.mapbox.com/mapbox-gl-js/v2.9.2/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.eyJ1IjoibWFyc28wOTMiLCJhIjoiY2w4dGdwcnUzMDc2NTQwcWUwYTBzY2Z4bSJ9.mWZa2RS2U7WrwQl-GO0jfQ';
const map = new mapboxgl.Map({
container: 'map',
// Replace YOUR_STYLE_URL with your style URL.
style: 'mapbox://styles/marso093/cl8th1cu6002414n0bejf2ass',
center: [0, 40],
zoom: 2.8
});
/*
Add an event listener that runs
when a user clicks on the map element.
*/
map.on('click', (event) => {
// If the user clicked on one of your markers, get its information.
const features = map.queryRenderedFeatures(event.point, {
layers: ['whc_sites_2021_geojson'] // replace with your layer name
});
if (!features.length) {
return;
}
const feature = features[0];
const popup = new mapboxgl.Popup({ offset: [0, -15] })
.setLngLat(feature.geometry.coordinates)
.setHTML(
`<h3>${feature.properties.Name}</h3><p>${feature.properties.Short_Description}</p>`
)
.addTo(map);
});
</script>
</body>
</html>