From 218633b1171b87f2f3c0520480c7a7ce24fabcb7 Mon Sep 17 00:00:00 2001 From: Nick Forbes-Smith Date: Thu, 30 Jun 2022 12:15:02 +1000 Subject: [PATCH 1/3] Update terriajs load procedure --- entry.js | 5 +- index.js | 233 ++++++++++++++++++++++++++++--------------------------- 2 files changed, 121 insertions(+), 117 deletions(-) diff --git a/entry.js b/entry.js index 8c8c37cea..3838127b9 100644 --- a/entry.js +++ b/entry.js @@ -9,7 +9,7 @@ function loadMainScript() { require.ensure(['terriajs/lib/Core/prerequisites'], function(require) { require('terriajs/lib/Core/prerequisites'); require.ensure(['./index'], function(require) { - resolve(require('./index')); + resolve(require('./index')()); }, reject, 'index'); }, reject, 'index'); }); @@ -35,7 +35,8 @@ function createLoader() { document.body.appendChild(loaderDiv); polyfill(function() { - loadMainScript().catch(() => { + loadMainScript().catch((e) => { + console.error(e); // Ignore errors and try to show the map anyway }).then(() => { loaderDiv.classList.add('loader-ui-hide'); diff --git a/index.js b/index.js index 241e86543..36e09c71f 100644 --- a/index.js +++ b/index.js @@ -1,47 +1,37 @@ -'use strict'; - -var terriaOptions = { - baseUrl: 'build/TerriaJS' -}; +"use strict"; import { runInAction } from "mobx"; -// checkBrowserCompatibility('ui'); -import ConsoleAnalytics from 'terriajs/lib/Core/ConsoleAnalytics'; -import GoogleAnalytics from 'terriajs/lib/Core/GoogleAnalytics'; -import ShareDataService from 'terriajs/lib/Models/ShareDataService'; -// 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/Models/SearchProviders/BingMapsSearchProvider'; -// 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 registerCatalogMembers from 'terriajs/lib/Models/Catalog/registerCatalogMembers'; -import defined from 'terriajs-cesium/Source/Core/defined'; +import ConsoleAnalytics from "terriajs/lib/Core/ConsoleAnalytics"; +import GoogleAnalytics from "terriajs/lib/Core/GoogleAnalytics"; +import isDefined from "terriajs/lib/Core/isDefined"; +import ShareDataService from "terriajs/lib/Models/ShareDataService"; +import registerCustomComponentTypes from "terriajs/lib/ReactViews/Custom/registerCustomComponentTypes"; +import Terria from "terriajs/lib/Models/Terria"; +import ViewState from "terriajs/lib/ReactViewModels/ViewState"; +import BingMapsSearchProviderViewModel from "terriajs/lib/Models/SearchProviders/BingMapsSearchProvider"; +import render from "./lib/Views/render"; +import registerCatalogMembers from "terriajs/lib/Models/Catalog/registerCatalogMembers"; import loadPlugins from "./lib/Core/loadPlugins"; import plugins from "./plugins"; -// 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(); +const terriaOptions = { + baseUrl: "build/TerriaJS" +}; // we check exact match for development to reduce chances that production flag isn't set on builds(?) if (process.env.NODE_ENV === "development") { - terriaOptions.analytics = new ConsoleAnalytics(); + terriaOptions.analytics = new ConsoleAnalytics(); } else { - terriaOptions.analytics = new GoogleAnalytics(); + terriaOptions.analytics = new GoogleAnalytics(); } // Construct the TerriaJS application, arrange to show errors to the user, and start it up. -var terria = new Terria(terriaOptions); +const terria = new Terria(terriaOptions); + +// 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 +registerCatalogMembers(); // 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. @@ -49,103 +39,116 @@ registerCustomComponentTypes(terria); // Create the ViewState before terria.start so that errors have somewhere to go. const viewState = new ViewState({ - terria: terria + terria: terria }); -registerCatalogMembers(); - - +// Add viewState to window global in dev environment for easy debugging if (process.env.NODE_ENV === "development") { - window.viewState = viewState; + 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 nationalmap.css then this will have to change. if (process.env.NODE_ENV !== "production" && module.hot) { - document.styleSheets[0].disabled = true; + document.styleSheets[0].disabled = true; } -module.exports = terria.start({ - configUrl: 'config.json', - shareDataService: new ShareDataService({ +/** Terria load procedure: + * - Terria.start + * - Load plugins + * - load init sources + * - render + */ +module.exports = async function() { + try { + await terria.start({ + configUrl: "config.json", + shareDataService: new ShareDataService({ terria: terria - }) -}).catch(function(e) { - terria.raiseErrorToUser(e); -}).finally(function() { - // Load plugins before reading the application URL and loading init sources - // as plugins can register new catalog member types. - loadPlugins(viewState, plugins) - .catch(error => { - console.error(`Error loading plugins`); - console.error(error); - }) - .finally(() => { - terria.updateApplicationUrl(window.location.href); - terria - .loadInitSources() - .then(result => result.raiseError(terria)); + }), + applicationUrl: window.location.href }); + } catch (e) { + terria.raiseErrorToUser(e); + } - 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); - - // Show a modal disclaimer before user can do anything else. - if (defined(terria.configParameters.globalDisclaimer)) { - var globalDisclaimer = terria.configParameters.globalDisclaimer; - var hostname = window.location.hostname; - if (globalDisclaimer.enableOnLocalhost || hostname.indexOf('localhost') === -1) { - var message = ''; - // Sometimes we want to show a preamble if the user is viewing a site other than the official production instance. - // This can be expressed as a devHostRegex ("any site starting with staging.") or a negative prodHostRegex ("any site not ending in .gov.au") - if (defined(globalDisclaimer.devHostRegex) && hostname.match(globalDisclaimer.devHostRegex) || - defined(globalDisclaimer.prodHostRegex) && !hostname.match(globalDisclaimer.prodHostRegex)) { - message += require('./lib/Views/DevelopmentDisclaimerPreamble.html'); - } - message += require('./lib/Views/GlobalDisclaimer.html'); - - var options = { - title: (globalDisclaimer.title !== undefined) ? globalDisclaimer.title : 'Warning', - confirmText: (globalDisclaimer.buttonTitle || "Ok"), - denyText: (globalDisclaimer.denyText || "Cancel"), - denyAction: globalDisclaimer.afterDenyLocation ? function() { - window.location = globalDisclaimer.afterDenyLocation; - } : undefined, - width: 600, - height: 550, - message: message, - horizontalPadding : 100 - }; - runInAction(() => { - viewState.disclaimerSettings = options; - viewState.disclaimerVisible = true; - }); - } - } - - // Add font-imports - const fontImports = terria.configParameters.theme?.fontImports; - if (fontImports) { - const styleSheet = document.createElement("style"); - styleSheet.type = "text/css"; - styleSheet.innerText = fontImports; - document.head.appendChild(styleSheet); + // Load plugins before loading init sources + // as plugins can register new catalog member types. + try { + await loadPlugins(viewState, plugins); + } catch (e) { + console.error(`Error loading plugins`); + console.error(e); + } + + // Asynchronously load InitSources + terria.loadInitSources().then(result => result.raiseError(terria)); + + try { + viewState.searchState.locationSearchProviders = [ + new BingMapsSearchProviderViewModel({ + terria: terria, + key: terria.configParameters.bingMapsKey + }) + ]; + + // Show a modal disclaimer before user can do anything else. + if (isDefined(terria.configParameters.globalDisclaimer)) { + const globalDisclaimer = terria.configParameters.globalDisclaimer; + const hostname = window.location.hostname; + if ( + globalDisclaimer.enableOnLocalhost || + hostname.indexOf("localhost") === -1 + ) { + let message = ""; + // Sometimes we want to show a preamble if the user is viewing a site other than the official production instance. + // This can be expressed as a devHostRegex ("any site starting with staging.") or a negative prodHostRegex ("any site not ending in .gov.au") + if ( + (isDefined(globalDisclaimer.devHostRegex) && + hostname.match(globalDisclaimer.devHostRegex)) || + (isDefined(globalDisclaimer.prodHostRegex) && + !hostname.match(globalDisclaimer.prodHostRegex)) + ) { + message += require("./lib/Views/DevelopmentDisclaimerPreamble.html"); } + message += require("./lib/Views/GlobalDisclaimer.html"); + + const options = { + title: + globalDisclaimer.title !== undefined + ? globalDisclaimer.title + : "Warning", + confirmText: globalDisclaimer.buttonTitle || "Ok", + denyText: globalDisclaimer.denyText || "Cancel", + denyAction: globalDisclaimer.afterDenyLocation + ? function() { + window.location = globalDisclaimer.afterDenyLocation; + } + : undefined, + width: 600, + height: 550, + message: message, + horizontalPadding: 100 + }; + runInAction(() => { + viewState.disclaimerSettings = options; + viewState.disclaimerVisible = true; + }); + } + } - render(terria, [], viewState); - } catch (e) { - console.error(e); - console.error(e.stack); + // Add font-imports + const fontImports = terria.configParameters.theme?.fontImports; + if (fontImports) { + const styleSheet = document.createElement("style"); + styleSheet.type = "text/css"; + styleSheet.innerText = fontImports; + document.head.appendChild(styleSheet); } -}); + + render(terria, [], viewState); + } catch (e) { + console.error(e); + console.error(e.stack); + } +}; From a16d3b32a49fd011ae564054a907858b5c829f80 Mon Sep 17 00:00:00 2001 From: Nick Forbes-Smith Date: Thu, 30 Jun 2022 12:33:54 +1000 Subject: [PATCH 2/3] update terriajs deps --- .prettierignore | 1 + package.json | 4 ++-- yarn.lock | 58 +++++++++++++++++++++++++++++++++++++------------ 3 files changed, 47 insertions(+), 16 deletions(-) diff --git a/.prettierignore b/.prettierignore index ca3832430..4296a89fd 100644 --- a/.prettierignore +++ b/.prettierignore @@ -8,3 +8,4 @@ !lib/**/*.ts !lib/**/*.tsx !lib/**/*.scss +!index.js diff --git a/package.json b/package.json index 536a79d85..34239744f 100644 --- a/package.json +++ b/package.json @@ -82,9 +82,9 @@ "semver": "^5.0.0", "style-loader": "^0.23.1", "svg-sprite-loader": "4.1.3", - "terriajs": "8.2.4", + "terriajs": "terriajs/terriajs#terria-cleanup", "terriajs-catalog-editor": "^0.2.0", - "terriajs-cesium": "1.81.3", + "terriajs-cesium": "1.92.0-tile-error-provider-fix-2", "terriajs-schema": "latest", "ts-loader": "^5.3.3", "typescript": "^3.9.2", diff --git a/yarn.lock b/yarn.lock index 8fa04df8f..fd0a18741 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1306,6 +1306,14 @@ resolved "https://registry.yarnpkg.com/@sindresorhus/is/-/is-2.1.1.tgz#ceff6a28a5b4867c2dd4a1ba513de278ccbe8bb1" integrity sha512-/aPsuoj/1Dw/kzhkgz+ES6TxG0zfTMGLwuK2ZG00k/iJzYHTLCE8mVU8EPqEOp/lmxPoq1C1C9RYToRKb2KEfg== +"@tinymce/tinymce-react@^4.1.0": + version "4.1.0" + resolved "https://registry.yarnpkg.com/@tinymce/tinymce-react/-/tinymce-react-4.1.0.tgz#e2a5e289dc1af03837365bebe969b1a722bf6d99" + integrity sha512-7qXheXhyY9a8mY5tXQUz3BFq+Z4TQ7zd/OIaKasbVzojkjCw3VWdwFhHOEcwmDDprepgQwECsYqe3AGOtehfFg== + dependencies: + prop-types "^15.6.2" + tinymce "^6.0.0 || ^5.5.1" + "@turf/bbox@*", "@turf/bbox@^6.5.0": version "6.5.0" resolved "https://registry.yarnpkg.com/@turf/bbox/-/bbox-6.5.0.tgz#bec30a744019eae420dac9ea46fb75caa44d8dc5" @@ -1504,6 +1512,11 @@ dependencies: "@types/trusted-types" "*" +"@types/file-saver@^1.3.0": + version "1.3.1" + resolved "https://registry.yarnpkg.com/@types/file-saver/-/file-saver-1.3.1.tgz#55d76b3c78b5fcc8a7588ead428dce0822464120" + integrity sha512-A+lNc0nnhtX3iTLEYd/DisKTZdNKTf1bN0aSfQD/fG8bQ6SfUe5u8Fm2ab8qQHaMY5GVZumAXLnYptwX+mmQgg== + "@types/flexsearch@^0.7.1": version "0.7.3" resolved "https://registry.yarnpkg.com/@types/flexsearch/-/flexsearch-0.7.3.tgz#ee79b1618035c82284278e05652e91116765b634" @@ -1626,6 +1639,21 @@ resolved "https://registry.yarnpkg.com/@types/rbush/-/rbush-3.0.0.tgz#b6887d99b159e87ae23cd14eceff34f139842aa6" integrity sha512-W3ue/GYWXBOpkRm0VSoifrP3HV0Ni47aVJWvXyWMcbtpBy/l/K/smBRiJ+fI8f7shXRjZBiux+iJzYbh7VmcZg== +"@types/rc-slider@^8.6.6": + version "8.6.6" + resolved "https://registry.yarnpkg.com/@types/rc-slider/-/rc-slider-8.6.6.tgz#961ccfd0b8c632a9d8cdcc28b54d6be4781c419f" + integrity sha512-2Q3vwKrSm3PbgiMNwzxMkOaMtcAGi0xQ8WPeVKoabk1vNYHiVR44DMC3mr9jC2lhbxCBgGBJWF9sBhmnSDQ8Bg== + dependencies: + "@types/rc-tooltip" "*" + "@types/react" "*" + +"@types/rc-tooltip@*": + version "3.7.6" + resolved "https://registry.yarnpkg.com/@types/rc-tooltip/-/rc-tooltip-3.7.6.tgz#d3833b3f3e494ab14e4a95158f9f6b321042c97a" + integrity sha512-Otouf6HW49RSwtTa3EBdp0+BZoOQy3KDTEcVgLdZEgcYp4HB5nP6N3S6bTUkPtq3H5KmYBzEOaiq0SNMB/MY2g== + dependencies: + "@types/react" "*" + "@types/react-color@^3.0.6": version "3.0.6" resolved "https://registry.yarnpkg.com/@types/react-color/-/react-color-3.0.6.tgz#602fed023802b2424e7cd6ff3594ccd3d5055f9a" @@ -9030,10 +9058,6 @@ pbkdf2@^3.0.3: safe-buffer "^5.0.1" sha.js "^2.4.8" -"pell@github:TerriaJS/pell#master": - version "1.0.6" - resolved "https://codeload.github.com/TerriaJS/pell/tar.gz/7cd23a55cdfd130fedf3679433991bb7d958fc42" - performance-now@^2.1.0: version "2.1.0" resolved "https://registry.yarnpkg.com/performance-now/-/performance-now-2.1.0.tgz#6309f4e0e5fa913ec1c69307ae364b4b377c9e7b" @@ -11528,10 +11552,10 @@ terriajs-catalog-editor@^0.2.0: resolved "https://registry.yarnpkg.com/terriajs-catalog-editor/-/terriajs-catalog-editor-0.2.0.tgz#d9c6679e53c4d92e87a531af896c6148888ed8e4" integrity sha1-2cZnnlPE2S6HpTGviWxhSIiO2OQ= -terriajs-cesium@1.81.3: - version "1.81.3" - resolved "https://registry.yarnpkg.com/terriajs-cesium/-/terriajs-cesium-1.81.3.tgz#97bb3de03dc531e3125548cb053c4cb86d2dd39a" - integrity sha512-jDEWXwWYnIdFlMePPnunsd3+Qbo205iNJSerU5lH/0nHOl5af4l1a8u8KTbHzatXFz9HAg8Q6nCsFLpjiZ6Klg== +terriajs-cesium@1.92.0-tile-error-provider-fix-2: + version "1.92.0-tile-error-provider-fix-2" + resolved "https://registry.yarnpkg.com/terriajs-cesium/-/terriajs-cesium-1.92.0-tile-error-provider-fix-2.tgz#f9cce39dd3bd18622ac8a44a20873fb0e9ebb103" + integrity sha512-0fDVJ9lzSRcz04xh2WjbV9vID7ZfEpFyw7j86uTW38AwAiUq642On/qdeK/1MP1aGdvNN15eevb4tjmWhdvgrw== dependencies: dompurify "^2.0.7" @@ -11600,10 +11624,9 @@ terriajs-server@^3.3.4: when "^3.7.7" yargs "^13.2.4" -terriajs@8.2.4: - version "8.2.4" - resolved "https://registry.yarnpkg.com/terriajs/-/terriajs-8.2.4.tgz#30b3409679548c3c60109e3cdc284197fff29e5d" - integrity sha512-qL+lgA3TXWe/9uXgtFFYWA3JMsle8BIMW37FJS1nP7hD3nedgKf5tr3CxDNBzfl2aVg8k5mvb8HceG/oGrWgjg== +terriajs@terriajs/terriajs#terria-cleanup: + version "8.2.6" + resolved "https://codeload.github.com/terriajs/terriajs/tar.gz/0ab6562b83cb7f2a8de33286397a2b178b9eae37" dependencies: "@babel/core" "^7.16.0" "@babel/parser" "^7.12.14" @@ -11616,6 +11639,7 @@ terriajs@8.2.4: "@mapbox/togeojson" "^0.16.0" "@mapbox/vector-tile" "^1.3.0" "@opendatasoft/api-client" "^0.1.0" + "@tinymce/tinymce-react" "^4.1.0" "@turf/bbox" "^6.5.0" "@turf/boolean-intersects" "^6.5.0" "@turf/circle" "^6.5.0" @@ -11631,6 +11655,7 @@ terriajs@8.2.4: "@types/d3-transition" "^1.1.4" "@types/dateformat" "^3.0.1" "@types/dompurify" "^2.3.1" + "@types/file-saver" "^1.3.0" "@types/flexsearch" "^0.7.1" "@types/jasmine" "^2.8.8" "@types/jasmine-ajax" "^3.3.0" @@ -11642,6 +11667,7 @@ terriajs@8.2.4: "@types/papaparse" "^4.5.9" "@types/pbf" "^3.0.1" "@types/rbush" "^3.0.0" + "@types/rc-slider" "^8.6.6" "@types/react" "^17.0.3" "@types/react-color" "^3.0.6" "@types/react-dom" "^17.0.2" @@ -11718,7 +11744,6 @@ terriajs@8.2.4: mutationobserver-shim "^0.3.1" papaparse "^5.2.0" pbf "^3.0.1" - pell "github:TerriaJS/pell#master" point-in-polygon "^1.0.1" proj4 "^2.4.4" prop-types "^15.6.0" @@ -11749,7 +11774,7 @@ terriajs@8.2.4: style-loader "^0.23.1" styled-components "^5.1.0" svg-sprite-loader "4.1.3" - terriajs-cesium "1.81.3" + terriajs-cesium "1.92.0-tile-error-provider-fix-2" terriajs-html2canvas "1.0.0-alpha.12-terriajs-1" thredds-catalog-crawler "0.0.5" ts-essentials "^5.0.0" @@ -11880,6 +11905,11 @@ tinycolor2@^1.4.1: resolved "https://registry.yarnpkg.com/tinycolor2/-/tinycolor2-1.4.2.tgz#3f6a4d1071ad07676d7fa472e1fac40a719d8803" integrity sha512-vJhccZPs965sV/L2sU4oRQVAos0pQXwsvTLkWYdqJ+a8Q5kPFzJTuOFwy7UniPli44NKQGAglksjvOcpo95aZA== +"tinymce@^6.0.0 || ^5.5.1": + version "6.0.3" + resolved "https://registry.yarnpkg.com/tinymce/-/tinymce-6.0.3.tgz#993db09afa473a764ad8b594cdaf744b2c7e2e74" + integrity sha512-4cu80kWF7nRGhviE10poZtjTkl3jNL+lycilCMfdm3KU5V7FtiQQrKbEo6GInXT05RY78Ha/NFP0gOBELcSpfg== + tinyqueue@^2.0.3: version "2.0.3" resolved "https://registry.yarnpkg.com/tinyqueue/-/tinyqueue-2.0.3.tgz#64d8492ebf39e7801d7bd34062e29b45b2035f08" From a8ddd63a267c9560bf945ac663880aed07fc1d44 Mon Sep 17 00:00:00 2001 From: Nick Forbes-Smith Date: Thu, 30 Jun 2022 12:50:53 +1000 Subject: [PATCH 3/3] fix applicationUrl --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index 36e09c71f..25b650e3a 100644 --- a/index.js +++ b/index.js @@ -66,7 +66,7 @@ module.exports = async function() { shareDataService: new ShareDataService({ terria: terria }), - applicationUrl: window.location.href + applicationUrl: window.location }); } catch (e) { terria.raiseErrorToUser(e);