diff --git a/3dwebclient/script.js b/3dwebclient/script.js index eec5987d..34884000 100644 --- a/3dwebclient/script.js +++ b/3dwebclient/script.js @@ -33,7 +33,7 @@ var urlController = new UrlController(); /*--------------------------------- set globe variables ----------------------------------------*/ // BingMapsAPI Key for Bing Imagery Layers and Geocoder // If this is not valid, the Bing Imagery Layers will be removed and the Bing Geocoder will be replaced with OSM Nominatim -var bingToken = CitydbUtil.parse_query_string('bingToken', window.location.href); +var bingToken = urlController.getUrlParaValue('bingToken', window.location.href, CitydbUtil); if (Cesium.defined(bingToken) && bingToken !== "") { Cesium.BingMapsApi.defaultKey = bingToken; } @@ -313,44 +313,51 @@ function observeActiveLayer() { } function adjustIonFeatures() { - // If neither BingMapsAPI key nor ion access token is present, remove Bing Maps from the Imagery Providers - if (!Cesium.defined(Cesium.BingMapsApi.defaultKey) || Cesium.BingMapsApi.defaultKey === "") { - var imageryProviders = cesiumViewer.baseLayerPicker.viewModel.imageryProviderViewModels; - var i = 0; - while (i < imageryProviders.length) { - if (imageryProviders[i].name.indexOf("Bing Maps") !== -1) { - //imageryProviders[i]._creationCommand.canExecute = false; - imageryProviders.remove(imageryProviders[i]); + // If ion token is not available, remove Cesium World Terrain from the Terrain Providers + if (!Cesium.defined(ionToken) || ionToken === "") { + var terrainProviders = cesiumViewer.baseLayerPicker.viewModel.terrainProviderViewModels; + i = 0; + while (i < terrainProviders.length) { + if (terrainProviders[i].name.indexOf("Cesium World Terrain") !== -1) { + //terrainProviders[i]._creationCommand.canExecute = false; + terrainProviders.remove(terrainProviders[i]); } else { i++; } } - console.warn("Please enter your Bing Maps API token using the URL-parameter \"bingToken=\" and refresh the page if you wish to use Bing Maps."); - // Set default imagery to ESRI World Imagery - cesiumViewer.baseLayerPicker.viewModel.selectedImagery = imageryProviders[3]; + // Set default imagery to an open-source terrain + cesiumViewer.baseLayerPicker.viewModel.selectedTerrain = terrainProviders[0]; + console.warn("Due to invalid or missing ion access token from user, Cesium World Terrain has been removed. Please enter your ion access token using the URL-parameter \"ionToken=\" and refresh the page if you wish to use ion features."); - // Disable auto-complete of OSM Geocoder due to OSM usage limitations - // see https://operations.osmfoundation.org/policies/nominatim/#unacceptable-use - cesiumViewer._geocoder._viewModel.autoComplete = false; - } + // Cesium ion uses Bing Maps by default -> no need to insert Bing token if an ion token is already available + + // If neither BingMapsAPI key nor ion access token is present, remove Bing Maps from the Imagery Providers + if (!Cesium.defined(Cesium.BingMapsApi.defaultKey) || Cesium.BingMapsApi.defaultKey === "") { + var imageryProviders = cesiumViewer.baseLayerPicker.viewModel.imageryProviderViewModels; + var i = 0; + while (i < imageryProviders.length) { + if (imageryProviders[i].name.indexOf("Bing Maps") !== -1) { + //imageryProviders[i]._creationCommand.canExecute = false; + imageryProviders.remove(imageryProviders[i]); + } else { + i++; + } + } + + // Set default imagery to ESRI World Imagery + cesiumViewer.baseLayerPicker.viewModel.selectedImagery = imageryProviders[3]; - // Remove Cesium World Terrain from the Terrain Providers -// var terrainProviders = cesiumViewer.baseLayerPicker.viewModel.terrainProviderViewModels; -// i = 0; -// while (i < terrainProviders.length) { -// if (terrainProviders[i].name.indexOf("Cesium World Terrain") !== -1) { -// //terrainProviders[i]._creationCommand.canExecute = false; -// terrainProviders.remove(terrainProviders[i]); -// } else { -// i++; -// } -// } -// console.log("Due to invalid or missing ion access token from user, Cesium World Terrain has been removed."); - - // Set default imagery to an open-source terrain - // cesiumViewer.baseLayerPicker.viewModel.selectedTerrain = terrainProviders[0]; - console.warn("Please enter your ion access token using the URL-parameter \"ionToken=\" and refresh the page if you wish to use ion features."); + // Disable auto-complete of OSM Geocoder due to OSM usage limitations + // see https://operations.osmfoundation.org/policies/nominatim/#unacceptable-use + cesiumViewer._geocoder._viewModel.autoComplete = false; + + console.warn("Due to invalid or missing Bing access token from user, all Bing Maps have been removed. Please enter your Bing Maps API token using the URL-parameter \"bingToken=\" and refresh the page if you wish to use Bing Maps."); + } else { + console.error("A Bing token has been detected. This requires an ion token to display the terrain correctly. Please either remove the Bing token in the URL to use the default terrain and imagery, or insert an ion token in addition to the existing Bing token to use Cesium World Terrain and Bing Maps.") + CitydbUtil.showAlertWindow("OK", "Error loading terrain", "A Bing token has been detected. This requires an ion token to display the terrain correctly. Please either remove the Bing token in the URL to use the default terrain and imagery, or insert an ion token in addition to the existing Bing token to use Cesium World Terrain and Bing Maps. Please refer to https://github.com/3dcitydb/3dcitydb-web-map/releases/tag/v1.9.0 for more information."); + } + } } /*--------------------------------- methods and functions ----------------------------------------*/ @@ -725,11 +732,16 @@ function flyToCameraPosition(cameraPosition) { // Creation of a scene link for sharing with other people.. function showSceneLink() { + var tokens = { + ionToken: ionToken, + bingToken: bingToken + } var sceneLink = urlController.generateLink( webMap, addWmsViewModel, addTerrainViewModel, addSplashWindowModel, + tokens, signInController, googleClientId, splashController, diff --git a/3dwebclient/utils/UrlController.js b/3dwebclient/utils/UrlController.js index 75060172..0d8b9ff2 100644 --- a/3dwebclient/utils/UrlController.js +++ b/3dwebclient/utils/UrlController.js @@ -54,6 +54,7 @@ var UrlController = /** @class */ (function () { // "url": "u", "showOnStart": "ss", "ionToken": "it", + "bingToken": "bt", "debug": "db", "googleClientId": "gid" }; @@ -85,14 +86,14 @@ var UrlController = /** @class */ (function () { // return the value defined by the URL parameter UrlController.prototype.getUrlParaValue = function (parameter, url, CitydbUtil) { var result = CitydbUtil.parse_query_string(this.getUrlParaForward(parameter), url); - if (typeof result === "undefined" || result === "") { + if (result == null || result === "") { // reverse mapping // result = CitydbUtil.parse_query_string(this.getUrlParaAuxReverse(parameter), url); result = CitydbUtil.parse_query_string(parameter, url); } return result; }; - UrlController.prototype.generateLink = function (webMap, addWmsViewModel, addTerrainViewModel, addSplashWindowModel, signInController, googleClientId, splashController, cesiumViewer, Cesium) { + UrlController.prototype.generateLink = function (webMap, addWmsViewModel, addTerrainViewModel, addSplashWindowModel, tokens, signInController, googleClientId, splashController, cesiumViewer, Cesium) { var cameraPosition = this.getCurrentCameraPostion(cesiumViewer, Cesium); var projectLink = location.protocol + '//' + location.host + location.pathname + '?'; var clock = cesiumViewer.cesiumWidget.clock; @@ -114,17 +115,24 @@ var UrlController = /** @class */ (function () { '&' + this.getUrlParaForward('roll') + '=' + Math.round(cameraPosition.roll * 1e2) / 1e2 + '&' + this.layersToQuery(webMap, Cesium); var basemap = this.basemapToQuery(addWmsViewModel, cesiumViewer, Cesium); - if (basemap != null) { + if (basemap != null && basemap !== "") { projectLink = projectLink + '&' + basemap; } var terrain = this.terrainToQuery(addTerrainViewModel, cesiumViewer, Cesium); - if (terrain != null) { + if (terrain != null && terrain !== "") { projectLink = projectLink + '&' + terrain; } var splashWindow = this.splashWindowToQuery(addSplashWindowModel, splashController, Cesium); - if (splashWindow != null) { + if (splashWindow != null && splashWindow !== "") { projectLink = projectLink + '&' + splashWindow; } + // export ion and Bing token if available + if (tokens.ionToken != null && tokens.ionToken !== "") { + projectLink = projectLink + '&' + this.getUrlParaForward('ionToken') + '=' + tokens.ionToken; + } + if (tokens.bingToken != null && tokens.bingToken !== "") { + projectLink = projectLink + '&' + this.getUrlParaForward('bingToken') + '=' + tokens.bingToken; + } // only export client ID if user is logged in if ((signInController && signInController.clientID && signInController.isSignIn())) { projectLink = projectLink + '&' + this.getUrlParaForward('googleClientId') + '=' + (signInController.clientID ? signInController.clientID : googleClientId); diff --git a/ts/UrlController.ts b/ts/UrlController.ts index d9f332a8..5c40615d 100644 --- a/ts/UrlController.ts +++ b/ts/UrlController.ts @@ -61,6 +61,7 @@ class UrlController { "showOnStart": "ss", "ionToken": "it", + "bingToken": "bt", "debug": "db", "googleClientId": "gid" }; @@ -94,7 +95,7 @@ class UrlController { // return the value defined by the URL parameter public getUrlParaValue(parameter: string, url: string, CitydbUtil: any): string { let result: any = CitydbUtil.parse_query_string(this.getUrlParaForward(parameter), url); - if (typeof result === "undefined" || result === "") { + if (result == null || result === "") { // reverse mapping // result = CitydbUtil.parse_query_string(this.getUrlParaAuxReverse(parameter), url); result = CitydbUtil.parse_query_string(parameter, url); @@ -107,6 +108,7 @@ class UrlController { addWmsViewModel: any, addTerrainViewModel: any, addSplashWindowModel: any, + tokens: any, signInController: any, googleClientId: any, splashController: SplashController, @@ -136,20 +138,28 @@ class UrlController { '&' + this.getUrlParaForward('roll') + '=' + Math.round(cameraPosition.roll * 1e2) / 1e2 + '&' + this.layersToQuery(webMap, Cesium); let basemap = this.basemapToQuery(addWmsViewModel, cesiumViewer, Cesium); - if (basemap != null) { + if (basemap != null && basemap !== "") { projectLink = projectLink + '&' + basemap; } let terrain = this.terrainToQuery(addTerrainViewModel, cesiumViewer, Cesium); - if (terrain != null) { + if (terrain != null && terrain !== "") { projectLink = projectLink + '&' + terrain; } let splashWindow = this.splashWindowToQuery(addSplashWindowModel, splashController, Cesium); - if (splashWindow != null) { + if (splashWindow != null && splashWindow !== "") { projectLink = projectLink + '&' + splashWindow; } + // export ion and Bing token if available + if (tokens.ionToken != null && tokens.ionToken !== "") { + projectLink = projectLink + '&' + this.getUrlParaForward('ionToken') + '=' + tokens.ionToken; + } + if (tokens.bingToken != null && tokens.bingToken !== "") { + projectLink = projectLink + '&' + this.getUrlParaForward('bingToken') + '=' + tokens.bingToken; + } + // only export client ID if user is logged in if ((signInController && signInController.clientID && signInController.isSignIn())) { projectLink = projectLink + '&' + this.getUrlParaForward('googleClientId') + '=' + (signInController.clientID ? signInController.clientID : googleClientId);