@opengeoweb/webmap-react 9.20.2 → 9.22.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.
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';
@@ -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) {
@@ -2822,12 +2828,15 @@ const checkHoverVertice = (feature, mouseX, mouseY, convertGeoCoordsToScreenCoor
2822
2828
  const featureCoords = feature.geometry.coordinates;
2823
2829
  /* Get all vertexes */
2824
2830
  const XYCoords = convertGeoCoordsToScreenCoords([featureCoords]);
2825
- if (XYCoords.length > 0 && distance(XYCoords[0], {
2831
+ const calculatedDistance = XYCoords.length > 0 ? distance(XYCoords[0], {
2826
2832
  x: mouseX,
2827
2833
  y: mouseY
2828
- }) < maxDistance) {
2834
+ }) : null;
2835
+ if (calculatedDistance && calculatedDistance < maxDistance) {
2829
2836
  return {
2830
- coordinateIndexInFeature: 0
2837
+ coordinateIndexInFeature: 0,
2838
+ distance: calculatedDistance,
2839
+ screenCoords: Object.assign({}, XYCoords[0])
2831
2840
  };
2832
2841
  }
2833
2842
  }
@@ -2840,12 +2849,15 @@ const checkHoverVertice = (feature, mouseX, mouseY, convertGeoCoordsToScreenCoor
2840
2849
  }
2841
2850
  /* Get all vertexes */
2842
2851
  const XYCoords = convertGeoCoordsToScreenCoords([featureCoords]);
2843
- if (XYCoords.length > 0 && distance(XYCoords[0], {
2852
+ const calculatedDistance = XYCoords.length > 0 && distance(XYCoords[0], {
2844
2853
  x: mouseX,
2845
2854
  y: mouseY
2846
- }) < maxDistance) {
2855
+ });
2856
+ if (calculatedDistance && calculatedDistance < maxDistance) {
2847
2857
  return {
2848
- coordinateIndexInFeature: polygonIndex
2858
+ coordinateIndexInFeature: polygonIndex,
2859
+ distance: calculatedDistance,
2860
+ screenCoords: Object.assign({}, XYCoords[0])
2849
2861
  };
2850
2862
  }
2851
2863
  }
@@ -2867,11 +2879,21 @@ const checkHoverVertice = (feature, mouseX, mouseY, convertGeoCoordsToScreenCoor
2867
2879
  if (isPointInPoly) {
2868
2880
  if (ignoreCoordinateIndexInFeature) {
2869
2881
  return {
2870
- coordinateIndexInFeature: 0
2882
+ coordinateIndexInFeature: 0,
2883
+ distance: 0,
2884
+ screenCoords: {
2885
+ x: mouseX,
2886
+ y: mouseY
2887
+ }
2871
2888
  };
2872
2889
  }
2873
2890
  return {
2874
- coordinateIndexInFeature: polygonIndex
2891
+ coordinateIndexInFeature: polygonIndex,
2892
+ distance: 0,
2893
+ screenCoords: {
2894
+ x: mouseX,
2895
+ y: mouseY
2896
+ }
2875
2897
  };
2876
2898
  }
2877
2899
  } catch (e) {
@@ -2894,7 +2916,12 @@ const checkHoverVertice = (feature, mouseX, mouseY, convertGeoCoordsToScreenCoor
2894
2916
  const isPointInPoly = turf.booleanPointInPolygon(turf.point(point), turf.polygon(poly));
2895
2917
  if (isPointInPoly) {
2896
2918
  return {
2897
- coordinateIndexInFeature: polygonIndex
2919
+ coordinateIndexInFeature: polygonIndex,
2920
+ distance: 0,
2921
+ screenCoords: {
2922
+ x: mouseX,
2923
+ y: mouseY
2924
+ }
2898
2925
  };
2899
2926
  }
2900
2927
  } catch (e) {
@@ -2914,7 +2941,9 @@ const checkHoverVertice = (feature, mouseX, mouseY, convertGeoCoordsToScreenCoor
2914
2941
  y: mouseY
2915
2942
  }) < maxDistance) {
2916
2943
  return {
2917
- coordinateIndexInFeature: j
2944
+ coordinateIndexInFeature: j,
2945
+ distance: 0,
2946
+ screenCoords: Object.assign({}, coord)
2918
2947
  };
2919
2948
  }
2920
2949
  }
@@ -2922,18 +2951,30 @@ const checkHoverVertice = (feature, mouseX, mouseY, convertGeoCoordsToScreenCoor
2922
2951
  return null;
2923
2952
  };
2924
2953
  const checkHoverFeatures = (geojson, mouseX, mouseY, convertGeoCoordsToScreenCoords, ignoreCoordinateIndexInFeature) => {
2954
+ const result = [];
2925
2955
  for (let j = 0; j < geojson.features.length; j += 1) {
2926
2956
  const feature = geojson.features[j];
2927
2957
  const hoverResult = checkHoverVertice(feature, mouseX, mouseY, convertGeoCoordsToScreenCoords, ignoreCoordinateIndexInFeature);
2928
- if (hoverResult != null) {
2929
- return {
2958
+ if (hoverResult != null && hoverResult.distance != null) {
2959
+ result.push({
2930
2960
  coordinateIndexInFeature: hoverResult.coordinateIndexInFeature,
2931
2961
  featureIndex: j,
2932
- feature
2933
- };
2962
+ feature,
2963
+ distance: hoverResult.distance,
2964
+ screenCoords: Object.assign({}, hoverResult.screenCoords)
2965
+ });
2934
2966
  }
2935
2967
  }
2936
- return null;
2968
+ if (result.length === 0) {
2969
+ return null;
2970
+ }
2971
+ /* Sort the list, closest distance on top */
2972
+ result.sort((a, b) => {
2973
+ const distanceA = a ? a.distance : 0;
2974
+ const distanceB = b ? b.distance : 0;
2975
+ return distanceA - distanceB;
2976
+ }); // b - a for reverse sort
2977
+ return result[0];
2937
2978
  };
2938
2979
  let generatedDrawFunctionIds = 0;
2939
2980
  const generateDrawFunctionId = () => {
@@ -3238,6 +3279,7 @@ class MapDraw extends React.PureComponent {
3238
3279
  }
3239
3280
  }
3240
3281
  componentDidUpdate(prevProps) {
3282
+ var _a;
3241
3283
  const {
3242
3284
  geojson,
3243
3285
  isInEditMode,
@@ -3264,7 +3306,7 @@ class MapDraw extends React.PureComponent {
3264
3306
  return;
3265
3307
  }
3266
3308
  }
3267
- webmapUtils.getWMJSMapById(mapId).draw('MapDraw::componentDidUpdateIsInEditMode');
3309
+ (_a = webmapUtils.getWMJSMapById(mapId)) === null || _a === void 0 ? void 0 : _a.draw('MapDraw::componentDidUpdateIsInEditMode');
3268
3310
  }
3269
3311
  /* Handle toggle delete */
3270
3312
  if (isInDeleteMode !== prevIsInDeleteMode) {
@@ -3454,7 +3496,8 @@ class MapDraw extends React.PureComponent {
3454
3496
  mouseX,
3455
3497
  mouseY,
3456
3498
  isInEditMode,
3457
- feature: result.feature
3499
+ feature: result.feature,
3500
+ screenCoords: result.screenCoords
3458
3501
  };
3459
3502
  onHoverFeature(this.featureEvent);
3460
3503
  } else {
@@ -3474,7 +3517,10 @@ class MapDraw extends React.PureComponent {
3474
3517
  return undefined;
3475
3518
  }
3476
3519
  const webmapjs = webmapUtils.getWMJSMapById(mapId);
3477
- this.mouseGeoCoord = webmapjs.getLatLongFromPixelCoord({
3520
+ if (!webmapjs) {
3521
+ return undefined;
3522
+ }
3523
+ this.mouseGeoCoord = getLatLongFromPixelCoord(webmapjs, {
3478
3524
  x: mouseX,
3479
3525
  y: mouseY
3480
3526
  });
@@ -3570,9 +3616,12 @@ class MapDraw extends React.PureComponent {
3570
3616
  mapId
3571
3617
  } = this.props;
3572
3618
  const webmapjs = webmapUtils.getWMJSMapById(mapId);
3619
+ if (!webmapjs) {
3620
+ return false;
3621
+ }
3573
3622
  if (this.myDrawMode === DRAWMODE.POLYGON) {
3574
3623
  if (this.selectedEdge !== EDGE.NONE && this.myEditMode !== EDITMODE.DELETE_FEATURES) {
3575
- this.mouseGeoCoord = webmapjs.getLatLongFromPixelCoord({
3624
+ this.mouseGeoCoord = getLatLongFromPixelCoord(webmapjs, {
3576
3625
  x: mouseX,
3577
3626
  y: mouseY
3578
3627
  });
@@ -3592,7 +3641,7 @@ class MapDraw extends React.PureComponent {
3592
3641
  }
3593
3642
  if (this.myDrawMode === DRAWMODE.LINESTRING) {
3594
3643
  if (this.selectedEdge !== EDGE.NONE && this.myEditMode !== EDITMODE.DELETE_FEATURES) {
3595
- this.mouseGeoCoord = webmapjs.getLatLongFromPixelCoord({
3644
+ this.mouseGeoCoord = getLatLongFromPixelCoord(webmapjs, {
3596
3645
  x: mouseX,
3597
3646
  y: mouseY
3598
3647
  });
@@ -3627,6 +3676,9 @@ class MapDraw extends React.PureComponent {
3627
3676
  selectedFeatureIndex
3628
3677
  } = this.props;
3629
3678
  const webmapjs = webmapUtils.getWMJSMapById(mapId);
3679
+ if (!webmapjs) {
3680
+ return;
3681
+ }
3630
3682
  if (this.myEditMode === EDITMODE.EMPTY) {
3631
3683
  this.myEditMode = EDITMODE.ADD_FEATURE;
3632
3684
  if (!this.geojson.features[selectedFeatureIndex]) {
@@ -3634,7 +3686,7 @@ class MapDraw extends React.PureComponent {
3634
3686
  }
3635
3687
  const feature = this.getSelectedFeature();
3636
3688
  this.initializeFeatureCoordinates(feature, this.myDrawMode);
3637
- this.mouseGeoCoord = webmapjs.getLatLongFromPixelCoord({
3689
+ this.mouseGeoCoord = getLatLongFromPixelCoord(webmapjs, {
3638
3690
  x: mouseX,
3639
3691
  y: mouseY
3640
3692
  });
@@ -3738,9 +3790,12 @@ class MapDraw extends React.PureComponent {
3738
3790
  mapId
3739
3791
  } = this.props;
3740
3792
  const webmapjs = webmapUtils.getWMJSMapById(mapId);
3793
+ if (!webmapjs) {
3794
+ return false;
3795
+ }
3741
3796
  if (this.myDrawMode === DRAWMODE.MULTIPOINT) {
3742
3797
  if (this.myEditMode === EDITMODE.ADD_FEATURE && this.snappedPolygonIndex !== SNAPPEDFEATURE.NONE) {
3743
- this.mouseGeoCoord = webmapjs.getLatLongFromPixelCoord({
3798
+ this.mouseGeoCoord = getLatLongFromPixelCoord(webmapjs, {
3744
3799
  x: mouseX,
3745
3800
  y: mouseY
3746
3801
  });
@@ -3766,19 +3821,34 @@ class MapDraw extends React.PureComponent {
3766
3821
  mapId
3767
3822
  } = this.props;
3768
3823
  const webmapjs = webmapUtils.getWMJSMapById(mapId);
3824
+ if (!webmapjs) {
3825
+ return false;
3826
+ }
3769
3827
  if (this.myDrawMode === DRAWMODE.POLYGON) {
3770
3828
  if (this.myEditMode === EDITMODE.ADD_FEATURE && this.snappedPolygonIndex !== SNAPPEDFEATURE.NONE) {
3771
- this.mouseGeoCoord = webmapjs.getLatLongFromPixelCoord({
3829
+ this.mouseGeoCoord = getLatLongFromPixelCoord(webmapjs, {
3772
3830
  x: mouseX,
3773
3831
  y: mouseY
3774
3832
  });
3775
3833
  const feature = this.getSelectedFeature();
3776
3834
  if (feature.geometry.type === 'Polygon') {
3777
3835
  const featureCoords = feature.geometry.coordinates[this.snappedPolygonIndex];
3778
- featureCoords.push([this.mouseGeoCoord.x, this.mouseGeoCoord.y]);
3779
- this.featureHasChanged('vertex added to polygon');
3780
- this.mouseIsOverVertexNr = featureCoords.length - 1;
3781
- this.mouseMove(event);
3836
+ // "featureCoords" is our polygon represented as a list of coordinates. The last element in the list is the ghost node following our cursor.
3837
+ // We therefore extract the last two nodes, which will tell us the distance between the last placed node and the ghost node
3838
+ const [coordA, coordB] = featureCoords.slice(-2);
3839
+ const coordDistance = distance({
3840
+ x: coordA[0],
3841
+ y: coordA[1]
3842
+ }, {
3843
+ x: coordB[0],
3844
+ y: coordB[1]
3845
+ });
3846
+ if (coordDistance > 0.005) {
3847
+ featureCoords.push([this.mouseGeoCoord.x, this.mouseGeoCoord.y]);
3848
+ this.featureHasChanged('vertex added to polygon');
3849
+ this.mouseIsOverVertexNr = featureCoords.length - 1;
3850
+ this.mouseMove(event);
3851
+ }
3782
3852
  }
3783
3853
  return false;
3784
3854
  }
@@ -3794,9 +3864,12 @@ class MapDraw extends React.PureComponent {
3794
3864
  mapId
3795
3865
  } = this.props;
3796
3866
  const webmapjs = webmapUtils.getWMJSMapById(mapId);
3867
+ if (!webmapjs) {
3868
+ return false;
3869
+ }
3797
3870
  if (this.myDrawMode === DRAWMODE.LINESTRING) {
3798
3871
  if (this.myEditMode === EDITMODE.ADD_FEATURE) {
3799
- this.mouseGeoCoord = webmapjs.getLatLongFromPixelCoord({
3872
+ this.mouseGeoCoord = getLatLongFromPixelCoord(webmapjs, {
3800
3873
  x: mouseX,
3801
3874
  y: mouseY
3802
3875
  });
@@ -3911,7 +3984,7 @@ class MapDraw extends React.PureComponent {
3911
3984
  this.deletePolygon(polygonIndex);
3912
3985
  }
3913
3986
  this.featureHasChanged('deleteFeature');
3914
- webmapjs.draw('MapDraw::deletefeatures');
3987
+ webmapjs === null || webmapjs === void 0 ? void 0 : webmapjs.draw('MapDraw::deletefeatures');
3915
3988
  }
3916
3989
  mouseUp(event) {
3917
3990
  const {
@@ -3938,7 +4011,8 @@ class MapDraw extends React.PureComponent {
3938
4011
  mouseX,
3939
4012
  mouseY,
3940
4013
  isInEditMode,
3941
- feature: result.feature
4014
+ feature: result.feature,
4015
+ screenCoords: Object.assign({}, result.screenCoords)
3942
4016
  };
3943
4017
  onClickFeature(featureEvent);
3944
4018
  } else {
@@ -4011,7 +4085,7 @@ class MapDraw extends React.PureComponent {
4011
4085
  featureCoords.pop();
4012
4086
  }
4013
4087
  this.featureHasChanged('cancelEdit');
4014
- webmapjs.draw('MapDraw::cancelEdit');
4088
+ webmapjs === null || webmapjs === void 0 ? void 0 : webmapjs.draw('MapDraw::cancelEdit');
4015
4089
  } else {
4016
4090
  /* When in deletefeatures mode, remove any vertex under the mousecursor */
4017
4091
  // eslint-disable-next-line no-lonely-if
@@ -4237,7 +4311,7 @@ class MapDraw extends React.PureComponent {
4237
4311
  just before viewer will flip the back canvas buffer to the front.
4238
4312
  You are free to draw anything you like on the canvas.
4239
4313
  */
4240
- var _a, _b, _c, _d, _e;
4314
+ var _a, _b, _c;
4241
4315
  const {
4242
4316
  selectedFeatureIndex,
4243
4317
  isInEditMode,
@@ -4249,9 +4323,8 @@ class MapDraw extends React.PureComponent {
4249
4323
  this.textPositions = [];
4250
4324
  this.mouseOverPolygonCoordinates = [];
4251
4325
  this.mouseOverPolygonFeatureIndex = -1;
4252
- /* Current selected feature from GeoJSON */
4253
- for (let featureIndex = 0; featureIndex < this.geojson.features.length; featureIndex += 1) {
4254
- const feature = this.geojson.features[featureIndex];
4326
+ const drawFeature = (feature, featureIndex) => {
4327
+ var _a, _b, _c;
4255
4328
  const featureType = feature.geometry.type;
4256
4329
  const totalmiddle = {
4257
4330
  x: 0,
@@ -4263,7 +4336,7 @@ class MapDraw extends React.PureComponent {
4263
4336
  const XYCoords = getPixelCoordFromGeoCoord([featureCoords], mapId);
4264
4337
  if (XYCoords.length === 0) {
4265
4338
  // eslint-disable-next-line no-continue
4266
- continue;
4339
+ return;
4267
4340
  }
4268
4341
  for (let j = 0; j < XYCoords.length; j += 1) {
4269
4342
  this.drawPoint(ctx, XYCoords[j], this.mouseIsOverVertexNr === j && selectedFeatureIndex === featureIndex, false, isInEditMode && selectedFeatureIndex === featureIndex, feature, featureIndex);
@@ -4273,8 +4346,7 @@ class MapDraw extends React.PureComponent {
4273
4346
  const featureCoords = feature.geometry.coordinates;
4274
4347
  const XYCoords = getPixelCoordFromGeoCoord(featureCoords, mapId);
4275
4348
  if (XYCoords.length === 0) {
4276
- // eslint-disable-next-line no-continue
4277
- continue;
4349
+ return;
4278
4350
  }
4279
4351
  for (let j = 0; j < XYCoords.length; j += 1) {
4280
4352
  this.drawPoint(ctx, XYCoords[j], this.mouseIsOverVertexNr === j && selectedFeatureIndex === featureIndex, false, isInEditMode && selectedFeatureIndex === featureIndex, feature, featureIndex);
@@ -4312,7 +4384,7 @@ class MapDraw extends React.PureComponent {
4312
4384
  if (totalmiddle.nr > 0) {
4313
4385
  const mx = totalmiddle.x / totalmiddle.nr;
4314
4386
  const my = totalmiddle.y / totalmiddle.nr;
4315
- if ((_c = feature.properties) === null || _c === void 0 ? void 0 : _c.text) {
4387
+ if ((_a = feature.properties) === null || _a === void 0 ? void 0 : _a.text) {
4316
4388
  this.textPositions.push({
4317
4389
  x: mx,
4318
4390
  y: my,
@@ -4333,7 +4405,7 @@ class MapDraw extends React.PureComponent {
4333
4405
  continue;
4334
4406
  }
4335
4407
  const middle = this.drawPolygon(ctx, XYCoords, featureIndex, polygonIndex);
4336
- if (middle && ((_d = feature.properties) === null || _d === void 0 ? void 0 : _d.text)) {
4408
+ if (middle && ((_b = feature.properties) === null || _b === void 0 ? void 0 : _b.text)) {
4337
4409
  this.textPositions.push({
4338
4410
  x: middle.x,
4339
4411
  y: middle.y,
@@ -4359,17 +4431,15 @@ class MapDraw extends React.PureComponent {
4359
4431
  /* Loop through all line pints of the same feature */
4360
4432
  const featureCoords = feature.geometry.coordinates;
4361
4433
  if (!featureCoords || !featureCoords.length) {
4362
- // eslint-disable-next-line no-continue
4363
- continue;
4434
+ return;
4364
4435
  }
4365
4436
  const XYCoords = getPixelCoordFromGeoCoord(featureCoords, mapId);
4366
4437
  /* Only draw if there is stuff to show */
4367
4438
  if (XYCoords.length === 0) {
4368
- // eslint-disable-next-line no-continue
4369
- continue;
4439
+ return;
4370
4440
  }
4371
4441
  const middle = this.drawLine(ctx, XYCoords, featureIndex, 0);
4372
- if (middle && ((_e = feature.properties) === null || _e === void 0 ? void 0 : _e.text)) {
4442
+ if (middle && ((_c = feature.properties) === null || _c === void 0 ? void 0 : _c.text)) {
4373
4443
  this.textPositions.push({
4374
4444
  x: middle.x,
4375
4445
  y: middle.y,
@@ -4383,7 +4453,17 @@ class MapDraw extends React.PureComponent {
4383
4453
  }
4384
4454
  }
4385
4455
  }
4456
+ };
4457
+ /* Draw all features */
4458
+ for (let featureIndex = 0; featureIndex < this.geojson.features.length; featureIndex += 1) {
4459
+ const feature = this.geojson.features[featureIndex];
4460
+ /* Do not draw selected feature here, should be done last */
4461
+ if (featureIndex !== selectedFeatureIndex) {
4462
+ drawFeature(feature, featureIndex);
4463
+ }
4386
4464
  }
4465
+ /* Draw selected feature to display it on top */
4466
+ drawFeature(this.getSelectedFeature(), selectedFeatureIndex);
4387
4467
  /* Higlight polygon with mousehover */
4388
4468
  if (isInEditMode === true && this.mouseOverPolygonFeatureIndex === selectedFeatureIndex && this.mouseIsOverVertexNr === VERTEX.NONE && this.snappedPolygonIndex === SNAPPEDFEATURE.NONE && this.selectedEdge === EDGE.NONE || this.mouseIsOverVertexNr === VERTEX.MIDDLE_POINT_OF_FEATURE) {
4389
4469
  const feature = this.getSelectedFeature();
@@ -4417,6 +4497,29 @@ class MapDraw extends React.PureComponent {
4417
4497
  ctx.font = '12px Arial';
4418
4498
  ctx.fillText(text, x, y);
4419
4499
  }
4500
+ /* Draw hovered feature */
4501
+ if (this.featureEvent) {
4502
+ const {
4503
+ feature,
4504
+ featureIndex,
4505
+ screenCoords
4506
+ } = this.featureEvent;
4507
+ const drawFunctionId = (_c = feature === null || feature === void 0 ? void 0 : feature.properties) === null || _c === void 0 ? void 0 : _c.hoverDrawFunctionId;
4508
+ const drawFunction = getDrawFunctionFromStore(drawFunctionId);
4509
+ if (drawFunction) {
4510
+ drawFunction({
4511
+ context: ctx,
4512
+ featureIndex,
4513
+ isInEditMode,
4514
+ feature,
4515
+ isHovered: true,
4516
+ coord: screenCoords,
4517
+ selected: featureIndex === selectedFeatureIndex,
4518
+ mouseX: 0,
4519
+ mouseY: 0
4520
+ });
4521
+ }
4522
+ }
4420
4523
  }
4421
4524
  /* Checks if mouse is in proximity of given coordinate */
4422
4525
  checkDist(coord, polygonIndex, mouseX, mouseY) {
@@ -4570,7 +4673,10 @@ class MapDraw extends React.PureComponent {
4570
4673
  mapId
4571
4674
  } = this.props;
4572
4675
  const webmapjs = webmapUtils.getWMJSMapById(mapId);
4573
- 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);
4574
4680
  if (image.isLoaded() === false && image.hasError() === false && image.isLoading() === false) {
4575
4681
  image.load();
4576
4682
  /* After the image is loaded the canvas will be redrawn and drawIcon will be triggered again
@@ -9489,8 +9595,7 @@ const getLayerUpdateInfo = (wmLayer, mapId) => {
9489
9595
  return updateObject;
9490
9596
  };
9491
9597
 
9492
- /**
9493
- * Returns filtered list of props with geoJson
9598
+ /** Returns filtered list of props with geoJson
9494
9599
  * @param children React.ReactNode, layers with geoJson
9495
9600
  */
9496
9601
  const getFeatureLayers = children => children && Array.isArray(children) ? children
@@ -9607,6 +9712,9 @@ const setWMLayerPropsBasedOnChildProps = (child, wmLayer, mapViewProps) => {
9607
9712
  };
9608
9713
  const addWMLayerPropsBasedOnChildProps = (child, mapId, props, onUpdateLayerInformation) => {
9609
9714
  const wmjsMap = getWMJSMapById(mapId);
9715
+ if (!wmjsMap) {
9716
+ return;
9717
+ }
9610
9718
  const keepOnTop = child.layerType === LayerType.overLayer || false;
9611
9719
  const newWMLayer = new WMLayer(Object.assign(Object.assign({}, child), {
9612
9720
  keepOnTop
@@ -9645,6 +9753,9 @@ const removeWMLayerFromMap = (wmLayer, mapId, onUpdateLayerInformation) => {
9645
9753
  wmLayer.remove();
9646
9754
  /// Trigger update of all map dimensions
9647
9755
  const wmjsMap = getWMJSMapById(mapId);
9756
+ if (!wmjsMap) {
9757
+ return;
9758
+ }
9648
9759
  onUpdateLayerInformation && onUpdateLayerInformation({
9649
9760
  origin: ORIGIN_REACTMAPVIEW_UTILS_ONUPDATELAYERINFO,
9650
9761
  layerStyle: null,
@@ -9707,8 +9818,7 @@ class ReactMapView extends React.Component {
9707
9818
  const {
9708
9819
  shouldAutoFetch
9709
9820
  } = this.props;
9710
- /*
9711
- TODO, Maarten Plieger, 2021-09-02, https://gitlab.com/opengeoweb/opengeoweb/-/issues/1159:
9821
+ /* TODO, Maarten Plieger, 2021-09-02, https://gitlab.com/opengeoweb/opengeoweb/-/issues/1159:
9712
9822
  This causes many issues, we should improve the update strategy.
9713
9823
  Certain presets have >20 layers. This causes 20 times parsing the GetCapabilities for a minor update of the store.
9714
9824
  */
@@ -9719,6 +9829,9 @@ class ReactMapView extends React.Component {
9719
9829
  mapId
9720
9830
  } = this.props;
9721
9831
  const wmjsMap = webmapUtils.getWMJSMapById(mapId);
9832
+ if (!wmjsMap) {
9833
+ return;
9834
+ }
9722
9835
  const layers = wmjsMap.getLayers();
9723
9836
  layers.forEach(layer => {
9724
9837
  if (layer.enabled !== false) {
@@ -10040,6 +10153,9 @@ class ReactMapView extends React.Component {
10040
10153
  mapId
10041
10154
  } = this.props;
10042
10155
  const wmjsMap = webmapUtils.getWMJSMapById(mapId);
10156
+ if (!wmjsMap) {
10157
+ return;
10158
+ }
10043
10159
  wmjsMap.getListener().suspendEvents();
10044
10160
  wmjsMap.draw();
10045
10161
  wmjsMap.getListener().resumeEvents();
@@ -10052,7 +10168,7 @@ class ReactMapView extends React.Component {
10052
10168
  bbox,
10053
10169
  onMapPinChangeLocation
10054
10170
  } = this.props;
10055
- /* Check if we have something to mount WMJSMap on */
10171
+ /* Check if we have something to mount IWMJSMap on */
10056
10172
  if (this.adagucWebMapJSRef.current === null) {
10057
10173
  console.warn('No this.adagucWebMapJSRef.current yet ');
10058
10174
  return null;
@@ -10134,6 +10250,9 @@ class ReactMapView extends React.Component {
10134
10250
  mapId
10135
10251
  } = this.props;
10136
10252
  const wmjsMap = webmapUtils.getWMJSMapById(mapId);
10253
+ if (!wmjsMap) {
10254
+ return;
10255
+ }
10137
10256
  wmjsMap.setSize(newWidth, newHeight);
10138
10257
  }
10139
10258
  }
@@ -10319,9 +10438,11 @@ const ProfileAxis = ({
10319
10438
  mapId
10320
10439
  }) => {
10321
10440
  const drawAxisOnMapDisplay = (ctx, webMap, axisStyle) => {
10322
- const bbox = webMap.getBBOX();
10323
- const width = webMap.getWidth();
10324
- const height = webMap.getHeight();
10441
+ const bbox = webMap.getDrawBBOX();
10442
+ const {
10443
+ width,
10444
+ height
10445
+ } = webMap.getSize();
10325
10446
  const offY = height - 50;
10326
10447
  const offX = 20;
10327
10448
  try {
@@ -10349,7 +10470,8 @@ const ProfileAxis = ({
10349
10470
  };
10350
10471
  // Draw on map canvas callback function
10351
10472
  const beforeCanvasDisplay = ctx => {
10352
- drawAxisOnMapDisplay(ctx, getWMJSMapById(mapId), axisStyle);
10473
+ const webmapjs = getWMJSMapById(mapId);
10474
+ webmapjs && drawAxisOnMapDisplay(ctx, webmapjs, axisStyle);
10353
10475
  };
10354
10476
  // unMount logic
10355
10477
  const unMount = () => {
@@ -10361,7 +10483,7 @@ const ProfileAxis = ({
10361
10483
  // Mount logic
10362
10484
  const webMap = getWMJSMapById(mapId);
10363
10485
  if (webMap && webMap.getProjection().srs === 'GFI:TIME_ELEVATION') {
10364
- webMap.hideScaleBar();
10486
+ webMap.displayScaleBarInMap(false);
10365
10487
  webMap.hideMouseCursorProperties();
10366
10488
  webMap.setTimeOffset('');
10367
10489
  webMap.addListener('beforecanvasdisplay', beforeCanvasDisplay, true);
@@ -10476,13 +10598,17 @@ const drawHeightAxis = (ctx, bbox, offsetX, offsetY, width, height, axisStyle) =
10476
10598
  ctx.stroke();
10477
10599
  };
10478
10600
  const drawCursor = (ctx, bbox, offsetX, offsetY, width, height, webMapJS, axisStyle) => {
10601
+ const {
10602
+ mouseX: mapMouseX,
10603
+ mouseY: mapMouseY
10604
+ } = webMapJS.getMapMouseCoordinates();
10479
10605
  // Do not draw if mouse is not in the map
10480
- if (webMapJS.mouseX < 5 && webMapJS.mouseY < 5) {
10606
+ if (mapMouseX < 5 && mapMouseY < 5) {
10481
10607
  return;
10482
10608
  }
10483
10609
  /* Draw cursor line */
10484
- const mouseX = Math.round(webMapJS.mouseX) + 0.5;
10485
- const mouseY = Math.round(webMapJS.mouseY) + 0.5;
10610
+ const mouseX = Math.round(mapMouseX) + 0.5;
10611
+ const mouseY = Math.round(mapMouseY) + 0.5;
10486
10612
  ctx.strokeStyle = '#303030';
10487
10613
  ctx.setLineDash([15, 5]);
10488
10614
  ctx.beginPath();
@@ -10570,15 +10696,18 @@ const MapView = _a => {
10570
10696
  mapId: mapId
10571
10697
  }), jsx(ZoomControls, {
10572
10698
  onZoomIn: () => {
10573
- const wmjsMap = webmapUtils.getWMJSMapById(mapId);
10574
- wmjsMap.zoomIn(undefined);
10699
+ var _a;
10700
+ (_a = webmapUtils.getWMJSMapById(mapId)) === null || _a === void 0 ? void 0 : _a.zoomIn(undefined);
10575
10701
  },
10576
10702
  onZoomOut: () => {
10577
- const wmjsMap = webmapUtils.getWMJSMapById(mapId);
10578
- wmjsMap.zoomOut();
10703
+ var _a;
10704
+ (_a = webmapUtils.getWMJSMapById(mapId)) === null || _a === void 0 ? void 0 : _a.zoomOut();
10579
10705
  },
10580
10706
  onZoomReset: () => {
10581
10707
  const wmjsMap = webmapUtils.getWMJSMapById(mapId);
10708
+ if (!wmjsMap) {
10709
+ return;
10710
+ }
10582
10711
  wmjsMap.zoomToLayer(wmjsMap.getActiveLayer());
10583
10712
  }
10584
10713
  })]
@@ -10592,7 +10721,11 @@ const MapView = _a => {
10592
10721
  showLegend: false,
10593
10722
  displayTimeInMap: false,
10594
10723
  onWMJSMount: id => {
10595
- wmjsMapRef.current = webmapUtils.getWMJSMapById(id);
10724
+ const webMapJS = webmapUtils.getWMJSMapById(id);
10725
+ if (!webMapJS) {
10726
+ return;
10727
+ }
10728
+ wmjsMapRef.current = webMapJS;
10596
10729
  if (onWMJSMount) {
10597
10730
  onWMJSMount(id);
10598
10731
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opengeoweb/webmap-react",
3
- "version": "9.20.2",
3
+ "version": "9.22.0",
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",
@@ -19,8 +19,8 @@
19
19
  "immer": "^10.0.3",
20
20
  "react-resize-detector": "^9.1.0",
21
21
  "throttle-debounce": "^5.0.0",
22
- "i18next": "^23.7.11",
23
- "react-i18next": "^13.5.0"
22
+ "i18next": "^23.11.5",
23
+ "react-i18next": "^14.1.2"
24
24
  },
25
25
  "peerDependencies": {
26
26
  "react": "18"
@@ -16,6 +16,10 @@ interface InputEvent {
16
16
  export interface FeatureEvent {
17
17
  coordinateIndexInFeature: number;
18
18
  featureIndex: number;
19
+ screenCoords: {
20
+ x: number;
21
+ y: number;
22
+ };
19
23
  mouseX: number;
20
24
  mouseY: number;
21
25
  isInEditMode: boolean;
@@ -5,6 +5,11 @@ export type CheckHoverFeaturesResult = {
5
5
  coordinateIndexInFeature: number;
6
6
  featureIndex: number;
7
7
  feature: GeoJsonFeature;
8
+ distance: number;
9
+ screenCoords: {
10
+ x: number;
11
+ y: number;
12
+ };
8
13
  } | null;
9
14
  export type ProjectorCache = Record<string, InterfaceProjection>;
10
15
  export declare const Proj4js: typeof proj4;
@@ -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";
@@ -51,7 +51,7 @@ export declare class ReactMapView extends React.Component<ReactMapViewProps, Rea
51
51
  clearRefetchTimer: () => void;
52
52
  updateWMJSMapProps(prevProps: ReactMapViewProps, props: ReactMapViewProps): void;
53
53
  drawDebounced(): void;
54
- mountWMJSMap(): WMJSMap | null;
54
+ mountWMJSMap(): IWMJSMap | null;
55
55
  resize(): void;
56
56
  render(): React.ReactElement;
57
57
  }
@@ -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;