@opengeoweb/webmap-react 9.21.0 → 9.23.1

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.
package/index.esm.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import { jsxs, jsx, Fragment } from 'react/jsx-runtime';
2
2
  import * as React from 'react';
3
3
  import React__default, { useRef, useState, useEffect } from 'react';
4
- import { legendImageStore, WMImageEventType, webmapUtils, getLegendGraphicURLForLayer, LayerType, getWMJSMapById, debugLogger, DebugType, WMLayer, registerWMLayer, WMBBOX, getWMLayerById, WMJSMap, tilesettings } from '@opengeoweb/webmap';
4
+ import { legendImageStore, WMImageEventType, webmapUtils, getLegendGraphicURLForLayer, getPixelCoordFromLatLong, WMJSMAP_LONLAT_EPSGCODE, getLatLongFromPixelCoord, LayerType, getWMJSMapById, debugLogger, DebugType, WMLayer, registerWMLayer, WMBBOX, getWMLayerById, WMJSMap, tilesettings } from '@opengeoweb/webmap';
5
5
  import { CustomTooltip, CanvasComponent, ToolContainerDraggable, CustomIconButton, dateUtils } from '@opengeoweb/shared';
6
6
  import i18n from 'i18next';
7
7
  import { initReactI18next, useTranslation } from 'react-i18next';
@@ -63,48 +63,48 @@ var en = {
63
63
  "webmap-react-linestring": "LineString"
64
64
  };
65
65
  var fi = {
66
- "webmap-react-event": "ei käännetty",
67
- "webmap-react-sent": "ei käännetty",
68
- "webmap-react-utc": "ei käännetty",
69
- "webmap-react-expires": "ei käännetty",
70
- "webmap-react-sender": "ei käännetty",
71
- "webmap-react-identifier": "ei käännetty",
72
- "webmap-react-no-layers": "ei käännetty",
73
- "webmap-react-legend": "ei käännetty",
74
- "webmap-react-title": "ei käännetty",
75
- "webmap-react-name": "ei käännetty",
76
- "webmap-react-service": "ei käännetty",
77
- "webmap-react-abstract": "ei käännetty",
78
- "webmap-react-dimensions": "ei käännetty",
79
- "webmap-react-styles": "ei käännetty",
80
- "webmap-react-bounding-box": "ei käännetty",
81
- "webmap-react-groups": "ei käännetty",
82
- "webmap-react-keywords": "ei käännetty",
83
- "webmap-react-zoom-reset": "ei käännetty",
84
- "webmap-react-zoom-in": "ei käännetty",
85
- "webmap-react-zoom-out": "ei käännetty",
86
- "webmap-react-show": "ei käännetty",
87
- "webmap-react-click-disconnect": "ei käännetty",
88
- "webmap-react-click-connect": "ei käännetty",
89
- "webmap-react-layer-info": "ei käännetty",
90
- "webmap-react-vertical-level": "ei käännetty",
91
- "webmap-react-hpa": "ei käännetty",
92
- "webmap-react-ensemble-member": "ei käännetty",
93
- "webmap-react-member": "ei käännetty",
94
- "webmap-react-probability": "ei käännetty",
95
- "webmap-react-percent": "ei käännetty",
96
- "webmap-react-level": "ei käännetty",
97
- "webmap-react-west": "ei käännetty",
98
- "webmap-react-east": "ei käännetty",
99
- "webmap-react-north": "ei käännetty",
100
- "webmap-react-south": "ei käännetty",
101
- "webmap-react-new-linestring-created": "ei käännetty",
102
- "webmap-react-new-feature": "ei käännetty",
103
- "webmap-react-new-point": "ei käännetty",
104
- "webmap-react-point": "ei käännetty",
105
- "webmap-react-polygon": "ei käännetty",
106
- "webmap-react-box": "ei käännetty",
107
- "webmap-react-linestring": "ei käännetty"
66
+ "webmap-react-event": "tapahtuma:",
67
+ "webmap-react-sent": "Lähetetty:",
68
+ "webmap-react-utc": "UTC",
69
+ "webmap-react-expires": "Vanhentunut",
70
+ "webmap-react-sender": "Lähettäjä:",
71
+ "webmap-react-identifier": "Tunniste",
72
+ "webmap-react-no-layers": "Ei karttatasoja",
73
+ "webmap-react-legend": "Selite",
74
+ "webmap-react-title": "Titteli",
75
+ "webmap-react-name": "Nimi",
76
+ "webmap-react-service": "Palvelu",
77
+ "webmap-react-abstract": "Tiivistelmä",
78
+ "webmap-react-dimensions": "Dimensiot",
79
+ "webmap-react-styles": "Tyylit",
80
+ "webmap-react-bounding-box": "Rajaava-alue",
81
+ "webmap-react-groups": "Ryhmät",
82
+ "webmap-react-keywords": "Avainsanat",
83
+ "webmap-react-zoom-reset": "Resetoi zoom",
84
+ "webmap-react-zoom-in": "Zoomaa sisään",
85
+ "webmap-react-zoom-out": "Zoomaa ulos",
86
+ "webmap-react-show": "Näytä",
87
+ "webmap-react-click-disconnect": "Irroita karttataso napsauttamalla",
88
+ "webmap-react-click-connect": "Yhdistä karttataso napsauttamalla",
89
+ "webmap-react-layer-info": "Karttatason tiedot",
90
+ "webmap-react-vertical-level": "pystytaso",
91
+ "webmap-react-hpa": "hPa",
92
+ "webmap-react-ensemble-member": "Yhdistelmämallijäsen",
93
+ "webmap-react-member": "jäsen",
94
+ "webmap-react-probability": "Todennäköisyys",
95
+ "webmap-react-percent": "%",
96
+ "webmap-react-level": "Taso",
97
+ "webmap-react-west": "länsi",
98
+ "webmap-react-east": "itä",
99
+ "webmap-react-north": "pohjoinen",
100
+ "webmap-react-south": "etelä",
101
+ "webmap-react-new-linestring-created": "Viivajonoon luotiin uusi piste",
102
+ "webmap-react-new-feature": "uusi kohde luotu",
103
+ "webmap-react-new-point": "uusi piste luotu",
104
+ "webmap-react-point": "Piste",
105
+ "webmap-react-polygon": "Monikulmio",
106
+ "webmap-react-box": "Laatikko",
107
+ "webmap-react-linestring": "Viivajono"
108
108
  };
109
109
  var no = {
110
110
  "webmap-react-event": "hendelse:",
@@ -175,24 +175,24 @@ var nl = {
175
175
  "webmap-react-click-disconnect": "Klik om laag los te koppelen",
176
176
  "webmap-react-click-connect": "Klik om laag te koppelen",
177
177
  "webmap-react-layer-info": "Laag Informatie",
178
- "webmap-react-vertical-level": "niet vertaald",
179
- "webmap-react-hpa": "niet vertaald",
180
- "webmap-react-ensemble-member": "niet vertaald",
181
- "webmap-react-member": "niet vertaald",
182
- "webmap-react-probability": "niet vertaald",
183
- "webmap-react-percent": "niet vertaald",
184
- "webmap-react-level": "niet vertaald",
185
- "webmap-react-west": "niet vertaald",
186
- "webmap-react-east": "niet vertaald",
187
- "webmap-react-north": "niet vertaald",
188
- "webmap-react-south": "niet vertaald",
189
- "webmap-react-new-linestring-created": "niet vertaald",
190
- "webmap-react-new-feature": "niet vertaald",
191
- "webmap-react-new-point": "niet vertaald",
192
- "webmap-react-point": "niet vertaald",
193
- "webmap-react-polygon": "niet vertaald",
194
- "webmap-react-box": "niet vertaald",
195
- "webmap-react-linestring": "niet vertaald"
178
+ "webmap-react-vertical-level": "Verticaal niveau",
179
+ "webmap-react-hpa": "hPa",
180
+ "webmap-react-ensemble-member": "Ensemble lid",
181
+ "webmap-react-member": "lid",
182
+ "webmap-react-probability": "Waarschijnlijkheid",
183
+ "webmap-react-percent": "%",
184
+ "webmap-react-level": "Niveau",
185
+ "webmap-react-west": "west",
186
+ "webmap-react-east": "oost",
187
+ "webmap-react-north": "noord",
188
+ "webmap-react-south": "zuid",
189
+ "webmap-react-new-linestring-created": "nieuw punt in lijn gemaakt",
190
+ "webmap-react-new-feature": "nieuwe feature gemaakt",
191
+ "webmap-react-new-point": "nieuw punt gemaakt",
192
+ "webmap-react-point": "Punt",
193
+ "webmap-react-polygon": "Polygoon",
194
+ "webmap-react-box": "Rechthoek",
195
+ "webmap-react-linestring": "Lijn"
196
196
  };
197
197
  var webmapReactTranslations = {
198
198
  en: en,
@@ -2748,13 +2748,16 @@ const isBetween = (a, c, b) => {
2748
2748
  };
2749
2749
  const convertGeoCoordsToScreenCoords = (featureCoords, mapId) => {
2750
2750
  const webmapjs = webmapUtils.getWMJSMapById(mapId);
2751
+ if (!webmapjs) {
2752
+ return [];
2753
+ }
2751
2754
  const XYCoords = [];
2752
2755
  for (const featureCoord of featureCoords) {
2753
2756
  if (featureCoord.length < 2) {
2754
2757
  // eslint-disable-next-line no-continue
2755
2758
  continue;
2756
2759
  }
2757
- const coord = webmapjs.getPixelCoordFromLatLong({
2760
+ const coord = getPixelCoordFromLatLong(webmapjs, {
2758
2761
  x: featureCoord[0],
2759
2762
  y: featureCoord[1]
2760
2763
  });
@@ -2764,14 +2767,17 @@ const convertGeoCoordsToScreenCoords = (featureCoords, mapId) => {
2764
2767
  };
2765
2768
  const getPixelCoordFromGeoCoord = (featureCoords, mapId) => {
2766
2769
  const webmapjs = webmapUtils.getWMJSMapById(mapId);
2770
+ if (!webmapjs) {
2771
+ return [];
2772
+ }
2767
2773
  const {
2768
2774
  width,
2769
2775
  height
2770
2776
  } = webmapjs.getSize();
2771
- const bbox = webmapjs.getBBOX();
2777
+ const bbox = webmapjs.getDrawBBOX();
2772
2778
  const proj = webmapjs.getProj4();
2773
2779
  const XYCoords = [];
2774
- const from = getProj4(proj.lonlat);
2780
+ const from = getProj4(WMJSMAP_LONLAT_EPSGCODE);
2775
2781
  const to = getProj4(proj.crs);
2776
2782
  for (const featureCoord of featureCoords) {
2777
2783
  if (featureCoord.length < 2) {
@@ -3273,6 +3279,7 @@ class MapDraw extends React.PureComponent {
3273
3279
  }
3274
3280
  }
3275
3281
  componentDidUpdate(prevProps) {
3282
+ var _a;
3276
3283
  const {
3277
3284
  geojson,
3278
3285
  isInEditMode,
@@ -3299,7 +3306,7 @@ class MapDraw extends React.PureComponent {
3299
3306
  return;
3300
3307
  }
3301
3308
  }
3302
- webmapUtils.getWMJSMapById(mapId).draw('MapDraw::componentDidUpdateIsInEditMode');
3309
+ (_a = webmapUtils.getWMJSMapById(mapId)) === null || _a === void 0 ? void 0 : _a.draw('MapDraw::componentDidUpdateIsInEditMode');
3303
3310
  }
3304
3311
  /* Handle toggle delete */
3305
3312
  if (isInDeleteMode !== prevIsInDeleteMode) {
@@ -3510,7 +3517,10 @@ class MapDraw extends React.PureComponent {
3510
3517
  return undefined;
3511
3518
  }
3512
3519
  const webmapjs = webmapUtils.getWMJSMapById(mapId);
3513
- this.mouseGeoCoord = webmapjs.getLatLongFromPixelCoord({
3520
+ if (!webmapjs) {
3521
+ return undefined;
3522
+ }
3523
+ this.mouseGeoCoord = getLatLongFromPixelCoord(webmapjs, {
3514
3524
  x: mouseX,
3515
3525
  y: mouseY
3516
3526
  });
@@ -3606,9 +3616,12 @@ class MapDraw extends React.PureComponent {
3606
3616
  mapId
3607
3617
  } = this.props;
3608
3618
  const webmapjs = webmapUtils.getWMJSMapById(mapId);
3619
+ if (!webmapjs) {
3620
+ return false;
3621
+ }
3609
3622
  if (this.myDrawMode === DRAWMODE.POLYGON) {
3610
3623
  if (this.selectedEdge !== EDGE.NONE && this.myEditMode !== EDITMODE.DELETE_FEATURES) {
3611
- this.mouseGeoCoord = webmapjs.getLatLongFromPixelCoord({
3624
+ this.mouseGeoCoord = getLatLongFromPixelCoord(webmapjs, {
3612
3625
  x: mouseX,
3613
3626
  y: mouseY
3614
3627
  });
@@ -3628,7 +3641,7 @@ class MapDraw extends React.PureComponent {
3628
3641
  }
3629
3642
  if (this.myDrawMode === DRAWMODE.LINESTRING) {
3630
3643
  if (this.selectedEdge !== EDGE.NONE && this.myEditMode !== EDITMODE.DELETE_FEATURES) {
3631
- this.mouseGeoCoord = webmapjs.getLatLongFromPixelCoord({
3644
+ this.mouseGeoCoord = getLatLongFromPixelCoord(webmapjs, {
3632
3645
  x: mouseX,
3633
3646
  y: mouseY
3634
3647
  });
@@ -3663,6 +3676,9 @@ class MapDraw extends React.PureComponent {
3663
3676
  selectedFeatureIndex
3664
3677
  } = this.props;
3665
3678
  const webmapjs = webmapUtils.getWMJSMapById(mapId);
3679
+ if (!webmapjs) {
3680
+ return;
3681
+ }
3666
3682
  if (this.myEditMode === EDITMODE.EMPTY) {
3667
3683
  this.myEditMode = EDITMODE.ADD_FEATURE;
3668
3684
  if (!this.geojson.features[selectedFeatureIndex]) {
@@ -3670,7 +3686,7 @@ class MapDraw extends React.PureComponent {
3670
3686
  }
3671
3687
  const feature = this.getSelectedFeature();
3672
3688
  this.initializeFeatureCoordinates(feature, this.myDrawMode);
3673
- this.mouseGeoCoord = webmapjs.getLatLongFromPixelCoord({
3689
+ this.mouseGeoCoord = getLatLongFromPixelCoord(webmapjs, {
3674
3690
  x: mouseX,
3675
3691
  y: mouseY
3676
3692
  });
@@ -3774,9 +3790,12 @@ class MapDraw extends React.PureComponent {
3774
3790
  mapId
3775
3791
  } = this.props;
3776
3792
  const webmapjs = webmapUtils.getWMJSMapById(mapId);
3793
+ if (!webmapjs) {
3794
+ return false;
3795
+ }
3777
3796
  if (this.myDrawMode === DRAWMODE.MULTIPOINT) {
3778
3797
  if (this.myEditMode === EDITMODE.ADD_FEATURE && this.snappedPolygonIndex !== SNAPPEDFEATURE.NONE) {
3779
- this.mouseGeoCoord = webmapjs.getLatLongFromPixelCoord({
3798
+ this.mouseGeoCoord = getLatLongFromPixelCoord(webmapjs, {
3780
3799
  x: mouseX,
3781
3800
  y: mouseY
3782
3801
  });
@@ -3802,9 +3821,12 @@ class MapDraw extends React.PureComponent {
3802
3821
  mapId
3803
3822
  } = this.props;
3804
3823
  const webmapjs = webmapUtils.getWMJSMapById(mapId);
3824
+ if (!webmapjs) {
3825
+ return false;
3826
+ }
3805
3827
  if (this.myDrawMode === DRAWMODE.POLYGON) {
3806
3828
  if (this.myEditMode === EDITMODE.ADD_FEATURE && this.snappedPolygonIndex !== SNAPPEDFEATURE.NONE) {
3807
- this.mouseGeoCoord = webmapjs.getLatLongFromPixelCoord({
3829
+ this.mouseGeoCoord = getLatLongFromPixelCoord(webmapjs, {
3808
3830
  x: mouseX,
3809
3831
  y: mouseY
3810
3832
  });
@@ -3842,9 +3864,12 @@ class MapDraw extends React.PureComponent {
3842
3864
  mapId
3843
3865
  } = this.props;
3844
3866
  const webmapjs = webmapUtils.getWMJSMapById(mapId);
3867
+ if (!webmapjs) {
3868
+ return false;
3869
+ }
3845
3870
  if (this.myDrawMode === DRAWMODE.LINESTRING) {
3846
3871
  if (this.myEditMode === EDITMODE.ADD_FEATURE) {
3847
- this.mouseGeoCoord = webmapjs.getLatLongFromPixelCoord({
3872
+ this.mouseGeoCoord = getLatLongFromPixelCoord(webmapjs, {
3848
3873
  x: mouseX,
3849
3874
  y: mouseY
3850
3875
  });
@@ -3959,7 +3984,7 @@ class MapDraw extends React.PureComponent {
3959
3984
  this.deletePolygon(polygonIndex);
3960
3985
  }
3961
3986
  this.featureHasChanged('deleteFeature');
3962
- webmapjs.draw('MapDraw::deletefeatures');
3987
+ webmapjs === null || webmapjs === void 0 ? void 0 : webmapjs.draw('MapDraw::deletefeatures');
3963
3988
  }
3964
3989
  mouseUp(event) {
3965
3990
  const {
@@ -4060,7 +4085,7 @@ class MapDraw extends React.PureComponent {
4060
4085
  featureCoords.pop();
4061
4086
  }
4062
4087
  this.featureHasChanged('cancelEdit');
4063
- webmapjs.draw('MapDraw::cancelEdit');
4088
+ webmapjs === null || webmapjs === void 0 ? void 0 : webmapjs.draw('MapDraw::cancelEdit');
4064
4089
  } else {
4065
4090
  /* When in deletefeatures mode, remove any vertex under the mousecursor */
4066
4091
  // eslint-disable-next-line no-lonely-if
@@ -4648,7 +4673,10 @@ class MapDraw extends React.PureComponent {
4648
4673
  mapId
4649
4674
  } = this.props;
4650
4675
  const webmapjs = webmapUtils.getWMJSMapById(mapId);
4651
- const image = webmapjs.getMapImageStore.getImage(featureProperties.imageURL);
4676
+ if (!webmapjs) {
4677
+ return undefined;
4678
+ }
4679
+ const image = webmapjs === null || webmapjs === void 0 ? void 0 : webmapjs.getMapImageStore.getImage(featureProperties.imageURL);
4652
4680
  if (image.isLoaded() === false && image.hasError() === false && image.isLoading() === false) {
4653
4681
  image.load();
4654
4682
  /* After the image is loaded the canvas will be redrawn and drawIcon will be triggered again
@@ -9567,8 +9595,7 @@ const getLayerUpdateInfo = (wmLayer, mapId) => {
9567
9595
  return updateObject;
9568
9596
  };
9569
9597
 
9570
- /**
9571
- * Returns filtered list of props with geoJson
9598
+ /** Returns filtered list of props with geoJson
9572
9599
  * @param children React.ReactNode, layers with geoJson
9573
9600
  */
9574
9601
  const getFeatureLayers = children => children && Array.isArray(children) ? children
@@ -9685,6 +9712,9 @@ const setWMLayerPropsBasedOnChildProps = (child, wmLayer, mapViewProps) => {
9685
9712
  };
9686
9713
  const addWMLayerPropsBasedOnChildProps = (child, mapId, props, onUpdateLayerInformation) => {
9687
9714
  const wmjsMap = getWMJSMapById(mapId);
9715
+ if (!wmjsMap) {
9716
+ return;
9717
+ }
9688
9718
  const keepOnTop = child.layerType === LayerType.overLayer || false;
9689
9719
  const newWMLayer = new WMLayer(Object.assign(Object.assign({}, child), {
9690
9720
  keepOnTop
@@ -9723,6 +9753,9 @@ const removeWMLayerFromMap = (wmLayer, mapId, onUpdateLayerInformation) => {
9723
9753
  wmLayer.remove();
9724
9754
  /// Trigger update of all map dimensions
9725
9755
  const wmjsMap = getWMJSMapById(mapId);
9756
+ if (!wmjsMap) {
9757
+ return;
9758
+ }
9726
9759
  onUpdateLayerInformation && onUpdateLayerInformation({
9727
9760
  origin: ORIGIN_REACTMAPVIEW_UTILS_ONUPDATELAYERINFO,
9728
9761
  layerStyle: null,
@@ -9781,24 +9814,49 @@ class ReactMapView extends React.Component {
9781
9814
  currentChildren: []
9782
9815
  };
9783
9816
  this.refetchTimer = null;
9784
- this.onStartRefetchTimer = () => {
9817
+ /**
9818
+ * Last epoch time the map was visible in millisecs. Null if the map is currently visible.
9819
+ */
9820
+ this.lastVisible = null;
9821
+ this.handleVisibilityChange = () => {
9785
9822
  const {
9786
9823
  shouldAutoFetch
9787
9824
  } = this.props;
9788
- /*
9789
- TODO, Maarten Plieger, 2021-09-02, https://gitlab.com/opengeoweb/opengeoweb/-/issues/1159:
9825
+ const autoFetchInterval = Number(shouldAutoFetch); // Default true -> 1 minute
9826
+ const autoFetchIntervalMilliSeconds = Math.abs(autoFetchInterval) * MINUTE_TO_MILLISECOND;
9827
+ if (document.visibilityState === 'visible') {
9828
+ if (this.lastVisible &&
9829
+ // skip if last visibility change was within 1 minute (or the autoFetchInterval)
9830
+ new Date().getTime() - this.lastVisible > autoFetchIntervalMilliSeconds) {
9831
+ this.onStartRefetchTimer(true);
9832
+ }
9833
+ this.lastVisible = null;
9834
+ } else {
9835
+ this.lastVisible = new Date().getTime();
9836
+ this.clearRefetchTimer();
9837
+ }
9838
+ };
9839
+ /**
9840
+ * Start the refetch timer
9841
+ * @param force - Force a fetch and wmLayer parse immediately
9842
+ */
9843
+ this.onStartRefetchTimer = force => {
9844
+ const {
9845
+ shouldAutoFetch
9846
+ } = this.props;
9847
+ /* TODO, Maarten Plieger, 2021-09-02
9790
9848
  This causes many issues, we should improve the update strategy.
9791
9849
  Certain presets have >20 layers. This causes 20 times parsing the GetCapabilities for a minor update of the store.
9792
9850
  */
9793
9851
  this.clearRefetchTimer();
9794
9852
  const autoFetchInterval = Number(shouldAutoFetch); // Default true -> 1 minute
9795
- this.refetchTimer = setInterval(() => {
9853
+ const refetch = () => {
9796
9854
  const {
9797
9855
  mapId
9798
9856
  } = this.props;
9799
9857
  const wmjsMap = webmapUtils.getWMJSMapById(mapId);
9800
- const layers = wmjsMap.getLayers();
9801
- layers.forEach(layer => {
9858
+ const layers = wmjsMap === null || wmjsMap === void 0 ? void 0 : wmjsMap.getLayers();
9859
+ layers === null || layers === void 0 ? void 0 : layers.forEach(layer => {
9802
9860
  if (layer.enabled !== false) {
9803
9861
  parseWMJSLayer(layer, true).then(wmLayer => {
9804
9862
  const {
@@ -9815,7 +9873,11 @@ class ReactMapView extends React.Component {
9815
9873
  });
9816
9874
  }
9817
9875
  });
9818
- }, Math.abs(autoFetchInterval) * MINUTE_TO_MILLISECOND);
9876
+ };
9877
+ this.refetchTimer = setInterval(refetch, Math.abs(autoFetchInterval) * MINUTE_TO_MILLISECOND);
9878
+ if (force) {
9879
+ refetch();
9880
+ }
9819
9881
  };
9820
9882
  this.clearRefetchTimer = () => {
9821
9883
  if (this.refetchTimer) {
@@ -9830,6 +9892,7 @@ class ReactMapView extends React.Component {
9830
9892
  this.drawDebounced = debounce(600, this.drawDebounced);
9831
9893
  this.updateWMJSMapProps = this.updateWMJSMapProps.bind(this);
9832
9894
  this.mountWMJSMap = this.mountWMJSMap.bind(this);
9895
+ this.handleVisibilityChange = this.handleVisibilityChange.bind(this);
9833
9896
  this.onAfterSetBBoxListener = this.onAfterSetBBoxListener.bind(this);
9834
9897
  this.onUpdateBBoxListener = this.onUpdateBBoxListener.bind(this);
9835
9898
  this.onDimChangeListener = this.onDimChangeListener.bind(this);
@@ -9850,6 +9913,7 @@ class ReactMapView extends React.Component {
9850
9913
  this.mountWMJSMap();
9851
9914
  if (shouldAutoFetch) {
9852
9915
  this.onStartRefetchTimer();
9916
+ document.addEventListener('visibilitychange', this.handleVisibilityChange);
9853
9917
  }
9854
9918
  onWMJSMount(mapId);
9855
9919
  }
@@ -9863,6 +9927,7 @@ class ReactMapView extends React.Component {
9863
9927
  } = this.props;
9864
9928
  window.removeEventListener('resize', this.handleWindowResize);
9865
9929
  this.clearRefetchTimer();
9930
+ document.removeEventListener('visibilitychange', this.handleVisibilityChange);
9866
9931
  webmapUtils.unRegisterWMJSMap(mapId);
9867
9932
  /* Reset adaguc properties */
9868
9933
  this.adaguc.initialized = false;
@@ -10118,6 +10183,9 @@ class ReactMapView extends React.Component {
10118
10183
  mapId
10119
10184
  } = this.props;
10120
10185
  const wmjsMap = webmapUtils.getWMJSMapById(mapId);
10186
+ if (!wmjsMap) {
10187
+ return;
10188
+ }
10121
10189
  wmjsMap.getListener().suspendEvents();
10122
10190
  wmjsMap.draw();
10123
10191
  wmjsMap.getListener().resumeEvents();
@@ -10130,7 +10198,7 @@ class ReactMapView extends React.Component {
10130
10198
  bbox,
10131
10199
  onMapPinChangeLocation
10132
10200
  } = this.props;
10133
- /* Check if we have something to mount WMJSMap on */
10201
+ /* Check if we have something to mount IWMJSMap on */
10134
10202
  if (this.adagucWebMapJSRef.current === null) {
10135
10203
  console.warn('No this.adagucWebMapJSRef.current yet ');
10136
10204
  return null;
@@ -10212,6 +10280,9 @@ class ReactMapView extends React.Component {
10212
10280
  mapId
10213
10281
  } = this.props;
10214
10282
  const wmjsMap = webmapUtils.getWMJSMapById(mapId);
10283
+ if (!wmjsMap) {
10284
+ return;
10285
+ }
10215
10286
  wmjsMap.setSize(newWidth, newHeight);
10216
10287
  }
10217
10288
  }
@@ -10397,9 +10468,11 @@ const ProfileAxis = ({
10397
10468
  mapId
10398
10469
  }) => {
10399
10470
  const drawAxisOnMapDisplay = (ctx, webMap, axisStyle) => {
10400
- const bbox = webMap.getBBOX();
10401
- const width = webMap.getWidth();
10402
- const height = webMap.getHeight();
10471
+ const bbox = webMap.getDrawBBOX();
10472
+ const {
10473
+ width,
10474
+ height
10475
+ } = webMap.getSize();
10403
10476
  const offY = height - 50;
10404
10477
  const offX = 20;
10405
10478
  try {
@@ -10427,7 +10500,8 @@ const ProfileAxis = ({
10427
10500
  };
10428
10501
  // Draw on map canvas callback function
10429
10502
  const beforeCanvasDisplay = ctx => {
10430
- drawAxisOnMapDisplay(ctx, getWMJSMapById(mapId), axisStyle);
10503
+ const webmapjs = getWMJSMapById(mapId);
10504
+ webmapjs && drawAxisOnMapDisplay(ctx, webmapjs, axisStyle);
10431
10505
  };
10432
10506
  // unMount logic
10433
10507
  const unMount = () => {
@@ -10439,7 +10513,7 @@ const ProfileAxis = ({
10439
10513
  // Mount logic
10440
10514
  const webMap = getWMJSMapById(mapId);
10441
10515
  if (webMap && webMap.getProjection().srs === 'GFI:TIME_ELEVATION') {
10442
- webMap.hideScaleBar();
10516
+ webMap.displayScaleBarInMap(false);
10443
10517
  webMap.hideMouseCursorProperties();
10444
10518
  webMap.setTimeOffset('');
10445
10519
  webMap.addListener('beforecanvasdisplay', beforeCanvasDisplay, true);
@@ -10554,13 +10628,17 @@ const drawHeightAxis = (ctx, bbox, offsetX, offsetY, width, height, axisStyle) =
10554
10628
  ctx.stroke();
10555
10629
  };
10556
10630
  const drawCursor = (ctx, bbox, offsetX, offsetY, width, height, webMapJS, axisStyle) => {
10631
+ const {
10632
+ mouseX: mapMouseX,
10633
+ mouseY: mapMouseY
10634
+ } = webMapJS.getMapMouseCoordinates();
10557
10635
  // Do not draw if mouse is not in the map
10558
- if (webMapJS.mouseX < 5 && webMapJS.mouseY < 5) {
10636
+ if (mapMouseX < 5 && mapMouseY < 5) {
10559
10637
  return;
10560
10638
  }
10561
10639
  /* Draw cursor line */
10562
- const mouseX = Math.round(webMapJS.mouseX) + 0.5;
10563
- const mouseY = Math.round(webMapJS.mouseY) + 0.5;
10640
+ const mouseX = Math.round(mapMouseX) + 0.5;
10641
+ const mouseY = Math.round(mapMouseY) + 0.5;
10564
10642
  ctx.strokeStyle = '#303030';
10565
10643
  ctx.setLineDash([15, 5]);
10566
10644
  ctx.beginPath();
@@ -10648,15 +10726,18 @@ const MapView = _a => {
10648
10726
  mapId: mapId
10649
10727
  }), jsx(ZoomControls, {
10650
10728
  onZoomIn: () => {
10651
- const wmjsMap = webmapUtils.getWMJSMapById(mapId);
10652
- wmjsMap.zoomIn(undefined);
10729
+ var _a;
10730
+ (_a = webmapUtils.getWMJSMapById(mapId)) === null || _a === void 0 ? void 0 : _a.zoomIn(undefined);
10653
10731
  },
10654
10732
  onZoomOut: () => {
10655
- const wmjsMap = webmapUtils.getWMJSMapById(mapId);
10656
- wmjsMap.zoomOut();
10733
+ var _a;
10734
+ (_a = webmapUtils.getWMJSMapById(mapId)) === null || _a === void 0 ? void 0 : _a.zoomOut();
10657
10735
  },
10658
10736
  onZoomReset: () => {
10659
10737
  const wmjsMap = webmapUtils.getWMJSMapById(mapId);
10738
+ if (!wmjsMap) {
10739
+ return;
10740
+ }
10660
10741
  wmjsMap.zoomToLayer(wmjsMap.getActiveLayer());
10661
10742
  }
10662
10743
  })]
@@ -10670,7 +10751,11 @@ const MapView = _a => {
10670
10751
  showLegend: false,
10671
10752
  displayTimeInMap: false,
10672
10753
  onWMJSMount: id => {
10673
- wmjsMapRef.current = webmapUtils.getWMJSMapById(id);
10754
+ const webMapJS = webmapUtils.getWMJSMapById(id);
10755
+ if (!webMapJS) {
10756
+ return;
10757
+ }
10758
+ wmjsMapRef.current = webMapJS;
10674
10759
  if (onWMJSMount) {
10675
10760
  onWMJSMount(id);
10676
10761
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opengeoweb/webmap-react",
3
- "version": "9.21.0",
3
+ "version": "9.23.1",
4
4
  "description": "GeoWeb react wrapper for webmap",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
@@ -11,7 +11,7 @@
11
11
  "@opengeoweb/webmap": "*",
12
12
  "axios": "1.5.0",
13
13
  "@opengeoweb/theme": "*",
14
- "@mui/material": "~5.15.11",
14
+ "@mui/material": "^5.16.0",
15
15
  "@opengeoweb/shared": "*",
16
16
  "lodash": "^4.17.21",
17
17
  "proj4": "^2.9.2",
@@ -1,9 +1,9 @@
1
1
  import * as React from 'react';
2
- import { LayerFoundation, WMJSMap, WMLayer } from '@opengeoweb/webmap';
2
+ import { LayerFoundation, IWMJSMap, WMLayer } from '@opengeoweb/webmap';
3
3
  import { DrawModeExitCallback, FeatureEvent } from '../MapDraw';
4
4
  export interface MapViewLayerProps extends LayerFoundation {
5
5
  id: string;
6
- onLayerReady?: (layer: WMLayer, webmap?: WMJSMap) => void;
6
+ onLayerReady?: (layer: WMLayer, webmap?: IWMJSMap) => void;
7
7
  onLayerError?: (layer: WMLayer, error?: Error) => void;
8
8
  isInEditMode?: boolean;
9
9
  drawMode?: string;
@@ -1,6 +1,6 @@
1
1
  /// <reference types="node" />
2
2
  import * as React from 'react';
3
- import { WMJSMap, WMLayer, WMBBOX } from '@opengeoweb/webmap';
3
+ import { IWMJSMap, WMLayer, WMBBOX } from '@opengeoweb/webmap';
4
4
  import { ReactMapViewProps } from './types';
5
5
  import type { MapViewLayerProps } from '../MapView';
6
6
  export declare const ORIGIN_REACTMAPVIEW_ONMAPCHANGEDIMENSION = "ORIGIN_REACTMAPVIEW_ONMAPCHANGEDIMENSION";
@@ -22,6 +22,10 @@ export declare class ReactMapView extends React.Component<ReactMapViewProps, Rea
22
22
  adagucContainerRef: React.RefObject<HTMLDivElement>;
23
23
  adagucWebMapJSRef: React.RefObject<HTMLDivElement>;
24
24
  refetchTimer: NodeJS.Timeout | number | null;
25
+ /**
26
+ * Last epoch time the map was visible in millisecs. Null if the map is currently visible.
27
+ */
28
+ lastVisible: number | null;
25
29
  static defaultProps: {
26
30
  srs: string;
27
31
  bbox: {
@@ -47,11 +51,16 @@ export declare class ReactMapView extends React.Component<ReactMapViewProps, Rea
47
51
  onDimChangeListener(): void;
48
52
  onAfterSetBBoxListener(): void;
49
53
  onUpdateBBoxListener(newBbox: WMBBOX): void;
50
- onStartRefetchTimer: () => void;
54
+ handleVisibilityChange: () => void;
55
+ /**
56
+ * Start the refetch timer
57
+ * @param force - Force a fetch and wmLayer parse immediately
58
+ */
59
+ onStartRefetchTimer: (force?: boolean) => void;
51
60
  clearRefetchTimer: () => void;
52
61
  updateWMJSMapProps(prevProps: ReactMapViewProps, props: ReactMapViewProps): void;
53
62
  drawDebounced(): void;
54
- mountWMJSMap(): WMJSMap | null;
63
+ mountWMJSMap(): IWMJSMap | null;
55
64
  resize(): void;
56
65
  render(): React.ReactElement;
57
66
  }
@@ -1 +1,2 @@
1
+ export declare const SECOND_TO_MILLISECOND = 1000;
1
2
  export declare const mockGeoJSON: GeoJSON.FeatureCollection;
@@ -1,11 +1,11 @@
1
1
  /// <reference types="react" />
2
- import { Bbox, Dimension, WMJSMap } from '@opengeoweb/webmap';
2
+ import { Bbox, Dimension, IWMJSMap } from '@opengeoweb/webmap';
3
3
  export interface ReactMapViewProps {
4
4
  listeners?: {
5
5
  name?: string;
6
6
  data: string;
7
7
  keep: boolean;
8
- callbackfunction: (webMap: WMJSMap, value: string) => void;
8
+ callbackfunction: (webMap: IWMJSMap, value: string) => void;
9
9
  }[];
10
10
  srs?: string;
11
11
  bbox?: Bbox;
@@ -1,10 +1,9 @@
1
- import { Dimension, LayerFoundation, WMJSMap, WMLayer } from '@opengeoweb/webmap';
1
+ import { Dimension, LayerFoundation, IWMJSMap, WMLayer } from '@opengeoweb/webmap';
2
2
  import React from 'react';
3
3
  import { FeatureLayer } from '../MapDraw';
4
4
  import type { MapViewLayerProps, MapViewProps } from '../MapView';
5
5
  import { ReactMapViewProps, UpdateLayerInfoPayload } from './types';
6
- /**
7
- * Returns filtered list of props with geoJson
6
+ /** Returns filtered list of props with geoJson
8
7
  * @param children React.ReactNode, layers with geoJson
9
8
  */
10
9
  export declare const getFeatureLayers: (children: React.ReactNode) => FeatureLayer[];
@@ -24,4 +23,4 @@ export declare const parseWMJSLayer: (wmLayer: WMLayer, forceReload: boolean) =>
24
23
  export declare const setWMLayerPropsBasedOnChildProps: (child: MapViewLayerProps, wmLayer: WMLayer, mapViewProps: ReactMapViewProps) => boolean;
25
24
  export declare const addWMLayerPropsBasedOnChildProps: (child: MapViewLayerProps, mapId: string, props: MapViewProps, onUpdateLayerInformation?: ((payload: UpdateLayerInfoPayload) => void) | undefined) => void;
26
25
  export declare const removeWMLayerFromMap: (wmLayer: WMLayer, mapId: string, onUpdateLayerInformation?: ((payload: UpdateLayerInfoPayload) => void) | undefined) => void;
27
- export declare const orderLayers: (wmjsMap: WMJSMap, _reactMapViewLayers: MapViewLayerProps[]) => boolean;
26
+ export declare const orderLayers: (wmjsMap: IWMJSMap, _reactMapViewLayers: MapViewLayerProps[]) => boolean;