@opengeoweb/webmap-react 9.20.1 → 9.21.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
|
@@ -2822,12 +2822,15 @@ const checkHoverVertice = (feature, mouseX, mouseY, convertGeoCoordsToScreenCoor
|
|
|
2822
2822
|
const featureCoords = feature.geometry.coordinates;
|
|
2823
2823
|
/* Get all vertexes */
|
|
2824
2824
|
const XYCoords = convertGeoCoordsToScreenCoords([featureCoords]);
|
|
2825
|
-
|
|
2825
|
+
const calculatedDistance = XYCoords.length > 0 ? distance(XYCoords[0], {
|
|
2826
2826
|
x: mouseX,
|
|
2827
2827
|
y: mouseY
|
|
2828
|
-
})
|
|
2828
|
+
}) : null;
|
|
2829
|
+
if (calculatedDistance && calculatedDistance < maxDistance) {
|
|
2829
2830
|
return {
|
|
2830
|
-
coordinateIndexInFeature: 0
|
|
2831
|
+
coordinateIndexInFeature: 0,
|
|
2832
|
+
distance: calculatedDistance,
|
|
2833
|
+
screenCoords: Object.assign({}, XYCoords[0])
|
|
2831
2834
|
};
|
|
2832
2835
|
}
|
|
2833
2836
|
}
|
|
@@ -2840,12 +2843,15 @@ const checkHoverVertice = (feature, mouseX, mouseY, convertGeoCoordsToScreenCoor
|
|
|
2840
2843
|
}
|
|
2841
2844
|
/* Get all vertexes */
|
|
2842
2845
|
const XYCoords = convertGeoCoordsToScreenCoords([featureCoords]);
|
|
2843
|
-
|
|
2846
|
+
const calculatedDistance = XYCoords.length > 0 && distance(XYCoords[0], {
|
|
2844
2847
|
x: mouseX,
|
|
2845
2848
|
y: mouseY
|
|
2846
|
-
})
|
|
2849
|
+
});
|
|
2850
|
+
if (calculatedDistance && calculatedDistance < maxDistance) {
|
|
2847
2851
|
return {
|
|
2848
|
-
coordinateIndexInFeature: polygonIndex
|
|
2852
|
+
coordinateIndexInFeature: polygonIndex,
|
|
2853
|
+
distance: calculatedDistance,
|
|
2854
|
+
screenCoords: Object.assign({}, XYCoords[0])
|
|
2849
2855
|
};
|
|
2850
2856
|
}
|
|
2851
2857
|
}
|
|
@@ -2867,11 +2873,21 @@ const checkHoverVertice = (feature, mouseX, mouseY, convertGeoCoordsToScreenCoor
|
|
|
2867
2873
|
if (isPointInPoly) {
|
|
2868
2874
|
if (ignoreCoordinateIndexInFeature) {
|
|
2869
2875
|
return {
|
|
2870
|
-
coordinateIndexInFeature: 0
|
|
2876
|
+
coordinateIndexInFeature: 0,
|
|
2877
|
+
distance: 0,
|
|
2878
|
+
screenCoords: {
|
|
2879
|
+
x: mouseX,
|
|
2880
|
+
y: mouseY
|
|
2881
|
+
}
|
|
2871
2882
|
};
|
|
2872
2883
|
}
|
|
2873
2884
|
return {
|
|
2874
|
-
coordinateIndexInFeature: polygonIndex
|
|
2885
|
+
coordinateIndexInFeature: polygonIndex,
|
|
2886
|
+
distance: 0,
|
|
2887
|
+
screenCoords: {
|
|
2888
|
+
x: mouseX,
|
|
2889
|
+
y: mouseY
|
|
2890
|
+
}
|
|
2875
2891
|
};
|
|
2876
2892
|
}
|
|
2877
2893
|
} catch (e) {
|
|
@@ -2894,7 +2910,12 @@ const checkHoverVertice = (feature, mouseX, mouseY, convertGeoCoordsToScreenCoor
|
|
|
2894
2910
|
const isPointInPoly = turf.booleanPointInPolygon(turf.point(point), turf.polygon(poly));
|
|
2895
2911
|
if (isPointInPoly) {
|
|
2896
2912
|
return {
|
|
2897
|
-
coordinateIndexInFeature: polygonIndex
|
|
2913
|
+
coordinateIndexInFeature: polygonIndex,
|
|
2914
|
+
distance: 0,
|
|
2915
|
+
screenCoords: {
|
|
2916
|
+
x: mouseX,
|
|
2917
|
+
y: mouseY
|
|
2918
|
+
}
|
|
2898
2919
|
};
|
|
2899
2920
|
}
|
|
2900
2921
|
} catch (e) {
|
|
@@ -2914,7 +2935,9 @@ const checkHoverVertice = (feature, mouseX, mouseY, convertGeoCoordsToScreenCoor
|
|
|
2914
2935
|
y: mouseY
|
|
2915
2936
|
}) < maxDistance) {
|
|
2916
2937
|
return {
|
|
2917
|
-
coordinateIndexInFeature: j
|
|
2938
|
+
coordinateIndexInFeature: j,
|
|
2939
|
+
distance: 0,
|
|
2940
|
+
screenCoords: Object.assign({}, coord)
|
|
2918
2941
|
};
|
|
2919
2942
|
}
|
|
2920
2943
|
}
|
|
@@ -2922,18 +2945,30 @@ const checkHoverVertice = (feature, mouseX, mouseY, convertGeoCoordsToScreenCoor
|
|
|
2922
2945
|
return null;
|
|
2923
2946
|
};
|
|
2924
2947
|
const checkHoverFeatures = (geojson, mouseX, mouseY, convertGeoCoordsToScreenCoords, ignoreCoordinateIndexInFeature) => {
|
|
2948
|
+
const result = [];
|
|
2925
2949
|
for (let j = 0; j < geojson.features.length; j += 1) {
|
|
2926
2950
|
const feature = geojson.features[j];
|
|
2927
2951
|
const hoverResult = checkHoverVertice(feature, mouseX, mouseY, convertGeoCoordsToScreenCoords, ignoreCoordinateIndexInFeature);
|
|
2928
|
-
if (hoverResult != null) {
|
|
2929
|
-
|
|
2952
|
+
if (hoverResult != null && hoverResult.distance != null) {
|
|
2953
|
+
result.push({
|
|
2930
2954
|
coordinateIndexInFeature: hoverResult.coordinateIndexInFeature,
|
|
2931
2955
|
featureIndex: j,
|
|
2932
|
-
feature
|
|
2933
|
-
|
|
2956
|
+
feature,
|
|
2957
|
+
distance: hoverResult.distance,
|
|
2958
|
+
screenCoords: Object.assign({}, hoverResult.screenCoords)
|
|
2959
|
+
});
|
|
2934
2960
|
}
|
|
2935
2961
|
}
|
|
2936
|
-
|
|
2962
|
+
if (result.length === 0) {
|
|
2963
|
+
return null;
|
|
2964
|
+
}
|
|
2965
|
+
/* Sort the list, closest distance on top */
|
|
2966
|
+
result.sort((a, b) => {
|
|
2967
|
+
const distanceA = a ? a.distance : 0;
|
|
2968
|
+
const distanceB = b ? b.distance : 0;
|
|
2969
|
+
return distanceA - distanceB;
|
|
2970
|
+
}); // b - a for reverse sort
|
|
2971
|
+
return result[0];
|
|
2937
2972
|
};
|
|
2938
2973
|
let generatedDrawFunctionIds = 0;
|
|
2939
2974
|
const generateDrawFunctionId = () => {
|
|
@@ -3454,7 +3489,8 @@ class MapDraw extends React.PureComponent {
|
|
|
3454
3489
|
mouseX,
|
|
3455
3490
|
mouseY,
|
|
3456
3491
|
isInEditMode,
|
|
3457
|
-
feature: result.feature
|
|
3492
|
+
feature: result.feature,
|
|
3493
|
+
screenCoords: result.screenCoords
|
|
3458
3494
|
};
|
|
3459
3495
|
onHoverFeature(this.featureEvent);
|
|
3460
3496
|
} else {
|
|
@@ -3775,10 +3811,22 @@ class MapDraw extends React.PureComponent {
|
|
|
3775
3811
|
const feature = this.getSelectedFeature();
|
|
3776
3812
|
if (feature.geometry.type === 'Polygon') {
|
|
3777
3813
|
const featureCoords = feature.geometry.coordinates[this.snappedPolygonIndex];
|
|
3778
|
-
featureCoords.
|
|
3779
|
-
|
|
3780
|
-
|
|
3781
|
-
|
|
3814
|
+
// "featureCoords" is our polygon represented as a list of coordinates. The last element in the list is the ghost node following our cursor.
|
|
3815
|
+
// We therefore extract the last two nodes, which will tell us the distance between the last placed node and the ghost node
|
|
3816
|
+
const [coordA, coordB] = featureCoords.slice(-2);
|
|
3817
|
+
const coordDistance = distance({
|
|
3818
|
+
x: coordA[0],
|
|
3819
|
+
y: coordA[1]
|
|
3820
|
+
}, {
|
|
3821
|
+
x: coordB[0],
|
|
3822
|
+
y: coordB[1]
|
|
3823
|
+
});
|
|
3824
|
+
if (coordDistance > 0.005) {
|
|
3825
|
+
featureCoords.push([this.mouseGeoCoord.x, this.mouseGeoCoord.y]);
|
|
3826
|
+
this.featureHasChanged('vertex added to polygon');
|
|
3827
|
+
this.mouseIsOverVertexNr = featureCoords.length - 1;
|
|
3828
|
+
this.mouseMove(event);
|
|
3829
|
+
}
|
|
3782
3830
|
}
|
|
3783
3831
|
return false;
|
|
3784
3832
|
}
|
|
@@ -3938,7 +3986,8 @@ class MapDraw extends React.PureComponent {
|
|
|
3938
3986
|
mouseX,
|
|
3939
3987
|
mouseY,
|
|
3940
3988
|
isInEditMode,
|
|
3941
|
-
feature: result.feature
|
|
3989
|
+
feature: result.feature,
|
|
3990
|
+
screenCoords: Object.assign({}, result.screenCoords)
|
|
3942
3991
|
};
|
|
3943
3992
|
onClickFeature(featureEvent);
|
|
3944
3993
|
} else {
|
|
@@ -4237,7 +4286,7 @@ class MapDraw extends React.PureComponent {
|
|
|
4237
4286
|
just before viewer will flip the back canvas buffer to the front.
|
|
4238
4287
|
You are free to draw anything you like on the canvas.
|
|
4239
4288
|
*/
|
|
4240
|
-
var _a, _b, _c
|
|
4289
|
+
var _a, _b, _c;
|
|
4241
4290
|
const {
|
|
4242
4291
|
selectedFeatureIndex,
|
|
4243
4292
|
isInEditMode,
|
|
@@ -4249,9 +4298,8 @@ class MapDraw extends React.PureComponent {
|
|
|
4249
4298
|
this.textPositions = [];
|
|
4250
4299
|
this.mouseOverPolygonCoordinates = [];
|
|
4251
4300
|
this.mouseOverPolygonFeatureIndex = -1;
|
|
4252
|
-
|
|
4253
|
-
|
|
4254
|
-
const feature = this.geojson.features[featureIndex];
|
|
4301
|
+
const drawFeature = (feature, featureIndex) => {
|
|
4302
|
+
var _a, _b, _c;
|
|
4255
4303
|
const featureType = feature.geometry.type;
|
|
4256
4304
|
const totalmiddle = {
|
|
4257
4305
|
x: 0,
|
|
@@ -4263,7 +4311,7 @@ class MapDraw extends React.PureComponent {
|
|
|
4263
4311
|
const XYCoords = getPixelCoordFromGeoCoord([featureCoords], mapId);
|
|
4264
4312
|
if (XYCoords.length === 0) {
|
|
4265
4313
|
// eslint-disable-next-line no-continue
|
|
4266
|
-
|
|
4314
|
+
return;
|
|
4267
4315
|
}
|
|
4268
4316
|
for (let j = 0; j < XYCoords.length; j += 1) {
|
|
4269
4317
|
this.drawPoint(ctx, XYCoords[j], this.mouseIsOverVertexNr === j && selectedFeatureIndex === featureIndex, false, isInEditMode && selectedFeatureIndex === featureIndex, feature, featureIndex);
|
|
@@ -4273,8 +4321,7 @@ class MapDraw extends React.PureComponent {
|
|
|
4273
4321
|
const featureCoords = feature.geometry.coordinates;
|
|
4274
4322
|
const XYCoords = getPixelCoordFromGeoCoord(featureCoords, mapId);
|
|
4275
4323
|
if (XYCoords.length === 0) {
|
|
4276
|
-
|
|
4277
|
-
continue;
|
|
4324
|
+
return;
|
|
4278
4325
|
}
|
|
4279
4326
|
for (let j = 0; j < XYCoords.length; j += 1) {
|
|
4280
4327
|
this.drawPoint(ctx, XYCoords[j], this.mouseIsOverVertexNr === j && selectedFeatureIndex === featureIndex, false, isInEditMode && selectedFeatureIndex === featureIndex, feature, featureIndex);
|
|
@@ -4312,7 +4359,7 @@ class MapDraw extends React.PureComponent {
|
|
|
4312
4359
|
if (totalmiddle.nr > 0) {
|
|
4313
4360
|
const mx = totalmiddle.x / totalmiddle.nr;
|
|
4314
4361
|
const my = totalmiddle.y / totalmiddle.nr;
|
|
4315
|
-
if ((
|
|
4362
|
+
if ((_a = feature.properties) === null || _a === void 0 ? void 0 : _a.text) {
|
|
4316
4363
|
this.textPositions.push({
|
|
4317
4364
|
x: mx,
|
|
4318
4365
|
y: my,
|
|
@@ -4333,7 +4380,7 @@ class MapDraw extends React.PureComponent {
|
|
|
4333
4380
|
continue;
|
|
4334
4381
|
}
|
|
4335
4382
|
const middle = this.drawPolygon(ctx, XYCoords, featureIndex, polygonIndex);
|
|
4336
|
-
if (middle && ((
|
|
4383
|
+
if (middle && ((_b = feature.properties) === null || _b === void 0 ? void 0 : _b.text)) {
|
|
4337
4384
|
this.textPositions.push({
|
|
4338
4385
|
x: middle.x,
|
|
4339
4386
|
y: middle.y,
|
|
@@ -4359,17 +4406,15 @@ class MapDraw extends React.PureComponent {
|
|
|
4359
4406
|
/* Loop through all line pints of the same feature */
|
|
4360
4407
|
const featureCoords = feature.geometry.coordinates;
|
|
4361
4408
|
if (!featureCoords || !featureCoords.length) {
|
|
4362
|
-
|
|
4363
|
-
continue;
|
|
4409
|
+
return;
|
|
4364
4410
|
}
|
|
4365
4411
|
const XYCoords = getPixelCoordFromGeoCoord(featureCoords, mapId);
|
|
4366
4412
|
/* Only draw if there is stuff to show */
|
|
4367
4413
|
if (XYCoords.length === 0) {
|
|
4368
|
-
|
|
4369
|
-
continue;
|
|
4414
|
+
return;
|
|
4370
4415
|
}
|
|
4371
4416
|
const middle = this.drawLine(ctx, XYCoords, featureIndex, 0);
|
|
4372
|
-
if (middle && ((
|
|
4417
|
+
if (middle && ((_c = feature.properties) === null || _c === void 0 ? void 0 : _c.text)) {
|
|
4373
4418
|
this.textPositions.push({
|
|
4374
4419
|
x: middle.x,
|
|
4375
4420
|
y: middle.y,
|
|
@@ -4383,7 +4428,17 @@ class MapDraw extends React.PureComponent {
|
|
|
4383
4428
|
}
|
|
4384
4429
|
}
|
|
4385
4430
|
}
|
|
4431
|
+
};
|
|
4432
|
+
/* Draw all features */
|
|
4433
|
+
for (let featureIndex = 0; featureIndex < this.geojson.features.length; featureIndex += 1) {
|
|
4434
|
+
const feature = this.geojson.features[featureIndex];
|
|
4435
|
+
/* Do not draw selected feature here, should be done last */
|
|
4436
|
+
if (featureIndex !== selectedFeatureIndex) {
|
|
4437
|
+
drawFeature(feature, featureIndex);
|
|
4438
|
+
}
|
|
4386
4439
|
}
|
|
4440
|
+
/* Draw selected feature to display it on top */
|
|
4441
|
+
drawFeature(this.getSelectedFeature(), selectedFeatureIndex);
|
|
4387
4442
|
/* Higlight polygon with mousehover */
|
|
4388
4443
|
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
4444
|
const feature = this.getSelectedFeature();
|
|
@@ -4417,6 +4472,29 @@ class MapDraw extends React.PureComponent {
|
|
|
4417
4472
|
ctx.font = '12px Arial';
|
|
4418
4473
|
ctx.fillText(text, x, y);
|
|
4419
4474
|
}
|
|
4475
|
+
/* Draw hovered feature */
|
|
4476
|
+
if (this.featureEvent) {
|
|
4477
|
+
const {
|
|
4478
|
+
feature,
|
|
4479
|
+
featureIndex,
|
|
4480
|
+
screenCoords
|
|
4481
|
+
} = this.featureEvent;
|
|
4482
|
+
const drawFunctionId = (_c = feature === null || feature === void 0 ? void 0 : feature.properties) === null || _c === void 0 ? void 0 : _c.hoverDrawFunctionId;
|
|
4483
|
+
const drawFunction = getDrawFunctionFromStore(drawFunctionId);
|
|
4484
|
+
if (drawFunction) {
|
|
4485
|
+
drawFunction({
|
|
4486
|
+
context: ctx,
|
|
4487
|
+
featureIndex,
|
|
4488
|
+
isInEditMode,
|
|
4489
|
+
feature,
|
|
4490
|
+
isHovered: true,
|
|
4491
|
+
coord: screenCoords,
|
|
4492
|
+
selected: featureIndex === selectedFeatureIndex,
|
|
4493
|
+
mouseX: 0,
|
|
4494
|
+
mouseY: 0
|
|
4495
|
+
});
|
|
4496
|
+
}
|
|
4497
|
+
}
|
|
4420
4498
|
}
|
|
4421
4499
|
/* Checks if mouse is in proximity of given coordinate */
|
|
4422
4500
|
checkDist(coord, polygonIndex, mouseX, mouseY) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@opengeoweb/webmap-react",
|
|
3
|
-
"version": "9.
|
|
3
|
+
"version": "9.21.0",
|
|
4
4
|
"description": "GeoWeb react wrapper for webmap",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"repository": {
|
|
@@ -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.
|
|
23
|
-
"react-i18next": "^
|
|
22
|
+
"i18next": "^23.11.5",
|
|
23
|
+
"react-i18next": "^14.1.2"
|
|
24
24
|
},
|
|
25
25
|
"peerDependencies": {
|
|
26
26
|
"react": "18"
|
|
@@ -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;
|