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