@opengeoweb/store 10.2.0 → 11.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (43) hide show
  1. package/index.esm.js +1318 -1366
  2. package/package.json +3 -2
  3. package/src/store/drawingTool/index.d.ts +2 -3
  4. package/src/store/generic/hooks.d.ts +1 -1
  5. package/src/store/generic/index.d.ts +15 -15
  6. package/src/store/generic/listener.d.ts +1 -1
  7. package/src/store/generic/selectors.d.ts +2 -2
  8. package/src/store/generic/{synchronizationGroups → syncGroups}/index.d.ts +2 -1
  9. package/src/store/generic/{synchronizationGroups → syncGroups}/reducer.d.ts +2 -2
  10. package/src/store/generic/{synchronizationGroups → syncGroups}/types.d.ts +6 -7
  11. package/src/store/index.d.ts +1 -2
  12. package/src/store/map/index.d.ts +0 -1
  13. package/src/store/map/layer/index.d.ts +1 -1
  14. package/src/store/map/layer/reducer.d.ts +1 -2
  15. package/src/store/map/layer/types.d.ts +2 -2
  16. package/src/store/map/map/index.d.ts +1 -1
  17. package/src/store/map/map/reducer.d.ts +1 -1
  18. package/src/store/map/service/index.d.ts +1 -1
  19. package/src/store/map/service/reducer.d.ts +1 -2
  20. package/src/store/map/service/types.d.ts +4 -4
  21. package/src/store/router/index.d.ts +1 -2
  22. package/src/store/router/reducer.d.ts +1 -2
  23. package/src/store/store.d.ts +18 -0
  24. package/src/store/types.d.ts +1 -1
  25. package/src/store/ui/index.d.ts +2 -1
  26. package/src/store/ui/reducer.d.ts +1 -2
  27. package/src/store/coreModuleConfig.d.ts +0 -9
  28. package/src/store/drawingTool/config.d.ts +0 -7
  29. package/src/store/generic/config.d.ts +0 -9
  30. package/src/store/map/config.d.ts +0 -8
  31. package/src/store/router/config.d.ts +0 -7
  32. package/src/store/ui/config.d.ts +0 -5
  33. package/src/store/utils/testUtils.d.ts +0 -3
  34. /package/src/store/generic/{synchronizationGroups → syncGroups}/__mocks__/mockState.d.ts +0 -0
  35. /package/src/store/generic/{synchronizationGroups → syncGroups}/constants.d.ts +0 -0
  36. /package/src/store/generic/{synchronizationGroups → syncGroups}/listener.d.ts +0 -0
  37. /package/src/store/generic/{synchronizationGroups → syncGroups}/listener.spec.d.ts +0 -0
  38. /package/src/store/generic/{synchronizationGroups → syncGroups}/reducer.spec.d.ts +0 -0
  39. /package/src/store/generic/{synchronizationGroups → syncGroups}/selector.d.ts +0 -0
  40. /package/src/store/generic/{synchronizationGroups → syncGroups}/selectors.d.ts +0 -0
  41. /package/src/store/generic/{synchronizationGroups → syncGroups}/selectors.spec.d.ts +0 -0
  42. /package/src/store/generic/{synchronizationGroups → syncGroups}/utils.d.ts +0 -0
  43. /package/src/store/generic/{synchronizationGroups → syncGroups}/utils.spec.d.ts +0 -0
package/index.esm.js CHANGED
@@ -1,4 +1,4 @@
1
- import { createSlice, createSelector, createAction, createListenerMiddleware, isAnyOf, createEntityAdapter } from '@reduxjs/toolkit';
1
+ import { createSlice, createSelector, createAction, createListenerMiddleware, isAnyOf, createEntityAdapter, combineReducers, configureStore } from '@reduxjs/toolkit';
2
2
  import { isEqual, isEmpty, compact } from 'lodash';
3
3
  import { dateUtils, PROJECTION, defaultDelay } from '@opengeoweb/shared';
4
4
  import { webmapUtils, parseISO8601IntervalToDateInterval, LayerType, getWMJSMapById, webmapTestSettings, WMLayer, getWMSRequests, handleDateUtilsISOString, isProjectionSupported, queryWMSLayers } from '@opengeoweb/webmap';
@@ -8,6 +8,7 @@ import { getGeoJson, moveFeature, createInterSections, getLastEmptyFeatureIndex,
8
8
  export { defaultLayers } from '@opengeoweb/webmap-react';
9
9
  import { useSelector, useDispatch } from 'react-redux';
10
10
  import { useCallback, useEffect } from 'react';
11
+ import * as turf from '@turf/turf';
11
12
  import { metronome } from '@opengeoweb/metronome';
12
13
 
13
14
  /* *
@@ -63,8 +64,8 @@ var slice$7 = createSlice({
63
64
  }
64
65
  }
65
66
  });
66
- var reducer$5 = slice$7.reducer;
67
- var serviceActions = slice$7.actions;
67
+ var serviceReducer = slice$7.reducer,
68
+ serviceActions = slice$7.actions;
68
69
 
69
70
  /* *
70
71
  * Licensed under the Apache License, Version 2.0 (the "License");
@@ -2025,7 +2026,7 @@ var slice$6 = createSlice({
2025
2026
  type: source && source.type
2026
2027
  };
2027
2028
  /* Handle the Layer action with the same logic, using the same reducer */
2028
- return reducer$4(prevState, action);
2029
+ return layerReducer(prevState, action);
2029
2030
  }, draft);
2030
2031
  }).addCase(setMapPreset, function (draft, action) {
2031
2032
  var mapId = action.payload.mapId;
@@ -2045,8 +2046,8 @@ var slice$6 = createSlice({
2045
2046
  });
2046
2047
  }
2047
2048
  });
2048
- var reducer$4 = slice$6.reducer;
2049
- var layerActions = slice$6.actions;
2049
+ var layerReducer = slice$6.reducer,
2050
+ layerActions = slice$6.actions;
2050
2051
 
2051
2052
  /* *
2052
2053
  * Licensed under the Apache License, Version 2.0 (the "License");
@@ -2179,8 +2180,8 @@ var slice$5 = createSlice({
2179
2180
  }
2180
2181
  }
2181
2182
  });
2182
- var reducer$3 = slice$5.reducer;
2183
- var uiActions = slice$5.actions;
2183
+ var uiReducer = slice$5.reducer,
2184
+ uiActions = slice$5.actions;
2184
2185
 
2185
2186
  /**
2186
2187
  * Checks if the layer id is already taken in one of the maps.
@@ -2799,7 +2800,7 @@ var slice$4 = createSlice({
2799
2800
  type: source && source.type
2800
2801
  };
2801
2802
  /* Handle the Layer action with the same logic, using the same reducer */
2802
- return reducer$2(prevState, action);
2803
+ return mapReducer(prevState, action);
2803
2804
  }, draft);
2804
2805
  }).addCase(layerActions.onUpdateLayerInformation, function (draft, action) {
2805
2806
  var mapDimensions = action.payload.mapDimensions;
@@ -2849,7 +2850,7 @@ var mapActions = Object.assign({}, slice$4.actions, {
2849
2850
  setMapPreset: setMapPreset,
2850
2851
  mapChangeDimension: mapChangeDimension
2851
2852
  });
2852
- var reducer$2 = slice$4.reducer;
2853
+ var mapReducer = slice$4.reducer;
2853
2854
 
2854
2855
  var layerStore = function layerStore(store) {
2855
2856
  return store == null ? void 0 : store.layers;
@@ -3965,8 +3966,8 @@ var _slice$actions = slice$3.actions;
3965
3966
  _slice$actions.syncGroupRemoveSource;
3966
3967
  _slice$actions.syncGroupRemoveTarget;
3967
3968
  _slice$actions.syncGroupSetViewState;
3968
- var actions = slice$3.actions,
3969
- reducer$1 = slice$3.reducer;
3969
+ var syncGroupsReducer = slice$3.reducer,
3970
+ syncGroupsActions = slice$3.actions;
3970
3971
 
3971
3972
  /* *
3972
3973
  * Licensed under the Apache License, Version 2.0 (the "License");
@@ -4237,7 +4238,7 @@ var selector = /*#__PURE__*/Object.freeze({
4237
4238
 
4238
4239
  var syncGroupsListener = createListenerMiddleware();
4239
4240
  syncGroupsListener.startListening({
4240
- matcher: isAnyOf(actions.syncGroupAddTarget, actions.syncGroupLinkTarget),
4241
+ matcher: isAnyOf(syncGroupsActions.syncGroupAddTarget, syncGroupsActions.syncGroupLinkTarget),
4241
4242
  effect: function () {
4242
4243
  var _effect = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(_ref, listenerApi) {
4243
4244
  var payload, groupId, linked, targetToUpdate, group;
@@ -4295,7 +4296,7 @@ syncGroupsListener.startListening({
4295
4296
  }()
4296
4297
  });
4297
4298
  syncGroupsListener.startListening({
4298
- matcher: isAnyOf(actions.syncGroupAddGroup, actions.syncGroupRemoveGroup, actions.syncGroupAddSource, actions.syncGroupRemoveSource, actions.syncGroupAddTarget, actions.syncGroupRemoveTarget, actions.syncGroupLinkTarget),
4299
+ matcher: isAnyOf(syncGroupsActions.syncGroupAddGroup, syncGroupsActions.syncGroupRemoveGroup, syncGroupsActions.syncGroupAddSource, syncGroupsActions.syncGroupRemoveSource, syncGroupsActions.syncGroupAddTarget, syncGroupsActions.syncGroupRemoveTarget, syncGroupsActions.syncGroupLinkTarget),
4299
4300
  effect: function () {
4300
4301
  var _effect2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(_, listenerApi) {
4301
4302
  var viewState;
@@ -4304,7 +4305,7 @@ syncGroupsListener.startListening({
4304
4305
  case 0:
4305
4306
  listenerApi.cancelActiveListeners();
4306
4307
  viewState = createSyncGroupViewStateSelector(listenerApi.getState());
4307
- listenerApi.dispatch(actions.syncGroupSetViewState({
4308
+ listenerApi.dispatch(syncGroupsActions.syncGroupSetViewState({
4308
4309
  viewState: viewState
4309
4310
  }));
4310
4311
  case 3:
@@ -4492,6 +4493,18 @@ function (state, mapId) {
4492
4493
  name: (_selectedFeature$prop3 = selectedFeature.properties) == null ? void 0 : _selectedFeature$prop3.name
4493
4494
  };
4494
4495
  }
4496
+ if (selectedFeature) {
4497
+ var _selectedFeature$prop4, _selectedFeature$prop5, _selectedFeature$prop6;
4498
+ var center = turf.center(selectedFeature);
4499
+ return {
4500
+ lat: center.geometry.coordinates[1],
4501
+ lon: center.geometry.coordinates[0],
4502
+ id: selectedFeature.id,
4503
+ serviceId: (_selectedFeature$prop4 = selectedFeature.properties) == null ? void 0 : _selectedFeature$prop4.serviceId,
4504
+ collectionId: (_selectedFeature$prop5 = selectedFeature.properties) == null ? void 0 : _selectedFeature$prop5.collectionId,
4505
+ name: (_selectedFeature$prop6 = selectedFeature.properties) == null ? void 0 : _selectedFeature$prop6.name
4506
+ };
4507
+ }
4495
4508
  return null;
4496
4509
  });
4497
4510
 
@@ -4537,7 +4550,7 @@ var useUpdateSharedData = function useUpdateSharedData(data, panelId) {
4537
4550
  useEffect(function () {
4538
4551
  var diff = Object.assign({}, sharedData, data);
4539
4552
  if (panelId && (linkedMaps == null ? void 0 : linkedMaps.length) > 0 && !isEqual(diff, sharedData)) {
4540
- dispatch(actions.addSharedData({
4553
+ dispatch(syncGroupsActions.addSharedData({
4541
4554
  panelId: panelId,
4542
4555
  data: data
4543
4556
  }));
@@ -4546,7 +4559,7 @@ var useUpdateSharedData = function useUpdateSharedData(data, panelId) {
4546
4559
  useEffect(function () {
4547
4560
  return function () {
4548
4561
  if (panelId) {
4549
- dispatch(actions.deleteSharedData({
4562
+ dispatch(syncGroupsActions.deleteSharedData({
4550
4563
  panelId: panelId
4551
4564
  }));
4552
4565
  }
@@ -4735,7 +4748,7 @@ var selectors$2 = /*#__PURE__*/Object.freeze({
4735
4748
  * Copyright 2022 - Finnish Meteorological Institute (FMI)
4736
4749
  * Copyright 2024 - The Norwegian Meteorological Institute (MET Norway)
4737
4750
  * */
4738
- var genericActions = Object.assign({}, actions, {
4751
+ var genericActions = Object.assign({}, syncGroupsActions, {
4739
4752
  initialSyncState: initialState$2,
4740
4753
  setTime: setTime,
4741
4754
  setBbox: setBbox
@@ -5963,218 +5976,217 @@ var storeTestSettings = /*#__PURE__*/Object.freeze({
5963
5976
  styleListForRADNLOPERR25PCPRRL3KNMILayer: styleListForRADNLOPERR25PCPRRL3KNMILayer
5964
5977
  });
5965
5978
 
5966
- /* A map with all the timerIds and their current step */
5967
- var stepMap = new Map();
5968
- /* A map with a list of timers and their dwell */
5969
- var timerDwellMap = new Map();
5979
+ var _excluded$1 = ["id"];
5970
5980
  /**
5971
- * Returns the next step for given timerId.
5972
- * @param timerId The timer id
5973
- * @param numberOfStepsInAnimation Animation length in steps
5974
- * @param numStepsToGoForward Amount of steps to go forwards, defaults to 1. Can be positive and negative
5981
+ * Tries to find the layerId's in the other map based on the payload of the action. It works for all layer actions.
5982
+ * @param state
5983
+ * @param mapId
5984
+ * @param targetMapId
5985
+ * @param payload
5975
5986
  * @returns
5976
5987
  */
5977
- var getNextStep = function getNextStep(timerId, numberOfStepsInAnimation, numStepsToGoForward) {
5978
- if (numStepsToGoForward === void 0) {
5979
- numStepsToGoForward = 1;
5988
+ var getTargetLayerIdFromPayload = function getTargetLayerIdFromPayload(state, mapId, targetMapId, payload) {
5989
+ if (!payload) {
5990
+ return null;
5980
5991
  }
5981
- var currentStep = getCurrentStep(timerId);
5982
- var nextStep = currentStep + numStepsToGoForward;
5983
- var nextStepClipped = (nextStep % numberOfStepsInAnimation + numberOfStepsInAnimation) % numberOfStepsInAnimation;
5984
- return nextStepClipped;
5992
+ /* Try to find the layer for the DeleteLayerPayload, it uses layerIndex to reference the layer */
5993
+ if ('layerIndex' in payload) {
5994
+ var tempLayerIndex = payload.layerIndex;
5995
+ if (tempLayerIndex !== undefined) {
5996
+ var targetLayer = getLayerByLayerIndex(state, targetMapId, tempLayerIndex);
5997
+ return !targetLayer ? null : targetLayer.id;
5998
+ }
5999
+ }
6000
+ /* Try to find the layer for the LayerActionsWithLayerIds, it uses layerId to reference the layer */
6001
+ if ('layerId' in payload) {
6002
+ var _targetLayer = getLayerByLayerIndex(state, targetMapId, getLayerIndexByLayerId(state, mapId, payload.layerId));
6003
+ return !_targetLayer ? null : _targetLayer.id;
6004
+ }
6005
+ /* This payload probably does not reference to a layerId */
6006
+ return null;
5985
6007
  };
5986
6008
  /**
5987
- * Handles dwell at the end of the animation loop sequence. The number of steps to wait till proceed can be set by the dwell parameter.
5988
- * @param timerId The timer id
5989
- * @param numberOfStepsInAnimation Number of steps in the animation
5990
- * @param dwell The number of steps to wait at the end of the animation sequence before to continue
5991
- * @returns
6009
+ * Local helper function used by getLayerDeleteActionsTargets, getLayerActionsTargets, getAddLayerActionsTargets, getTargetLayerIdFromPayload to find the targets
6010
+ * @param state
6011
+ * @param payload
6012
+ * @param actionType
6013
+ * @param sourceMapId
6014
+ * @returns The found targets
5992
6015
  */
5993
- var handleTimerDwell = function handleTimerDwell(timerId, numberOfStepsInAnimation, dwell) {
5994
- if (dwell === void 0) {
5995
- dwell = 8;
5996
- }
5997
- if (dwell > 0) {
5998
- var currentStep = getCurrentStep(timerId);
5999
- // Reset the dwell if we are not at the last animation step
6000
- if (currentStep < numberOfStepsInAnimation - 1) {
6001
- timerDwellMap.set(timerId, dwell);
6002
- return false;
6003
- }
6004
- // We are at the last animation step, check the dwell
6005
- var timerDwell = timerDwellMap.has(timerId) && timerDwellMap.get(timerId) || 0;
6006
- if (currentStep === numberOfStepsInAnimation - 1 && timerDwell > 0) {
6007
- timerDwellMap.set(timerId, timerDwell - 1);
6008
- return true;
6009
- }
6016
+ var findTargets = function findTargets(state, payload, actionType, sourceMapId) {
6017
+ var actionPayloads = [];
6018
+ var targetsInActionPayload = {};
6019
+ var syncGroups = syncGroupStore(state);
6020
+ if (syncGroups && payload) {
6021
+ syncGroups.groups.allIds.forEach(function (id) {
6022
+ var syncronizationGroup = syncGroups.groups.byId[id];
6023
+ if (actionType === syncronizationGroup.type) {
6024
+ /* Check if the source is in the target list of the synchonizationGroup */
6025
+ var source = syncronizationGroup.targets.byId[sourceMapId];
6026
+ /* If the source is part of the target list, and is linked, continue syncing the other targets */
6027
+ if (source && source.linked) {
6028
+ syncronizationGroup.targets.allIds.forEach(function (targetId) {
6029
+ var target = syncronizationGroup.targets.byId[targetId];
6030
+ if (targetId !== sourceMapId && target.linked && !targetsInActionPayload[targetId]) {
6031
+ /* Remember that we have already added this target in the action payloads, prevents adding it twice */
6032
+ targetsInActionPayload[targetId] = true;
6033
+ var otherLayerId = getTargetLayerIdFromPayload(state, sourceMapId, targetId, payload);
6034
+ actionPayloads.push({
6035
+ payload: payload,
6036
+ targetId: targetId,
6037
+ layerId: otherLayerId
6038
+ });
6039
+ }
6040
+ });
6041
+ }
6042
+ }
6043
+ });
6010
6044
  }
6011
- return false;
6045
+ return actionPayloads;
6012
6046
  };
6013
6047
  /**
6014
- * Set step for the timerId
6015
- * @param timerId
6016
- * @param timerStep
6048
+ * These targets are found for layer actions that work with a layerId like: SetLayerName, SetLayerEnabled, SetLayerOpacity, SetLayerDimension and SetLayerStyle
6049
+ * @param state
6050
+ * @param payload
6051
+ * @param actionType
6052
+ * @returns
6017
6053
  */
6018
- var setStep = function setStep(timerId, timerStep) {
6019
- stepMap.set(timerId, timerStep);
6054
+ var getLayerActionsTargets = function getLayerActionsTargets(state, payload, actionType) {
6055
+ var mapId = getMapIdFromLayerId(state, payload.layerId);
6056
+ if (!mapId) {
6057
+ return [];
6058
+ }
6059
+ var foundTargets = findTargets(state, payload, actionType, mapId);
6060
+ return foundTargets.map(function (target) {
6061
+ var payload = target.payload;
6062
+ return Object.assign({}, payload, {
6063
+ layerId: target.layerId,
6064
+ origin: SyncGroupActionOrigin.layerActions,
6065
+ mapId: payload.mapId
6066
+ });
6067
+ });
6020
6068
  };
6021
6069
  /**
6022
- * Gets the current step for the timer
6023
- * @param timerId
6070
+ * These targets are found for the layer/map action AddLayer. AddLayer does not have a layerId (because it's new)
6071
+ * @param state
6072
+ * @param payload
6073
+ * @param actionType
6024
6074
  * @returns
6025
6075
  */
6026
- var getCurrentStep = function getCurrentStep(timerId) {
6027
- return stepMap.get(timerId) || 0;
6076
+ var getAddLayerActionsTargets = function getAddLayerActionsTargets(state, payload, actionType) {
6077
+ var foundTargets = findTargets(state, payload, actionType, payload.mapId);
6078
+ return foundTargets.map(function (_ref) {
6079
+ var payload = _ref.payload,
6080
+ targetId = _ref.targetId;
6081
+ var layer = payload.layer;
6082
+ layer.id;
6083
+ var layerWithoutId = _objectWithoutPropertiesLoose(layer, _excluded$1);
6084
+ var layerId = webmapUtils.generateLayerId();
6085
+ return Object.assign({}, payload, {
6086
+ layer: layerWithoutId,
6087
+ layerId: layerId,
6088
+ mapId: targetId,
6089
+ origin: SyncGroupActionOrigin.add
6090
+ });
6091
+ });
6028
6092
  };
6029
- var MAX_NUMBER_STEPS_FORWARD_TO_PREFETCH = 2;
6030
- var MAX_NUMBER_OF_PARALLEL_LOADING_IMAGES = 8;
6031
6093
  /**
6032
- * This prefetches all images connected to the same sync group as provided timerId
6033
- * @param timerId The timerId
6034
- * @param animationListValues List of animation steps in isostring to animate
6035
- * @param targets List of targets to check
6036
- * @returns True if all maps are ready to go forward, false if the map has no data to display yet.
6094
+ * These targets are found for the layer/map action DeleteLayer. The layer is already gone, so there is no layerId anymore. Using layerIndex instead.
6095
+ * @param state
6096
+ * @param payload
6097
+ * @param actionType
6098
+ * @returns
6037
6099
  */
6038
- var prefetchAnimationTargetsForMetronome = function prefetchAnimationTargetsForMetronome(timerId, animationListValues, targets) {
6039
- var timerShouldStepForward = true;
6040
- // The following code prefetches/buffers for all maps in the group
6041
- for (var numPrefetch = 0; numPrefetch < MAX_NUMBER_STEPS_FORWARD_TO_PREFETCH; numPrefetch += 1) {
6042
- var nextStep = getNextStep(timerId, animationListValues.length, numPrefetch + 1);
6043
- var nextTimeValueStepToCheck = animationListValues[nextStep];
6044
- for (var _iterator = _createForOfIteratorHelperLoose(targets), _step; !(_step = _iterator()).done;) {
6045
- var target = _step.value;
6046
- var targetMapId = target.targetId;
6047
- var wmMap = getWMJSMapById(targetMapId);
6048
- if (!wmMap) {
6049
- return true; // Map was not registered so there is nothing to prefetch, do not block going forward
6050
- }
6051
- var layersImageUrls = getWMSRequests(wmMap, [{
6052
- name: 'time',
6053
- currentValue: nextTimeValueStepToCheck
6054
- }]);
6055
- for (var _iterator2 = _createForOfIteratorHelperLoose(layersImageUrls), _step2; !(_step2 = _iterator2()).done;) {
6056
- var layersImageUrl = _step2.value;
6057
- var image = wmMap.getMapImageStore.getImage(layersImageUrl.url);
6058
- if (!image.isLoaded()) {
6059
- if (wmMap.getMapImageStore.getNumImagesLoading() < MAX_NUMBER_OF_PARALLEL_LOADING_IMAGES) {
6060
- image.load();
6061
- }
6062
- if (numPrefetch === 0) {
6063
- var altImage = wmMap.getAlternativeImage(layersImageUrl.url, wmMap.getBBOX(), true);
6064
- // No alternative image available yet, so skipping animation.
6065
- if (altImage.length === 0) {
6066
- // This is useful to indicate that the map is loading and has nothing yet to display.
6067
- // console.warn('No data available: Not stepping forward');
6068
- timerShouldStepForward = false;
6069
- }
6070
- }
6071
- } else if (image.isStale()) {
6072
- if (wmMap.getMapImageStore.getNumImagesLoading() < MAX_NUMBER_OF_PARALLEL_LOADING_IMAGES) {
6073
- image.forceReload(true);
6074
- }
6075
- }
6076
- }
6077
- }
6078
- }
6079
- return timerShouldStepForward;
6100
+ var getLayerDeleteActionsTargets = function getLayerDeleteActionsTargets(state, payload, actionType) {
6101
+ var foundTargets = findTargets(state, payload, actionType, payload.mapId);
6102
+ return foundTargets.map(function (target) {
6103
+ return Object.assign({}, target.payload, {
6104
+ mapId: target.targetId,
6105
+ layerId: target.layerId,
6106
+ origin: SyncGroupActionOrigin["delete"]
6107
+ });
6108
+ });
6080
6109
  };
6081
-
6082
6110
  /**
6083
- * This handler is triggered by the metronome. An array of timerIds is given as argument.
6084
- * It will update the animation loop of multiple maps and sliders
6085
- * It will prefetch images for maps
6086
- * @param timerIds string[] array of timerIds
6087
- * @param listenerApi ListenerEffectAPI<CoreAppStore, Dispatch, unknown> listenerApi as received from listener
6111
+ * These targets are found for the layer/map action MoveLayer. Here layers are referenced by newIndex and oldIndex.
6112
+ * @param state
6113
+ * @param payload
6114
+ * @param actionType
6115
+ * @returns
6088
6116
  */
6089
- var metronomeHandler = function metronomeHandler(timerIds, listenerApi) {
6090
- var targetsWithUpdateValue = [];
6091
- var _loop = function _loop() {
6092
- var timerId = _step.value;
6093
- var animationListValuesNameAndValue = getAnimationList(listenerApi.getState(), timerId);
6094
- var animationListValues = animationListValuesNameAndValue.map(function (nameAndValue) {
6095
- return nameAndValue.value;
6117
+ var getLayerMoveActionsTargets = function getLayerMoveActionsTargets(state, payload, actionType) {
6118
+ var foundTargets = findTargets(state, payload, actionType, payload.mapId);
6119
+ return foundTargets.map(function (target) {
6120
+ return Object.assign({}, target.payload, {
6121
+ mapId: target.targetId,
6122
+ origin: SyncGroupActionOrigin.move
6096
6123
  });
6097
- var targets = getTargets(listenerApi.getState(), {
6098
- sourceId: timerId,
6099
- origin: timerId
6100
- }, SYNCGROUPS_TYPE_SETTIME);
6101
- if (targets.length === 0) {
6102
- // When there are no targets, default to one
6103
- targets.push({
6104
- targetId: timerId,
6105
- value: ''
6106
- });
6107
- }
6108
- var timerIsInDwell = handleTimerDwell(timerId, animationListValues.length);
6109
- var timerShouldStepForward = prefetchAnimationTargetsForMetronome(timerId, animationListValues, targets) && !timerIsInDwell;
6110
- // Determine the next step
6111
- var timerStep = timerShouldStepForward ? getNextStep(timerId, animationListValues.length) : getCurrentStep(timerId);
6112
- setStep(timerId, timerStep);
6113
- var updatedValue = animationListValues[timerStep];
6114
- targetsWithUpdateValue.push.apply(targetsWithUpdateValue, targets.map(function (target) {
6115
- return Object.assign({}, target, {
6116
- value: updatedValue
6117
- });
6118
- }));
6119
- var speedDelay = getMapAnimationDelay(listenerApi.getState(), timerId);
6120
- var speed = 1000 / (speedDelay || 1);
6121
- metronome.setSpeed(timerId, speed);
6122
- };
6123
- for (var _iterator = _createForOfIteratorHelperLoose(timerIds), _step; !(_step = _iterator()).done;) {
6124
- _loop();
6125
- }
6126
- // Update all targets of all sync groups in one action.
6127
- if (targetsWithUpdateValue.length > 0) {
6128
- listenerApi.dispatch(setTimeSync(null, targetsWithUpdateValue, ['metronomelistener']));
6129
- }
6124
+ });
6125
+ };
6126
+ /**
6127
+ * These targets are found for the map action SetAutoLayerId. It needs both a target mapId and layerId
6128
+ * @param state
6129
+ * @param payload
6130
+ * @param actionType
6131
+ * @returns
6132
+ */
6133
+ var getSetAutoLayerIdActionsTargets = function getSetAutoLayerIdActionsTargets(state, payload, actionType) {
6134
+ var payloadWithLayerId = Object.assign({}, payload, {
6135
+ layerId: payload.autoUpdateLayerId || payload.autoTimeStepLayerId || payload.layerId
6136
+ });
6137
+ var foundTargets = findTargets(state, payloadWithLayerId, actionType, payload.mapId);
6138
+ return foundTargets.map(function (target) {
6139
+ return {
6140
+ mapId: target.targetId,
6141
+ layerId: target.layerId,
6142
+ origin: SyncGroupActionOrigin.autoLayerId
6143
+ };
6144
+ });
6145
+ };
6146
+ /**
6147
+ * These targets are found for baselayer actions that work with a mapId like: setBaseLayers
6148
+ * @param state
6149
+ * @param payload
6150
+ * @param actionType
6151
+ * @returns
6152
+ */
6153
+ var getMapBaseLayerActionsTargets = function getMapBaseLayerActionsTargets(state, payload, actionType) {
6154
+ var foundTargets = findTargets(state, payload, actionType, payload.mapId);
6155
+ return foundTargets.map(function (target) {
6156
+ return {
6157
+ layers: payload.layers.map(function (layer) {
6158
+ return Object.assign({}, layer, {
6159
+ id: webmapUtils.generateLayerId()
6160
+ });
6161
+ }),
6162
+ mapId: target.targetId,
6163
+ origin: SyncGroupActionOrigin.layerActions
6164
+ };
6165
+ });
6130
6166
  };
6131
- var metronomeListener = createListenerMiddleware();
6132
- metronomeListener.startListening({
6133
- actionCreator: mapActions.mapStartAnimation,
6134
- effect: function () {
6135
- var _effect = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(_, listenerApi) {
6136
- return _regeneratorRuntime().wrap(function _callee$(_context) {
6137
- while (1) switch (_context.prev = _context.next) {
6138
- case 0:
6139
- // register handler with access to listenerApi
6140
- metronome.handleTimerTicks = function (timerIds) {
6141
- metronomeHandler(timerIds, listenerApi);
6142
- };
6143
- case 1:
6144
- case "end":
6145
- return _context.stop();
6146
- }
6147
- }, _callee);
6148
- }));
6149
- function effect(_x, _x2) {
6150
- return _effect.apply(this, arguments);
6151
- }
6152
- return effect;
6153
- }()
6154
- });
6155
6167
 
6156
- var layersListener = createListenerMiddleware();
6157
- layersListener.startListening({
6158
- actionCreator: layerActions.showLayerInfo,
6168
+ var setTimeValidatorRexexp = /^(19|20)\d\d-(0[1-9]|1[012])-([012]\d|3[01])T([01]\d|2[0-3]):([0-5]\d):([0-5]\d)Z$/;
6169
+ var genericListener = createListenerMiddleware();
6170
+ genericListener.startListening({
6171
+ actionCreator: setTime,
6159
6172
  effect: function () {
6160
6173
  var _effect = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(_ref, listenerApi) {
6161
- var payload, mapId, source, currentActiveMapId, isOpenInStore;
6174
+ var payload, value, origin, targets, groups;
6162
6175
  return _regeneratorRuntime().wrap(function _callee$(_context) {
6163
6176
  while (1) switch (_context.prev = _context.next) {
6164
6177
  case 0:
6165
6178
  payload = _ref.payload;
6166
- mapId = payload.mapId, source = payload.source;
6167
- currentActiveMapId = getDialogMapId(listenerApi.getState(), DialogTypes.LayerInfo);
6168
- isOpenInStore = getisDialogOpen(listenerApi.getState(), DialogTypes.LayerInfo);
6169
- if (currentActiveMapId !== mapId ? true : !isOpenInStore) {
6170
- listenerApi.dispatch(uiActions.setActiveMapIdForDialog({
6171
- type: DialogTypes.LayerInfo,
6172
- mapId: mapId,
6173
- setOpen: true,
6174
- source: source
6175
- }));
6179
+ listenerApi.cancelActiveListeners();
6180
+ value = payload.value, origin = payload.origin;
6181
+ /* Test if the value is according to the expected time format */
6182
+ if (!setTimeValidatorRexexp.test(value)) {
6183
+ console.error("setTime value " + value + " does not conform to format [YYYY-MM-DDThh:mm:ssZ]. It was triggered by " + origin);
6184
+ } else {
6185
+ targets = getTargets(listenerApi.getState(), payload, SYNCGROUPS_TYPE_SETTIME);
6186
+ groups = getTargetGroups(listenerApi.getState(), payload, SYNCGROUPS_TYPE_SETTIME);
6187
+ listenerApi.dispatch(setTimeSync(payload, targets, groups));
6176
6188
  }
6177
- case 5:
6189
+ case 4:
6178
6190
  case "end":
6179
6191
  return _context.stop();
6180
6192
  }
@@ -6186,23 +6198,20 @@ layersListener.startListening({
6186
6198
  return effect;
6187
6199
  }()
6188
6200
  });
6189
- layersListener.startListening({
6190
- actionCreator: uiActions.setToggleOpenDialog,
6201
+ genericListener.startListening({
6202
+ actionCreator: setBbox,
6191
6203
  effect: function () {
6192
6204
  var _effect2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(_ref2, listenerApi) {
6193
- var payload, setOpen, type, isOpenInStore;
6205
+ var payload, targets, groups;
6194
6206
  return _regeneratorRuntime().wrap(function _callee2$(_context2) {
6195
6207
  while (1) switch (_context2.prev = _context2.next) {
6196
6208
  case 0:
6197
6209
  payload = _ref2.payload;
6198
- setOpen = payload.setOpen, type = payload.type; // close LayerInfo if open and LayerManager is closed
6199
- if (type === DialogTypes.LayerManager && !setOpen) {
6200
- isOpenInStore = getisDialogOpen(listenerApi.getState(), DialogTypes.LayerInfo);
6201
- if (isOpenInStore) {
6202
- listenerApi.dispatch(layerActions.hideLayerInfo());
6203
- }
6204
- }
6205
- case 3:
6210
+ listenerApi.cancelActiveListeners();
6211
+ targets = getTargets(listenerApi.getState(), payload, SYNCGROUPS_TYPE_SETBBOX);
6212
+ groups = getTargetGroups(listenerApi.getState(), payload, SYNCGROUPS_TYPE_SETBBOX);
6213
+ listenerApi.dispatch(setBboxSync(payload, targets, groups));
6214
+ case 5:
6206
6215
  case "end":
6207
6216
  return _context2.stop();
6208
6217
  }
@@ -6214,1166 +6223,1042 @@ layersListener.startListening({
6214
6223
  return effect;
6215
6224
  }()
6216
6225
  });
6217
-
6218
- var isAnimationEndTimeValid = function isAnimationEndTimeValid(animationEndTime) {
6219
- var hasValidPrefix = animationEndTime.split(/[-+]/)[0] === 'NOW' || animationEndTime.split(/[-+]/)[0] === 'TODAY';
6220
- var durationString = animationEndTime.substring(animationEndTime.indexOf('PT') + 2);
6221
- var hasValidDate = /^(\d+H)?(\d+M)?$/.test(durationString);
6222
- if (hasValidPrefix && hasValidDate) {
6223
- return true;
6224
- }
6225
- var parsedDate = dateUtils.parseISO(animationEndTime);
6226
- return dateUtils.isValid(parsedDate);
6227
- };
6228
- var mapListener = createListenerMiddleware();
6229
- mapListener.startListening({
6230
- actionCreator: layerActions.layerDelete,
6231
- effect: function effect(_ref, listenerApi) {
6232
- var payload = _ref.payload;
6233
- var mapId = payload.mapId;
6234
- var layers = getMapLayersWithoutDimensionCurrentValue(listenerApi.getState(), mapId);
6235
- if (!layers.length) {
6236
- listenerApi.dispatch(mapActions.mapStopAnimation({
6237
- mapId: mapId
6238
- }));
6239
- }
6240
- }
6241
- });
6242
- // update layer, synced maps and animation on latest max time if autoupdating
6243
- mapListener.startListening({
6244
- actionCreator: layerActions.onUpdateLayerInformation,
6245
- effect: function effect(_ref2, listenerApi) {
6246
- var payload = _ref2.payload;
6247
- try {
6248
- var layerDimensions = payload.layerDimensions;
6249
- if (!layerDimensions) {
6250
- return;
6251
- }
6252
- var dimensions = layerDimensions.dimensions,
6253
- layerId = layerDimensions.layerId;
6254
- var layer = getLayerById(listenerApi.getState(), layerId);
6255
- if (!layer) {
6256
- return;
6257
- }
6258
- var newTimeDimension = dimensions.find(function (dimension) {
6259
- return dimension.name === 'time';
6260
- });
6261
- var mapId = layer.mapId;
6262
- if (!mapId) {
6263
- return;
6264
- }
6265
- var autoUpdateLayerId = getAutoUpdateLayerId(listenerApi.getState(), mapId);
6266
- var shouldAutoUpdate = isAutoUpdating(listenerApi.getState(), mapId);
6267
- var prevTimeDimension = getLayerTimeDimension(listenerApi.getState(), layerId);
6268
- var isAutoUpdateLayer = layerId === autoUpdateLayerId;
6269
- var incomingMaxTime = newTimeDimension == null ? void 0 : newTimeDimension.maxValue;
6270
- var isIncomingMaxTimeLaterThanCurrentLayerTime = incomingMaxTime && (prevTimeDimension == null ? void 0 : prevTimeDimension.currentValue) && prevTimeDimension.currentValue !== incomingMaxTime;
6271
- if (isAutoUpdateLayer &&
6272
- // only update the active layer
6273
- shouldAutoUpdate && isIncomingMaxTimeLaterThanCurrentLayerTime) {
6274
- var isMapAnimating = isAnimating(listenerApi.getState(), mapId);
6275
- if (!isMapAnimating) {
6276
- listenerApi.dispatch(layerActions.layerChangeDimension({
6277
- layerId: layerId,
6278
- origin: LayerActionOrigin.updateLayerInformationListener,
6279
- dimension: {
6280
- name: 'time',
6281
- currentValue: incomingMaxTime
6282
- }
6283
- }));
6284
- // Each time a layer updates, set the new time for all synced timesliders
6285
- var syncedMapIds = getSyncedMapIdsForTimeslider(listenerApi.getState());
6286
- if (syncedMapIds) {
6287
- // Change time value for all other timesliders
6288
- syncedMapIds.map(function (syncedMapId) {
6289
- return listenerApi.dispatch(setTime({
6290
- origin: LayerActionOrigin.updateLayerInformationListener,
6291
- sourceId: syncedMapId,
6292
- value: incomingMaxTime
6293
- }));
6294
- });
6295
- }
6296
- }
6297
- updateAnimation(mapId, incomingMaxTime, listenerApi);
6298
- }
6299
- } catch (error) {
6300
- // eslint-disable-next-line no-console
6301
- console.warn(error);
6302
- }
6303
- }
6304
- });
6305
- var updateAnimation = function updateAnimation(mapId, maxValue, listenerApi) {
6306
- var shouldEndtimeOverride$1 = shouldEndtimeOverride(listenerApi.getState(), mapId);
6307
- if (shouldEndtimeOverride$1 === true) {
6308
- return;
6309
- }
6310
- var animationStart = getAnimationStartTime(listenerApi.getState(), mapId);
6311
- // Calculate how much time the animation start need to move forwards
6312
- var animationEnd = getAnimationEndTime(listenerApi.getState(), mapId);
6313
- var animationEndUnix = dateUtils.unix(dateUtils.utc(animationEnd));
6314
- var maxTimeAsUnix = dateUtils.unix(dateUtils.utc(maxValue));
6315
- var timeInSecondToShiftAnimationForwards = maxTimeAsUnix - animationEndUnix;
6316
- var animationStartUnix = dateUtils.unix(dateUtils.utc(animationStart));
6317
- var newAnimationStartTime = dateUtils.dateToString(dateUtils.fromUnix(animationStartUnix + timeInSecondToShiftAnimationForwards), dateFormat);
6318
- var newAnimationEndTime = dateUtils.dateToString(dateUtils.fromUnix(animationEndUnix + timeInSecondToShiftAnimationForwards), dateFormat);
6319
- if (!newAnimationStartTime || !newAnimationEndTime) {
6320
- return;
6321
- }
6322
- listenerApi.dispatch(mapActions.setAnimationEndTime({
6323
- mapId: mapId,
6324
- animationEndTime: newAnimationEndTime
6325
- }));
6326
- listenerApi.dispatch(mapActions.setAnimationStartTime({
6327
- mapId: mapId,
6328
- animationStartTime: newAnimationStartTime
6329
- }));
6330
- };
6331
- mapListener.startListening({
6332
- actionCreator: mapActions.toggleAutoUpdate,
6226
+ genericListener.startListening({
6227
+ matcher: isAnyOf(layerActions.layerChangeName, layerActions.layerChangeEnabled, layerActions.layerChangeOpacity, layerActions.layerChangeDimension, layerActions.layerChangeStyle),
6333
6228
  effect: function () {
6334
- var _effect = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(_ref3, listenerApi) {
6335
- var payload, shouldAutoUpdate, mapId, autoUpdateLayerId, timeDimension, syncedMapIds, payloads;
6336
- return _regeneratorRuntime().wrap(function _callee$(_context) {
6337
- while (1) switch (_context.prev = _context.next) {
6229
+ var _effect3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(_ref3, listenerApi) {
6230
+ var payload, type, targets;
6231
+ return _regeneratorRuntime().wrap(function _callee3$(_context3) {
6232
+ while (1) switch (_context3.prev = _context3.next) {
6338
6233
  case 0:
6339
- payload = _ref3.payload;
6234
+ payload = _ref3.payload, type = _ref3.type;
6340
6235
  listenerApi.cancelActiveListeners();
6341
- shouldAutoUpdate = payload.shouldAutoUpdate, mapId = payload.mapId;
6342
- if (shouldAutoUpdate) {
6343
- _context.next = 5;
6236
+ /* Should not listen to actions from itself */
6237
+ if (!(payload && payload.origin === LayerActionOrigin.ReactMapViewParseLayer)) {
6238
+ _context3.next = 4;
6344
6239
  break;
6345
6240
  }
6346
- return _context.abrupt("return");
6347
- case 5:
6348
- try {
6349
- autoUpdateLayerId = getAutoUpdateLayerId(listenerApi.getState(), mapId);
6350
- timeDimension = getLayerTimeDimension(listenerApi.getState(), autoUpdateLayerId);
6351
- syncedMapIds = getSyncedMapIdsForTimeslider(listenerApi.getState()); // go to end of active layer
6352
- if (timeDimension != null && timeDimension.maxValue && autoUpdateLayerId) {
6353
- listenerApi.dispatch(layerActions.layerChangeDimension({
6354
- layerId: autoUpdateLayerId,
6355
- origin: LayerActionOrigin.toggleAutoUpdateListener,
6356
- dimension: {
6357
- name: 'time',
6358
- currentValue: timeDimension.maxValue
6359
- }
6360
- }));
6361
- // Change time value for all timesliders that are synced by syncgroups
6362
- if (syncedMapIds.length > 0) {
6363
- syncedMapIds.map(function (syncedMapId) {
6364
- return listenerApi.dispatch(setTime({
6365
- origin: LayerActionOrigin.toggleAutoUpdateListener,
6366
- sourceId: syncedMapId,
6367
- value: timeDimension.maxValue
6368
- }));
6369
- });
6370
- }
6371
- updateAnimation(mapId, timeDimension.maxValue, listenerApi);
6372
- }
6373
- // Toggle autoupdate off for synced timesliders
6374
- payloads = syncedMapIds.reduce(function (syncedMapIdList, syncedMapId) {
6375
- if (syncedMapId !== mapId) {
6376
- return syncedMapIdList.concat({
6377
- mapId: syncedMapId,
6378
- shouldAutoUpdate: false
6379
- });
6380
- }
6381
- return syncedMapIdList;
6382
- }, []);
6383
- if (payloads.length > 0) {
6384
- payloads.map(function (payload) {
6385
- return listenerApi.dispatch(mapActions.toggleAutoUpdate(payload));
6386
- });
6387
- }
6388
- } catch (error) {
6389
- // eslint-disable-next-line no-console
6390
- console.warn(error);
6241
+ return _context3.abrupt("return");
6242
+ case 4:
6243
+ targets = getLayerActionsTargets(listenerApi.getState(), payload, SYNCGROUPS_TYPE_SETLAYERACTIONS);
6244
+ if (targets && targets.length > 0) {
6245
+ listenerApi.dispatch(setLayerActionSync(payload, targets, type));
6391
6246
  }
6392
6247
  case 6:
6393
6248
  case "end":
6394
- return _context.stop();
6249
+ return _context3.stop();
6395
6250
  }
6396
- }, _callee);
6251
+ }, _callee3);
6397
6252
  }));
6398
- function effect(_x, _x2) {
6399
- return _effect.apply(this, arguments);
6253
+ function effect(_x5, _x6) {
6254
+ return _effect3.apply(this, arguments);
6400
6255
  }
6401
6256
  return effect;
6402
6257
  }()
6403
6258
  });
6404
- mapListener.startListening({
6405
- actionCreator: mapActions.mapStartAnimation,
6406
- effect: function effect(_ref4, listenerApi) {
6407
- var payload = _ref4.payload;
6408
- var mapId = payload.mapId,
6409
- initialTime = payload.initialTime;
6410
- var speedDelay = getMapAnimationDelay(listenerApi.getState(), mapId);
6411
- var speed = 1000 / (speedDelay || 1);
6412
- metronome.register(null, speed, mapId);
6413
- var timeList = getAnimationList(listenerApi.getState(), mapId);
6414
- // In case of the timeList
6415
- if (timeList && timeList.length > 0) {
6416
- // Determine animation step based on initialTime and timeList
6417
- var initalTimerStep = timeList == null ? void 0 : timeList.findIndex(function (timeNameValue) {
6418
- return timeNameValue.value === initialTime;
6419
- });
6420
- if (initalTimerStep !== -1) {
6421
- setStep(mapId, initalTimerStep);
6422
- }
6423
- }
6424
- }
6425
- });
6426
- mapListener.startListening({
6427
- actionCreator: mapActions.mapStopAnimation,
6428
- effect: function effect(_ref5) {
6429
- var payload = _ref5.payload;
6430
- var mapId = payload.mapId;
6431
- metronome.unregister(mapId);
6432
- }
6433
- });
6434
- var handleBaseLayers = function handleBaseLayers(mapId, baseLayers, listenerApi) {
6435
- var baseLayer = baseLayers.find(function (layer) {
6436
- return layer.layerType === 'baseLayer';
6437
- });
6438
- var currentAvailableBaseLayers = getAvailableBaseLayersForMap(listenerApi.getState(), mapId);
6439
- // find a availableBaseLayer with the same name, and use that id for the active baselayer
6440
- var activeAvailableBaseLayer = currentAvailableBaseLayers.find(function (availableBaseLayer) {
6441
- return availableBaseLayer.name === baseLayer.name;
6442
- });
6443
- var activeBaseLayerId = activeAvailableBaseLayer ? activeAvailableBaseLayer.id : webmapUtils.generateLayerId();
6444
- // if the baseLayer can't be found in a visible available baseLayer list, add it
6445
- // This happens when switching to a preset that has non-default baselayers
6446
- if (!activeAvailableBaseLayer && currentAvailableBaseLayers.length) {
6447
- listenerApi.dispatch(layerActions.addAvailableBaseLayers({
6448
- layers: [Object.assign({}, baseLayer, {
6449
- mapId: mapId,
6450
- id: activeBaseLayerId
6451
- })]
6452
- }));
6453
- }
6454
- var baseLayersWithActiveId = baseLayers.map(function (layer, index) {
6455
- return index === 0 ? Object.assign({}, layer, {
6456
- id: activeBaseLayerId || layer.id
6457
- }) : layer;
6458
- });
6459
- listenerApi.dispatch(layerActions.setBaseLayers({
6460
- mapId: mapId,
6461
- layers: baseLayersWithActiveId
6462
- }));
6463
- };
6464
- mapListener.startListening({
6465
- actionCreator: mapActions.setMapPreset,
6259
+ genericListener.startListening({
6260
+ actionCreator: layerActions.addLayer,
6466
6261
  effect: function () {
6467
- var _effect2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(_ref6, listenerApi) {
6468
- var payload, mapId, initialProps, mapPreset, layers, activeLayerId, autoTimeStepLayerId, autoUpdateLayerId, proj, shouldAutoUpdate, shouldAnimate, animationPayload, toggleTimestepAuto, showTimeSlider, displayMapPin, shouldShowZoomControls, shouldShowLegend, dockedLayerManagerSize, timeSliderSpan, toggleTimeSpanAuto, _filterLayers, mapLayers, baseLayers, overLayers, _newLayerIds$layers$f, _newLayerIds$layers$, _newLayerIds$layers$f2, _newLayerIds$layers$2, autoTimeStepLayerIdNew, autoUpdateLayerIdNew, onlyActiveLayerIdIsSet, newLayerIds, newAutoUpdateLayerId, newAutoTimeStepLayerId, customLayers, customBaseLayer, customOverLayer, baseLayersWithDefaultLayer, overLayersWithDefaultLayer, allBaseLayers, checkIsprojectionSupported, animationLength, animationEndTime, shouldEndtimeOverride, interval, endTime, startTime, centerTimeInSeconds, animationEnd, _startTime, duration, _animationEnd, animationStart, shouldOpenLegend, legendId, fiveMinuteDelayForAnimation, _animationEnd2, _animationStart;
6469
- return _regeneratorRuntime().wrap(function _callee2$(_context2) {
6470
- while (1) switch (_context2.prev = _context2.next) {
6262
+ var _effect4 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(_ref4, listenerApi) {
6263
+ var payload, type, targets;
6264
+ return _regeneratorRuntime().wrap(function _callee4$(_context4) {
6265
+ while (1) switch (_context4.prev = _context4.next) {
6471
6266
  case 0:
6472
- payload = _ref6.payload;
6473
- _context2.prev = 1;
6474
- mapId = payload.mapId, initialProps = payload.initialProps;
6475
- mapPreset = initialProps.mapPreset;
6476
- if (!mapPreset) {
6477
- _context2.next = 50;
6267
+ payload = _ref4.payload, type = _ref4.type;
6268
+ listenerApi.cancelActiveListeners();
6269
+ /* Should not listen to actions from itself */
6270
+ if (!(payload && payload.origin === LayerActionOrigin.ReactMapViewParseLayer)) {
6271
+ _context4.next = 4;
6478
6272
  break;
6479
6273
  }
6480
- layers = mapPreset.layers, activeLayerId = mapPreset.activeLayerId, autoTimeStepLayerId = mapPreset.autoTimeStepLayerId, autoUpdateLayerId = mapPreset.autoUpdateLayerId, proj = mapPreset.proj, shouldAutoUpdate = mapPreset.shouldAutoUpdate, shouldAnimate = mapPreset.shouldAnimate, animationPayload = mapPreset.animationPayload, toggleTimestepAuto = mapPreset.toggleTimestepAuto, showTimeSlider = mapPreset.showTimeSlider, displayMapPin = mapPreset.displayMapPin, shouldShowZoomControls = mapPreset.shouldShowZoomControls, shouldShowLegend = mapPreset.shouldShowLegend, dockedLayerManagerSize = mapPreset.dockedLayerManagerSize, timeSliderSpan = mapPreset.timeSliderSpan, toggleTimeSpanAuto = mapPreset.toggleTimeSpanAuto;
6481
- _filterLayers = filterLayers(layers), mapLayers = _filterLayers.mapLayers, baseLayers = _filterLayers.baseLayers, overLayers = _filterLayers.overLayers;
6482
- if (layers) {
6483
- // make sure all layers have a unique id before going forward
6484
- autoTimeStepLayerIdNew = autoTimeStepLayerId;
6485
- autoUpdateLayerIdNew = autoUpdateLayerId;
6486
- onlyActiveLayerIdIsSet = !autoTimeStepLayerId && !autoUpdateLayerId && activeLayerId;
6487
- if (onlyActiveLayerIdIsSet) {
6488
- autoTimeStepLayerIdNew = activeLayerId;
6489
- autoUpdateLayerIdNew = activeLayerId;
6490
- }
6491
- newLayerIds = replaceLayerIdsToEnsureUniqueLayerIdsInStore({
6492
- layers: mapLayers,
6493
- autoTimeStepLayerId: autoTimeStepLayerIdNew,
6494
- autoUpdateLayerId: autoUpdateLayerIdNew
6495
- }); // set layers
6496
- listenerApi.dispatch(layerActions.setLayers({
6497
- mapId: mapId,
6498
- layers: newLayerIds.layers
6499
- }));
6500
- // make sure layer with new id exist and if not, default to first layer
6501
- newAutoUpdateLayerId = ((_newLayerIds$layers$f = newLayerIds.layers.find(function (layer) {
6502
- return layer.id === newLayerIds.autoUpdateLayerId;
6503
- })) == null ? void 0 : _newLayerIds$layers$f.id) || ((_newLayerIds$layers$ = newLayerIds.layers[0]) == null ? void 0 : _newLayerIds$layers$.id);
6504
- newAutoTimeStepLayerId = ((_newLayerIds$layers$f2 = newLayerIds.layers.find(function (layer) {
6505
- return layer.id === newLayerIds.autoTimeStepLayerId;
6506
- })) == null ? void 0 : _newLayerIds$layers$f2.id) || ((_newLayerIds$layers$2 = newLayerIds.layers[0]) == null ? void 0 : _newLayerIds$layers$2.id);
6507
- listenerApi.dispatch(mapActions.setAutoLayerId({
6508
- mapId: mapId,
6509
- autoUpdateLayerId: newAutoUpdateLayerId,
6510
- autoTimeStepLayerId: newAutoTimeStepLayerId
6511
- }));
6274
+ return _context4.abrupt("return");
6275
+ case 4:
6276
+ targets = getAddLayerActionsTargets(listenerApi.getState(), payload, SYNCGROUPS_TYPE_SETLAYERACTIONS);
6277
+ if (targets && targets.length > 0) {
6278
+ listenerApi.dispatch(setLayerActionSync(payload, targets, type));
6512
6279
  }
6513
- customLayers = getdefaultMapSettingsLayers(listenerApi.getState());
6514
- customBaseLayer = customLayers == null ? void 0 : customLayers.find(function (layer) {
6515
- return layer.layerType === LayerType.baseLayer;
6516
- });
6517
- customOverLayer = customLayers == null ? void 0 : customLayers.find(function (layer) {
6518
- return layer.layerType === LayerType.overLayer;
6519
- }); // sets (default) baseLayers
6520
- baseLayersWithDefaultLayer = baseLayers.length ? baseLayers : [customBaseLayer || defaultLayers.baseLayerGrey]; // sets (default) overLayers
6521
- overLayersWithDefaultLayer = overLayers.length ? overLayers : [customOverLayer || defaultLayers.overLayer];
6522
- allBaseLayers = [].concat(baseLayersWithDefaultLayer, overLayersWithDefaultLayer).map(function (layer) {
6523
- return Object.assign({}, layer, {
6524
- id: webmapUtils.generateLayerId()
6525
- });
6526
- });
6527
- handleBaseLayers(mapId, allBaseLayers, listenerApi);
6528
- if (!proj) {
6529
- _context2.next = 20;
6530
- break;
6280
+ case 6:
6281
+ case "end":
6282
+ return _context4.stop();
6283
+ }
6284
+ }, _callee4);
6285
+ }));
6286
+ function effect(_x7, _x8) {
6287
+ return _effect4.apply(this, arguments);
6288
+ }
6289
+ return effect;
6290
+ }()
6291
+ });
6292
+ genericListener.startListening({
6293
+ actionCreator: layerActions.duplicateMapLayer,
6294
+ effect: function () {
6295
+ var _effect5 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(_ref5, listenerApi) {
6296
+ var payload, sourceLayer, newPayload, targets;
6297
+ return _regeneratorRuntime().wrap(function _callee5$(_context5) {
6298
+ while (1) switch (_context5.prev = _context5.next) {
6299
+ case 0:
6300
+ payload = _ref5.payload;
6301
+ listenerApi.cancelActiveListeners();
6302
+ sourceLayer = getLayerById(listenerApi.getState(), payload.oldLayerId);
6303
+ newPayload = {
6304
+ mapId: payload.mapId,
6305
+ layer: sourceLayer,
6306
+ origin: payload.origin
6307
+ };
6308
+ targets = getAddLayerActionsTargets(listenerApi.getState(), newPayload, SYNCGROUPS_TYPE_SETLAYERACTIONS);
6309
+ if (targets && targets.length > 0) {
6310
+ listenerApi.dispatch(setLayerActionSync(newPayload, targets, layerActions.addLayer.type));
6531
6311
  }
6532
- checkIsprojectionSupported = isProjectionSupported(proj.srs);
6533
- if (checkIsprojectionSupported) {
6534
- _context2.next = 19;
6312
+ case 6:
6313
+ case "end":
6314
+ return _context5.stop();
6315
+ }
6316
+ }, _callee5);
6317
+ }));
6318
+ function effect(_x9, _x10) {
6319
+ return _effect5.apply(this, arguments);
6320
+ }
6321
+ return effect;
6322
+ }()
6323
+ });
6324
+ genericListener.startListening({
6325
+ actionCreator: mapActions.layerMoveLayer,
6326
+ effect: function () {
6327
+ var _effect6 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6(_ref6, listenerApi) {
6328
+ var payload, type, targets;
6329
+ return _regeneratorRuntime().wrap(function _callee6$(_context6) {
6330
+ while (1) switch (_context6.prev = _context6.next) {
6331
+ case 0:
6332
+ payload = _ref6.payload, type = _ref6.type;
6333
+ listenerApi.cancelActiveListeners();
6334
+ /* Should not listen to actions from itself */
6335
+ if (!(payload && payload.origin === LayerActionOrigin.ReactMapViewParseLayer)) {
6336
+ _context6.next = 4;
6535
6337
  break;
6536
6338
  }
6537
- throw new Error("Projection " + proj.srs + " is not supported");
6538
- case 19:
6539
- // set bbox
6540
- listenerApi.dispatch(mapActions.setBbox({
6541
- mapId: mapId,
6542
- bbox: proj.bbox,
6543
- srs: proj.srs
6544
- }));
6545
- case 20:
6546
- animationLength = animationPayload && animationPayload.duration;
6547
- animationEndTime = animationPayload && animationPayload.endTime && isAnimationEndTimeValid(animationPayload.endTime) && animationPayload.endTime;
6548
- shouldEndtimeOverride = animationPayload ? animationPayload.shouldEndtimeOverride : false;
6549
- if (shouldEndtimeOverride) {
6550
- // auto update
6551
- listenerApi.dispatch(mapActions.setEndTimeOverriding({
6552
- mapId: mapId,
6553
- shouldEndtimeOverride: shouldEndtimeOverride
6554
- }));
6555
- }
6556
- if (shouldAutoUpdate !== undefined && !animationEndTime) {
6557
- // auto update
6558
- listenerApi.dispatch(mapActions.toggleAutoUpdate({
6559
- mapId: mapId,
6560
- shouldAutoUpdate: shouldAutoUpdate
6561
- }));
6562
- }
6563
- if (showTimeSlider !== undefined) {
6564
- // toggle timeslider
6565
- listenerApi.dispatch(mapActions.toggleTimeSliderIsVisible({
6566
- mapId: mapId,
6567
- isTimeSliderVisible: showTimeSlider
6568
- }));
6569
- }
6570
- if (timeSliderSpan !== undefined) {
6571
- // set timeslider span
6572
- listenerApi.dispatch(mapActions.setTimeSliderSpan({
6573
- mapId: mapId,
6574
- timeSliderSpan: timeSliderSpan
6575
- }));
6576
- }
6577
- if (toggleTimeSpanAuto !== undefined) {
6578
- // toggle timeslider span auto
6579
- listenerApi.dispatch(mapActions.toggleTimeSpanAuto({
6580
- mapId: mapId,
6581
- timeSpanAuto: toggleTimeSpanAuto
6582
- }));
6583
- }
6584
- if (shouldShowZoomControls !== undefined) {
6585
- // toggle zoom controls
6586
- listenerApi.dispatch(mapActions.toggleZoomControls({
6587
- mapId: mapId,
6588
- shouldShowZoomControls: shouldShowZoomControls
6589
- }));
6590
- }
6591
- if (displayMapPin !== undefined) {
6592
- // display map pin
6593
- listenerApi.dispatch(mapActions.toggleMapPinIsVisible({
6594
- mapId: mapId,
6595
- displayMapPin: displayMapPin
6596
- }));
6597
- }
6598
- // sets timestep by interval of animationPayload
6599
- interval = animationPayload && animationPayload.interval;
6600
- if (interval) {
6601
- listenerApi.dispatch(mapActions.setTimeStep({
6602
- mapId: mapId,
6603
- timeStep: interval
6604
- }));
6605
- }
6606
- // sets animationEndTime by endTime of animationPayload
6607
- if (animationEndTime) {
6608
- endTime = animationEndTime.includes('NOW') || animationEndTime.includes('TODAY') ? dateUtils.convertNOWandTODAYFormatsToUTC(animationEndTime) : animationEndTime;
6609
- listenerApi.dispatch(mapActions.setAnimationEndTime({
6610
- mapId: mapId,
6611
- animationEndTime: handleDateUtilsISOString(endTime)
6612
- }));
6613
- startTime = handleDateUtilsISOString(dateUtils.sub(dateUtils.utc(endTime), {
6614
- minutes: 5 * 60 // set to default of 5 hours
6615
- }).toISOString());
6616
- listenerApi.dispatch(mapActions.setAnimationStartTime({
6617
- mapId: mapId,
6618
- animationStartTime: startTime
6619
- }));
6620
- listenerApi.dispatch(genericActions.setTime({
6621
- origin: '',
6622
- sourceId: mapId,
6623
- value: startTime
6624
- }));
6625
- centerTimeInSeconds = new Date(handleDateUtilsISOString(endTime)).getTime();
6626
- listenerApi.dispatch(mapActions.setTimeSliderCenterTime({
6627
- mapId: mapId,
6628
- timeSliderCenterTime: centerTimeInSeconds
6629
- }));
6630
- }
6631
- // sets animationStartTime by duration of animationPayload
6632
- if (animationLength) {
6633
- animationEnd = getAnimationEndTime(listenerApi.getState(), mapId);
6634
- _startTime = handleDateUtilsISOString(dateUtils.sub(dateUtils.utc(animationEnd), {
6635
- minutes: animationLength
6636
- }).toISOString());
6637
- listenerApi.dispatch(mapActions.setAnimationStartTime({
6638
- mapId: mapId,
6639
- animationStartTime: _startTime
6640
- }));
6641
- listenerApi.dispatch(genericActions.setTime({
6642
- origin: '',
6643
- sourceId: mapId,
6644
- value: _startTime
6645
- }));
6646
- }
6647
- // sets animationDelay by speed of animationPayload
6648
- if (animationPayload && animationPayload.speed) {
6649
- listenerApi.dispatch(mapActions.setAnimationDelay({
6650
- mapId: mapId,
6651
- animationDelay: getSpeedDelay(animationPayload.speed)
6652
- }));
6653
- }
6654
- // turn animation on
6655
- if (shouldAnimate === true) {
6656
- duration = animationPayload && animationPayload.duration ? animationPayload.duration : 5 * 60; // set to default of 5 hours
6657
- _animationEnd = shouldEndtimeOverride && animationEndTime ? getAnimationEndTime(listenerApi.getState(), mapId) : dateUtils.dateToString(dateUtils.utc(), dateFormat);
6658
- animationStart = shouldEndtimeOverride && animationLength ? getAnimationStartTime(listenerApi.getState(), mapId) : dateUtils.dateToString(dateUtils.sub(dateUtils.utc(_animationEnd), {
6659
- minutes: duration
6660
- }), dateFormat);
6661
- listenerApi.dispatch(mapActions.mapStartAnimation({
6662
- mapId: mapId,
6663
- start: animationStart,
6664
- end: _animationEnd,
6665
- interval: interval || defaultTimeStep
6666
- }));
6667
- // If animation interval set, set the timestep auto property to false
6668
- if (interval) {
6669
- listenerApi.dispatch(mapActions.toggleTimestepAuto({
6670
- mapId: mapId,
6671
- timestepAuto: false
6672
- }));
6673
- }
6674
- } else if (toggleTimestepAuto !== undefined) {
6675
- // Set timestep auto based on preset if animation is off
6676
- listenerApi.dispatch(mapActions.toggleTimestepAuto({
6677
- mapId: mapId,
6678
- timestepAuto: toggleTimestepAuto
6679
- }));
6680
- }
6681
- // show legend
6682
- shouldOpenLegend = shouldShowLegend !== undefined ? shouldShowLegend : IS_LEGEND_OPEN_BY_DEFAULT;
6683
- legendId = getLegendId(listenerApi.getState(), mapId);
6684
- if (legendId) {
6685
- listenerApi.dispatch(uiActions.setToggleOpenDialog({
6686
- type: legendId,
6687
- setOpen: shouldOpenLegend
6688
- }));
6339
+ return _context6.abrupt("return");
6340
+ case 4:
6341
+ targets = getLayerMoveActionsTargets(listenerApi.getState(), payload, SYNCGROUPS_TYPE_SETLAYERACTIONS);
6342
+ if (targets && targets.length > 0) {
6343
+ listenerApi.dispatch(setLayerActionSync(payload, targets, type));
6689
6344
  }
6690
- if (dockedLayerManagerSize) {
6691
- listenerApi.dispatch(mapActions.setDockedLayerManagerSize({
6692
- mapId: mapId,
6693
- dockedLayerManagerSize: dockedLayerManagerSize
6694
- }));
6345
+ case 6:
6346
+ case "end":
6347
+ return _context6.stop();
6348
+ }
6349
+ }, _callee6);
6350
+ }));
6351
+ function effect(_x11, _x12) {
6352
+ return _effect6.apply(this, arguments);
6353
+ }
6354
+ return effect;
6355
+ }()
6356
+ });
6357
+ genericListener.startListening({
6358
+ matcher: isAnyOf(mapActions.setAutoLayerId, mapActions.setAutoUpdateLayerId, mapActions.setAutoTimestepLayerId),
6359
+ effect: function () {
6360
+ var _effect7 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7(_ref7, listenerApi) {
6361
+ var payload, type, targets;
6362
+ return _regeneratorRuntime().wrap(function _callee7$(_context7) {
6363
+ while (1) switch (_context7.prev = _context7.next) {
6364
+ case 0:
6365
+ payload = _ref7.payload, type = _ref7.type;
6366
+ listenerApi.cancelActiveListeners();
6367
+ targets = getSetAutoLayerIdActionsTargets(listenerApi.getState(), payload, SYNCGROUPS_TYPE_SETLAYERACTIONS);
6368
+ if (targets && targets.length > 0) {
6369
+ listenerApi.dispatch(setLayerActionSync(payload, targets, type));
6695
6370
  }
6696
- case 40:
6697
- if (!(animationEndTime && (shouldEndtimeOverride || !(shouldAutoUpdate || shouldAnimate)))) {
6698
- _context2.next = 50;
6371
+ case 4:
6372
+ case "end":
6373
+ return _context7.stop();
6374
+ }
6375
+ }, _callee7);
6376
+ }));
6377
+ function effect(_x13, _x14) {
6378
+ return _effect7.apply(this, arguments);
6379
+ }
6380
+ return effect;
6381
+ }()
6382
+ });
6383
+ genericListener.startListening({
6384
+ actionCreator: layerActions.setBaseLayers,
6385
+ effect: function () {
6386
+ var _effect8 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee8(_ref8, listenerApi) {
6387
+ var payload, type, targets;
6388
+ return _regeneratorRuntime().wrap(function _callee8$(_context8) {
6389
+ while (1) switch (_context8.prev = _context8.next) {
6390
+ case 0:
6391
+ payload = _ref8.payload, type = _ref8.type;
6392
+ listenerApi.cancelActiveListeners();
6393
+ /* Should not listen to actions from itself */
6394
+ if (!(payload && payload.origin === LayerActionOrigin.ReactMapViewParseLayer)) {
6395
+ _context8.next = 4;
6699
6396
  break;
6700
6397
  }
6701
- fiveMinuteDelayForAnimation = 1000 * 60 * 5; // eslint-disable-next-line no-await-in-loop
6702
- _context2.next = 44;
6703
- return listenerApi.delay(fiveMinuteDelayForAnimation);
6704
- case 44:
6705
- _animationEnd2 = getAnimationEndTime(listenerApi.getState(), mapId);
6706
- listenerApi.dispatch(mapActions.setAnimationEndTime({
6707
- mapId: mapId,
6708
- animationEndTime: dateUtils.add(dateUtils.utc(_animationEnd2), {
6709
- minutes: 5
6710
- }).toISOString()
6711
- }));
6712
- _animationStart = getAnimationStartTime(listenerApi.getState(), mapId);
6713
- listenerApi.dispatch(mapActions.setAnimationStartTime({
6714
- mapId: mapId,
6715
- animationStartTime: dateUtils.add(dateUtils.utc(_animationStart), {
6716
- minutes: 5
6717
- }).toISOString()
6718
- }));
6719
- _context2.next = 40;
6720
- break;
6721
- case 50:
6722
- _context2.next = 55;
6723
- break;
6724
- case 52:
6725
- _context2.prev = 52;
6726
- _context2.t0 = _context2["catch"](1);
6727
- if (_context2.t0 instanceof Error) {
6728
- listenerApi.dispatch(mapActions.setMapPresetError({
6729
- mapId: payload.mapId,
6730
- error: _context2.t0.message
6731
- }));
6398
+ return _context8.abrupt("return");
6399
+ case 4:
6400
+ targets = getMapBaseLayerActionsTargets(listenerApi.getState(), payload, SYNCGROUPS_TYPE_SETLAYERACTIONS);
6401
+ if (targets && targets.length > 0) {
6402
+ listenerApi.dispatch(setLayerActionSync(payload, targets, type));
6732
6403
  }
6733
- case 55:
6404
+ case 6:
6734
6405
  case "end":
6735
- return _context2.stop();
6406
+ return _context8.stop();
6736
6407
  }
6737
- }, _callee2, null, [[1, 52]]);
6408
+ }, _callee8);
6738
6409
  }));
6739
- function effect(_x3, _x4) {
6740
- return _effect2.apply(this, arguments);
6410
+ function effect(_x15, _x16) {
6411
+ return _effect8.apply(this, arguments);
6741
6412
  }
6742
6413
  return effect;
6743
6414
  }()
6744
6415
  });
6745
- mapListener.startListening({
6746
- actionCreator: mapActions.unregisterMap,
6747
- effect: function effect(_ref7, listenerApi) {
6748
- var payload = _ref7.payload;
6749
- var mapId = payload.mapId;
6750
- var layerList = getLayersByMapId(listenerApi.getState(), mapId);
6751
- metronome.unregister(mapId);
6752
- layerList.map(function (layer) {
6753
- return listenerApi.dispatch(layerActions.layerDelete({
6754
- mapId: mapId,
6755
- layerId: layer.id,
6756
- origin: LayerActionOrigin.unregisterMapListener
6757
- }));
6758
- });
6759
- }
6760
- });
6761
- mapListener.startListening({
6762
- actionCreator: mapActions.setStepBackwardOrForward,
6763
- effect: function effect(_ref8, listenerApi) {
6764
- var payload = _ref8.payload;
6765
- var mapId = payload.mapId,
6766
- isForwardStep = payload.isForwardStep;
6767
- var timeStep = getMapTimeStep(listenerApi.getState(), mapId);
6768
- var currentTime = getSelectedTime(listenerApi.getState(), mapId);
6769
- var _mapSelectors$getData = getDataLimitsFromLayers(listenerApi.getState(), mapId),
6770
- dataStartTime = _mapSelectors$getData[0],
6771
- dataEndTime = _mapSelectors$getData[1];
6772
- if (dateUtils.isValid(currentTime)) {
6773
- var makeForwardStep = function makeForwardStep() {
6774
- var nextTime = currentTime + timeStep;
6775
- var roundedTime = roundWithTimeStep(nextTime, timeStep, 'ceil');
6776
- var newTime = Math.min(roundedTime, dataEndTime || roundedTime);
6777
- return dateUtils.fromUnix(newTime).toISOString();
6778
- };
6779
- var makeBackwardStep = function makeBackwardStep() {
6780
- var nextTime = currentTime - timeStep;
6781
- var roundedTime = roundWithTimeStep(nextTime, timeStep, 'floor');
6782
- var newTime = Math.max(roundedTime, dataStartTime || roundedTime);
6783
- return dateUtils.fromUnix(newTime).toISOString();
6784
- };
6785
- var selectedTimeString = isForwardStep ? makeForwardStep() : makeBackwardStep();
6786
- var isMapAnimating = isAnimating(listenerApi.getState(), mapId);
6787
- if (isMapAnimating) {
6788
- listenerApi.dispatch(mapActions.mapStopAnimation({
6789
- mapId: mapId,
6790
- origin: MapActionOrigin.map
6791
- }));
6792
- }
6793
- listenerApi.dispatch(genericActions.setTime({
6794
- origin: '',
6795
- sourceId: mapId,
6796
- value: handleDateUtilsISOString(selectedTimeString)
6797
- }));
6798
- }
6799
- }
6800
- });
6801
-
6802
- var _excluded$1 = ["url"];
6803
- var serviceListener = createListenerMiddleware();
6804
- var fetchService = /*#__PURE__*/function () {
6805
- var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(service, listenerApi) {
6806
- var layers;
6807
- return _regeneratorRuntime().wrap(function _callee$(_context) {
6808
- while (1) switch (_context.prev = _context.next) {
6809
- case 0:
6810
- _context.prev = 0;
6811
- _context.next = 3;
6812
- return queryWMSLayers(service.serviceUrl);
6813
- case 3:
6814
- layers = _context.sent;
6815
- listenerApi.dispatch(serviceActions.serviceSetLayers(Object.assign({}, service, {
6816
- layers: layers
6817
- })));
6818
- _context.next = 10;
6819
- break;
6820
- case 7:
6821
- _context.prev = 7;
6822
- _context.t0 = _context["catch"](0);
6823
- if (_context.t0 instanceof Error) {
6824
- console.warn(_context.t0.message);
6825
- }
6826
- case 10:
6827
- case "end":
6828
- return _context.stop();
6829
- }
6830
- }, _callee, null, [[0, 7]]);
6831
- }));
6832
- return function fetchService(_x, _x2) {
6833
- return _ref.apply(this, arguments);
6834
- };
6835
- }();
6836
- var fetchInitialServices = /*#__PURE__*/function () {
6837
- var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(payload, listenerApi) {
6838
- return _regeneratorRuntime().wrap(function _callee2$(_context2) {
6839
- while (1) switch (_context2.prev = _context2.next) {
6840
- case 0:
6841
- if (!(!payload || !payload.services)) {
6842
- _context2.next = 2;
6843
- break;
6844
- }
6845
- return _context2.abrupt("return");
6846
- case 2:
6847
- _context2.prev = 2;
6848
- _context2.next = 5;
6849
- return Promise.all(payload.services.map(function (_ref3) {
6850
- var url = _ref3.url,
6851
- service = _objectWithoutPropertiesLoose(_ref3, _excluded$1);
6852
- return fetchService(Object.assign({}, service, {
6853
- serviceUrl: url
6854
- }), listenerApi);
6855
- }));
6856
- case 5:
6857
- _context2.next = 10;
6858
- break;
6859
- case 7:
6860
- _context2.prev = 7;
6861
- _context2.t0 = _context2["catch"](2);
6862
- // eslint-disable-next-line no-console
6863
- console.warn(_context2.t0);
6864
- case 10:
6865
- case "end":
6866
- return _context2.stop();
6867
- }
6868
- }, _callee2, null, [[2, 7]]);
6869
- }));
6870
- return function fetchInitialServices(_x3, _x4) {
6871
- return _ref2.apply(this, arguments);
6872
- };
6873
- }();
6874
- serviceListener.startListening({
6875
- actionCreator: serviceActions.fetchInitialServices,
6416
+ genericListener.startListening({
6417
+ actionCreator: layerActions.layerDelete,
6876
6418
  effect: function () {
6877
- var _effect = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(_ref4, listenerApi) {
6878
- var payload;
6879
- return _regeneratorRuntime().wrap(function _callee3$(_context3) {
6880
- while (1) switch (_context3.prev = _context3.next) {
6419
+ var _effect9 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee9(_ref9, listenerApi) {
6420
+ var payload, type, targets;
6421
+ return _regeneratorRuntime().wrap(function _callee9$(_context9) {
6422
+ while (1) switch (_context9.prev = _context9.next) {
6881
6423
  case 0:
6882
- payload = _ref4.payload;
6424
+ payload = _ref9.payload, type = _ref9.type;
6883
6425
  listenerApi.cancelActiveListeners();
6884
- _context3.next = 4;
6885
- return fetchInitialServices(payload, listenerApi);
6426
+ /* Should not listen to actions from itself */
6427
+ if (!(payload && payload.origin === LayerActionOrigin.ReactMapViewParseLayer)) {
6428
+ _context9.next = 4;
6429
+ break;
6430
+ }
6431
+ return _context9.abrupt("return");
6886
6432
  case 4:
6433
+ targets = getLayerDeleteActionsTargets(listenerApi.getState(), payload, SYNCGROUPS_TYPE_SETLAYERACTIONS);
6434
+ if (targets && targets.length > 0) {
6435
+ listenerApi.dispatch(setLayerActionSync(payload, targets, type));
6436
+ }
6437
+ case 6:
6887
6438
  case "end":
6888
- return _context3.stop();
6439
+ return _context9.stop();
6889
6440
  }
6890
- }, _callee3);
6441
+ }, _callee9);
6891
6442
  }));
6892
- function effect(_x5, _x6) {
6893
- return _effect.apply(this, arguments);
6443
+ function effect(_x17, _x18) {
6444
+ return _effect9.apply(this, arguments);
6894
6445
  }
6895
6446
  return effect;
6896
6447
  }()
6897
6448
  });
6898
6449
 
6899
- // use `required` type because all props are provided
6900
- var mapStoreReducers = {
6901
- webmap: reducer$2,
6902
- services: reducer$5,
6903
- layers: reducer$4
6904
- };
6905
- var mapStoreMiddlewares = [metronomeListener.middleware, layersListener.middleware, mapListener.middleware, serviceListener.middleware];
6906
- var mapStoreModuleConfig = {
6907
- reducersMap: mapStoreReducers,
6908
- middlewares: mapStoreMiddlewares
6450
+ /* A map with all the timerIds and their current step */
6451
+ var stepMap = new Map();
6452
+ /* A map with a list of timers and their dwell */
6453
+ var timerDwellMap = new Map();
6454
+ /**
6455
+ * Returns the next step for given timerId.
6456
+ * @param timerId The timer id
6457
+ * @param numberOfStepsInAnimation Animation length in steps
6458
+ * @param numStepsToGoForward Amount of steps to go forwards, defaults to 1. Can be positive and negative
6459
+ * @returns
6460
+ */
6461
+ var getNextStep = function getNextStep(timerId, numberOfStepsInAnimation, numStepsToGoForward) {
6462
+ if (numStepsToGoForward === void 0) {
6463
+ numStepsToGoForward = 1;
6464
+ }
6465
+ var currentStep = getCurrentStep(timerId);
6466
+ var nextStep = currentStep + numStepsToGoForward;
6467
+ var nextStepClipped = (nextStep % numberOfStepsInAnimation + numberOfStepsInAnimation) % numberOfStepsInAnimation;
6468
+ return nextStepClipped;
6909
6469
  };
6910
-
6911
- var _excluded = ["id"];
6912
6470
  /**
6913
- * Tries to find the layerId's in the other map based on the payload of the action. It works for all layer actions.
6914
- * @param state
6915
- * @param mapId
6916
- * @param targetMapId
6917
- * @param payload
6471
+ * Handles dwell at the end of the animation loop sequence. The number of steps to wait till proceed can be set by the dwell parameter.
6472
+ * @param timerId The timer id
6473
+ * @param numberOfStepsInAnimation Number of steps in the animation
6474
+ * @param dwell The number of steps to wait at the end of the animation sequence before to continue
6918
6475
  * @returns
6919
6476
  */
6920
- var getTargetLayerIdFromPayload = function getTargetLayerIdFromPayload(state, mapId, targetMapId, payload) {
6921
- if (!payload) {
6922
- return null;
6477
+ var handleTimerDwell = function handleTimerDwell(timerId, numberOfStepsInAnimation, dwell) {
6478
+ if (dwell === void 0) {
6479
+ dwell = 8;
6923
6480
  }
6924
- /* Try to find the layer for the DeleteLayerPayload, it uses layerIndex to reference the layer */
6925
- if ('layerIndex' in payload) {
6926
- var tempLayerIndex = payload.layerIndex;
6927
- if (tempLayerIndex !== undefined) {
6928
- var targetLayer = getLayerByLayerIndex(state, targetMapId, tempLayerIndex);
6929
- return !targetLayer ? null : targetLayer.id;
6481
+ if (dwell > 0) {
6482
+ var currentStep = getCurrentStep(timerId);
6483
+ // Reset the dwell if we are not at the last animation step
6484
+ if (currentStep < numberOfStepsInAnimation - 1) {
6485
+ timerDwellMap.set(timerId, dwell);
6486
+ return false;
6487
+ }
6488
+ // We are at the last animation step, check the dwell
6489
+ var timerDwell = timerDwellMap.has(timerId) && timerDwellMap.get(timerId) || 0;
6490
+ if (currentStep === numberOfStepsInAnimation - 1 && timerDwell > 0) {
6491
+ timerDwellMap.set(timerId, timerDwell - 1);
6492
+ return true;
6930
6493
  }
6931
6494
  }
6932
- /* Try to find the layer for the LayerActionsWithLayerIds, it uses layerId to reference the layer */
6933
- if ('layerId' in payload) {
6934
- var _targetLayer = getLayerByLayerIndex(state, targetMapId, getLayerIndexByLayerId(state, mapId, payload.layerId));
6935
- return !_targetLayer ? null : _targetLayer.id;
6936
- }
6937
- /* This payload probably does not reference to a layerId */
6938
- return null;
6495
+ return false;
6939
6496
  };
6940
6497
  /**
6941
- * Local helper function used by getLayerDeleteActionsTargets, getLayerActionsTargets, getAddLayerActionsTargets, getTargetLayerIdFromPayload to find the targets
6942
- * @param state
6943
- * @param payload
6944
- * @param actionType
6945
- * @param sourceMapId
6946
- * @returns The found targets
6498
+ * Set step for the timerId
6499
+ * @param timerId
6500
+ * @param timerStep
6947
6501
  */
6948
- var findTargets = function findTargets(state, payload, actionType, sourceMapId) {
6949
- var actionPayloads = [];
6950
- var targetsInActionPayload = {};
6951
- var syncGroups = syncGroupStore(state);
6952
- if (syncGroups && payload) {
6953
- syncGroups.groups.allIds.forEach(function (id) {
6954
- var syncronizationGroup = syncGroups.groups.byId[id];
6955
- if (actionType === syncronizationGroup.type) {
6956
- /* Check if the source is in the target list of the synchonizationGroup */
6957
- var source = syncronizationGroup.targets.byId[sourceMapId];
6958
- /* If the source is part of the target list, and is linked, continue syncing the other targets */
6959
- if (source && source.linked) {
6960
- syncronizationGroup.targets.allIds.forEach(function (targetId) {
6961
- var target = syncronizationGroup.targets.byId[targetId];
6962
- if (targetId !== sourceMapId && target.linked && !targetsInActionPayload[targetId]) {
6963
- /* Remember that we have already added this target in the action payloads, prevents adding it twice */
6964
- targetsInActionPayload[targetId] = true;
6965
- var otherLayerId = getTargetLayerIdFromPayload(state, sourceMapId, targetId, payload);
6966
- actionPayloads.push({
6967
- payload: payload,
6968
- targetId: targetId,
6969
- layerId: otherLayerId
6970
- });
6971
- }
6972
- });
6973
- }
6974
- }
6975
- });
6976
- }
6977
- return actionPayloads;
6978
- };
6979
- /**
6980
- * These targets are found for layer actions that work with a layerId like: SetLayerName, SetLayerEnabled, SetLayerOpacity, SetLayerDimension and SetLayerStyle
6981
- * @param state
6982
- * @param payload
6983
- * @param actionType
6984
- * @returns
6985
- */
6986
- var getLayerActionsTargets = function getLayerActionsTargets(state, payload, actionType) {
6987
- var mapId = getMapIdFromLayerId(state, payload.layerId);
6988
- if (!mapId) {
6989
- return [];
6990
- }
6991
- var foundTargets = findTargets(state, payload, actionType, mapId);
6992
- return foundTargets.map(function (target) {
6993
- var payload = target.payload;
6994
- return Object.assign({}, payload, {
6995
- layerId: target.layerId,
6996
- origin: SyncGroupActionOrigin.layerActions,
6997
- mapId: payload.mapId
6998
- });
6999
- });
7000
- };
7001
- /**
7002
- * These targets are found for the layer/map action AddLayer. AddLayer does not have a layerId (because it's new)
7003
- * @param state
7004
- * @param payload
7005
- * @param actionType
7006
- * @returns
7007
- */
7008
- var getAddLayerActionsTargets = function getAddLayerActionsTargets(state, payload, actionType) {
7009
- var foundTargets = findTargets(state, payload, actionType, payload.mapId);
7010
- return foundTargets.map(function (_ref) {
7011
- var payload = _ref.payload,
7012
- targetId = _ref.targetId;
7013
- var layer = payload.layer;
7014
- layer.id;
7015
- var layerWithoutId = _objectWithoutPropertiesLoose(layer, _excluded);
7016
- var layerId = webmapUtils.generateLayerId();
7017
- return Object.assign({}, payload, {
7018
- layer: layerWithoutId,
7019
- layerId: layerId,
7020
- mapId: targetId,
7021
- origin: SyncGroupActionOrigin.add
7022
- });
7023
- });
7024
- };
7025
- /**
7026
- * These targets are found for the layer/map action DeleteLayer. The layer is already gone, so there is no layerId anymore. Using layerIndex instead.
7027
- * @param state
7028
- * @param payload
7029
- * @param actionType
7030
- * @returns
7031
- */
7032
- var getLayerDeleteActionsTargets = function getLayerDeleteActionsTargets(state, payload, actionType) {
7033
- var foundTargets = findTargets(state, payload, actionType, payload.mapId);
7034
- return foundTargets.map(function (target) {
7035
- return Object.assign({}, target.payload, {
7036
- mapId: target.targetId,
7037
- layerId: target.layerId,
7038
- origin: SyncGroupActionOrigin["delete"]
7039
- });
7040
- });
7041
- };
7042
- /**
7043
- * These targets are found for the layer/map action MoveLayer. Here layers are referenced by newIndex and oldIndex.
7044
- * @param state
7045
- * @param payload
7046
- * @param actionType
7047
- * @returns
7048
- */
7049
- var getLayerMoveActionsTargets = function getLayerMoveActionsTargets(state, payload, actionType) {
7050
- var foundTargets = findTargets(state, payload, actionType, payload.mapId);
7051
- return foundTargets.map(function (target) {
7052
- return Object.assign({}, target.payload, {
7053
- mapId: target.targetId,
7054
- origin: SyncGroupActionOrigin.move
7055
- });
7056
- });
6502
+ var setStep = function setStep(timerId, timerStep) {
6503
+ stepMap.set(timerId, timerStep);
7057
6504
  };
7058
6505
  /**
7059
- * These targets are found for the map action SetAutoLayerId. It needs both a target mapId and layerId
7060
- * @param state
7061
- * @param payload
7062
- * @param actionType
6506
+ * Gets the current step for the timer
6507
+ * @param timerId
7063
6508
  * @returns
7064
6509
  */
7065
- var getSetAutoLayerIdActionsTargets = function getSetAutoLayerIdActionsTargets(state, payload, actionType) {
7066
- var payloadWithLayerId = Object.assign({}, payload, {
7067
- layerId: payload.autoUpdateLayerId || payload.autoTimeStepLayerId || payload.layerId
7068
- });
7069
- var foundTargets = findTargets(state, payloadWithLayerId, actionType, payload.mapId);
7070
- return foundTargets.map(function (target) {
7071
- return {
7072
- mapId: target.targetId,
7073
- layerId: target.layerId,
7074
- origin: SyncGroupActionOrigin.autoLayerId
7075
- };
7076
- });
6510
+ var getCurrentStep = function getCurrentStep(timerId) {
6511
+ return stepMap.get(timerId) || 0;
7077
6512
  };
6513
+ var MAX_NUMBER_STEPS_FORWARD_TO_PREFETCH = 2;
6514
+ var MAX_NUMBER_OF_PARALLEL_LOADING_IMAGES = 8;
7078
6515
  /**
7079
- * These targets are found for baselayer actions that work with a mapId like: setBaseLayers
7080
- * @param state
7081
- * @param payload
7082
- * @param actionType
7083
- * @returns
6516
+ * This prefetches all images connected to the same sync group as provided timerId
6517
+ * @param timerId The timerId
6518
+ * @param animationListValues List of animation steps in isostring to animate
6519
+ * @param targets List of targets to check
6520
+ * @returns True if all maps are ready to go forward, false if the map has no data to display yet.
7084
6521
  */
7085
- var getMapBaseLayerActionsTargets = function getMapBaseLayerActionsTargets(state, payload, actionType) {
7086
- var foundTargets = findTargets(state, payload, actionType, payload.mapId);
7087
- return foundTargets.map(function (target) {
7088
- return {
7089
- layers: payload.layers.map(function (layer) {
7090
- return Object.assign({}, layer, {
7091
- id: webmapUtils.generateLayerId()
7092
- });
7093
- }),
7094
- mapId: target.targetId,
7095
- origin: SyncGroupActionOrigin.layerActions
7096
- };
7097
- });
7098
- };
7099
-
7100
- var setTimeValidatorRexexp = /^(19|20)\d\d-(0[1-9]|1[012])-([012]\d|3[01])T([01]\d|2[0-3]):([0-5]\d):([0-5]\d)Z$/;
7101
- var genericListener = createListenerMiddleware();
7102
- genericListener.startListening({
7103
- actionCreator: setTime,
7104
- effect: function () {
7105
- var _effect = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(_ref, listenerApi) {
7106
- var payload, value, origin, targets, groups;
7107
- return _regeneratorRuntime().wrap(function _callee$(_context) {
7108
- while (1) switch (_context.prev = _context.next) {
7109
- case 0:
7110
- payload = _ref.payload;
7111
- listenerApi.cancelActiveListeners();
7112
- value = payload.value, origin = payload.origin;
7113
- /* Test if the value is according to the expected time format */
7114
- if (!setTimeValidatorRexexp.test(value)) {
7115
- console.error("setTime value " + value + " does not conform to format [YYYY-MM-DDThh:mm:ssZ]. It was triggered by " + origin);
7116
- } else {
7117
- targets = getTargets(listenerApi.getState(), payload, SYNCGROUPS_TYPE_SETTIME);
7118
- groups = getTargetGroups(listenerApi.getState(), payload, SYNCGROUPS_TYPE_SETTIME);
7119
- listenerApi.dispatch(setTimeSync(payload, targets, groups));
6522
+ var prefetchAnimationTargetsForMetronome = function prefetchAnimationTargetsForMetronome(timerId, animationListValues, targets) {
6523
+ var timerShouldStepForward = true;
6524
+ // The following code prefetches/buffers for all maps in the group
6525
+ for (var numPrefetch = 0; numPrefetch < MAX_NUMBER_STEPS_FORWARD_TO_PREFETCH; numPrefetch += 1) {
6526
+ var nextStep = getNextStep(timerId, animationListValues.length, numPrefetch + 1);
6527
+ var nextTimeValueStepToCheck = animationListValues[nextStep];
6528
+ for (var _iterator = _createForOfIteratorHelperLoose(targets), _step; !(_step = _iterator()).done;) {
6529
+ var target = _step.value;
6530
+ var targetMapId = target.targetId;
6531
+ var wmMap = getWMJSMapById(targetMapId);
6532
+ if (!wmMap) {
6533
+ return true; // Map was not registered so there is nothing to prefetch, do not block going forward
6534
+ }
6535
+ var layersImageUrls = getWMSRequests(wmMap, [{
6536
+ name: 'time',
6537
+ currentValue: nextTimeValueStepToCheck
6538
+ }]);
6539
+ for (var _iterator2 = _createForOfIteratorHelperLoose(layersImageUrls), _step2; !(_step2 = _iterator2()).done;) {
6540
+ var layersImageUrl = _step2.value;
6541
+ var image = wmMap.getMapImageStore.getImage(layersImageUrl.url);
6542
+ if (!image.isLoaded()) {
6543
+ if (wmMap.getMapImageStore.getNumImagesLoading() < MAX_NUMBER_OF_PARALLEL_LOADING_IMAGES) {
6544
+ image.load();
6545
+ }
6546
+ if (numPrefetch === 0) {
6547
+ var altImage = wmMap.getAlternativeImage(layersImageUrl.url, wmMap.getBBOX(), true);
6548
+ // No alternative image available yet, so skipping animation.
6549
+ if (altImage.length === 0) {
6550
+ // This is useful to indicate that the map is loading and has nothing yet to display.
6551
+ // console.warn('No data available: Not stepping forward');
6552
+ timerShouldStepForward = false;
7120
6553
  }
7121
- case 4:
7122
- case "end":
7123
- return _context.stop();
6554
+ }
6555
+ } else if (image.isStale()) {
6556
+ if (wmMap.getMapImageStore.getNumImagesLoading() < MAX_NUMBER_OF_PARALLEL_LOADING_IMAGES) {
6557
+ image.forceReload(true);
6558
+ }
7124
6559
  }
7125
- }, _callee);
7126
- }));
7127
- function effect(_x, _x2) {
7128
- return _effect.apply(this, arguments);
6560
+ }
7129
6561
  }
7130
- return effect;
7131
- }()
7132
- });
7133
- genericListener.startListening({
7134
- actionCreator: setBbox,
7135
- effect: function () {
7136
- var _effect2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(_ref2, listenerApi) {
7137
- var payload, targets, groups;
7138
- return _regeneratorRuntime().wrap(function _callee2$(_context2) {
7139
- while (1) switch (_context2.prev = _context2.next) {
7140
- case 0:
7141
- payload = _ref2.payload;
7142
- listenerApi.cancelActiveListeners();
7143
- targets = getTargets(listenerApi.getState(), payload, SYNCGROUPS_TYPE_SETBBOX);
7144
- groups = getTargetGroups(listenerApi.getState(), payload, SYNCGROUPS_TYPE_SETBBOX);
7145
- listenerApi.dispatch(setBboxSync(payload, targets, groups));
7146
- case 5:
7147
- case "end":
7148
- return _context2.stop();
7149
- }
7150
- }, _callee2);
7151
- }));
7152
- function effect(_x3, _x4) {
7153
- return _effect2.apply(this, arguments);
6562
+ }
6563
+ return timerShouldStepForward;
6564
+ };
6565
+
6566
+ var isAnimationEndTimeValid = function isAnimationEndTimeValid(animationEndTime) {
6567
+ var hasValidPrefix = animationEndTime.split(/[-+]/)[0] === 'NOW' || animationEndTime.split(/[-+]/)[0] === 'TODAY';
6568
+ var durationString = animationEndTime.substring(animationEndTime.indexOf('PT') + 2);
6569
+ var hasValidDate = /^(\d+H)?(\d+M)?$/.test(durationString);
6570
+ if (hasValidPrefix && hasValidDate) {
6571
+ return true;
6572
+ }
6573
+ var parsedDate = dateUtils.parseISO(animationEndTime);
6574
+ return dateUtils.isValid(parsedDate);
6575
+ };
6576
+ var mapListener = createListenerMiddleware();
6577
+ mapListener.startListening({
6578
+ actionCreator: layerActions.layerDelete,
6579
+ effect: function effect(_ref, listenerApi) {
6580
+ var payload = _ref.payload;
6581
+ var mapId = payload.mapId;
6582
+ var layers = getMapLayersWithoutDimensionCurrentValue(listenerApi.getState(), mapId);
6583
+ if (!layers.length) {
6584
+ listenerApi.dispatch(mapActions.mapStopAnimation({
6585
+ mapId: mapId
6586
+ }));
7154
6587
  }
7155
- return effect;
7156
- }()
6588
+ }
7157
6589
  });
7158
- genericListener.startListening({
7159
- matcher: isAnyOf(layerActions.layerChangeName, layerActions.layerChangeEnabled, layerActions.layerChangeOpacity, layerActions.layerChangeDimension, layerActions.layerChangeStyle),
7160
- effect: function () {
7161
- var _effect3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(_ref3, listenerApi) {
7162
- var payload, type, targets;
7163
- return _regeneratorRuntime().wrap(function _callee3$(_context3) {
7164
- while (1) switch (_context3.prev = _context3.next) {
7165
- case 0:
7166
- payload = _ref3.payload, type = _ref3.type;
7167
- listenerApi.cancelActiveListeners();
7168
- /* Should not listen to actions from itself */
7169
- if (!(payload && payload.origin === LayerActionOrigin.ReactMapViewParseLayer)) {
7170
- _context3.next = 4;
7171
- break;
7172
- }
7173
- return _context3.abrupt("return");
7174
- case 4:
7175
- targets = getLayerActionsTargets(listenerApi.getState(), payload, SYNCGROUPS_TYPE_SETLAYERACTIONS);
7176
- if (targets && targets.length > 0) {
7177
- listenerApi.dispatch(setLayerActionSync(payload, targets, type));
6590
+ // update layer, synced maps and animation on latest max time if autoupdating
6591
+ mapListener.startListening({
6592
+ actionCreator: layerActions.onUpdateLayerInformation,
6593
+ effect: function effect(_ref2, listenerApi) {
6594
+ var payload = _ref2.payload;
6595
+ try {
6596
+ var layerDimensions = payload.layerDimensions;
6597
+ if (!layerDimensions) {
6598
+ return;
6599
+ }
6600
+ var dimensions = layerDimensions.dimensions,
6601
+ layerId = layerDimensions.layerId;
6602
+ var layer = getLayerById(listenerApi.getState(), layerId);
6603
+ if (!layer) {
6604
+ return;
6605
+ }
6606
+ var newTimeDimension = dimensions.find(function (dimension) {
6607
+ return dimension.name === 'time';
6608
+ });
6609
+ var mapId = layer.mapId;
6610
+ if (!mapId) {
6611
+ return;
6612
+ }
6613
+ var autoUpdateLayerId = getAutoUpdateLayerId(listenerApi.getState(), mapId);
6614
+ var shouldAutoUpdate = isAutoUpdating(listenerApi.getState(), mapId);
6615
+ var prevTimeDimension = getLayerTimeDimension(listenerApi.getState(), layerId);
6616
+ var isAutoUpdateLayer = layerId === autoUpdateLayerId;
6617
+ var incomingMaxTime = newTimeDimension == null ? void 0 : newTimeDimension.maxValue;
6618
+ var isIncomingMaxTimeLaterThanCurrentLayerTime = incomingMaxTime && (prevTimeDimension == null ? void 0 : prevTimeDimension.currentValue) && prevTimeDimension.currentValue !== incomingMaxTime;
6619
+ if (isAutoUpdateLayer &&
6620
+ // only update the active layer
6621
+ shouldAutoUpdate && isIncomingMaxTimeLaterThanCurrentLayerTime) {
6622
+ var isMapAnimating = isAnimating(listenerApi.getState(), mapId);
6623
+ if (!isMapAnimating) {
6624
+ listenerApi.dispatch(layerActions.layerChangeDimension({
6625
+ layerId: layerId,
6626
+ origin: LayerActionOrigin.updateLayerInformationListener,
6627
+ dimension: {
6628
+ name: 'time',
6629
+ currentValue: incomingMaxTime
7178
6630
  }
7179
- case 6:
7180
- case "end":
7181
- return _context3.stop();
6631
+ }));
6632
+ // Each time a layer updates, set the new time for all synced timesliders
6633
+ var syncedMapIds = getSyncedMapIdsForTimeslider(listenerApi.getState());
6634
+ if (syncedMapIds) {
6635
+ // Change time value for all other timesliders
6636
+ syncedMapIds.map(function (syncedMapId) {
6637
+ return listenerApi.dispatch(setTime({
6638
+ origin: LayerActionOrigin.updateLayerInformationListener,
6639
+ sourceId: syncedMapId,
6640
+ value: incomingMaxTime
6641
+ }));
6642
+ });
6643
+ }
7182
6644
  }
7183
- }, _callee3);
7184
- }));
7185
- function effect(_x5, _x6) {
7186
- return _effect3.apply(this, arguments);
6645
+ updateAnimation(mapId, incomingMaxTime, listenerApi);
6646
+ }
6647
+ } catch (error) {
6648
+ // eslint-disable-next-line no-console
6649
+ console.warn(error);
7187
6650
  }
7188
- return effect;
7189
- }()
6651
+ }
7190
6652
  });
7191
- genericListener.startListening({
7192
- actionCreator: layerActions.addLayer,
6653
+ var updateAnimation = function updateAnimation(mapId, maxValue, listenerApi) {
6654
+ var shouldEndtimeOverride$1 = shouldEndtimeOverride(listenerApi.getState(), mapId);
6655
+ if (shouldEndtimeOverride$1 === true) {
6656
+ return;
6657
+ }
6658
+ var animationStart = getAnimationStartTime(listenerApi.getState(), mapId);
6659
+ // Calculate how much time the animation start need to move forwards
6660
+ var animationEnd = getAnimationEndTime(listenerApi.getState(), mapId);
6661
+ var animationEndUnix = dateUtils.unix(dateUtils.utc(animationEnd));
6662
+ var maxTimeAsUnix = dateUtils.unix(dateUtils.utc(maxValue));
6663
+ var timeInSecondToShiftAnimationForwards = maxTimeAsUnix - animationEndUnix;
6664
+ var animationStartUnix = dateUtils.unix(dateUtils.utc(animationStart));
6665
+ var newAnimationStartTime = dateUtils.dateToString(dateUtils.fromUnix(animationStartUnix + timeInSecondToShiftAnimationForwards), dateFormat);
6666
+ var newAnimationEndTime = dateUtils.dateToString(dateUtils.fromUnix(animationEndUnix + timeInSecondToShiftAnimationForwards), dateFormat);
6667
+ if (!newAnimationStartTime || !newAnimationEndTime) {
6668
+ return;
6669
+ }
6670
+ // Check if the mapId is part of a syncgroup
6671
+ var syncedMapIds = getSyncedMapIdsForTimeslider(listenerApi.getState());
6672
+ var isSyncedMap = syncedMapIds.includes(mapId);
6673
+ var mapIdsToUpdate = isSyncedMap ? syncedMapIds : [mapId];
6674
+ // Update new animation times for the map or in case of syncgroup, all maps in the syncgroup
6675
+ mapIdsToUpdate.forEach(function (id) {
6676
+ listenerApi.dispatch(mapActions.setAnimationEndTime({
6677
+ mapId: id,
6678
+ animationEndTime: newAnimationEndTime
6679
+ }));
6680
+ listenerApi.dispatch(mapActions.setAnimationStartTime({
6681
+ mapId: id,
6682
+ animationStartTime: newAnimationStartTime
6683
+ }));
6684
+ });
6685
+ };
6686
+ mapListener.startListening({
6687
+ actionCreator: mapActions.toggleAutoUpdate,
7193
6688
  effect: function () {
7194
- var _effect4 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(_ref4, listenerApi) {
7195
- var payload, type, targets;
7196
- return _regeneratorRuntime().wrap(function _callee4$(_context4) {
7197
- while (1) switch (_context4.prev = _context4.next) {
6689
+ var _effect = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(_ref3, listenerApi) {
6690
+ var payload, shouldAutoUpdate, mapId, autoUpdateLayerId, timeDimension, syncedMapIds, payloads;
6691
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
6692
+ while (1) switch (_context.prev = _context.next) {
7198
6693
  case 0:
7199
- payload = _ref4.payload, type = _ref4.type;
6694
+ payload = _ref3.payload;
7200
6695
  listenerApi.cancelActiveListeners();
7201
- /* Should not listen to actions from itself */
7202
- if (!(payload && payload.origin === LayerActionOrigin.ReactMapViewParseLayer)) {
7203
- _context4.next = 4;
6696
+ shouldAutoUpdate = payload.shouldAutoUpdate, mapId = payload.mapId;
6697
+ if (shouldAutoUpdate) {
6698
+ _context.next = 5;
7204
6699
  break;
7205
6700
  }
7206
- return _context4.abrupt("return");
7207
- case 4:
7208
- targets = getAddLayerActionsTargets(listenerApi.getState(), payload, SYNCGROUPS_TYPE_SETLAYERACTIONS);
7209
- if (targets && targets.length > 0) {
7210
- listenerApi.dispatch(setLayerActionSync(payload, targets, type));
6701
+ return _context.abrupt("return");
6702
+ case 5:
6703
+ try {
6704
+ autoUpdateLayerId = getAutoUpdateLayerId(listenerApi.getState(), mapId);
6705
+ timeDimension = getLayerTimeDimension(listenerApi.getState(), autoUpdateLayerId);
6706
+ syncedMapIds = getSyncedMapIdsForTimeslider(listenerApi.getState()); // go to end of active layer
6707
+ if (timeDimension != null && timeDimension.maxValue && autoUpdateLayerId) {
6708
+ listenerApi.dispatch(layerActions.layerChangeDimension({
6709
+ layerId: autoUpdateLayerId,
6710
+ origin: LayerActionOrigin.toggleAutoUpdateListener,
6711
+ dimension: {
6712
+ name: 'time',
6713
+ currentValue: timeDimension.maxValue
6714
+ }
6715
+ }));
6716
+ // Change time value for all timesliders that are synced by syncgroups
6717
+ if (syncedMapIds.length > 0) {
6718
+ syncedMapIds.map(function (syncedMapId) {
6719
+ return listenerApi.dispatch(setTime({
6720
+ origin: LayerActionOrigin.toggleAutoUpdateListener,
6721
+ sourceId: syncedMapId,
6722
+ value: timeDimension.maxValue
6723
+ }));
6724
+ });
6725
+ }
6726
+ updateAnimation(mapId, timeDimension.maxValue, listenerApi);
6727
+ }
6728
+ // Toggle autoupdate off for synced timesliders
6729
+ payloads = syncedMapIds.reduce(function (syncedMapIdList, syncedMapId) {
6730
+ if (syncedMapId !== mapId) {
6731
+ return syncedMapIdList.concat({
6732
+ mapId: syncedMapId,
6733
+ shouldAutoUpdate: false
6734
+ });
6735
+ }
6736
+ return syncedMapIdList;
6737
+ }, []);
6738
+ if (payloads.length > 0) {
6739
+ payloads.map(function (payload) {
6740
+ return listenerApi.dispatch(mapActions.toggleAutoUpdate(payload));
6741
+ });
6742
+ }
6743
+ } catch (error) {
6744
+ // eslint-disable-next-line no-console
6745
+ console.warn(error);
7211
6746
  }
7212
6747
  case 6:
7213
6748
  case "end":
7214
- return _context4.stop();
6749
+ return _context.stop();
7215
6750
  }
7216
- }, _callee4);
6751
+ }, _callee);
7217
6752
  }));
7218
- function effect(_x7, _x8) {
7219
- return _effect4.apply(this, arguments);
6753
+ function effect(_x, _x2) {
6754
+ return _effect.apply(this, arguments);
7220
6755
  }
7221
6756
  return effect;
7222
6757
  }()
7223
6758
  });
7224
- genericListener.startListening({
7225
- actionCreator: layerActions.duplicateMapLayer,
7226
- effect: function () {
7227
- var _effect5 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(_ref5, listenerApi) {
7228
- var payload, sourceLayer, newPayload, targets;
7229
- return _regeneratorRuntime().wrap(function _callee5$(_context5) {
7230
- while (1) switch (_context5.prev = _context5.next) {
7231
- case 0:
7232
- payload = _ref5.payload;
7233
- listenerApi.cancelActiveListeners();
7234
- sourceLayer = getLayerById(listenerApi.getState(), payload.oldLayerId);
7235
- newPayload = {
7236
- mapId: payload.mapId,
7237
- layer: sourceLayer,
7238
- origin: payload.origin
7239
- };
7240
- targets = getAddLayerActionsTargets(listenerApi.getState(), newPayload, SYNCGROUPS_TYPE_SETLAYERACTIONS);
7241
- if (targets && targets.length > 0) {
7242
- listenerApi.dispatch(setLayerActionSync(newPayload, targets, layerActions.addLayer.type));
7243
- }
7244
- case 6:
7245
- case "end":
7246
- return _context5.stop();
7247
- }
7248
- }, _callee5);
7249
- }));
7250
- function effect(_x9, _x10) {
7251
- return _effect5.apply(this, arguments);
6759
+ mapListener.startListening({
6760
+ actionCreator: mapActions.mapStartAnimation,
6761
+ effect: function effect(_ref4, listenerApi) {
6762
+ var payload = _ref4.payload;
6763
+ var mapId = payload.mapId,
6764
+ initialTime = payload.initialTime;
6765
+ // Check if the mapId is part of a syncgroup
6766
+ var syncedMapIds = getSyncedMapIdsForTimeslider(listenerApi.getState());
6767
+ var isSyncedMap = syncedMapIds.includes(mapId);
6768
+ var autoUpdateMapId = syncedMapIds.find(function (syncedMapId) {
6769
+ return isAutoUpdating(listenerApi.getState(), syncedMapId);
6770
+ });
6771
+ // Start animation with the mapId that started the animation or in case of syncgroup, the map that is auto updating
6772
+ var useMapId = isSyncedMap ? autoUpdateMapId || mapId : mapId;
6773
+ var speedDelay = getMapAnimationDelay(listenerApi.getState(), useMapId);
6774
+ var speed = 1000 / (speedDelay || 1);
6775
+ metronome.register(null, speed, useMapId);
6776
+ var timeList = getAnimationList(listenerApi.getState(), useMapId);
6777
+ // In case of the timeList
6778
+ if (timeList && timeList.length > 0) {
6779
+ // Determine animation step based on initialTime and timeList
6780
+ var initalTimerStep = timeList == null ? void 0 : timeList.findIndex(function (timeNameValue) {
6781
+ return timeNameValue.value === initialTime;
6782
+ });
6783
+ if (initalTimerStep !== -1) {
6784
+ setStep(useMapId, initalTimerStep);
6785
+ }
7252
6786
  }
7253
- return effect;
7254
- }()
6787
+ }
7255
6788
  });
7256
- genericListener.startListening({
7257
- actionCreator: mapActions.layerMoveLayer,
6789
+ mapListener.startListening({
6790
+ actionCreator: mapActions.mapStopAnimation,
6791
+ effect: function effect(_ref5, listenerApi) {
6792
+ var mapId = _ref5.payload.mapId;
6793
+ // Check if the mapId is part of a syncgroup
6794
+ var syncedMapIds = getSyncedMapIdsForTimeslider(listenerApi.getState());
6795
+ var isSyncedMap = syncedMapIds.includes(mapId);
6796
+ var mapIdsToUnregister = isSyncedMap ? syncedMapIds : [mapId];
6797
+ mapIdsToUnregister.forEach(function (mapId) {
6798
+ return metronome.unregister(mapId);
6799
+ });
6800
+ }
6801
+ });
6802
+ var handleBaseLayers = function handleBaseLayers(mapId, baseLayers, listenerApi) {
6803
+ var baseLayer = baseLayers.find(function (layer) {
6804
+ return layer.layerType === 'baseLayer';
6805
+ });
6806
+ var currentAvailableBaseLayers = getAvailableBaseLayersForMap(listenerApi.getState(), mapId);
6807
+ // find a availableBaseLayer with the same name, and use that id for the active baselayer
6808
+ var activeAvailableBaseLayer = currentAvailableBaseLayers.find(function (availableBaseLayer) {
6809
+ return availableBaseLayer.name === baseLayer.name;
6810
+ });
6811
+ var activeBaseLayerId = activeAvailableBaseLayer ? activeAvailableBaseLayer.id : webmapUtils.generateLayerId();
6812
+ // if the baseLayer can't be found in a visible available baseLayer list, add it
6813
+ // This happens when switching to a preset that has non-default baselayers
6814
+ if (!activeAvailableBaseLayer && currentAvailableBaseLayers.length) {
6815
+ listenerApi.dispatch(layerActions.addAvailableBaseLayers({
6816
+ layers: [Object.assign({}, baseLayer, {
6817
+ mapId: mapId,
6818
+ id: activeBaseLayerId
6819
+ })]
6820
+ }));
6821
+ }
6822
+ var baseLayersWithActiveId = baseLayers.map(function (layer, index) {
6823
+ return index === 0 ? Object.assign({}, layer, {
6824
+ id: activeBaseLayerId || layer.id
6825
+ }) : layer;
6826
+ });
6827
+ listenerApi.dispatch(layerActions.setBaseLayers({
6828
+ mapId: mapId,
6829
+ layers: baseLayersWithActiveId
6830
+ }));
6831
+ };
6832
+ mapListener.startListening({
6833
+ actionCreator: mapActions.setMapPreset,
7258
6834
  effect: function () {
7259
- var _effect6 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6(_ref6, listenerApi) {
7260
- var payload, type, targets;
7261
- return _regeneratorRuntime().wrap(function _callee6$(_context6) {
7262
- while (1) switch (_context6.prev = _context6.next) {
6835
+ var _effect2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(_ref6, listenerApi) {
6836
+ var payload, mapId, initialProps, mapPreset, layers, activeLayerId, autoTimeStepLayerId, autoUpdateLayerId, proj, shouldAutoUpdate, shouldAnimate, animationPayload, toggleTimestepAuto, showTimeSlider, displayMapPin, shouldShowZoomControls, shouldShowLegend, dockedLayerManagerSize, timeSliderSpan, toggleTimeSpanAuto, _filterLayers, mapLayers, baseLayers, overLayers, _newLayerIds$layers$f, _newLayerIds$layers$, _newLayerIds$layers$f2, _newLayerIds$layers$2, autoTimeStepLayerIdNew, autoUpdateLayerIdNew, onlyActiveLayerIdIsSet, newLayerIds, newAutoUpdateLayerId, newAutoTimeStepLayerId, customLayers, customBaseLayer, customOverLayer, baseLayersWithDefaultLayer, overLayersWithDefaultLayer, allBaseLayers, checkIsprojectionSupported, animationLength, animationEndTime, shouldEndtimeOverride, interval, endTime, startTime, centerTimeInSeconds, animationEnd, _startTime, duration, _animationEnd, animationStart, shouldOpenLegend, legendId, fiveMinuteDelayForAnimation, _animationEnd2, _animationStart;
6837
+ return _regeneratorRuntime().wrap(function _callee2$(_context2) {
6838
+ while (1) switch (_context2.prev = _context2.next) {
7263
6839
  case 0:
7264
- payload = _ref6.payload, type = _ref6.type;
7265
- listenerApi.cancelActiveListeners();
7266
- /* Should not listen to actions from itself */
7267
- if (!(payload && payload.origin === LayerActionOrigin.ReactMapViewParseLayer)) {
7268
- _context6.next = 4;
6840
+ payload = _ref6.payload;
6841
+ _context2.prev = 1;
6842
+ mapId = payload.mapId, initialProps = payload.initialProps;
6843
+ mapPreset = initialProps.mapPreset;
6844
+ if (!mapPreset) {
6845
+ _context2.next = 50;
6846
+ break;
6847
+ }
6848
+ layers = mapPreset.layers, activeLayerId = mapPreset.activeLayerId, autoTimeStepLayerId = mapPreset.autoTimeStepLayerId, autoUpdateLayerId = mapPreset.autoUpdateLayerId, proj = mapPreset.proj, shouldAutoUpdate = mapPreset.shouldAutoUpdate, shouldAnimate = mapPreset.shouldAnimate, animationPayload = mapPreset.animationPayload, toggleTimestepAuto = mapPreset.toggleTimestepAuto, showTimeSlider = mapPreset.showTimeSlider, displayMapPin = mapPreset.displayMapPin, shouldShowZoomControls = mapPreset.shouldShowZoomControls, shouldShowLegend = mapPreset.shouldShowLegend, dockedLayerManagerSize = mapPreset.dockedLayerManagerSize, timeSliderSpan = mapPreset.timeSliderSpan, toggleTimeSpanAuto = mapPreset.toggleTimeSpanAuto;
6849
+ _filterLayers = filterLayers(layers), mapLayers = _filterLayers.mapLayers, baseLayers = _filterLayers.baseLayers, overLayers = _filterLayers.overLayers;
6850
+ if (layers) {
6851
+ // make sure all layers have a unique id before going forward
6852
+ autoTimeStepLayerIdNew = autoTimeStepLayerId;
6853
+ autoUpdateLayerIdNew = autoUpdateLayerId;
6854
+ onlyActiveLayerIdIsSet = !autoTimeStepLayerId && !autoUpdateLayerId && activeLayerId;
6855
+ if (onlyActiveLayerIdIsSet) {
6856
+ autoTimeStepLayerIdNew = activeLayerId;
6857
+ autoUpdateLayerIdNew = activeLayerId;
6858
+ }
6859
+ newLayerIds = replaceLayerIdsToEnsureUniqueLayerIdsInStore({
6860
+ layers: mapLayers,
6861
+ autoTimeStepLayerId: autoTimeStepLayerIdNew,
6862
+ autoUpdateLayerId: autoUpdateLayerIdNew
6863
+ }); // set layers
6864
+ listenerApi.dispatch(layerActions.setLayers({
6865
+ mapId: mapId,
6866
+ layers: newLayerIds.layers
6867
+ }));
6868
+ // make sure layer with new id exist and if not, default to first layer
6869
+ newAutoUpdateLayerId = ((_newLayerIds$layers$f = newLayerIds.layers.find(function (layer) {
6870
+ return layer.id === newLayerIds.autoUpdateLayerId;
6871
+ })) == null ? void 0 : _newLayerIds$layers$f.id) || ((_newLayerIds$layers$ = newLayerIds.layers[0]) == null ? void 0 : _newLayerIds$layers$.id);
6872
+ newAutoTimeStepLayerId = ((_newLayerIds$layers$f2 = newLayerIds.layers.find(function (layer) {
6873
+ return layer.id === newLayerIds.autoTimeStepLayerId;
6874
+ })) == null ? void 0 : _newLayerIds$layers$f2.id) || ((_newLayerIds$layers$2 = newLayerIds.layers[0]) == null ? void 0 : _newLayerIds$layers$2.id);
6875
+ listenerApi.dispatch(mapActions.setAutoLayerId({
6876
+ mapId: mapId,
6877
+ autoUpdateLayerId: newAutoUpdateLayerId,
6878
+ autoTimeStepLayerId: newAutoTimeStepLayerId
6879
+ }));
6880
+ }
6881
+ customLayers = getdefaultMapSettingsLayers(listenerApi.getState());
6882
+ customBaseLayer = customLayers == null ? void 0 : customLayers.find(function (layer) {
6883
+ return layer.layerType === LayerType.baseLayer;
6884
+ });
6885
+ customOverLayer = customLayers == null ? void 0 : customLayers.find(function (layer) {
6886
+ return layer.layerType === LayerType.overLayer;
6887
+ }); // sets (default) baseLayers
6888
+ baseLayersWithDefaultLayer = baseLayers.length ? baseLayers : [customBaseLayer || defaultLayers.baseLayerGrey]; // sets (default) overLayers
6889
+ overLayersWithDefaultLayer = overLayers.length ? overLayers : [customOverLayer || defaultLayers.overLayer];
6890
+ allBaseLayers = [].concat(baseLayersWithDefaultLayer, overLayersWithDefaultLayer).map(function (layer) {
6891
+ return Object.assign({}, layer, {
6892
+ id: webmapUtils.generateLayerId()
6893
+ });
6894
+ });
6895
+ handleBaseLayers(mapId, allBaseLayers, listenerApi);
6896
+ if (!proj) {
6897
+ _context2.next = 20;
7269
6898
  break;
7270
6899
  }
7271
- return _context6.abrupt("return");
7272
- case 4:
7273
- targets = getLayerMoveActionsTargets(listenerApi.getState(), payload, SYNCGROUPS_TYPE_SETLAYERACTIONS);
7274
- if (targets && targets.length > 0) {
7275
- listenerApi.dispatch(setLayerActionSync(payload, targets, type));
6900
+ checkIsprojectionSupported = isProjectionSupported(proj.srs);
6901
+ if (checkIsprojectionSupported) {
6902
+ _context2.next = 19;
6903
+ break;
6904
+ }
6905
+ throw new Error("Projection " + proj.srs + " is not supported");
6906
+ case 19:
6907
+ // set bbox
6908
+ listenerApi.dispatch(mapActions.setBbox({
6909
+ mapId: mapId,
6910
+ bbox: proj.bbox,
6911
+ srs: proj.srs
6912
+ }));
6913
+ case 20:
6914
+ animationLength = animationPayload && animationPayload.duration;
6915
+ animationEndTime = animationPayload && animationPayload.endTime && isAnimationEndTimeValid(animationPayload.endTime) && animationPayload.endTime;
6916
+ shouldEndtimeOverride = animationPayload ? animationPayload.shouldEndtimeOverride : false;
6917
+ if (shouldEndtimeOverride) {
6918
+ // auto update
6919
+ listenerApi.dispatch(mapActions.setEndTimeOverriding({
6920
+ mapId: mapId,
6921
+ shouldEndtimeOverride: shouldEndtimeOverride
6922
+ }));
6923
+ }
6924
+ if (shouldAutoUpdate !== undefined && !animationEndTime) {
6925
+ // auto update
6926
+ listenerApi.dispatch(mapActions.toggleAutoUpdate({
6927
+ mapId: mapId,
6928
+ shouldAutoUpdate: shouldAutoUpdate
6929
+ }));
6930
+ }
6931
+ if (showTimeSlider !== undefined) {
6932
+ // toggle timeslider
6933
+ listenerApi.dispatch(mapActions.toggleTimeSliderIsVisible({
6934
+ mapId: mapId,
6935
+ isTimeSliderVisible: showTimeSlider
6936
+ }));
6937
+ }
6938
+ if (timeSliderSpan !== undefined) {
6939
+ // set timeslider span
6940
+ listenerApi.dispatch(mapActions.setTimeSliderSpan({
6941
+ mapId: mapId,
6942
+ timeSliderSpan: timeSliderSpan
6943
+ }));
6944
+ }
6945
+ if (toggleTimeSpanAuto !== undefined) {
6946
+ // toggle timeslider span auto
6947
+ listenerApi.dispatch(mapActions.toggleTimeSpanAuto({
6948
+ mapId: mapId,
6949
+ timeSpanAuto: toggleTimeSpanAuto
6950
+ }));
6951
+ }
6952
+ if (shouldShowZoomControls !== undefined) {
6953
+ // toggle zoom controls
6954
+ listenerApi.dispatch(mapActions.toggleZoomControls({
6955
+ mapId: mapId,
6956
+ shouldShowZoomControls: shouldShowZoomControls
6957
+ }));
6958
+ }
6959
+ if (displayMapPin !== undefined) {
6960
+ // display map pin
6961
+ listenerApi.dispatch(mapActions.toggleMapPinIsVisible({
6962
+ mapId: mapId,
6963
+ displayMapPin: displayMapPin
6964
+ }));
6965
+ }
6966
+ // sets timestep by interval of animationPayload
6967
+ interval = animationPayload && animationPayload.interval;
6968
+ if (interval) {
6969
+ listenerApi.dispatch(mapActions.setTimeStep({
6970
+ mapId: mapId,
6971
+ timeStep: interval
6972
+ }));
6973
+ }
6974
+ // sets animationEndTime by endTime of animationPayload
6975
+ if (animationEndTime) {
6976
+ endTime = animationEndTime.includes('NOW') || animationEndTime.includes('TODAY') ? dateUtils.convertNOWandTODAYFormatsToUTC(animationEndTime) : animationEndTime;
6977
+ listenerApi.dispatch(mapActions.setAnimationEndTime({
6978
+ mapId: mapId,
6979
+ animationEndTime: handleDateUtilsISOString(endTime)
6980
+ }));
6981
+ startTime = handleDateUtilsISOString(dateUtils.sub(dateUtils.utc(endTime), {
6982
+ minutes: 5 * 60 // set to default of 5 hours
6983
+ }).toISOString());
6984
+ listenerApi.dispatch(mapActions.setAnimationStartTime({
6985
+ mapId: mapId,
6986
+ animationStartTime: startTime
6987
+ }));
6988
+ listenerApi.dispatch(genericActions.setTime({
6989
+ origin: '',
6990
+ sourceId: mapId,
6991
+ value: startTime
6992
+ }));
6993
+ centerTimeInSeconds = new Date(handleDateUtilsISOString(endTime)).getTime();
6994
+ listenerApi.dispatch(mapActions.setTimeSliderCenterTime({
6995
+ mapId: mapId,
6996
+ timeSliderCenterTime: centerTimeInSeconds
6997
+ }));
6998
+ }
6999
+ // sets animationStartTime by duration of animationPayload
7000
+ if (animationLength) {
7001
+ animationEnd = getAnimationEndTime(listenerApi.getState(), mapId);
7002
+ _startTime = handleDateUtilsISOString(dateUtils.sub(dateUtils.utc(animationEnd), {
7003
+ minutes: animationLength
7004
+ }).toISOString());
7005
+ listenerApi.dispatch(mapActions.setAnimationStartTime({
7006
+ mapId: mapId,
7007
+ animationStartTime: _startTime
7008
+ }));
7009
+ listenerApi.dispatch(genericActions.setTime({
7010
+ origin: '',
7011
+ sourceId: mapId,
7012
+ value: _startTime
7013
+ }));
7014
+ }
7015
+ // sets animationDelay by speed of animationPayload
7016
+ if (animationPayload && animationPayload.speed) {
7017
+ listenerApi.dispatch(mapActions.setAnimationDelay({
7018
+ mapId: mapId,
7019
+ animationDelay: getSpeedDelay(animationPayload.speed)
7020
+ }));
7021
+ }
7022
+ // turn animation on
7023
+ if (shouldAnimate === true) {
7024
+ duration = animationPayload && animationPayload.duration ? animationPayload.duration : 5 * 60; // set to default of 5 hours
7025
+ _animationEnd = shouldEndtimeOverride && animationEndTime ? getAnimationEndTime(listenerApi.getState(), mapId) : dateUtils.dateToString(dateUtils.utc(), dateFormat);
7026
+ animationStart = shouldEndtimeOverride && animationLength ? getAnimationStartTime(listenerApi.getState(), mapId) : dateUtils.dateToString(dateUtils.sub(dateUtils.utc(_animationEnd), {
7027
+ minutes: duration
7028
+ }), dateFormat);
7029
+ listenerApi.dispatch(mapActions.mapStartAnimation({
7030
+ mapId: mapId,
7031
+ start: animationStart,
7032
+ end: _animationEnd,
7033
+ interval: interval || defaultTimeStep
7034
+ }));
7035
+ // If animation interval set, set the timestep auto property to false
7036
+ if (interval) {
7037
+ listenerApi.dispatch(mapActions.toggleTimestepAuto({
7038
+ mapId: mapId,
7039
+ timestepAuto: false
7040
+ }));
7041
+ }
7042
+ } else if (toggleTimestepAuto !== undefined) {
7043
+ // Set timestep auto based on preset if animation is off
7044
+ listenerApi.dispatch(mapActions.toggleTimestepAuto({
7045
+ mapId: mapId,
7046
+ timestepAuto: toggleTimestepAuto
7047
+ }));
7048
+ }
7049
+ // show legend
7050
+ shouldOpenLegend = shouldShowLegend !== undefined ? shouldShowLegend : IS_LEGEND_OPEN_BY_DEFAULT;
7051
+ legendId = getLegendId(listenerApi.getState(), mapId);
7052
+ if (legendId) {
7053
+ listenerApi.dispatch(uiActions.setToggleOpenDialog({
7054
+ type: legendId,
7055
+ setOpen: shouldOpenLegend
7056
+ }));
7276
7057
  }
7277
- case 6:
7278
- case "end":
7279
- return _context6.stop();
7280
- }
7281
- }, _callee6);
7282
- }));
7283
- function effect(_x11, _x12) {
7284
- return _effect6.apply(this, arguments);
7285
- }
7286
- return effect;
7287
- }()
7288
- });
7289
- genericListener.startListening({
7290
- matcher: isAnyOf(mapActions.setAutoLayerId, mapActions.setAutoUpdateLayerId, mapActions.setAutoTimestepLayerId),
7291
- effect: function () {
7292
- var _effect7 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7(_ref7, listenerApi) {
7293
- var payload, type, targets;
7294
- return _regeneratorRuntime().wrap(function _callee7$(_context7) {
7295
- while (1) switch (_context7.prev = _context7.next) {
7296
- case 0:
7297
- payload = _ref7.payload, type = _ref7.type;
7298
- listenerApi.cancelActiveListeners();
7299
- targets = getSetAutoLayerIdActionsTargets(listenerApi.getState(), payload, SYNCGROUPS_TYPE_SETLAYERACTIONS);
7300
- if (targets && targets.length > 0) {
7301
- listenerApi.dispatch(setLayerActionSync(payload, targets, type));
7058
+ if (dockedLayerManagerSize) {
7059
+ listenerApi.dispatch(mapActions.setDockedLayerManagerSize({
7060
+ mapId: mapId,
7061
+ dockedLayerManagerSize: dockedLayerManagerSize
7062
+ }));
7302
7063
  }
7303
- case 4:
7304
- case "end":
7305
- return _context7.stop();
7306
- }
7307
- }, _callee7);
7308
- }));
7309
- function effect(_x13, _x14) {
7310
- return _effect7.apply(this, arguments);
7311
- }
7312
- return effect;
7313
- }()
7314
- });
7315
- genericListener.startListening({
7316
- actionCreator: layerActions.setBaseLayers,
7317
- effect: function () {
7318
- var _effect8 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee8(_ref8, listenerApi) {
7319
- var payload, type, targets;
7320
- return _regeneratorRuntime().wrap(function _callee8$(_context8) {
7321
- while (1) switch (_context8.prev = _context8.next) {
7322
- case 0:
7323
- payload = _ref8.payload, type = _ref8.type;
7324
- listenerApi.cancelActiveListeners();
7325
- /* Should not listen to actions from itself */
7326
- if (!(payload && payload.origin === LayerActionOrigin.ReactMapViewParseLayer)) {
7327
- _context8.next = 4;
7064
+ case 40:
7065
+ if (!(animationEndTime && (shouldEndtimeOverride || !(shouldAutoUpdate || shouldAnimate)))) {
7066
+ _context2.next = 50;
7328
7067
  break;
7329
7068
  }
7330
- return _context8.abrupt("return");
7331
- case 4:
7332
- targets = getMapBaseLayerActionsTargets(listenerApi.getState(), payload, SYNCGROUPS_TYPE_SETLAYERACTIONS);
7333
- if (targets && targets.length > 0) {
7334
- listenerApi.dispatch(setLayerActionSync(payload, targets, type));
7069
+ fiveMinuteDelayForAnimation = 1000 * 60 * 5; // eslint-disable-next-line no-await-in-loop
7070
+ _context2.next = 44;
7071
+ return listenerApi.delay(fiveMinuteDelayForAnimation);
7072
+ case 44:
7073
+ _animationEnd2 = getAnimationEndTime(listenerApi.getState(), mapId);
7074
+ listenerApi.dispatch(mapActions.setAnimationEndTime({
7075
+ mapId: mapId,
7076
+ animationEndTime: dateUtils.add(dateUtils.utc(_animationEnd2), {
7077
+ minutes: 5
7078
+ }).toISOString()
7079
+ }));
7080
+ _animationStart = getAnimationStartTime(listenerApi.getState(), mapId);
7081
+ listenerApi.dispatch(mapActions.setAnimationStartTime({
7082
+ mapId: mapId,
7083
+ animationStartTime: dateUtils.add(dateUtils.utc(_animationStart), {
7084
+ minutes: 5
7085
+ }).toISOString()
7086
+ }));
7087
+ _context2.next = 40;
7088
+ break;
7089
+ case 50:
7090
+ _context2.next = 55;
7091
+ break;
7092
+ case 52:
7093
+ _context2.prev = 52;
7094
+ _context2.t0 = _context2["catch"](1);
7095
+ if (_context2.t0 instanceof Error) {
7096
+ listenerApi.dispatch(mapActions.setMapPresetError({
7097
+ mapId: payload.mapId,
7098
+ error: _context2.t0.message
7099
+ }));
7335
7100
  }
7336
- case 6:
7101
+ case 55:
7337
7102
  case "end":
7338
- return _context8.stop();
7103
+ return _context2.stop();
7339
7104
  }
7340
- }, _callee8);
7105
+ }, _callee2, null, [[1, 52]]);
7341
7106
  }));
7342
- function effect(_x15, _x16) {
7343
- return _effect8.apply(this, arguments);
7107
+ function effect(_x3, _x4) {
7108
+ return _effect2.apply(this, arguments);
7344
7109
  }
7345
7110
  return effect;
7346
7111
  }()
7347
7112
  });
7348
- genericListener.startListening({
7349
- actionCreator: layerActions.layerDelete,
7350
- effect: function () {
7351
- var _effect9 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee9(_ref9, listenerApi) {
7352
- var payload, type, targets;
7353
- return _regeneratorRuntime().wrap(function _callee9$(_context9) {
7354
- while (1) switch (_context9.prev = _context9.next) {
7113
+ mapListener.startListening({
7114
+ actionCreator: mapActions.unregisterMap,
7115
+ effect: function effect(_ref7, listenerApi) {
7116
+ var payload = _ref7.payload;
7117
+ var mapId = payload.mapId;
7118
+ var layerList = getLayersByMapId(listenerApi.getState(), mapId);
7119
+ metronome.unregister(mapId);
7120
+ layerList.map(function (layer) {
7121
+ return listenerApi.dispatch(layerActions.layerDelete({
7122
+ mapId: mapId,
7123
+ layerId: layer.id,
7124
+ origin: LayerActionOrigin.unregisterMapListener
7125
+ }));
7126
+ });
7127
+ }
7128
+ });
7129
+ mapListener.startListening({
7130
+ actionCreator: mapActions.setStepBackwardOrForward,
7131
+ effect: function effect(_ref8, listenerApi) {
7132
+ var payload = _ref8.payload;
7133
+ var mapId = payload.mapId,
7134
+ isForwardStep = payload.isForwardStep;
7135
+ var timeStep = getMapTimeStep(listenerApi.getState(), mapId);
7136
+ var currentTime = getSelectedTime(listenerApi.getState(), mapId);
7137
+ var _mapSelectors$getData = getDataLimitsFromLayers(listenerApi.getState(), mapId),
7138
+ dataStartTime = _mapSelectors$getData[0],
7139
+ dataEndTime = _mapSelectors$getData[1];
7140
+ if (dateUtils.isValid(currentTime)) {
7141
+ var makeForwardStep = function makeForwardStep() {
7142
+ var nextTime = currentTime + timeStep;
7143
+ var roundedTime = roundWithTimeStep(nextTime, timeStep, 'ceil');
7144
+ var newTime = Math.min(roundedTime, dataEndTime || roundedTime);
7145
+ return dateUtils.fromUnix(newTime).toISOString();
7146
+ };
7147
+ var makeBackwardStep = function makeBackwardStep() {
7148
+ var nextTime = currentTime - timeStep;
7149
+ var roundedTime = roundWithTimeStep(nextTime, timeStep, 'floor');
7150
+ var newTime = Math.max(roundedTime, dataStartTime || roundedTime);
7151
+ return dateUtils.fromUnix(newTime).toISOString();
7152
+ };
7153
+ var selectedTimeString = isForwardStep ? makeForwardStep() : makeBackwardStep();
7154
+ var isMapAnimating = isAnimating(listenerApi.getState(), mapId);
7155
+ if (isMapAnimating) {
7156
+ listenerApi.dispatch(mapActions.mapStopAnimation({
7157
+ mapId: mapId,
7158
+ origin: MapActionOrigin.map
7159
+ }));
7160
+ }
7161
+ listenerApi.dispatch(genericActions.setTime({
7162
+ origin: '',
7163
+ sourceId: mapId,
7164
+ value: handleDateUtilsISOString(selectedTimeString)
7165
+ }));
7166
+ }
7167
+ }
7168
+ });
7169
+
7170
+ var _excluded = ["url"];
7171
+ var serviceListener = createListenerMiddleware();
7172
+ var fetchService = /*#__PURE__*/function () {
7173
+ var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(service, listenerApi) {
7174
+ var layers;
7175
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
7176
+ while (1) switch (_context.prev = _context.next) {
7177
+ case 0:
7178
+ _context.prev = 0;
7179
+ _context.next = 3;
7180
+ return queryWMSLayers(service.serviceUrl);
7181
+ case 3:
7182
+ layers = _context.sent;
7183
+ listenerApi.dispatch(serviceActions.serviceSetLayers(Object.assign({}, service, {
7184
+ layers: layers
7185
+ })));
7186
+ _context.next = 10;
7187
+ break;
7188
+ case 7:
7189
+ _context.prev = 7;
7190
+ _context.t0 = _context["catch"](0);
7191
+ if (_context.t0 instanceof Error) {
7192
+ console.warn(_context.t0.message);
7193
+ }
7194
+ case 10:
7195
+ case "end":
7196
+ return _context.stop();
7197
+ }
7198
+ }, _callee, null, [[0, 7]]);
7199
+ }));
7200
+ return function fetchService(_x, _x2) {
7201
+ return _ref.apply(this, arguments);
7202
+ };
7203
+ }();
7204
+ var fetchInitialServices = /*#__PURE__*/function () {
7205
+ var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(payload, listenerApi) {
7206
+ return _regeneratorRuntime().wrap(function _callee2$(_context2) {
7207
+ while (1) switch (_context2.prev = _context2.next) {
7208
+ case 0:
7209
+ if (!(!payload || !payload.services)) {
7210
+ _context2.next = 2;
7211
+ break;
7212
+ }
7213
+ return _context2.abrupt("return");
7214
+ case 2:
7215
+ _context2.prev = 2;
7216
+ _context2.next = 5;
7217
+ return Promise.all(payload.services.map(function (_ref3) {
7218
+ var url = _ref3.url,
7219
+ service = _objectWithoutPropertiesLoose(_ref3, _excluded);
7220
+ return fetchService(Object.assign({}, service, {
7221
+ serviceUrl: url
7222
+ }), listenerApi);
7223
+ }));
7224
+ case 5:
7225
+ _context2.next = 10;
7226
+ break;
7227
+ case 7:
7228
+ _context2.prev = 7;
7229
+ _context2.t0 = _context2["catch"](2);
7230
+ // eslint-disable-next-line no-console
7231
+ console.warn(_context2.t0);
7232
+ case 10:
7233
+ case "end":
7234
+ return _context2.stop();
7235
+ }
7236
+ }, _callee2, null, [[2, 7]]);
7237
+ }));
7238
+ return function fetchInitialServices(_x3, _x4) {
7239
+ return _ref2.apply(this, arguments);
7240
+ };
7241
+ }();
7242
+ serviceListener.startListening({
7243
+ actionCreator: serviceActions.fetchInitialServices,
7244
+ effect: function () {
7245
+ var _effect = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(_ref4, listenerApi) {
7246
+ var payload;
7247
+ return _regeneratorRuntime().wrap(function _callee3$(_context3) {
7248
+ while (1) switch (_context3.prev = _context3.next) {
7355
7249
  case 0:
7356
- payload = _ref9.payload, type = _ref9.type;
7250
+ payload = _ref4.payload;
7357
7251
  listenerApi.cancelActiveListeners();
7358
- /* Should not listen to actions from itself */
7359
- if (!(payload && payload.origin === LayerActionOrigin.ReactMapViewParseLayer)) {
7360
- _context9.next = 4;
7361
- break;
7362
- }
7363
- return _context9.abrupt("return");
7252
+ _context3.next = 4;
7253
+ return fetchInitialServices(payload, listenerApi);
7364
7254
  case 4:
7365
- targets = getLayerDeleteActionsTargets(listenerApi.getState(), payload, SYNCGROUPS_TYPE_SETLAYERACTIONS);
7366
- if (targets && targets.length > 0) {
7367
- listenerApi.dispatch(setLayerActionSync(payload, targets, type));
7368
- }
7369
- case 6:
7370
7255
  case "end":
7371
- return _context9.stop();
7256
+ return _context3.stop();
7372
7257
  }
7373
- }, _callee9);
7258
+ }, _callee3);
7374
7259
  }));
7375
- function effect(_x17, _x18) {
7376
- return _effect9.apply(this, arguments);
7260
+ function effect(_x5, _x6) {
7261
+ return _effect.apply(this, arguments);
7377
7262
  }
7378
7263
  return effect;
7379
7264
  }()
@@ -7408,8 +7293,8 @@ var slice$1 = createSlice({
7408
7293
  action) {}
7409
7294
  }
7410
7295
  });
7411
- var reducer = slice$1.reducer;
7412
- var routerActions = slice$1.actions;
7296
+ var routerReducer = slice$1.reducer,
7297
+ routerActions = slice$1.actions;
7413
7298
 
7414
7299
  /* *
7415
7300
  * Licensed under the Apache License, Version 2.0 (the "License");
@@ -7960,57 +7845,141 @@ drawingToolListener.startListening({
7960
7845
  }()
7961
7846
  });
7962
7847
 
7963
- /* *
7964
- * Licensed under the Apache License, Version 2.0 (the "License");
7965
- * you may not use this file except in compliance with the License.
7966
- * You may obtain a copy of the License at
7967
- *
7968
- * http://www.apache.org/licenses/LICENSE-2.0
7969
- *
7970
- * Unless required by applicable law or agreed to in writing, software
7971
- * distributed under the License is distributed on an "AS IS" BASIS,
7972
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
7973
- * See the License for the specific language governing permissions and
7974
- * limitations under the License.
7975
- *
7976
- * Copyright 2023 - Koninklijk Nederlands Meteorologisch Instituut (KNMI)
7977
- * Copyright 2023 - Finnish Meteorological Institute (FMI)
7978
- * Copyright 2024 - The Norwegian Meteorological Institute (MET Norway)
7979
- * */
7980
- var routerReducersMap = {
7981
- router: reducer
7982
- };
7983
- var routerMiddlewares = [routerListener.middleware];
7984
- var routerModuleConfig = {
7985
- reducersMap: routerReducersMap,
7986
- middlewares: routerMiddlewares
7987
- };
7848
+ var layersListener = createListenerMiddleware();
7849
+ layersListener.startListening({
7850
+ actionCreator: layerActions.showLayerInfo,
7851
+ effect: function () {
7852
+ var _effect = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(_ref, listenerApi) {
7853
+ var payload, mapId, source, currentActiveMapId, isOpenInStore;
7854
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
7855
+ while (1) switch (_context.prev = _context.next) {
7856
+ case 0:
7857
+ payload = _ref.payload;
7858
+ mapId = payload.mapId, source = payload.source;
7859
+ currentActiveMapId = getDialogMapId(listenerApi.getState(), DialogTypes.LayerInfo);
7860
+ isOpenInStore = getisDialogOpen(listenerApi.getState(), DialogTypes.LayerInfo);
7861
+ if (currentActiveMapId !== mapId ? true : !isOpenInStore) {
7862
+ listenerApi.dispatch(uiActions.setActiveMapIdForDialog({
7863
+ type: DialogTypes.LayerInfo,
7864
+ mapId: mapId,
7865
+ setOpen: true,
7866
+ source: source
7867
+ }));
7868
+ }
7869
+ case 5:
7870
+ case "end":
7871
+ return _context.stop();
7872
+ }
7873
+ }, _callee);
7874
+ }));
7875
+ function effect(_x, _x2) {
7876
+ return _effect.apply(this, arguments);
7877
+ }
7878
+ return effect;
7879
+ }()
7880
+ });
7881
+ layersListener.startListening({
7882
+ actionCreator: uiActions.setToggleOpenDialog,
7883
+ effect: function () {
7884
+ var _effect2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(_ref2, listenerApi) {
7885
+ var payload, setOpen, type, isOpenInStore;
7886
+ return _regeneratorRuntime().wrap(function _callee2$(_context2) {
7887
+ while (1) switch (_context2.prev = _context2.next) {
7888
+ case 0:
7889
+ payload = _ref2.payload;
7890
+ setOpen = payload.setOpen, type = payload.type; // close LayerInfo if open and LayerManager is closed
7891
+ if (type === DialogTypes.LayerManager && !setOpen) {
7892
+ isOpenInStore = getisDialogOpen(listenerApi.getState(), DialogTypes.LayerInfo);
7893
+ if (isOpenInStore) {
7894
+ listenerApi.dispatch(layerActions.hideLayerInfo());
7895
+ }
7896
+ }
7897
+ case 3:
7898
+ case "end":
7899
+ return _context2.stop();
7900
+ }
7901
+ }, _callee2);
7902
+ }));
7903
+ function effect(_x3, _x4) {
7904
+ return _effect2.apply(this, arguments);
7905
+ }
7906
+ return effect;
7907
+ }()
7908
+ });
7988
7909
 
7989
- /* *
7990
- * Licensed under the Apache License, Version 2.0 (the "License");
7991
- * you may not use this file except in compliance with the License.
7992
- * You may obtain a copy of the License at
7993
- *
7994
- * http://www.apache.org/licenses/LICENSE-2.0
7995
- *
7996
- * Unless required by applicable law or agreed to in writing, software
7997
- * distributed under the License is distributed on an "AS IS" BASIS,
7998
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
7999
- * See the License for the specific language governing permissions and
8000
- * limitations under the License.
8001
- *
8002
- * Copyright 2023 - Koninklijk Nederlands Meteorologisch Instituut (KNMI)
8003
- * Copyright 2023 - Finnish Meteorological Institute (FMI)
8004
- * Copyright 2024 - The Norwegian Meteorological Institute (MET Norway)
8005
- * */
8006
- var drawtoolReducersMap = {
8007
- drawingtools: drawingToolReducer
8008
- };
8009
- var drawtoolMiddlewares = [drawingToolListener.middleware];
8010
- var drawtoolModuleConfig = {
8011
- reducersMap: drawtoolReducersMap,
8012
- middlewares: drawtoolMiddlewares
7910
+ /**
7911
+ * This handler is triggered by the metronome. An array of timerIds is given as argument.
7912
+ * It will update the animation loop of multiple maps and sliders
7913
+ * It will prefetch images for maps
7914
+ * @param timerIds string[] array of timerIds
7915
+ * @param listenerApi ListenerEffectAPI<CoreAppStore, Dispatch, unknown> listenerApi as received from listener
7916
+ */
7917
+ var metronomeHandler = function metronomeHandler(timerIds, listenerApi) {
7918
+ var targetsWithUpdateValue = [];
7919
+ var _loop = function _loop() {
7920
+ var timerId = _step.value;
7921
+ var animationListValuesNameAndValue = getAnimationList(listenerApi.getState(), timerId);
7922
+ var animationListValues = animationListValuesNameAndValue.map(function (nameAndValue) {
7923
+ return nameAndValue.value;
7924
+ });
7925
+ var targets = getTargets(listenerApi.getState(), {
7926
+ sourceId: timerId,
7927
+ origin: timerId
7928
+ }, SYNCGROUPS_TYPE_SETTIME);
7929
+ if (targets.length === 0) {
7930
+ // When there are no targets, default to one
7931
+ targets.push({
7932
+ targetId: timerId,
7933
+ value: ''
7934
+ });
7935
+ }
7936
+ var timerIsInDwell = handleTimerDwell(timerId, animationListValues.length);
7937
+ var timerShouldStepForward = prefetchAnimationTargetsForMetronome(timerId, animationListValues, targets) && !timerIsInDwell;
7938
+ // Determine the next step
7939
+ var timerStep = timerShouldStepForward ? getNextStep(timerId, animationListValues.length) : getCurrentStep(timerId);
7940
+ setStep(timerId, timerStep);
7941
+ var updatedValue = animationListValues[timerStep];
7942
+ targetsWithUpdateValue.push.apply(targetsWithUpdateValue, targets.map(function (target) {
7943
+ return Object.assign({}, target, {
7944
+ value: updatedValue
7945
+ });
7946
+ }));
7947
+ var speedDelay = getMapAnimationDelay(listenerApi.getState(), timerId);
7948
+ var speed = 1000 / (speedDelay || 1);
7949
+ metronome.setSpeed(timerId, speed);
7950
+ };
7951
+ for (var _iterator = _createForOfIteratorHelperLoose(timerIds), _step; !(_step = _iterator()).done;) {
7952
+ _loop();
7953
+ }
7954
+ // Update all targets of all sync groups in one action.
7955
+ if (targetsWithUpdateValue.length > 0) {
7956
+ listenerApi.dispatch(setTimeSync(null, targetsWithUpdateValue, ['metronomelistener']));
7957
+ }
8013
7958
  };
7959
+ var metronomeListener = createListenerMiddleware();
7960
+ metronomeListener.startListening({
7961
+ actionCreator: mapActions.mapStartAnimation,
7962
+ effect: function () {
7963
+ var _effect = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(_, listenerApi) {
7964
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
7965
+ while (1) switch (_context.prev = _context.next) {
7966
+ case 0:
7967
+ // register handler with access to listenerApi
7968
+ metronome.handleTimerTicks = function (timerIds) {
7969
+ metronomeHandler(timerIds, listenerApi);
7970
+ };
7971
+ case 1:
7972
+ case "end":
7973
+ return _context.stop();
7974
+ }
7975
+ }, _callee);
7976
+ }));
7977
+ function effect(_x, _x2) {
7978
+ return _effect.apply(this, arguments);
7979
+ }
7980
+ return effect;
7981
+ }()
7982
+ });
8014
7983
 
8015
7984
  /* *
8016
7985
  * Licensed under the Apache License, Version 2.0 (the "License");
@@ -8391,17 +8360,6 @@ var storeTestUtils = /*#__PURE__*/Object.freeze({
8391
8360
  webmapStateWithAddedLayer: webmapStateWithAddedLayer
8392
8361
  });
8393
8362
 
8394
- var synchronizationGroupReducersMap = {
8395
- syncGroups: reducer$1,
8396
- loadingIndicator: loadingIndicatorReducer
8397
- };
8398
- var synchronizationGroupMiddlewares = [genericListener.middleware, syncGroupsListener.middleware];
8399
- var synchronizationGroupConfig = {
8400
- id: 'syncGroups-module',
8401
- reducersMap: synchronizationGroupReducersMap,
8402
- middlewares: synchronizationGroupMiddlewares
8403
- };
8404
-
8405
8363
  /* *
8406
8364
  * Licensed under the Apache License, Version 2.0 (the "License");
8407
8365
  * you may not use this file except in compliance with the License.
@@ -8415,37 +8373,22 @@ var synchronizationGroupConfig = {
8415
8373
  * See the License for the specific language governing permissions and
8416
8374
  * limitations under the License.
8417
8375
  *
8418
- * Copyright 2022 - Koninklijk Nederlands Meteorologisch Instituut (KNMI)
8419
- * Copyright 2022 - Finnish Meteorological Institute (FMI)
8376
+ * Copyright 2024 - Koninklijk Nederlands Meteorologisch Instituut (KNMI)
8377
+ * Copyright 2024 - Finnish Meteorological Institute (FMI)
8420
8378
  * Copyright 2024 - The Norwegian Meteorological Institute (MET Norway)
8421
8379
  * */
8422
- var uiReducersMap = {
8423
- ui: reducer$3
8424
- };
8425
- var uiModuleConfig = {
8426
- reducersMap: uiReducersMap
8427
- };
8380
+ var SupportedComponentTypes;
8381
+ (function (SupportedComponentTypes) {
8382
+ SupportedComponentTypes["WarningList"] = "WarningList";
8383
+ SupportedComponentTypes["TimeSeries"] = "TimeSeries";
8384
+ })(SupportedComponentTypes || (SupportedComponentTypes = {}));
8385
+ var supportedComponentTypesForLinking = [SupportedComponentTypes.WarningList, SupportedComponentTypes.TimeSeries];
8428
8386
 
8429
- /* *
8430
- * Licensed under the Apache License, Version 2.0 (the "License");
8431
- * you may not use this file except in compliance with the License.
8432
- * You may obtain a copy of the License at
8433
- *
8434
- * http://www.apache.org/licenses/LICENSE-2.0
8435
- *
8436
- * Unless required by applicable law or agreed to in writing, software
8437
- * distributed under the License is distributed on an "AS IS" BASIS,
8438
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
8439
- * See the License for the specific language governing permissions and
8440
- * limitations under the License.
8441
- *
8442
- * Copyright 2021 - Koninklijk Nederlands Meteorologisch Instituut (KNMI)
8443
- * Copyright 2021 - Finnish Meteorological Institute (FMI)
8444
- * Copyright 2024 - The Norwegian Meteorological Institute (MET Norway)
8445
- * */
8446
- var coreModuleConfig = [mapStoreModuleConfig, synchronizationGroupConfig, uiModuleConfig, drawtoolModuleConfig];
8447
- var coreModuleReducersMap = Object.assign({}, mapStoreReducers, synchronizationGroupReducersMap, uiReducersMap, drawtoolReducersMap);
8448
- var coreModuleMiddlewares = [].concat(mapStoreMiddlewares, synchronizationGroupMiddlewares, drawtoolMiddlewares);
8387
+ var constants = /*#__PURE__*/Object.freeze({
8388
+ __proto__: null,
8389
+ get SupportedComponentTypes () { return SupportedComponentTypes; },
8390
+ supportedComponentTypesForLinking: supportedComponentTypesForLinking
8391
+ });
8449
8392
 
8450
8393
  /* *
8451
8394
  * Licensed under the Apache License, Version 2.0 (the "License");
@@ -8460,21 +8403,30 @@ var coreModuleMiddlewares = [].concat(mapStoreMiddlewares, synchronizationGroupM
8460
8403
  * See the License for the specific language governing permissions and
8461
8404
  * limitations under the License.
8462
8405
  *
8463
- * Copyright 2024 - Koninklijk Nederlands Meteorologisch Instituut (KNMI)
8464
- * Copyright 2024 - Finnish Meteorological Institute (FMI)
8465
- * Copyright 2024 - The Norwegian Meteorological Institute (MET Norway)
8406
+ * Copyright 2025 - Koninklijk Nederlands Meteorologisch Instituut (KNMI)
8407
+ * Copyright 2025 - Finnish Meteorological Institute (FMI)
8408
+ * Copyright 2025 - The Norwegian Meteorological Institute (MET Norway)
8466
8409
  * */
8467
- var SupportedComponentTypes;
8468
- (function (SupportedComponentTypes) {
8469
- SupportedComponentTypes["WarningList"] = "WarningList";
8470
- SupportedComponentTypes["TimeSeries"] = "TimeSeries";
8471
- })(SupportedComponentTypes || (SupportedComponentTypes = {}));
8472
- var supportedComponentTypesForLinking = [SupportedComponentTypes.WarningList, SupportedComponentTypes.TimeSeries];
8473
-
8474
- var constants = /*#__PURE__*/Object.freeze({
8475
- __proto__: null,
8476
- get SupportedComponentTypes () { return SupportedComponentTypes; },
8477
- supportedComponentTypesForLinking: supportedComponentTypesForLinking
8478
- });
8410
+ var storeReducerMap = {
8411
+ webmap: mapReducer,
8412
+ services: serviceReducer,
8413
+ layers: layerReducer,
8414
+ syncGroups: syncGroupsReducer,
8415
+ loadingIndicator: loadingIndicatorReducer,
8416
+ ui: uiReducer,
8417
+ drawingtools: drawingToolReducer,
8418
+ router: routerReducer
8419
+ };
8420
+ var storeMiddlewares = [mapListener.middleware, serviceListener.middleware, layersListener.middleware, metronomeListener.middleware, syncGroupsListener.middleware, genericListener.middleware, drawingToolListener.middleware, routerListener.middleware];
8421
+ var storeRootReducer = combineReducers(storeReducerMap);
8422
+ var createMockStore = function createMockStore(mockState) {
8423
+ return configureStore({
8424
+ reducer: storeRootReducer,
8425
+ preloadedState: mockState,
8426
+ middleware: function middleware(getDefaultMiddleware) {
8427
+ return getDefaultMiddleware().concat(storeMiddlewares);
8428
+ }
8429
+ });
8430
+ };
8479
8431
 
8480
- export { IS_LEGEND_OPEN_BY_DEFAULT, coreModuleConfig, coreModuleMiddlewares, coreModuleReducersMap, drawingToolActions, drawingToolListener, drawingToolReducer, drawtoolMiddlewares, drawtoolModuleConfig, drawtoolReducersMap, selectors as drawtoolSelectors, filterLayers$1 as filterLayers, genericActions, genericListener, selectors$3 as genericSelectors, types as genericTypes, getSingularDrawtoolDrawLayerId, getUserAddedServices, initialState$2 as initialState, layerActions, reducer$4 as layerReducer, selectors$6 as layerSelectors, types$3 as layerTypes, utils$1 as layerUtils, layersListener, constants as linkComponentTypesConstants, loadingIndicatorActions, constants$1 as loadingIndicatorConstants, loadingIndicatorReducer, selectors$2 as loadingIndicatorSelectors, mapActions, enums as mapEnums, mapListener, selectors$1 as mapSelectors, mapStoreMiddlewares, mapStoreModuleConfig, mapStoreReducers, types$4 as mapTypes, mapUtils, metronomeListener, routerActions, routerListener, routerMiddlewares, routerModuleConfig, reducer as routerReducer, routerReducersMap, utils as routerUtils, selectorMemoizationOptions, serviceActions, serviceListener, reducer$5 as serviceReducer, selectors$7 as serviceSelectors, types$5 as serviceTypes, setUserAddedServices, storeTestSettings, storeTestUtils, utils$3 as storeUtils, constants$2 as syncConstants, actions as syncGroupsActions, syncGroupsListener, reducer$1 as syncGroupsReducer, selector as syncGroupsSelector, selectors$4 as syncGroupsSelectors, types$1 as syncGroupsTypes, types$1 as types, uiActions, uiModuleConfig, reducer$3 as uiReducer, selectors$5 as uiSelectors, types$2 as uiTypes, useSetupDialog, useUpdateSharedData, reducer$2 as webmapReducer };
8432
+ export { IS_LEGEND_OPEN_BY_DEFAULT, createMockStore, drawingToolActions, drawingToolListener, drawingToolReducer, selectors as drawingToolSelectors, filterLayers$1 as filterLayers, genericActions, genericListener, selectors$3 as genericSelectors, types as genericTypes, getSingularDrawtoolDrawLayerId, getUserAddedServices, initialState$2 as initialState, layerActions, layerReducer, selectors$6 as layerSelectors, types$3 as layerTypes, utils$1 as layerUtils, layersListener, constants as linkComponentTypesConstants, loadingIndicatorActions, constants$1 as loadingIndicatorConstants, loadingIndicatorReducer, selectors$2 as loadingIndicatorSelectors, mapActions, enums as mapEnums, mapListener, mapReducer, selectors$1 as mapSelectors, types$4 as mapTypes, mapUtils, metronomeListener, routerActions, routerListener, routerReducer, utils as routerUtils, selectorMemoizationOptions, serviceActions, serviceListener, serviceReducer, selectors$7 as serviceSelectors, types$5 as serviceTypes, setUserAddedServices, storeMiddlewares, storeReducerMap, storeTestSettings, storeTestUtils, utils$3 as storeUtils, constants$2 as syncConstants, syncGroupsActions, syncGroupsListener, syncGroupsReducer, selector as syncGroupsSelector, selectors$4 as syncGroupsSelectors, types$1 as syncGroupsTypes, types$1 as types, uiActions, uiReducer, selectors$5 as uiSelectors, types$2 as uiTypes, useSetupDialog, useUpdateSharedData };