-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmap.html
More file actions
174 lines (159 loc) · 3.82 KB
/
Copy pathmap.html
File metadata and controls
174 lines (159 loc) · 3.82 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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
<!DOCTYPE html>
<html>
/* the following code is adapted from: https://docs.mapbox.com/mapbox-gl-js/example/custom-style-id/ */
<head>
<meta charset="utf-8" />
<title>WRAG</title>
<meta name="viewport" content="initial-scale=1,maximum-scale=1,user-scalable=yes" />
<script src="https://api.mapbox.com/mapbox-gl-js/v1.6.1/mapbox-gl.js"></script>
<link href="https://api.mapbox.com/mapbox-gl-js/v1.6.1/mapbox-gl.css" rel="stylesheet" />
<style>
body { margin: 0; padding: 0; }
#map { position: absolute; top: 0; bottom: 0; width: 100%; }
/* the following code is adapted from: https://docs.mapbox.com/mapbox-gl-js/example/fitbounds/ */
#fit {
display: block;
position: relative;
margin: 0px auto;
width: 20%;
height: 40px;
padding: 10px;
border: none;
border-radius: 3px;
font-size: 10px;
text-align: left;
color: #fff;
background: #ee8a65;
#menu {
background: #fff;
position: absolute;
z-index: 1;
top: 10px;
right: 10px;
border-radius: 3px;
width: 30px;
border: 1px solid rgba(0, 0, 0, 0.4);
font-family: 'Open Sans', sans-serif;
}
#menu a {
font-size: 13px;
color: #404040;
display: block;
margin: 0;
padding: 0;
padding: 10px;
text-decoration: none;
border-bottom: 1px solid rgba(0, 0, 0, 0.25);
text-align: center;
}
#menu a:last-child {
border: none;
}
#menu a:hover {
background-color: #f8f8f8;
color: #404040;
}
#menu a.active {
background-color: #3887be;
color: #ffffff;
}
#menu a.active:hover {
background: #3074a4;
}
</style>
</head>
<body>
<nav id="menu"></nav>
<div id="map"></div>
<br />
<button id="fit">Zoom to Woodhouse Ridge</button>
<script>
mapboxgl.accessToken = 'pk.eyJ1Ijoic2ltb25sMTEiLCJhIjoiY2s1dHBxejRiMHBpcjNrbnd4Z3R6eWhjcyJ9.lFOgWPzWjq91hQTg6acmkg';
var map = new mapboxgl.Map({
container: 'map', // container id
style: 'mapbox://styles/simonl11/ck5tq2qw11a3y1ito2pjk7086', //hosted style id
center: [-1.549325,53.816487], // starting position [lng, lat]
zoom: 9 // starting zoom
/* following code adapted from: https://docs.mapbox.com/mapbox-gl-js/example/fitbounds/ */
});
document.getElementById('fit').addEventListener('click', function() {
map.fitBounds([
[-1.553477,53.817738],
[-1.546826,53.815388]
]);
});
// Add zoom and rotation controls to the map.
map.addControl(new mapboxgl.NavigationControl());
// Add geolocate control to the map.
map.addControl(
new mapboxgl.GeolocateControl({
positionOptions: {
enableHighAccuracy: true
},
trackUserLocation: true
})
);
map.on('load', function() {
map.addSource('museums', {
type: 'vector',
url: 'mapbox://mapbox.2opop9hr'
});
map.addLayer({
'id': 'museums',
'type': 'circle',
'source': 'museums',
'layout': {
'visibility': 'visible'
},
'paint': {
'circle-radius': 8,
'circle-color': 'rgba(55,148,179,1)'
},
'source-layer': 'museum-cusco'
});
map.addSource('contours', {
type: 'vector',
url: 'mapbox://mapbox.mapbox-terrain-v2'
});
map.addLayer({
'id': 'contours',
'type': 'line',
'source': 'contours',
'source-layer': 'contour',
'layout': {
'visibility': 'visible',
'line-join': 'round',
'line-cap': 'round'
},
'paint': {
'line-color': '#877b59',
'line-width': 1
}
});
});
var toggleableLayerIds = ['contours', 'museums'];
for (var i = 0; i < toggleableLayerIds.length; i++) {
var id = toggleableLayerIds[i];
var link = document.createElement('a');
link.href = '#';
link.className = 'active';
link.textContent = id;
link.onclick = function(e) {
var clickedLayer = this.textContent;
e.preventDefault();
e.stopPropagation();
var visibility = map.getLayoutProperty(clickedLayer, 'visibility');
if (visibility === 'visible') {
map.setLayoutProperty(clickedLayer, 'visibility', 'none');
this.className = '';
} else {
this.className = 'active';
map.setLayoutProperty(clickedLayer, 'visibility', 'visible');
}
};
var layers = document.getElementById('menu');
layers.appendChild(link);
}
</script>
</body>
</html>