-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFishMapbox.html
More file actions
78 lines (72 loc) · 2.04 KB
/
FishMapbox.html
File metadata and controls
78 lines (72 loc) · 2.04 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>Demo: Make a choropleth map</title>
<meta name="viewport" content="width=device-width, initial-scale=1" />
<script src="https://api.tiles.mapbox.com/mapbox-gl-js/v2.14.1/mapbox-gl.js"></script>
<link
href="https://api.tiles.mapbox.com/mapbox-gl-js/v2.14.1/mapbox-gl.css"
rel="stylesheet"
/>
<style>
body {
margin: 0;
padding: 0;
}
h2,
h3 {
margin: 10px;
font-size: 18px;
}
h3 {
font-size: 16px;
}
p {
margin: 10px;
}
#map {
position: absolute;
top: 0;
bottom: 0;
width: 100%;
}
#features {
top: 0;
height: 100px;
margin-top: 20px;
width: 250px;
}
</style>
</head>
<body>
<div id="map"></div>
<div class="map-overlay" id="features">
<h2>US population density</h2>
</div>
<div class="map-overlay" id="legend"></div>
<script>
// define access token
mapboxgl.accessToken = 'pk.eyJ1IjoianRzYWxhaCIsImEiOiJjbGdwNHY1bXQwdmxiM3BtdTJheXdzY3VxIn0.jW2gvf6Te-yCGnPrxoOBxw';
// create map
const map = new mapboxgl.Map({
container: 'map', // container id
style: 'mapbox://styles/jtsalah/clwd0z95o010a01qlejhrgzns' // map style URL from Mapbox Studio
});
// wait for map to load before adjusting it
map.on('load', () => {
// make a pointer cursor
map.getCanvas().style.cursor = 'default';
// change info window on hover
map.on('mousemove', (event) => {
const states = map.queryRenderedFeatures(event.point, {
layers: ['statedata']
});
document.getElementById('pd').innerHTML = states.length
? `<h3>${states[0].properties.name}</h3><p><strong><em>${states[0].properties.density}</strong> people per square mile</em></p>`
: `<p>Hover over a state!</p>`;
});
});
</script>
</body>
</html>