Skip to content

Commit

Permalink
feat(gallery-layer-type): add boilerplate
Browse files Browse the repository at this point in the history
  • Loading branch information
mrMetalWood committed Aug 28, 2020
1 parent 1234893 commit 811cf12
Show file tree
Hide file tree
Showing 12 changed files with 82 additions and 34 deletions.
1 change: 1 addition & 0 deletions src/scripts/config/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ export default {
layer: `${baseUrlTiles}/{id}/metadata.json`,
layerTiles: `${baseUrlTiles}/{id}/tiles/{timeIndex}/{z}/{x}/{reverseY}.png`,
layerImage: `${baseUrlTiles}/{id}/tiles/{timeIndex}/full.png`,
layerGalleryImage: `${baseUrlTiles}/{id}/tiles/{timeIndex}/full.jpg`,
layerOfflinePackage: `${baseUrlTiles}/{id}/package.zip`,
storyOfflinePackage: `${baseUrlStorage}/stories/{id}/package.zip`,
storyMediaBase: `${baseUrlStorage}/stories/{id}`,
Expand Down
8 changes: 4 additions & 4 deletions src/scripts/hooks/use-globe-layer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
} from 'cesium';

import {GlobeImageLayerData} from '../types/globe-image-layer-data';
import {GlobeLayerType} from '../types/globe-layer-type';
import {LayerType} from '../types/globe-layer-type';

// update layer image when url changes
export function useGlobeLayer(
Expand Down Expand Up @@ -53,12 +53,12 @@ export function useGlobeLayer(
layersToRemove.forEach(layer => layers.remove(layer, true));

// preload next images
if (imageLayer.type === GlobeLayerType.Image) {
if (imageLayer.type === LayerType.Image) {
preloadNext(imageLayer.nextUrls);
}
};

if (imageLayer.type === GlobeLayerType.Tiles) {
if (imageLayer.type === LayerType.Tiles) {
setTimeout(cleanAndCache, 500);
} else {
requestAnimationFrame(cleanAndCache);
Expand All @@ -72,7 +72,7 @@ export function useGlobeLayer(
}

function getImageProvider(imageLayer: GlobeImageLayerData) {
return imageLayer.type === GlobeLayerType.Tiles
return imageLayer.type === LayerType.Tiles
? new UrlTemplateImageryProvider({
url: imageLayer.url,
tilingScheme: new GeographicTilingScheme(),
Expand Down
48 changes: 29 additions & 19 deletions src/scripts/libs/electron/get-offline-tiles-url.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,37 @@
import {GlobeLayerType} from '../../types/globe-layer-type';
import {LayerType} from '../../types/globe-layer-type';

// Returns the url template for offline usage
export function getOfflineTilesUrl(type: GlobeLayerType): string {
export function getOfflineTilesUrl(type: LayerType): string {
if (!window.cfs) {
console.error('Calling electron function from a non-electron environment');
return '';
}

return type === GlobeLayerType.Tiles
? window.cfs.getDownloadsPath(
'downloads',
'{id}',
'tiles',
'{timeIndex}',
'{z}',
'{x}',
'{reverseY}.png'
)
: window.cfs.getDownloadsPath(
'downloads',
'{id}',
'tiles',
'{timeIndex}',
'full.png'
);
return {
[LayerType.Tiles]: window.cfs.getDownloadsPath(
'downloads',
'{id}',
'tiles',
'{timeIndex}',
'{z}',
'{x}',
'{reverseY}.png'
),

[LayerType.Image]: window.cfs.getDownloadsPath(
'downloads',
'{id}',
'tiles',
'{timeIndex}',
'full.png'
),

[LayerType.Gallery]: window.cfs.getDownloadsPath(
'downloads',
'{id}',
'tiles',
'{timeIndex}',
'full.jpg'
)
}[type];
}
11 changes: 6 additions & 5 deletions src/scripts/libs/get-image-layer-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {isElectron, isOffline, getOfflineTilesUrl} from './electron/index';

import {Layer} from '../types/layer';
import {GlobeImageLayerData} from '../types/globe-image-layer-data';
import {GlobeLayerType} from '../types/globe-layer-type';
import {LayerType} from '../types/globe-layer-type';

const NUM_PRELOAD_URLS = 5;

Expand All @@ -20,10 +20,11 @@ export function getImageLayerData(
return null;
}

let url =
layer.type === GlobeLayerType.Tiles
? config.api.layerTiles
: config.api.layerImage;
let url = {
[LayerType.Tiles]: config.api.layerTiles,
[LayerType.Image]: config.api.layerImage,
[LayerType.Gallery]: config.api.layerGalleryImage
}[layer.type];

// use local tiles when offline and in electron
if (isElectron() && isOffline()) {
Expand Down
4 changes: 2 additions & 2 deletions src/scripts/types/globe-image-layer-data.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import {GlobeLayerType} from './globe-layer-type';
import {LayerType} from './globe-layer-type';

export interface GlobeImageLayerData {
id: string;
type: GlobeLayerType;
type: LayerType;
url: string;
nextUrls: string[];
zoomLevels: number;
Expand Down
5 changes: 3 additions & 2 deletions src/scripts/types/globe-layer-type.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export enum GlobeLayerType {
export enum LayerType {
Tiles = 'tiles',
Image = 'image'
Image = 'image',
Gallery = 'gallery'
}
4 changes: 2 additions & 2 deletions src/scripts/types/layer.d.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import {BasemapId} from '../types/basemap';
import {GlobeView} from './globe-view';
import {GlobeLayerType} from './globe-layer-type';
import {LayerType} from './globe-layer-type';

export interface Layer {
id: string;
type: GlobeLayerType;
type: LayerType;
zoomLevels: number;
basemap: BasemapId | null;
timestamps: string[]; // ISO 8601 timestamps
Expand Down
7 changes: 7 additions & 0 deletions storage/layers/layers-de.json
Original file line number Diff line number Diff line change
Expand Up @@ -163,5 +163,12 @@
"shortName": "Lakes Color",
"description": "",
"link": "http://..."
},
{
"id": "ozone.ozone_profile",
"type": "Layertype",
"name": "Ozone Profile",
"shortName": "Ozone Profile",
"description": ""
}
]
7 changes: 7 additions & 0 deletions storage/layers/layers-en.json
Original file line number Diff line number Diff line change
Expand Up @@ -164,5 +164,12 @@
"shortName": "Lakes Color",
"description": "",
"link": "http://..."
},
{
"id": "ozone.ozone_profile",
"type": "Layertype",
"name": "Ozone Profile",
"shortName": "Ozone Profile",
"description": ""
}
]
7 changes: 7 additions & 0 deletions storage/layers/layers-es.json
Original file line number Diff line number Diff line change
Expand Up @@ -164,5 +164,12 @@
"shortName": "Lakes Color",
"description": "",
"link": "http://..."
},
{
"id": "ozone.ozone_profile",
"type": "Layertype",
"name": "Ozone Profile",
"shortName": "Ozone Profile",
"description": ""
}
]
7 changes: 7 additions & 0 deletions storage/layers/layers-fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -164,5 +164,12 @@
"shortName": "Lakes Color",
"description": "",
"link": "http://..."
},
{
"id": "ozone.ozone_profile",
"type": "Layertype",
"name": "Ozone Profile",
"shortName": "Ozone Profile",
"description": ""
}
]
7 changes: 7 additions & 0 deletions storage/layers/layers-nl.json
Original file line number Diff line number Diff line change
Expand Up @@ -164,5 +164,12 @@
"shortName": "Lakes Color",
"description": "",
"link": "http://..."
},
{
"id": "ozone.ozone_profile",
"type": "Layertype",
"name": "Ozone Profile",
"shortName": "Ozone Profile",
"description": ""
}
]

0 comments on commit 811cf12

Please sign in to comment.