forked from ngageoint/opensphere
-
Notifications
You must be signed in to change notification settings - Fork 0
/
addlayer.js
62 lines (52 loc) · 1.69 KB
/
addlayer.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
(function() {
var type;
var status = $('#status');
var to = 'opensphere';
var from = to + '-addLayer.' + Date.now();
var str = window.location.hash;
var isAlive = function() {
var ping = window.localStorage.getItem(['xt', 'default', to, 'ping'].join('.'));
return ping && ping - Date.now() < 10000;
};
if (!window.localStorage) {
status.append('<div class="error">Error: localStorage not present</div>');
return;
}
if (!str) {
status.html('<div class="error">Error: No URI-encoded file path or ' +
'JSON string was found in the location fragment</div>');
return;
}
status.append('<div>Adding layer(s) ... </div>');
str = decodeURIComponent(str.substring(1));
var data;
if (str.startsWith('file=')) {
data = {'url': str.substring(5)};
type = 'file.load';
} else {
try {
data = JSON.parse(str);
type = 'addLayer';
} catch (e) {
status.append('<div class="error">Error: malformed JSON in fragment.</div>');
}
}
if (!data) {
status.html('<div class="error">Error: No URI-encoded file path or ' +
'JSON string was found in the location fragment</div>');
return;
}
if (!type) {
status.html('<div class="error">Error: No message type was found</div>');
return;
}
window.localStorage.setItem(
['xt', 'default', to, from].join('.'),
JSON.stringify({'type': type, 'data': data, 'time': Date.now()}));
if (!isAlive()) {
window.location = window.location.toString().replace(/addlayer.html.*/g, '');
status.append('<div>Launching {APP} ...</div>');
} else {
status.append('<div>Done! You can close this and switch over to {APP} to see your layer(s).</div>');
}
})();