Interactive interface for browsing global, full-resolution satellite imagery
Added rt param (#6435)
christof-wittreichbc51face3803
diff --git a/doc/url_parameters.md b/doc/url_parameters.mdindex ac3f4989f..8da489c5c 100644--- a/doc/url_parameters.md+++ b/doc/url_parameters.md@@ -45,6 +45,7 @@| `em` | boolean | <i>`true`</i> or <i>`false`</i> | If `true` value is set, embed mode will be activated. Embed mode is disabled by default. || `tr` | string | *`tour_id`* | The id of the tour story to load. Stories will load from step 1. || `abt` | string | *`on`* | Indicates whether the about modal is open or not. Allows for permalinks that have the about page open |+| `rt` | string | *`duration`* | The relative time duration (from the current date) to set the selected Date & Time to (within permalinks). Expects the duration in ISO 8601 Duration format (`PnYnMnDTnHnMnS` or `PnW`) |\* *1 = yearly, 2 = monthly, 3 = daily, 4 = hourly, and 5 = minutely. The subdaily zoom levels (4 & 5) will only be available when subdaily layers are active.*diff --git a/web/js/modules/date/util.js b/web/js/modules/date/util.jsindex c74f1978b..545ebfeb1 100644--- a/web/js/modules/date/util.js+++ b/web/js/modules/date/util.js@@ -278,8 +278,17 @@ export function mapLocationToDateState() {let stateFromLocation = stateFromLocationObj;const appNow = get(state, 'date.appNow');- // legacy time permalink+ if (parameters.rt) {+ const relativeTimeInMinutes = Math.abs(moment.duration(parameters.rt).asMinutes());+ const date = util.earliestValidDate(util.dateAdd(appNow, 'minute', -relativeTimeInMinutes));+ stateFromLocation = update(stateFromLocation, {+ date: {+ selected: { $set: date },+ },+ });+ }+ // legacy time permalinkif (parameters.time && !parameters.t && appNow) {const date = tryCatchDate(parameters.time, appNow);if (date && date !== appNow) {diff --git a/web/js/util/util.js b/web/js/util/util.jsindex 0b20a9295..0ed3a4d62 100644--- a/web/js/util/util.js+++ b/web/js/util/util.js@@ -340,6 +340,12 @@ export default (function(selfObj) {return newDate;};+ self.earliestValidDate = function(date) {+ const currDate = new Date(date);+ const earliestDate = self.parseDateUTC('1948-01-01-T00:00:00Z');+ return currDate < earliestDate ? earliestDate : currDate;+ };+self.daysInYear = function(date) {const jStart = self.parseDateUTC(`${date.getUTCFullYear()}-01-01`);const jDate = `00${Math.ceil((date.getTime() - jStart) / 86400000) + 1}`;