Skip to content

Interactive interface for browsing global, full-resolution satellite imagery

save the timeline/animation interval as a param in the URL and restore state from the param on page load. update documentation with new param

Jason Kent9fdeb1c45c67
diff --git a/doc/url_parameters.md b/doc/url_parameters.md
index ebe0d5d76..f1d1098a7 100644
--- a/doc/url_parameters.md
+++ b/doc/url_parameters.md
@@ -12,16 +12,17 @@
| | string | _`layer_id(`**`min`**`=value1,value2)`_ | If `min` is present, the raster layer `palettes` will start at the defined value. This value can be paired with `max` and `squash` to customize the entire palette range. |
| | string | _`layer_id(`**`max`**`=value1,value2)`_ | If `max` is present, the raster layer `palettes` will end at the defined value. This value can be paired with `min` and `squash` to customize the entire palette range. |
| | string | _`layer_id(`**`style`**`=value)`_ | If `style` is present, a custom vector style, will be assigned to a vector layer where `layer_id` is the identifier of the layer and `value` is the identifier of the vector style, as defined in the configuration file. |
-| `l` | date | _`YYYY-MM-DD-Thh:mm:ssZ`_ | Selected UTC day and time. _\*Time fields will only be shown when subdaily layers are active._ |
-| `t (t1 for B state)` | date | _`YYYY-MM-DD-Thh:mm:ssZ`_ | Selected UTC day and time. _\*Time fields will only be shown when subdaily layers are active._ |
-| `z` | number | **`1`** to **`5`** | The timescale axis zoom value from 1 to 5. 1 = yearly, 2 = monthly, 3 = daily, 4 = hourly, and 5 = minutely. _\*The subdaily zoom level will only be available when subdaily layers are active._ |
+| `l` | date | _`YYYY-MM-DD-Thh:mm:ssZ`_ | Selected UTC day and time.** |
+| `t (t1 for B state)` | date | _`YYYY-MM-DD-Thh:mm:ssZ`_ | Selected UTC day and time.** |
+| `z` | number | **`1`** to **`5`** | The timescale axis zoom value from 1 to 5.*
+| `i` | number | **`1`** to **`5`** | The timeline interval value from 1 to 5.* |
| `ics` | boolean | _`true`_ or _`false`_ | If `custom selected` is `true`, a `custom interval` and `custom delta` will be active and allow custom intervals in time changes. |
-| `ici` | number | **`1`** to **`5`** | The `custom interval` value from 1 to 5 identifies which time unit is changed by the date change arrows and optionally animation. 1 = yearly, 2 = monthly, 3 = daily, 4 = hourly, and 5 = minutely. _\*Only active and saved in url if `custom selected` is true._ |
+| `ici` | number | **`1`** to **`5`** | The `custom interval` value from 1 to 5* identifies which time unit is changed by the date change arrows and optionally animation. _\*Only active and saved in url if `custom selected` is true._ |
| `icd` | number | **`1`** to **`999`** | The `custom delta` value for how many `custom interval` time units are added or subtracted when using the date change arrows and optionally animation. _\*Only active and saved in url if `custom selected` is true._ |
| `e` | string,date | _`event_id,yyyy-mm-dd`_ | If any value is present, the events tab will be activated. If the value is a valid event_id, the corresponding event will be highlighted in the event list. If a date (YYYY-MM-DD) is added to the event_id, then the selected event for the specified date will be shown. |
| `ab` | boolean | **`on`** | If set to "on", the animation widget will be shown. |
-| `as` | date | _`YYYY-MM-DDThh:mm:ssZ`_ | The animation start day & time. _\*Time fields will only be shown when subdaily layers are active._ |
-| `ae` | date | _`YYYY-MM-DDThh:mm:ssZ`_ | The animation end day & time _\*Time fields will only be shown when subdaily layers are active._ |
+| `as` | date | _`YYYY-MM-DDThh:mm:ssZ`_ | The animation start day & time.** |
+| `ae` | date | _`YYYY-MM-DDThh:mm:ssZ`_ | The animation end day & time.** |
| `av` | number | **`1`** to **`10`** | The animation speed value from 1 to 10. 1 = slowest, 10 = fastest. |
| `al` | boolean | _`true`_ or _`false`_ | If any value is set, the animation loop will be turned on. Animation looping is disabled by default. |
| `ca` | boolean | _`true`_ or _`false`_ | Determines if the A or B state is active. If this parameter exists at all, compare mode will be active. If `ca=true`, Compare mode will be active in the A state. |
@@ -29,6 +30,10 @@
| `cv` | Number | **`0`** to **`100`** | If `ca='true|false'`, The `cv` parameter is used to determine the location of the swiper or the value of opacity depending on the selected mode. Default is `50` which will place the swiper on the middle of any screen. This parameter is irrelevant when the `spy` mode is active (`cm=spy`) |
| `download` | string | _`product_id`_ | If any value is set, the data download tab will be activated. If a product identifier is set, the corresponding will be selected. |
| `r` | number | **`-180.0000`** to **`180.0000`** | The degree of map rotation. Only applies when `arctic` or `antarctic` projection is selected. |
-| `tr` | string | _`tour_id`_ | The id of the tour story to load. Stories will load from step 1. |
+| `tr` | string | _`tour_id`_ | The id of the tour story to load. Stories will load from step 1. |
+
+\* _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._
+
+\*\* _Time fields will only be shown when subdaily layers are active._
For debugging with URL parameters, see: [Testing / Debug Parameters](testing.md#debug-parameters)
diff --git a/web/js/location.js b/web/js/location.js
index d46439588..ca56bf2cb 100644
--- a/web/js/location.js
+++ b/web/js/location.js
@@ -236,6 +236,28 @@ const getParameters = function(config, parameters) {
}
}
},
+ i: {
+ stateKey: 'date.interval',
+ initialState: 3,
+ options: {
+ serializeNeedsGlobalState: true,
+ serialize: (currentItemState, state) => {
+ let interval = currentItemState;
+ // check if subdaily timescale zoom to determine if reset is needed
+ if (interval > 3) {
+ const { layers, compare } = state;
+ const hasSubdailyLayers = hasSubDaily(layers[compare.activeString]);
+ if (!hasSubdailyLayers) {
+ interval = 3; // reset to day
+ }
+ }
+ return interval === 3 ? undefined : interval.toString();
+ },
+ parse: str => {
+ return str ? Number(str) : 3;
+ }
+ }
+ },
ics: {
stateKey: 'date.customSelected',
initialState: false,
diff --git a/web/js/modules/date/util.js b/web/js/modules/date/util.js
index d96632af5..bc084a8a0 100644
--- a/web/js/modules/date/util.js
+++ b/web/js/modules/date/util.js
@@ -15,11 +15,13 @@ export function serializeDate(date) {
'Z'
);
}
+
export function getActiveTime(state) {
const { compare, date } = state;
const activeStr = compare.isCompareA ? 'selected' : 'selectedB';
return date[activeStr];
}
+
export function tryCatchDate(str, initialState) {
try {
return util.parseDateUTC(str);
@@ -28,6 +30,7 @@ export function tryCatchDate(str, initialState) {
return initialState;
}
}
+
/**
* Checks the date provided against the active layers.
*
@@ -45,6 +48,14 @@ export function getLayersActiveAtDate(layers, date) {
});
return arra;
}
+
+/**
+ *
+ * @param {*} parameters
+ * @param {*} stateFromLocation
+ * @param {*} state
+ * @param {*} config
+ */
export function mapLocationToDateState(
parameters,
stateFromLocation,
@@ -52,14 +63,9 @@ export function mapLocationToDateState(
config
) {
const appNow = get(state, 'date.appNow');
- const interval =
- get(stateFromLocation, 'date.interval') || get(state, 'date.interval');
- const selectedZoom =
- get(stateFromLocation, 'date.selectedZoom') ||
- get(state, 'date.selectedZoom');
- const isCustom =
- get(stateFromLocation, 'date.customSelected') ||
- get(state, 'date.customSelected');
+ const interval = get(stateFromLocation, 'date.interval') || get(state, 'date.interval');
+ const selectedZoom = get(stateFromLocation, 'date.selectedZoom') || get(state, 'date.selectedZoom');
+ const isCustom = get(stateFromLocation, 'date.customSelected') || get(state, 'date.customSelected');
const timeScaleChangeUnit = timeScaleFromNumberKey[interval];
const timeScale = timeScaleFromNumberKey[selectedZoom.toString()];
// legacy time permalink
@@ -77,7 +83,7 @@ export function mapLocationToDateState(
// update interval selectedzoom level as default interval
if (timeScale !== timeScaleChangeUnit && !isCustom) {
const defaultValues = {
- interval: timeScaleToNumberKey[timeScale],
+ interval,
delta: 1,
customSelected: false
};