forked from TerriaJS/aremi-natmap
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
435 lines (390 loc) · 17.8 KB
/
index.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
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
/**
* @license
* Copyright(c) 2012-2015 National ICT Australia Limited (NICTA).
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
'use strict';
/*global require*/
var version = require('./version');
var configuration = {
terriaBaseUrl: 'build/TerriaJS',
cesiumBaseUrl: undefined, // use default
bingMapsKey: undefined, // use Cesium key
proxyBaseUrl: 'proxy/',
conversionServiceBaseUrl: 'convert',
regionMappingDefinitionsUrl: 'data/regionMapping.json'
};
// Check browser compatibility early on.
// A very old browser (e.g. Internet Explorer 8) will fail on requiring-in many of the modules below.
// 'ui' is the name of the DOM element that should contain the error popup if the browser is not compatible
var checkBrowserCompatibility = require('terriajs/lib/ViewModels/checkBrowserCompatibility');
checkBrowserCompatibility('ui');
var knockout = require('terriajs-cesium/Source/ThirdParty/knockout');
var defined = require('terriajs-cesium/Source/Core/defined');
var fs = require('fs');
var isCommonMobilePlatform = require('terriajs/lib/Core/isCommonMobilePlatform');
var TerriaViewer = require('terriajs/lib/ViewModels/TerriaViewer');
var registerKnockoutBindings = require('terriajs/lib/Core/registerKnockoutBindings');
var corsProxy = require('terriajs/lib/Core/corsProxy');
var GoogleAnalytics = require('terriajs/lib/Core/GoogleAnalytics');
var AddDataPanelViewModel = require('terriajs/lib/ViewModels/AddDataPanelViewModel');
var AnimationViewModel = require('terriajs/lib/ViewModels/AnimationViewModel');
var BingMapsSearchProviderViewModel = require('terriajs/lib/ViewModels/BingMapsSearchProviderViewModel');
var BrandBarViewModel = require('terriajs/lib/ViewModels/BrandBarViewModel');
var CatalogItemNameSearchProviderViewModel = require('terriajs/lib/ViewModels/CatalogItemNameSearchProviderViewModel');
var createAustraliaBaseMapOptions = require('terriajs/lib/ViewModels/createAustraliaBaseMapOptions');
var createGlobalBaseMapOptions = require('terriajs/lib/ViewModels/createGlobalBaseMapOptions');
var createToolsMenuItem = require('terriajs/lib/ViewModels/createToolsMenuItem');
var DataCatalogTabViewModel = require('terriajs/lib/ViewModels/DataCatalogTabViewModel');
var DistanceLegendViewModel = require('terriajs/lib/ViewModels/DistanceLegendViewModel');
var DragDropViewModel = require('terriajs/lib/ViewModels/DragDropViewModel');
var ExplorerPanelViewModel = require('terriajs/lib/ViewModels/ExplorerPanelViewModel');
var FeatureInfoPanelViewModel = require('terriajs/lib/ViewModels/FeatureInfoPanelViewModel');
var GazetteerSearchProviderViewModel = require('terriajs/lib/ViewModels/GazetteerSearchProviderViewModel');
var GoogleUrlShortener = require('terriajs/lib/Models/GoogleUrlShortener');
var LocationBarViewModel = require('terriajs/lib/ViewModels/LocationBarViewModel');
var MenuBarItemViewModel = require('terriajs/lib/ViewModels/MenuBarItemViewModel');
var MenuBarViewModel = require('terriajs/lib/ViewModels/MenuBarViewModel');
var MutuallyExclusivePanels = require('terriajs/lib/ViewModels/MutuallyExclusivePanels');
var NavigationViewModel = require('terriajs/lib/ViewModels/NavigationViewModel');
var NowViewingAttentionGrabberViewModel = require('terriajs/lib/ViewModels/NowViewingAttentionGrabberViewModel');
var NowViewingTabViewModel = require('terriajs/lib/ViewModels/NowViewingTabViewModel');
var PopupMessageViewModel = require('terriajs/lib/ViewModels/PopupMessageViewModel');
var PopupMessageConfirmationViewModel = require('terriajs/lib/ViewModels/PopupMessageConfirmationViewModel');
var SearchTabViewModel = require('terriajs/lib/ViewModels/SearchTabViewModel');
var SettingsPanelViewModel = require('terriajs/lib/ViewModels/SettingsPanelViewModel');
var SharePopupViewModel = require('terriajs/lib/ViewModels/SharePopupViewModel');
var MapProgressBarViewModel = require('terriajs/lib/ViewModels/MapProgressBarViewModel');
var updateApplicationOnHashChange = require('terriajs/lib/ViewModels/updateApplicationOnHashChange');
var ViewerMode = require('terriajs/lib/Models/ViewerMode');
var updateApplicationOnMessageFromParentWindow = require('terriajs/lib/ViewModels/updateApplicationOnMessageFromParentWindow');
var BaseMapViewModel = require('terriajs/lib/ViewModels/BaseMapViewModel');
var Terria = require('terriajs/lib/Models/Terria');
var OgrCatalogItem = require('terriajs/lib/Models/OgrCatalogItem');
var registerCatalogMembers = require('terriajs/lib/Models/registerCatalogMembers');
var raiseErrorToUser = require('terriajs/lib/Models/raiseErrorToUser');
var WebMapServiceCatalogItem = require('terriajs/lib/Models/WebMapServiceCatalogItem');
var selectBaseMap = require('terriajs/lib/ViewModels/selectBaseMap');
var svgInfo = require('terriajs/lib/SvgPaths/svgInfo');
var svgPlus = require('terriajs/lib/SvgPaths/svgPlus');
var svgRelated = require('terriajs/lib/SvgPaths/svgRelated');
var svgShare = require('terriajs/lib/SvgPaths/svgShare');
var svgWorld = require('terriajs/lib/SvgPaths/svgWorld');
// Configure the base URL for the proxy service used to work around CORS restrictions.
corsProxy.baseProxyUrl = configuration.proxyBaseUrl;
// Tell the OGR catalog item where to find its conversion service. If you're not using OgrCatalogItem you can remove this.
OgrCatalogItem.conversionServiceBaseUrl = configuration.conversionServiceBaseUrl;
// Register custom Knockout.js bindings. If you're not using the TerriaJS user interface, you can remove this.
registerKnockoutBindings();
// Register all types of catalog members in the core TerriaJS. If you only want to register a subset of them
// (i.e. to reduce the size of your application if you don't actually use them all), feel free to copy a subset of
// the code in the registerCatalogMembers function here instead.
registerCatalogMembers();
// Construct the TerriaJS application, arrange to show errors to the user, and start it up.
var terria = new Terria({
appName: 'AREMI',
supportEmail: 'aremi@nicta.com.au',
baseUrl: configuration.terriaBaseUrl,
cesiumBaseUrl: configuration.cesiumBaseUrl,
regionMappingDefinitionsUrl: configuration.regionMappingDefinitionsUrl,
analytics: new GoogleAnalytics()
});
// We'll put the entire user interface into a DOM element called 'ui'.
var ui = document.getElementById('ui');
terria.error.addEventListener(function(e) {
PopupMessageViewModel.open(ui, {
title: e.title,
message: e.message
});
});
terria.start({
// If you don't want the user to be able to control catalog loading via the URL, remove the applicationUrl property below
// as well as the call to "updateApplicationOnHashChange" further down.
applicationUrl: window.location,
configUrl: 'config.json',
defaultTo2D: isCommonMobilePlatform(),
urlShortener: new GoogleUrlShortener({
terria: terria
})
}).otherwise(function(e) {
raiseErrorToUser(terria, e);
}).always(function() {
configuration.bingMapsKey = terria.configParameters.bingMapsKey ? terria.configParameters.bingMapsKey : configuration.bingMapsKey;
// Automatically update Terria (load new catalogs, etc.) when the hash part of the URL changes.
updateApplicationOnHashChange(terria, window);
updateApplicationOnMessageFromParentWindow(terria, window);
// Create the map/globe.
TerriaViewer.create(terria, {
developerAttribution: {
text: 'NICTA',
link: 'http://www.nicta.com.au'
}
});
terria.viewerMode = ViewerMode.CesiumEllipsoid;
// Create the various base map options.
var australiaBaseMaps = createAustraliaBaseMapOptions(terria);
var globalBaseMaps = createGlobalBaseMapOptions(terria, configuration.bingMapsKey);
/* turn off the custom AREMI maps for now
var aremiBaseMaps = [];
var osmSimpleLight = new WebMapServiceCatalogItem(terria);
osmSimpleLight.name = 'OpenStreeMaps Light (BETA)';
osmSimpleLight.url = 'https://maps.aurin.org.au/cgi-bin/tilecache.cgi';
osmSimpleLight.layers = 'austatesgrey';
osmSimpleLight.getFeatureInfoFormats = [];
osmSimpleLight.parameters = {
tiled: true
};
osmSimpleLight.opacity = 1.0;
aremiBaseMaps.push(new BaseMapViewModel({
image: 'images/osmLight.png',
catalogItem: osmSimpleLight,
}));
var osmSimpleDark = new WebMapServiceCatalogItem(terria);
osmSimpleDark.name = 'OpenStreeMaps Dark (BETA)';
osmSimpleDark.url = 'https://maps.aurin.org.au/cgi-bin/tilecache.cgi';
osmSimpleDark.layers = 'austatesdark';
osmSimpleDark.getFeatureInfoFormats = [];
osmSimpleDark.parameters = {
tiled: true
};
osmSimpleDark.opacity = 1.0;
aremiBaseMaps.push(new BaseMapViewModel({
image: 'images/osmDark.png',
catalogItem: osmSimpleDark,
}));
*/
var allBaseMaps = australiaBaseMaps.concat(globalBaseMaps);//.concat(aremiBaseMaps);
selectBaseMap(terria, allBaseMaps, 'Positron (Light)');
// Create the Settings / Map panel.
var settingsPanel = SettingsPanelViewModel.create({
container: ui,
terria: terria,
isVisible: false,
baseMaps: allBaseMaps
});
// Create the brand bar.
BrandBarViewModel.create({
container: ui,
elements: [
'<div class="ausglobe-title-aremi">\
<a href="http://arena.gov.au/" target="_blank"><img class="left" src="images/ARENA-logo2.png" alt="Australian Renewable Energy Agency" /></a>\
<a href="https://www.nicta.com.au/" target="_blank"><img class="right" src="images/DATA61_CSIRO.png" alt="NICTA" width="55px" height="33px"/></a>\
<br/>\
<strong>Australian Renewable Energy</strong>\
<br/>\
<small>Mapping Infrastructure</small>\
<br/>\
<span><a target="_blank" href="https://github.com/NICTA/aremi-natmap/blob/master/Changelog.md#version-' + version + '">Version: ' + version + '</a></span>\
</div>'
]
});
// Create the menu bar.
MenuBarViewModel.create({
container: ui,
terria: terria,
items: [
// Add a Tools menu that only appears when "tools=1" is present in the URL.
createToolsMenuItem(terria, ui),
new MenuBarItemViewModel({
label: 'Add data',
tooltip: 'Add your own data to the map.',
svgPath: svgPlus,
svgPathWidth: 11,
svgPathHeight: 12,
callback: function() {
AddDataPanelViewModel.open({
container: ui,
terria: terria
});
}
}),
new MenuBarItemViewModel({
label: 'Base Maps',
tooltip: 'Change the map mode (2D/3D) and base map.',
svgPath: svgWorld,
svgPathWidth: 17,
svgPathHeight: 17,
observableToToggle: knockout.getObservable(settingsPanel, 'isVisible')
}),
new MenuBarItemViewModel({
label: 'Share',
tooltip: 'Share your map with others.',
svgPath: svgShare,
svgPathWidth: 11,
svgPathHeight: 13,
callback: function() {
SharePopupViewModel.open({
container: ui,
terria: terria
});
}
}),
new MenuBarItemViewModel({
label: 'Related Maps',
tooltip: 'View other maps in the NationalMap family.',
svgPath: svgRelated,
svgPathWidth: 14,
svgPathHeight: 13,
callback: function() {
PopupMessageViewModel.open(ui, {
title: 'Related Maps',
message: require('fs').readFileSync(__dirname + '/lib/Views/RelatedMaps.html', 'utf8'),
width: 600,
height: 430
});
}
}),
new MenuBarItemViewModel({
label: 'About',
tooltip: 'About AREMI.',
svgPath: svgInfo,
svgPathWidth: 18,
svgPathHeight: 18,
svgFillRule: 'evenodd',
href: 'About.html'
})
]
});
// Create the lat/lon/elev and distance widgets.
LocationBarViewModel.create({
container: ui,
terria: terria,
mapElement: document.getElementById('cesiumContainer')
});
DistanceLegendViewModel.create({
container: ui,
terria: terria,
mapElement: document.getElementById('cesiumContainer')
});
// Create the navigation controls.
NavigationViewModel.create({
container: ui,
terria: terria
});
// Create the animation controls.
AnimationViewModel.create({
container: document.getElementById('cesiumContainer'),
terria: terria,
autoPlay: false,
mapElementsToDisplace: [
'cesium-widget-credits',
'leaflet-control-attribution',
'distance-legend',
'location-bar'
]
});
var nowViewingTab = new NowViewingTabViewModel({
nowViewing: terria.nowViewing,
name: 'Legends'
});
var isSmallScreen = document.body.clientWidth <= 700 || document.body.clientHeight <= 420;
// Create the explorer panel.
ExplorerPanelViewModel.create({
container: ui,
terria: terria,
mapElementToDisplace: 'cesiumContainer',
isOpen: !isSmallScreen && !terria.userProperties.hideExplorerPanel,
tabs: [
new DataCatalogTabViewModel({
catalog: terria.catalog
}),
nowViewingTab,
new SearchTabViewModel({
searchProviders: [
new CatalogItemNameSearchProviderViewModel({
terria: terria
}),
new BingMapsSearchProviderViewModel({
terria: terria,
key: configuration.bingMapsKey
}),
new GazetteerSearchProviderViewModel({
terria: terria
})
]
})
]
});
// Create the feature information popup.
var featureInfoPanel = FeatureInfoPanelViewModel.create({
container: ui,
terria: terria
});
// Handle the user dragging/dropping files onto the application.
DragDropViewModel.create({
container: ui,
terria: terria,
dropTarget: document,
allowDropInitFiles: true,
allowDropDataFiles: true,
validDropElements: ['ui', 'cesiumContainer'],
invalidDropClasses: ['modal-background']
});
// Add a popup that appears the first time a catalog item is enabled,
// calling the user's attention to the Now Viewing tab.
NowViewingAttentionGrabberViewModel.create({
container: ui,
terria: terria,
nowViewingTabViewModel: nowViewingTab
});
// Make sure only one panel is open in the top right at any time.
MutuallyExclusivePanels.create({
panels: [
settingsPanel,
featureInfoPanel
]
});
// Add the disclaimer, if specified
if(defined(terria.configParameters.globalDisclaimer)) {
var disclaimer = terria.configParameters.globalDisclaimer;
if(defined(disclaimer.enabled) && disclaimer.enabled) {
var message = '';
if (location.hostname.indexOf('nationalmap.gov.au') === -1) {
message += fs.readFileSync(__dirname + '/lib/Views/DevelopmentDisclaimer.html', 'utf8');
}
message += fs.readFileSync(__dirname + '/lib/Views/GlobalDisclaimer.html', 'utf8');
var options = {
title: defined(disclaimer.title) ? disclaimer.title : 'Disclaimer',
confirmText: "I Agree",
width: 600,
height: 550,
message: message,
horizontalPadding : 100
};
if(defined(disclaimer.confirmationRequired) && disclaimer.confirmationRequired) {
// To account for confirmation buttons
options.height += 30;
PopupMessageConfirmationViewModel.open(ui, options);
} else if(!defined(disclaimer.confirmationRequired) ||
(defined(disclaimer.confirmationRequired) && !disclaimer.confirmationRequired)) {
PopupMessageViewModel.open(ui, options);
}
}
}
// Add the survey link
var surveyLink = 'https://docs.google.com/forms/d/1ZQkNgSWA2mmxlsEICxlm7cOhJ2xVxRGScsvJ83i0F3M/viewform';
var surveyContainer = document.createElement("div");
document.querySelector(".explorer-panel-body-pane").appendChild(surveyContainer);
surveyContainer.innerHTML =
'<div class="feedback-request">\
<p><a target="_blank" href="' + surveyLink + '">Give Feedback</a></p>\
<p>This site is still in development, so please <a target="_blank" href="' + surveyLink + '">tell us what you think</a>. Our survey will take 5 mins.</p>\
</div>';
MapProgressBarViewModel.create({
container: document.getElementById('cesiumContainer'),
terria: terria
});
document.getElementById('loadingIndicator').style.display = 'none';
});