forked from mapbox/mapbox-gl-js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprojections.html
221 lines (203 loc) · 6.26 KB
/
projections.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
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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
<!DOCTYPE html>
<html>
<head>
<title>Mapbox GL JS debug page</title>
<meta charset='utf-8'>
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
<link rel='stylesheet' href='../dist/mapbox-gl.css' />
<style>
body { margin: 0; padding: 0; }
html, body, #map { height: 100%; }
</style>
<style>
.map-overlay {
font: 12px/20px 'Helvetica Neue', Arial, Helvetica, sans-serif;
position: absolute;
width: 200px;
top: 0;
left: 0;
padding: 10px;
}
.map-overlay .map-overlay-inner {
background-color: #fff;
box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
border-radius: 3px;
padding: 10px;
margin-bottom: 10px;
}
.map-overlay-inner fieldset {
border: none;
padding: 0;
margin: 0 0 10px;
}
.map-overlay-inner fieldset:last-child {
margin: 0;
}
.map-overlay-inner select,
.map-overlay-inner input {
width: 100%;
}
.map-overlay-inner label {
display: block;
font-weight: bold;
margin: 0 0 5px;
}
</style>
</head>
<body>
<div id='map'></div>
<div class="map-overlay top">
<details open>
<summary>Toggle controls</summary>
<div class="map-overlay-inner">
<fieldset>
<label>Select style</label>
<select id="style" name="style">
<option value="streets-v11">Streets</option>
<option value="satellite-v9">Satellite</option>
</select>
</fieldset>
<fieldset>
<label>Select projection</label>
<select id="projection" name="projection">
<option value="albers" selected>Albers</option>
<option value="equalEarth">Equal Earth</option>
<option value="equirectangular">Equirectangular</option>
<option value="lambertConformalConic">
Lambert Conformal Conic
</option>
<option value="mercator">Mercator</option>
<option value="globe">Globe</option>
<option value="naturalEarth">Natural Earth</option>
<option value="winkelTripel">Winkel Tripel</option>
</select>
</fieldset>
<fieldset class="conic-param-input">
<label>Center Longitude: <span id="lng-value">0</span></label>
<input
id="lng"
type="range"
min="-180"
max="180"
step="any"
value="0"
/>
</fieldset>
<fieldset class="conic-param-input">
<label>Center Latitude: <span id="lat-value">30</span></label>
<input
id="lat"
type="range"
min="-90"
max="90"
step="any"
value="30"
/>
</fieldset>
<fieldset class="conic-param-input">
<label
>Southern Parallel Lat: <span id="lat1-value">29.5</span></label
>
<input
id="lat1"
type="range"
min="-90"
max="90"
step="any"
value="29.5"
/>
</fieldset>
<fieldset class="conic-param-input">
<label
>Northern Parallel Lat: <span id="lat2-value">45.5</span></label
>
<input
id="lat2"
type="range"
min="-90"
max="90"
step="any"
value="45.5"
/>
</fieldset>
<fieldset>
<label>Show Debug Tiles:</label>
<input id="debug" type="checkbox">
</fieldset>
</div>
</details>
</div>
<script src='../dist/mapbox-gl-dev.js'></script>
<script src='../debug/access_token_generated.js'></script>
<script>
const map = new mapboxgl.Map({
container: 'map',
hash: true,
style: 'mapbox://styles/mapbox/streets-v12',
zoom: 0,
center: [0, 1],
projection: {
name: 'albers'
}
});
const projectionInput = document.getElementById('projection');
const styleInput = document.getElementById('style');
const debugInput = document.getElementById('debug');
const conicParamInputs =
document.getElementsByClassName('conic-param-input');
const lngInput = document.getElementById('lng');
const lngValue = document.getElementById('lng-value');
const latInput = document.getElementById('lat');
const latValue = document.getElementById('lat-value');
const lat1Input = document.getElementById('lat1');
const lat1Value = document.getElementById('lat1-value');
const lat2Input = document.getElementById('lat2');
const lat2Value = document.getElementById('lat2-value');
projectionInput.addEventListener('change', (e) => {
const isConic = ['albers', 'lambertConformalConic'].includes(
e.target.value
);
// Hide non-conic projection params
for (const input of conicParamInputs) {
input.style.display = isConic ? 'block' : 'none';
}
const projection = isConic ? {
name: e.target.value
} : e.target.value;
map.setProjection(projection);
if (isConic) {
const p = map.getProjection();
lngInput.value = p.center[0];
latInput.value = p.center[1];
lat1Input.value = p.parallels[0];
lat2Input.value = p.parallels[1];
for (const [input, value] of inputs) {
value.textContent = input.value;
}
}
});
styleInput.addEventListener('change', () => {
map.setStyle('mapbox://styles/mapbox/' + styleInput.value);
});
debugInput.addEventListener('change', () => {
map.showTileBoundaries = debugInput.checked;
});
const inputs = [
[lngInput, lngValue],
[latInput, latValue],
[lat1Input, lat1Value],
[lat2Input, lat2Value]
];
for (const [input, value] of inputs) {
input.addEventListener('change', (e) => {
value.textContent = e.target.value;
map.setProjection({
name: projectionInput.value,
center: [Number(lngInput.value), Number(latInput.value)],
parallels: [Number(lat1Input.value), Number(lat2Input.value)]
});
});
}
</script>
</body>
</html>