-
Notifications
You must be signed in to change notification settings - Fork 4
/
basemaps.js
360 lines (344 loc) · 9.26 KB
/
basemaps.js
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
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
import _ from 'lodash';
export function getBasemapScene(basemap, projection) {
// deep copy the selected basemap object with lodash, to avoid modifying the original object
var b = _.merge({}, basemaps[basemap]);
// add the desired projection to the imports
var p = getProjectionScene(projection);
if (b.import && p) b.import = b.import.concat(p)
return b;
}
export function getBasemapName(basemap) {
// if the basemap looks like a number, return name from by index number
// this is mostly for backwards compatibility, could be removed in future
const index = parseInt(basemap);
if (typeof index === 'number' && !isNaN(index)) {
return Object.keys(basemaps)[index];
}
// otherwise just return the name
return basemap;
}
export function getDefaultBasemapName() {
return Object.keys(basemaps)[0];
}
export function getNextBasemap(basemap) {
// return (index + 1) % Object.keys(basemaps).length;
const names = Object.keys(basemaps);
const index = names.indexOf(basemap);
if (index > -1) {
return names[(index + 1) % names.length]; // return next basemap if current one found
}
return names[0]; // otherwise just return first basemap
}
// add the base path of the current page to the URL
function addBasePath(url) {
let base = window.location.origin + window.location.pathname;
base = base.substr(0, base.lastIndexOf('/') + 1);
if (base.slice(-1) !== '/') {
base += '/';
}
return base + url;
}
// load the files for a named projection
export function getProjectionScene(projection) {
if (typeof projection !== "undefined") {
if (!projections[projection]) {
throw new Error("Projection \""+projection+"\" not found");
}
return projections[projection].files;
}
else return null
}
export function getDefaultProjectionName() {
return Object.keys(projections)[0]; // mercator
}
// skeletal structure of Invader viz scene, merged on top of underlying basemap, extended at run-time
// based on current viz settings
const xyzTangramBaseScene = addBasePath('tangram_xyz_scene.yaml');
// this gets merged into basemaps to change 'mapzen' vector tile source definitions to their XYZ HERE equivalent
// TODO: this does not yet override terrain/normal tiles for hillshading
const xyzTilezenSourceOverride = {
sources: {
mapzen: {
url: 'https://xyz.api.here.com/tiles/osmbase/512/all/{z}/{x}/{y}.mvt',
url_params: {
'access_token': 'global.xyz_access_token'
}
}
}
};
// each basemap can reference one of these font presets for labels, or define its own inline instead
const labelFontPresets = {
// for dark basemaps
dark: {
fill: [.9, .9, .1],
size: '12px',
stroke: {
color: 'black',
width: '4px'
}
},
// for light basemaps
light: {
fill: 'darkred',
size: '12px',
stroke: {
color: 'white',
width: '4px'
}
}
};
export const basemaps = {
'xyz-pixel': {
import: [
'https://raw.githubusercontent.com/sensescape/xyz-pixel/master/scene.yaml',
xyzTangramBaseScene
],
global: {
featureLabelFont: labelFontPresets.light
},
...xyzTilezenSourceOverride
},
'xyz-pixel-dark': {
import: [
'https://raw.githubusercontent.com/sensescape/xyz-pixel-dark/master/scene.yaml',
xyzTangramBaseScene
],
global: {
featureLabelFont: labelFontPresets.dark
},
...xyzTilezenSourceOverride
},
'xyz-pixel-pastel': {
import: [
'https://raw.githubusercontent.com/sensescape/xyz-pixel-pastel/master/scene.yaml',
xyzTangramBaseScene
],
global: {
featureLabelFont: labelFontPresets.light
},
...xyzTilezenSourceOverride
},
'xyz-dots': {
import: [
'https://raw.githubusercontent.com/sensescape/xyz-dots/master/scene.yaml',
xyzTangramBaseScene
],
global: {
featureLabelFont: labelFontPresets.light
},
...xyzTilezenSourceOverride
},
'xyz-dots-dark': {
import: [
'https://raw.githubusercontent.com/sensescape/xyz-dots-dark/master/scene.yaml',
xyzTangramBaseScene
],
global: {
featureLabelFont: labelFontPresets.dark
},
...xyzTilezenSourceOverride
},
'xyz-bw-texture': {
import: [
'https://raw.githubusercontent.com/sensescape/bw-texture/master/scene.yaml',
xyzTangramBaseScene
],
global: {
featureLabelFont: labelFontPresets.light
},
...xyzTilezenSourceOverride
},
'xyz-grid': {
import: [
'https://raw.githubusercontent.com/sensescape/xyz-grid/master/scene.yaml',
xyzTangramBaseScene
],
global: {
featureLabelFont: labelFontPresets.light
},
...xyzTilezenSourceOverride
},
'xyz-grid-dark': {
import: [
'https://raw.githubusercontent.com/sensescape/xyz-grid-dark/master/scene.yaml',
xyzTangramBaseScene
],
global: {
featureLabelFont: labelFontPresets.dark
},
...xyzTilezenSourceOverride
},
'xyz-grid-color': {
import: [
'https://raw.githubusercontent.com/sensescape/xyz-grid-color/master/scene.yaml',
xyzTangramBaseScene
],
global: {
featureLabelFont: labelFontPresets.light
},
...xyzTilezenSourceOverride
},
'xyz-elevation-dots': {
import: [
'https://raw.githubusercontent.com/sensescape/xyz-elevation-dots/master/scene.yaml',
xyzTangramBaseScene
],
global: {
featureLabelFont: labelFontPresets.dark
},
...xyzTilezenSourceOverride
},
'xyz-studio-spring-soft': {
import: [
'https://raw.githubusercontent.com/sensescape/xyz-studio-spring-soft/master/scene.yaml',
xyzTangramBaseScene
],
global: {
featureLabelFont: labelFontPresets.light
},
...xyzTilezenSourceOverride
},
'xyz-studio-spring-bright': {
import: [
'https://raw.githubusercontent.com/sensescape/xyz-studio-spring-bright/master/scene.yaml',
xyzTangramBaseScene
],
global: {
featureLabelFont: labelFontPresets.light
},
...xyzTilezenSourceOverride
},
'xyz-studio-miami-day': {
import: [
'https://raw.githubusercontent.com/sensescape/xyz-studio-miami-day/master/scene.yaml',
xyzTangramBaseScene
],
global: {
featureLabelFont: labelFontPresets.light
},
...xyzTilezenSourceOverride
},
'xyz-studio-light': {
import: [
'https://raw.githubusercontent.com/sensescape/xyz-studio-light/master/scene.yaml',
xyzTangramBaseScene
],
global: {
featureLabelFont: labelFontPresets.light
},
...xyzTilezenSourceOverride
},
'xyz-studio-dark': {
import: [
'https://raw.githubusercontent.com/sensescape/xyz-studio-dark/master/scene.yaml',
xyzTangramBaseScene
],
global: {
featureLabelFont: labelFontPresets.dark
},
...xyzTilezenSourceOverride
},
'xyz-reduction-light': {
import: [
'xyz-reduction-light.yaml',
xyzTangramBaseScene
],
global: {
featureLabelFont: labelFontPresets.light
},
...xyzTilezenSourceOverride
},
'xyz-reduction-dark': {
import: [
'xyz-reduction-dark.yaml',
xyzTangramBaseScene
],
global: {
featureLabelFont: labelFontPresets.dark
},
...xyzTilezenSourceOverride
},
'mapzen-refill-dark': {
import: [
'https://www.nextzen.org/carto/refill-style/refill-style.zip',
'https://www.nextzen.org/carto/refill-style/themes/color-gray-gold.zip',
'https://www.nextzen.org/carto/refill-style/themes/label-4.zip',
// 'https://www.nextzen.org/carto/refill-style/themes/terrain-shading-dark.zip',
xyzTangramBaseScene
],
global: {
featureLabelFont: labelFontPresets.dark
},
...xyzTilezenSourceOverride
},
'mapzen-refill': {
import: [
'https://www.nextzen.org/carto/refill-style/refill-style.zip',
'https://www.nextzen.org/carto/refill-style/themes/label-4.zip',
'https://www.nextzen.org/carto/refill-style/themes/terrain-shading-dark.zip',
xyzTangramBaseScene
],
global: {
featureLabelFont: labelFontPresets.light
},
...xyzTilezenSourceOverride
},
'mapzen-walkabout': {
import: [
'https://www.nextzen.org/carto/walkabout-style/walkabout-style.zip',
xyzTangramBaseScene
],
global: {
featureLabelFont: labelFontPresets.light
},
...xyzTilezenSourceOverride
},
'none': {
import: [
xyzTangramBaseScene
],
global: {
featureLabelFont: labelFontPresets.dark
},
scene: {
background: {
color: [0, 0, 0]
}
}
},
'satellite': {
import: [
'https://www.nextzen.org/carto/refill-style/refill-style.zip',
xyzTangramBaseScene,
addBasePath('satellite.yaml'),
],
global: {
featureLabelFont: labelFontPresets.dark
},
...xyzTilezenSourceOverride
},
};
export const projections = {
'mercator': {
files: ['mercator.yaml']
},
'albers': {
files: ['albers.yaml']
},
'mollweide': {
files: ['mollweide.yaml', 'mollweide-points.yaml']
},
'globe': {
files: ['globe.yaml', 'globe-points.yaml']
}
};
// array of projectable basemaps - if one of these is selected in the "basemap" menu,
// the "projection" menu will become available
const projectable = [
"none",
"xyz-reduction-light",
"xyz-reduction-dark",
]
export function isProjectable(basemap) {
return projectable.indexOf(basemap) > -1;
}