From 4db4e03073b79cb9daaf6995b4e6458dd5d88741 Mon Sep 17 00:00:00 2001 From: Philipp Wambach Date: Wed, 8 Jul 2020 09:07:36 +0200 Subject: [PATCH] fix(electron): make multiple basemaps work offline (#379) --- ci/cloudbuild-electron-builder.yaml | 13 +++++++++++++ package.json | 4 +++- scripts/basemap-tiles.sh | 2 +- src/scripts/components/globe/globe.tsx | 7 +++++-- src/scripts/config/main.ts | 8 ++++++++ 5 files changed, 30 insertions(+), 4 deletions(-) diff --git a/ci/cloudbuild-electron-builder.yaml b/ci/cloudbuild-electron-builder.yaml index c977236b7..291e65aaa 100644 --- a/ci/cloudbuild-electron-builder.yaml +++ b/ci/cloudbuild-electron-builder.yaml @@ -2,6 +2,19 @@ steps: - name: 'gcr.io/cloud-builders/npm' entrypoint: npm args: ['ci'] + + - name: 'stedolan/jq' + entrypoint: 'bash' + args: ['-c', 'jq -r version.txt'] + + - name: 'gcr.io/esa-climate-from-space/electron-builder' + entrypoint: 'npm' + args: ['run', 'electron:prepare-build'] + + - name: 'gcr.io/google.com/cloudsdktool/cloud-sdk:alpine' + entrypoint: 'bash' + args: ['-c', 'gsutil -m cp -r gs://esa-cfs-tiles/$(cat version.txt)/basemaps ./dist'] + - name: 'gcr.io/esa-climate-from-space/electron-builder' env: - 'ELECTRON_CACHE=/root/.cache/electron' diff --git a/package.json b/package.json index f5e0fa970..6d90dedee 100644 --- a/package.json +++ b/package.json @@ -21,7 +21,9 @@ "electron:start": "npm run electron:compile && electron .", "electron:install": "electron-builder install-app-deps", "electron:clean": "rm -rf ./dist-electron && rm -rf ./dist-src-electron", - "electron:build": "npm run electron:clean && npm run electron:install && npm run build && npm run electron:compile && electron-builder -mwl --x64 --config electron-builder.json", + "electron:prepare-build": "npm run electron:clean && npm run electron:install && npm run build && npm run electron:compile", + "electron:build": "electron-builder -mwl --x64 --config electron-builder.json", + "electron:download-basemaps": "gsutil -m cp -r gs://esa-cfs-tiles/${npm_package_version}/basemaps ./dist", "story-packages": "./scripts/create-story-packages.sh", "clean:story-packages": "find ./storage -type f -name \"*.zip\" -delete", "upload-storage": "npm run story-packages && gsutil rsync -r -x \".DS_Store\" ./storage gs://esa-cfs-storage/$npm_package_version && gsutil -m setmeta -r -h \"Cache-Control: no-cache\" gs://esa-cfs-storage/$npm_package_version/ && npm run clean:story-packages" diff --git a/scripts/basemap-tiles.sh b/scripts/basemap-tiles.sh index e647355a8..b5426376b 100755 --- a/scripts/basemap-tiles.sh +++ b/scripts/basemap-tiles.sh @@ -1,7 +1,7 @@ #!/usr/bin/env bash # Usage: ./basemap-tiles.sh -# with Docker: docker run -v `pwd`:/data -w /data --name gdal2 -it --rm geographica/gdal2 ./basemap-tiles +# with Docker: docker run -v `pwd`:/data -w /data --name gdal2 -it --rm geographica/gdal2 ./basemap-tiles # Images and worldfiles can be found here: https://drive.google.com/drive/folders/15UR1BBZRVPvLlvPF3s5yYNqpdmd6PMcF # Upload tiles with: gsutil -m cp -r .// gs://esa-cfs-tiles//basemaps/ diff --git a/src/scripts/components/globe/globe.tsx b/src/scripts/components/globe/globe.tsx index 37e11d65a..a30a87047 100644 --- a/src/scripts/components/globe/globe.tsx +++ b/src/scripts/components/globe/globe.tsx @@ -16,6 +16,7 @@ import { setGlobeView, flyToGlobeView } from '../../libs/get-globe-view'; +import {isElectron} from '../../libs/electron/index'; import {GlobeView} from '../../types/globe-view'; import {GlobeProjection} from '../../types/globe-projection'; @@ -57,10 +58,12 @@ let basemapLayer: Cesium.ImageryLayer | null = null; function getBasemapUrl(id: BasemapId | null) { if (!id || !config.basemapUrls[id]) { - return config.basemapUrls[config.defaultBasemap]; + return isElectron() + ? config.basemapUrlsOffline[config.defaultBasemap] + : config.basemapUrls[config.defaultBasemap]; } - return config.basemapUrls[id]; + return isElectron() ? config.basemapUrlsOffline[id] : config.basemapUrls[id]; } const Globe: FunctionComponent = ({ diff --git a/src/scripts/config/main.ts b/src/scripts/config/main.ts index a2aa8fb92..177d2e452 100644 --- a/src/scripts/config/main.ts +++ b/src/scripts/config/main.ts @@ -34,6 +34,13 @@ const basemapUrls = { blue: `${baseUrlTiles}/basemaps/blue` }; +const basemapUrlsOffline = { + land: 'basemaps/land', + ocean: 'basemaps/ocean', + atmosphere: 'basemaps/atmosphere', + blue: 'basemaps/blue' +}; + export default { api: { layers: `${baseUrlStorage}/layers/layers-{lang}.json`, @@ -47,6 +54,7 @@ export default { }, defaultBasemap: 'land' as keyof typeof basemapUrls, basemapUrls, + basemapUrlsOffline, globe: globeState, share: { facebook: