-
Notifications
You must be signed in to change notification settings - Fork 69
Expand file tree
/
Copy pathQueryURL.js
More file actions
470 lines (411 loc) · 15.6 KB
/
Copy pathQueryURL.js
File metadata and controls
470 lines (411 loc) · 15.6 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
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
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
import * as moment from 'moment'
import F_ from '../Basics/Formulae_/Formulae_'
import L_ from '../Basics/Layers_/Layers_'
import T_ from '../Basics/ToolController_/ToolController_'
import calls from '../../pre/calls'
import TimeControl from './TimeControl'
import TimeUI from './TimeUI'
var QueryURL = {
checkIfMission: function () {
return this.getSingleQueryVariable('mission')
},
queryURL: function () {
//Set the site and view if specified in the url
var urlSite = this.getSingleQueryVariable('site')
var urlMapLat = this.getSingleQueryVariable('mapLat')
var urlMapLon = this.getSingleQueryVariable('mapLon')
var urlMapZoom = this.getSingleQueryVariable('mapZoom')
var urlGlobeLat = this.getSingleQueryVariable('globeLat')
var urlGlobeLon = this.getSingleQueryVariable('globeLon')
var urlGlobeZoom = this.getSingleQueryVariable('globeZoom')
var urlGlobeCamera = this.getSingleQueryVariable('globeCamera')
var urlPanePercents = this.getSingleQueryVariable('panePercents')
var urlToolsObj = this.getSingleQueryVariable('tools')
var urlCenterPin = this.getSingleQueryVariable('centerPin')
var searchFile = this.getSingleQueryVariable('searchFile')
var searchStrings = this.getMultipleQueryVariable('searchstr')
var layersOn = this.getSingleQueryVariable('on')
var selected = this.getSingleQueryVariable('selected')
var viewerImg = this.getSingleQueryVariable('viewerImg')
var viewerLoc = this.getSingleQueryVariable('viewerLoc')
var rmcxyzoom = this.getSingleQueryVariable('rmcxyzoom')
var startTime = this.getSingleQueryVariable('startTime')
var endTime = this.getSingleQueryVariable('endTime')
var live = this.getSingleQueryVariable('live')
var follow = this.getSingleQueryVariable('follow')
if (urlSite !== false) {
L_.FUTURES.site = urlSite
}
if (urlMapLat !== false && urlMapLon !== false) {
// lat, lon, zoom
L_.FUTURES.mapView = [
parseFloat(urlMapLat),
parseFloat(urlMapLon),
urlMapZoom !== false ? parseInt(urlMapZoom) : null,
]
}
if (
urlGlobeLat !== false &&
urlGlobeLon != false &&
urlGlobeZoom != false
) {
// lat, lon, zoom
L_.FUTURES.globeView = [
parseFloat(urlGlobeLat),
parseFloat(urlGlobeLon),
parseInt(urlGlobeZoom),
]
}
if (urlGlobeCamera !== false) {
var c = urlGlobeCamera.split(',')
// posX, posY, posZ, targetX, targetY, targetZ
L_.FUTURES.globeCamera = [
parseFloat(c[0]),
parseFloat(c[1]),
parseInt(c[2]),
parseFloat(c[3]),
parseFloat(c[4]),
parseInt(c[5]),
]
}
if (urlPanePercents !== false) {
// viewerPercent, mapPercent, globePercent
// sum == 100
L_.FUTURES.panelPercents = urlPanePercents.split(',')
}
if (urlToolsObj !== false) {
L_.FUTURES.tools = urlToolsObj.split(',')
}
if (urlCenterPin !== false) {
L_.FUTURES.centerPin = urlCenterPin
}
if (searchFile !== false) {
L_.searchFile = searchFile
}
if (searchStrings !== false) {
L_.searchStrings = searchStrings
}
if (selected !== false) {
var s = selected.split(',')
//1 and 2 could be either lat, lng or key, value
let isKeyValue = isNaN(parseFloat(s[1])) || isNaN(parseFloat(s[2]))
if (isKeyValue) {
L_.FUTURES.activePoint = {
layerName: s[0],
key: s[1],
value: s[2],
view: s[3],
zoom: s[4],
}
} else {
L_.FUTURES.activePoint = {
layerName: s[0],
lat: parseFloat(s[1]),
lon: parseFloat(s[2]),
view: s[3],
zoom: s[4],
}
}
}
if (viewerImg !== false) {
L_.FUTURES.viewerImg = viewerImg
}
if (viewerLoc !== false) {
var l = viewerLoc.split(',')
for (var i = 0; i < l.length; i++) l[i] = parseFloat(l[i])
L_.FUTURES.viewerLoc = l
}
if (rmcxyzoom) {
let s = rmcxyzoom.split(',')
if (s.length == 5) {
calls.api(
'spatial_published',
{
rmc: s[0] + ',' + s[1],
x: s[2],
y: s[3],
query: 'self',
},
function (d) {
console.log(d)
},
function (d) {
console.warn(d)
}
)
}
}
if (startTime !== false) {
// Parse to an int if a unix timestamp
if (F_.isStringNumeric(startTime)) startTime = parseInt(startTime)
const date = new moment(startTime)
if (!isNaN(date) && date.isValid()) {
L_.FUTURES.startTime = date
} else {
console.warn('Invalid startTime from deep link in the url')
}
}
if (endTime !== false) {
if (F_.isStringNumeric(endTime)) endTime = parseInt(endTime)
const date = new moment(endTime)
if (!isNaN(date) && date.isValid()) {
L_.FUTURES.endTime = date
} else {
console.warn('Invalid endTime from deep link in the url')
}
}
if (live !== false) {
const liveStr = (live + '').toLowerCase()
L_.FUTURES.live = liveStr === 'true' || liveStr === '1'
}
if (follow !== false) {
const followStr = (follow + '').toLowerCase()
L_.FUTURES.follow = followStr === 'true' || followStr === '1'
}
if (layersOn !== false || selected !== false) {
L_.FUTURES.customOn = true
// lists all the on layers
// if the url has the on parameter and a layer is not listed in that url, the layer is off
// on layers are split into <layername>$<layeropacity>, <layername>$<layeropacity>, ...
var onLayers = {}
//'replace' makes it so that onLayers are the only ones on,
//'add' makes it so that onLayers and union of default are on
var method = 'replace'
if (layersOn !== false) {
L_.initialLayersOn = layersOn
var arr = layersOn.split(',')
for (var l of arr) {
let s = l.split('$')
onLayers[s[0]] = { opacity: parseFloat(s[1]) }
}
}
//Turn the selected layer on too
if (selected !== false) {
let s = selected.split(',')
onLayers[s[0]] = { opacity: 1 }
}
//This is so that when preselecting data the layer can turn on along with all default layers
if (layersOn == false && selected != false) method = 'add'
return {
onLayers: onLayers,
method: method,
}
}
return null
},
getSingleQueryVariable: function (variable) {
var query = window.location.search.substring(1)
var vars = query.split('&')
for (var i = 0; i < vars.length; i++) {
var pair = vars[i].split('=')
if (pair[0] == variable) {
return decodeURIComponent(pair[1])
}
}
return false
},
getMultipleQueryVariable: function (variable) {
var parameterList = []
var query = window.location.search.substring(1)
var vars = query.split('&')
for (var i = 0; i < vars.length; i++) {
var pair = vars[i].split('=')
if (pair[0].toLowerCase() == variable) {
parameterList.push(decodeURIComponent(pair[1]))
}
}
if (parameterList.length == 0) {
return false
} else {
return parameterList
}
},
/*
mission
site
mapLon
mapLat
mapZoom
globeLon
globeLat
globeZoom
globeCamera posX,posY,posZ,tarX,tarY,tarZ
panePercents
on name$opacity,
selected name,lat,lon
viewerImg
viewerLoc
image posX,posY,w,h
photosphere az,el,fov
model posX,posY,posZ,tarX,tarY,tarZ
tools
"tools=camp$1.3.4,"
*/
writeCoordinateURL: function (
shortenURL = true,
mapLon,
mapLat,
mapZoom,
globeLon,
globeLat,
globeZoom
) {
L_.Viewer_.getLocation()
var callback
if (typeof mapLon === 'function') {
callback = mapLon
mapLon = undefined
}
//Defaults
if (mapLon == undefined) mapLon = L_.Map_.map.getCenter().lng
if (mapLat == undefined) mapLat = L_.Map_.map.getCenter().lat
if (mapZoom == undefined) mapZoom = L_.Map_.map.getZoom()
var globeCenter = L_.Globe_.litho.getCenter()
if (globeCenter) {
if (globeLon == undefined) globeLon = globeCenter.lng
if (globeLat == undefined) globeLat = globeCenter.lat
if (globeZoom == undefined) globeZoom = L_.Globe_.litho.zoom
}
var viewerImg = L_.Viewer_.getLastImageId()
var viewerLoc = L_.Viewer_.getLocation()
//mission
var urlAppendage = '?mission=' + L_.mission
//site
if (L_.site) urlAppendage += '&site=' + L_.site
//mapLon
urlAppendage += '&mapLon=' + mapLon
//mapLat
urlAppendage += '&mapLat=' + mapLat
//mapZoom
urlAppendage += '&mapZoom=' + mapZoom
//globeLon
urlAppendage += '&globeLon=' + globeLon
//globeLat
urlAppendage += '&globeLat=' + globeLat
//globeZoom
urlAppendage += '&globeZoom=' + globeZoom
//globeCamera
const lithoCams = L_.Globe_.litho.getCameras()
if (lithoCams != null) {
var orbit = lithoCams.orbit
var cam = orbit.camera
var con = orbit.controls
var pos = cam.position
var tar = con.target
var globeCamera =
pos.x +
',' +
pos.y +
',' +
pos.z +
',' +
tar.x +
',' +
tar.y +
',' +
tar.z
urlAppendage += '&globeCamera=' + globeCamera
}
//panePercents
var pP = L_.UserInterface_.getPanelPercents()
var panePercents = pP.viewer + ',' + pP.map + ',' + pP.globe
urlAppendage += '&panePercents=' + panePercents
//on
var layersOnString = ''
for (var l in L_.layers.on) {
if (L_.layers.on[l] && L_.layers.data[l].type !== 'header')
layersOnString +=
l + '$' + parseFloat(L_.layers.opacity[l]).toFixed(2) + ','
}
layersOnString = layersOnString.substring(0, layersOnString.length - 1)
if (layersOnString.length > 0) urlAppendage += '&on=' + layersOnString
//selected
if (L_.lastActiveFeature.layerName != null) {
if (L_.layers.on[L_.lastActiveFeature.layerName])
if (
L_.lastActiveFeature.key != null &&
L_.lastActiveFeature.value != null
) {
urlAppendage +=
'&selected=' +
L_.lastActiveFeature.layerName +
',' +
L_.lastActiveFeature.key +
',' +
L_.lastActiveFeature.value
} else if (
L_.lastActiveFeature.lat != null &&
L_.lastActiveFeature.lon != null
)
urlAppendage +=
'&selected=' +
L_.lastActiveFeature.layerName +
',' +
L_.lastActiveFeature.lat +
',' +
L_.lastActiveFeature.lon
}
//viewer
if (viewerImg !== false) urlAppendage += '&viewerImg=' + viewerImg
if (viewerImg !== false && viewerLoc !== false)
urlAppendage += '&viewerLoc=' + viewerLoc
//tools
var urlTools = T_.getToolsUrl()
if (urlTools !== false) urlAppendage += '&tools=' + urlTools
//time
if (L_.configData.time && L_.configData.time.enabled === true) {
// If the time UI is in the Range mode, then we have a start time
if (TimeControl.timeUI.modeIndex === 0)
if (TimeControl.startTime)
urlAppendage += '&startTime=' + TimeControl.startTime
if (TimeControl.endTime)
urlAppendage += '&endTime=' + TimeControl.endTime
if (TimeControl.timeUI && typeof TimeControl.timeUI.now === 'boolean')
urlAppendage += '&live=' + (TimeControl.timeUI.now ? '1' : '0')
// Follow state
if (typeof TimeUI !== 'undefined' && TimeUI.followEnabled && TimeUI.followedFeature) {
urlAppendage += '&follow=1'
}
}
var url = encodeURI(urlAppendage)
if (shortenURL) {
calls.api(
'shortener_shorten',
{
url: url,
},
function (s) {
//Set and update the short url
L_.url =
window.location.href.split('?')[0] + '?s=' + s.body.url
window.history.replaceState('', '', L_.url)
if (typeof callback === 'function') callback()
},
function (e) {
//Set and update the full url
L_.url = window.location.href.split('?')[0] + url
window.history.replaceState('', '', L_.url)
if (typeof callback === 'function') callback()
}
)
}
return window.location.href.split('?')[0] + url
},
writeSearchURL: function (searchStrs, searchFile) {
return //!!!!!!!!!!!!!!!!
/*
var url =
window.location.href.split('?')[0] +
'?mission=' +
L_.mission +
'&site=' +
L_.site
for (var i = 0; i < searchStrs.length; i++) {
url = url + '&searchStr=' + searchStrs[i]
}
url = url + '&searchFile=' + searchFile
window.history.replaceState('', '', url)
*/
},
}
export default QueryURL