This repository has been archived by the owner on Nov 18, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
158 lines (136 loc) · 7.51 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
'use strict';
/*global require,window */
var terriaOptions = {
baseUrl: 'build/TerriaJS'
};
// checkBrowserCompatibility('ui');
import GoogleAnalytics from 'terriajs/lib/Core/GoogleAnalytics';
import ShareDataService from 'terriajs/lib/Models/ShareDataService';
import raiseErrorToUser from 'terriajs/lib/Models/raiseErrorToUser';
import registerAnalytics from 'terriajs/lib/Models/registerAnalytics';
import registerCatalogMembers from 'terriajs/lib/Models/registerCatalogMembers';
import registerCustomComponentTypes from 'terriajs/lib/ReactViews/Custom/registerCustomComponentTypes';
import Terria from 'terriajs/lib/Models/Terria';
import updateApplicationOnHashChange from 'terriajs/lib/ViewModels/updateApplicationOnHashChange';
import updateApplicationOnMessageFromParentWindow from 'terriajs/lib/ViewModels/updateApplicationOnMessageFromParentWindow';
import ViewState from 'terriajs/lib/ReactViewModels/ViewState';
import BingMapsSearchProviderViewModel from 'terriajs/lib/ViewModels/BingMapsSearchProviderViewModel.js';
import GazetteerSearchProviderViewModel from 'terriajs/lib/ViewModels/GazetteerSearchProviderViewModel.js';
import GnafSearchProviderViewModel from 'terriajs/lib/ViewModels/GnafSearchProviderViewModel.js';
import defined from 'terriajs-cesium/Source/Core/defined';
import render from './lib/Views/render';
import GnafAddressGeocoder from 'terriajs/lib/Map/GnafAddressGeocoder.js';
import ViewerMode from 'terriajs/lib/Models/ViewerMode.js';
import NswTrafficVolume from './lib/Models/NswTrafficVolume';
import NswTrafficHourlyVolume from './lib/Models/NswTrafficHourlyVolume';
// 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();
registerAnalytics();
NswTrafficVolume.register();
NswTrafficHourlyVolume.register();
terriaOptions.analytics = new GoogleAnalytics();
terriaOptions.batchGeocoder = new GnafAddressGeocoder();
terriaOptions.viewerMode = ViewerMode.CesiumEllipsoid;
// Construct the TerriaJS application, arrange to show errors to the user, and start it up.
var terria = new Terria(terriaOptions);
// Register custom components in the core TerriaJS. If you only want to register a subset of them, or to add your own,
// insert your custom version of the code in the registerCustomComponentTypes function here instead.
registerCustomComponentTypes(terria);
// Create the ViewState before terria.start so that errors have somewhere to go.
const viewState = new ViewState({
terria: terria
});
if (process.env.NODE_ENV === "development") {
window.viewState = viewState;
}
// If we're running in dev mode, disable the built style sheet as we'll be using the webpack style loader.
// Note that if the first stylesheet stops being TerriaMap.css then this will have to change.
if (process.env.NODE_ENV !== "production" && module.hot) {
document.styleSheets[0].disabled = true;
}
terria.filterStartDataCallback = function(startData) {
if (startData.initSources) {
// Do not allow share URLs to load old versions of the catalog that
// are included in the initSources.
startData.initSources = startData.initSources.filter(function(initSource) {
if (typeof initSource === 'string') {
return initSource.indexOf('static.aremi.data61.io/init') < 0 &&
initSource.indexOf('init/aremi.json') < 0;
}
return true;
});
// Backward compatibility for old ABS-ITT catalog items. Go load an annex catalog that contains them.
const containsAbsIttItems = startData.initSources.some(function(initSource) {
return initSource.sharedCatalogMembers && Object.keys(initSource.sharedCatalogMembers).some(shareKey => initSource.sharedCatalogMembers[shareKey].type === 'abs-itt');
});
if (containsAbsIttItems) {
terria.error.raiseEvent({
title: 'Warning',
message: 'The share link you just visited is using an old interface to the ABS census data that will stop working in a future version of NationalMap. If this is your link, please update it to use the new ABS catalog items in the National Datasets section.'
});
startData.initSources.unshift('init/abs-itt.json');
}
}
};
module.exports = 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',
shareDataService: new ShareDataService({
terria: terria
}),
globalDisclaimerHtml: require('./lib/Views/GlobalDisclaimer.html'),
developmentDisclaimerPreambleHtml: require('./lib/Views/DevelopmentDisclaimerPreamble.html')
}).otherwise(function(e) {
raiseErrorToUser(terria, e);
}).always(function() {
try {
viewState.searchState.locationSearchProviders = [
new BingMapsSearchProviderViewModel({
terria: terria,
key: terria.configParameters.bingMapsKey
}),
new GazetteerSearchProviderViewModel({terria}),
new GnafSearchProviderViewModel({terria})
];
// Automatically update Terria (load new catalogs, etc.) when the hash part of the URL changes.
updateApplicationOnHashChange(terria, window);
updateApplicationOnMessageFromParentWindow(terria, window);
// Create the various base map options.
var createAustraliaBaseMapOptions = require('terriajs/lib/ViewModels/createAustraliaBaseMapOptions');
var createGlobalBaseMapOptions = require('terriajs/lib/ViewModels/createGlobalBaseMapOptions');
var createExtraBaseMapOptions = require('./lib/ViewModels/createExtraBaseMapOptions');
var selectBaseMap = require('terriajs/lib/ViewModels/selectBaseMap');
var australiaBaseMaps = createAustraliaBaseMapOptions(terria);
var globalBaseMaps = createGlobalBaseMapOptions(terria, terria.configParameters.bingMapsKey);
var extraBaseMaps = createExtraBaseMapOptions(terria);
var allBaseMaps = australiaBaseMaps.concat(globalBaseMaps.concat(extraBaseMaps));
var toRemove = ["Bing Maps Roads", "Natural Earth II", "NASA Black Marble"];
allBaseMaps = allBaseMaps.filter(basemap => toRemove.indexOf(basemap.catalogItem.name) < 0);
selectBaseMap(terria, allBaseMaps, 'Positron (Light)', true);
// Add the disclaimer, if specified
if (defined(terria.configParameters.globalDisclaimer)) {
var disclaimer = terria.configParameters.globalDisclaimer;
if (defined(disclaimer.enabled) && disclaimer.enabled) {
var message = '';
/* disabling the dev disclaimer for the UX testing
if (location.hostname.indexOf('nationalmap.gov.au') === -1) {
message += fs.readFileSync(__dirname + '/lib/Views/DevelopmentDisclaimer.html', 'utf8');
}
*/
message += require('./lib/Views/GlobalDisclaimer.html');
var options = {
message: message
};
viewState.notifications.push(options);
}
}
render(terria, allBaseMaps, viewState);
} catch (e) {
console.error(e);
console.error(e.stack);
}
});