-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(globe): show single tile images on globes (#172)
- Loading branch information
Showing
6 changed files
with
102 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import config from '../config/main'; | ||
import {replaceUrlPlaceholders} from '../libs/replace-url-placeholders'; | ||
|
||
import {DetailsById} from '../reducers/layers/details'; | ||
|
||
/** | ||
* Returns the current layer tile url based on the time and the | ||
* layer's availbale timestmaps | ||
*/ | ||
export function getLayerTileUrl( | ||
id: string | null, | ||
detailedLayers: DetailsById, | ||
time: number | ||
): string | null { | ||
if (!id) { | ||
return null; | ||
} | ||
|
||
const layer = detailedLayers[id]; | ||
|
||
if (!layer) { | ||
return null; | ||
} | ||
|
||
const layerTime = getLayerTime(time, layer.timestamps); | ||
const date = new Date(layerTime); | ||
const name = date | ||
.toISOString() | ||
.substr(0, 10) | ||
.replace(/-/g, ''); | ||
|
||
return replaceUrlPlaceholders(config.api.layerTiles, {id, name}); | ||
} | ||
|
||
/** | ||
* Returns the best matching time of all layer timestamps | ||
* based on the current global time | ||
*/ | ||
function getLayerTime(sliderTime: number, timestamps: string[]): number { | ||
const lastTimestamp = timestamps[timestamps.length - 1]; | ||
let time = Number(new Date(lastTimestamp)); | ||
|
||
for (let i = timestamps.length - 1; i > 0; i--) { | ||
const layerTime = Number(new Date(timestamps[i])); | ||
|
||
if (sliderTime > layerTime) { | ||
time = layerTime; | ||
break; | ||
} | ||
} | ||
|
||
return time; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters