@evergis/react 3.1.0 → 3.1.2

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 (87) hide show
  1. package/dist/components/ErrorBoundary/index.d.ts +12 -0
  2. package/dist/components/ErrorBoundary/styled.d.ts +1 -0
  3. package/dist/components/ErrorBoundary/types.d.ts +7 -0
  4. package/dist/components/Map/Map.d.ts +5 -0
  5. package/dist/components/Map/components/BuildingsLayer/BuildingsLayer.d.ts +3 -0
  6. package/dist/components/Map/components/BuildingsLayer/index.d.ts +2 -0
  7. package/dist/components/Map/components/BuildingsLayer/types.d.ts +4 -0
  8. package/dist/components/Map/components/Layer/Layer.d.ts +3 -0
  9. package/dist/components/Map/components/Layer/RasterLayer.d.ts +3 -0
  10. package/dist/components/Map/components/Layer/VectorLayer.d.ts +3 -0
  11. package/dist/components/Map/components/Layer/constants.d.ts +137 -0
  12. package/dist/components/Map/components/Layer/index.d.ts +2 -0
  13. package/dist/components/Map/components/Layer/types.d.ts +12 -0
  14. package/dist/components/Map/components/Layer/utils/getClientStyleItemPrefixSuffix.d.ts +3 -0
  15. package/dist/components/Map/components/index.d.ts +2 -0
  16. package/dist/components/Map/index.d.ts +3 -0
  17. package/dist/components/Map/styled.d.ts +4 -0
  18. package/dist/components/Map/types.d.ts +10 -0
  19. package/dist/components/MapContext/MapContext.d.ts +2 -0
  20. package/dist/components/MapContext/MapProvider.d.ts +3 -0
  21. package/dist/components/MapContext/index.d.ts +3 -0
  22. package/dist/components/MapContext/types.d.ts +138 -0
  23. package/dist/components/ResizablePanel/ResizablePanel.d.ts +3 -0
  24. package/dist/components/ResizablePanel/index.d.ts +2 -0
  25. package/dist/components/ResizablePanel/styled.d.ts +11 -0
  26. package/dist/components/ResizablePanel/types.d.ts +14 -0
  27. package/dist/components/ServerNotificationsContext/ServerNotificationsContext.d.ts +2 -0
  28. package/dist/components/ServerNotificationsContext/ServerNotificationsProvider.d.ts +3 -0
  29. package/dist/components/ServerNotificationsContext/index.d.ts +3 -0
  30. package/dist/components/ServerNotificationsContext/types.d.ts +12 -0
  31. package/dist/components/index.d.ts +5 -0
  32. package/dist/core/classification/findAttributeInExpression.d.ts +2 -0
  33. package/dist/core/classification/getActualExtrusionHeight.d.ts +2 -0
  34. package/dist/core/classification/index.d.ts +3 -0
  35. package/dist/core/classification/parseClientStyle.d.ts +2 -0
  36. package/dist/core/feature/convertSpToTurfFeature.d.ts +3 -0
  37. package/dist/core/feature/index.d.ts +1 -0
  38. package/dist/core/geometrySelection/drawModeToGeometrySelectionType.d.ts +3 -0
  39. package/dist/core/geometrySelection/getGeometrySelectionTurfFeature.d.ts +3 -0
  40. package/dist/core/geometrySelection/index.d.ts +2 -0
  41. package/dist/core/index.d.ts +4 -0
  42. package/dist/core/types/index.d.ts +2 -0
  43. package/dist/core/types/map.d.ts +5 -0
  44. package/dist/core/types/styling.d.ts +15 -0
  45. package/dist/hooks/index.d.ts +4 -0
  46. package/dist/hooks/map/index.d.ts +22 -0
  47. package/dist/hooks/map/useCurrentSelectedFeature.d.ts +2 -0
  48. package/dist/hooks/map/useEditingFeature.d.ts +1 -0
  49. package/dist/hooks/map/useEwktGeometry.d.ts +1 -0
  50. package/dist/hooks/map/useGeometryEditor.d.ts +2 -0
  51. package/dist/hooks/map/useGeometrySelection.d.ts +2 -0
  52. package/dist/hooks/map/useGeometrySelectionBuffer.d.ts +1 -0
  53. package/dist/hooks/map/useMapContext.d.ts +1 -0
  54. package/dist/hooks/map/useMapDraw/customModes.d.ts +2 -0
  55. package/dist/hooks/map/useMapDraw/customStyles.d.ts +58 -0
  56. package/dist/hooks/map/useMapDraw/index.d.ts +1 -0
  57. package/dist/hooks/map/useRedrawLayer.d.ts +1 -0
  58. package/dist/hooks/map/useSelectFeaturesCount.d.ts +1 -0
  59. package/dist/hooks/map/useSelectFeaturesCurrentIndex.d.ts +1 -0
  60. package/dist/hooks/map/useSelectFeaturesGeometryMasking.d.ts +1 -0
  61. package/dist/hooks/map/useSelectFeaturesInitialized.d.ts +1 -0
  62. package/dist/hooks/map/useSelectFeaturesLayerName.d.ts +1 -0
  63. package/dist/hooks/map/useSelectFeaturesPagination.d.ts +4 -0
  64. package/dist/hooks/map/useSelectFeaturesStatisticsActive.d.ts +1 -0
  65. package/dist/hooks/map/useSelectFeaturesTotalCounts.d.ts +1 -0
  66. package/dist/hooks/map/useSelectedFeatures.d.ts +2 -0
  67. package/dist/hooks/map/useUpdateCurrentFeature.d.ts +2 -0
  68. package/dist/hooks/map/useZoomToFeatures.d.ts +2 -0
  69. package/dist/hooks/map/useZoomToLayer.d.ts +7 -0
  70. package/dist/hooks/map/useZoomToPoint.d.ts +1 -0
  71. package/dist/hooks/serverNotifications/index.d.ts +2 -0
  72. package/dist/hooks/serverNotifications/useServerNotifications.d.ts +2 -0
  73. package/dist/hooks/serverNotifications/useServerNotificationsContext.d.ts +1 -0
  74. package/dist/hooks/useResizer.d.ts +28 -0
  75. package/dist/hooks/useToggle.d.ts +1 -0
  76. package/dist/index.d.ts +1 -0
  77. package/dist/jest.config.d.ts +11 -0
  78. package/dist/react.cjs.development.js +814 -0
  79. package/dist/react.cjs.development.js.map +1 -1
  80. package/dist/react.cjs.production.min.js +1 -1
  81. package/dist/react.cjs.production.min.js.map +1 -1
  82. package/dist/react.esm.js +783 -1
  83. package/dist/react.esm.js.map +1 -1
  84. package/dist/utils/date.d.ts +2 -2
  85. package/dist/utils/geometryToWkt.d.ts +2 -0
  86. package/dist/utils/index.d.ts +1 -0
  87. package/package.json +30 -23
package/dist/react.esm.js CHANGED
@@ -1,4 +1,208 @@
1
+ import { isEmpty, isNil } from 'lodash-es';
2
+ import { GeometryType } from '@evergis/api';
3
+ import { polygon, multiLineString, multiPoint, point, bbox, toWgs84, lineString, toMercator } from '@turf/turf';
4
+ import { useContext, useMemo, createContext, useCallback, useEffect, useRef, useState, useLayoutEffect } from 'react';
5
+ import 'styled-components';
6
+ import 'react-map-gl/mapbox';
7
+ import '@mapbox/mapbox-gl-draw/dist/mapbox-gl-draw.css';
8
+ import 'find-and';
1
9
  import { isValid, toDate, format, parseJSON, parseISO } from 'date-fns';
10
+ import { stringify } from 'wkt';
11
+ import MapboxDraw from '@mapbox/mapbox-gl-draw';
12
+ import { HubConnectionBuilder, LogLevel } from '@microsoft/signalr';
13
+ import 'mapbox-gl/dist/mapbox-gl.css';
14
+
15
+ const findAttributeInExpression = expression => {
16
+ if (Array.isArray(expression) && expression.length === 2 && expression[0] === "get") {
17
+ return [expression[1]];
18
+ }
19
+
20
+ return expression.reduce((acc, curr) => {
21
+ if (!Array.isArray(curr)) {
22
+ return acc;
23
+ }
24
+
25
+ if (curr[0] === "get") {
26
+ return [...new Set([...acc, curr[1]])];
27
+ }
28
+
29
+ return [...new Set([...acc, ...findAttributeInExpression(curr)])];
30
+ }, []);
31
+ };
32
+
33
+ const getActualExtrusionHeight = paint => {
34
+ return Array.isArray(paint == null ? void 0 : paint["fill-extrusion-height"]) && (paint == null ? void 0 : paint["fill-extrusion-height"][0]) === "+" ? paint == null ? void 0 : paint["fill-extrusion-height"][1] : paint == null ? void 0 : paint["fill-extrusion-height"];
35
+ };
36
+
37
+ const parseClientStyle = style => {
38
+ var _style$items;
39
+
40
+ if (!style) {
41
+ return [];
42
+ }
43
+
44
+ return style == null || (_style$items = style.items) == null ? void 0 : _style$items.reduce((acc, curr) => {
45
+ var _Object$entries;
46
+
47
+ if (!curr.paint || isEmpty(curr.paint)) {
48
+ return acc;
49
+ }
50
+
51
+ return (_Object$entries = Object.entries(curr.paint)) == null ? void 0 : _Object$entries.reduce((paintAcc, _ref) => {
52
+ let [, value] = _ref;
53
+
54
+ if (!Array.isArray(value)) {
55
+ return paintAcc;
56
+ }
57
+
58
+ return [...new Set([...paintAcc, ...findAttributeInExpression(value)])];
59
+ }, []);
60
+ }, []);
61
+ };
62
+
63
+ const convertSpToTurfFeature = geometry => {
64
+ if (!geometry) {
65
+ return;
66
+ }
67
+
68
+ switch (geometry.type) {
69
+ case GeometryType.Point:
70
+ return point(geometry.coordinates);
71
+
72
+ case GeometryType.Multipoint:
73
+ return multiPoint(geometry.coordinates);
74
+
75
+ case GeometryType.Polyline:
76
+ return multiLineString(geometry.coordinates);
77
+
78
+ case GeometryType.Polygon:
79
+ case GeometryType.Envelope:
80
+ return polygon(geometry.coordinates);
81
+ }
82
+ };
83
+
84
+ function _extends() {
85
+ _extends = Object.assign || function (target) {
86
+ for (var i = 1; i < arguments.length; i++) {
87
+ var source = arguments[i];
88
+
89
+ for (var key in source) {
90
+ if (Object.prototype.hasOwnProperty.call(source, key)) {
91
+ target[key] = source[key];
92
+ }
93
+ }
94
+ }
95
+
96
+ return target;
97
+ };
98
+
99
+ return _extends.apply(this, arguments);
100
+ }
101
+
102
+ const useMapContext = () => {
103
+ return useContext(MapContext);
104
+ };
105
+
106
+ const useCurrentSelectedFeature = () => {
107
+ const {
108
+ selectFeatures
109
+ } = useMapContext();
110
+ return useMemo(() => {
111
+ var _selectFeatures$featu;
112
+
113
+ return (_selectFeatures$featu = selectFeatures.features) == null || (_selectFeatures$featu = _selectFeatures$featu[selectFeatures.layerName]) == null ? void 0 : _selectFeatures$featu.find(item => item.id === selectFeatures.currentId);
114
+ }, [selectFeatures]);
115
+ };
116
+
117
+ const MapContext = /*#__PURE__*/createContext({});
118
+
119
+ var BaseMapTheme;
120
+
121
+ (function (BaseMapTheme) {
122
+ BaseMapTheme["Light"] = "light";
123
+ BaseMapTheme["Dark"] = "dark";
124
+ })(BaseMapTheme || (BaseMapTheme = {}));
125
+
126
+ var GeometrySelectionTypes;
127
+
128
+ (function (GeometrySelectionTypes) {
129
+ GeometrySelectionTypes["Point"] = "select_point";
130
+ GeometrySelectionTypes["Line"] = "select_line";
131
+ GeometrySelectionTypes["Circle"] = "select_circle";
132
+ GeometrySelectionTypes["Rect"] = "select_rect";
133
+ GeometrySelectionTypes["Polygon"] = "select_polygon";
134
+ GeometrySelectionTypes["Zones"] = "zones_selection";
135
+ GeometrySelectionTypes["Coordinates"] = "xy";
136
+ GeometrySelectionTypes["Route"] = "selection_route";
137
+ })(GeometrySelectionTypes || (GeometrySelectionTypes = {}));
138
+
139
+ var GeometrySelectionToolTypes;
140
+
141
+ (function (GeometrySelectionToolTypes) {
142
+ GeometrySelectionToolTypes["Replace"] = "Replace";
143
+ GeometrySelectionToolTypes["Unite"] = "Unite";
144
+ GeometrySelectionToolTypes["Crop"] = "Crop";
145
+ GeometrySelectionToolTypes["Edit"] = "Edit";
146
+ })(GeometrySelectionToolTypes || (GeometrySelectionToolTypes = {}));
147
+
148
+ var GeometrySelectionZoneTypes;
149
+
150
+ (function (GeometrySelectionZoneTypes) {
151
+ GeometrySelectionZoneTypes["Walking"] = "Walking";
152
+ GeometrySelectionZoneTypes["Car"] = "Car";
153
+ })(GeometrySelectionZoneTypes || (GeometrySelectionZoneTypes = {}));
154
+
155
+ var GeometrySelectionRouteTypes;
156
+
157
+ (function (GeometrySelectionRouteTypes) {
158
+ GeometrySelectionRouteTypes["Walking"] = "Walking";
159
+ GeometrySelectionRouteTypes["Car"] = "Car";
160
+ })(GeometrySelectionRouteTypes || (GeometrySelectionRouteTypes = {}));
161
+
162
+ var GeometryEditorMode;
163
+
164
+ (function (GeometryEditorMode) {
165
+ GeometryEditorMode[GeometryEditorMode["Create"] = 0] = "Create";
166
+ GeometryEditorMode[GeometryEditorMode["Edit"] = 1] = "Edit";
167
+ GeometryEditorMode[GeometryEditorMode["Transform"] = 2] = "Transform";
168
+ GeometryEditorMode[GeometryEditorMode["Expand"] = 3] = "Expand";
169
+ GeometryEditorMode[GeometryEditorMode["Unite"] = 4] = "Unite";
170
+ GeometryEditorMode[GeometryEditorMode["Subtract"] = 5] = "Subtract";
171
+ })(GeometryEditorMode || (GeometryEditorMode = {}));
172
+
173
+ const useGeometryEditor = () => {
174
+ const {
175
+ geometryEditor,
176
+ setGeometryEditor
177
+ } = useMapContext();
178
+ const update = useCallback(newState => {
179
+ setGeometryEditor(prevState => _extends({}, prevState, newState));
180
+ }, [setGeometryEditor]);
181
+ return [geometryEditor, update];
182
+ };
183
+
184
+ const useEditingFeature = () => {
185
+ const [{
186
+ layerName,
187
+ active,
188
+ mode
189
+ }] = useGeometryEditor();
190
+ const currentSelectedFeature = useCurrentSelectedFeature();
191
+ return useMemo(() => {
192
+ return active && (mode === GeometryEditorMode.Edit && layerName === (currentSelectedFeature == null ? void 0 : currentSelectedFeature.layer) || mode === GeometryEditorMode.Create);
193
+ }, [active, currentSelectedFeature, layerName, mode]);
194
+ };
195
+
196
+ const useGeometrySelection = () => {
197
+ const {
198
+ geometrySelection,
199
+ setGeometrySelection
200
+ } = useMapContext();
201
+ const updateGeometrySelection = useCallback(newState => {
202
+ setGeometrySelection(prevState => _extends({}, prevState, newState));
203
+ }, [setGeometrySelection]);
204
+ return [geometrySelection, updateGeometrySelection];
205
+ };
2
206
 
3
207
  const NO_CONTENT_VALUE = "—";
4
208
  var DateFormat;
@@ -43,11 +247,589 @@ const formatDate = function formatDate(date, _temp) {
43
247
  return defaultValue.toString();
44
248
  };
45
249
 
250
+ const geometryToWkt = function geometryToWkt(features) {
251
+ if (features === void 0) {
252
+ features = [];
253
+ }
254
+
255
+ if (features.length === 0) {
256
+ return "";
257
+ }
258
+
259
+ return stringify(features[0]);
260
+ };
261
+
46
262
  const isNumeric = number => !isNaN(parseFloat(number)) && isFinite(number);
47
263
 
48
264
  function isObject(value) {
49
265
  return typeof value === "object" && value !== null && !Array.isArray(value);
50
266
  }
51
267
 
52
- export { DateFormat, NO_CONTENT_VALUE, formatDate, getDate, isNumeric, isObject };
268
+ const useEwktGeometry = () => {
269
+ const [{
270
+ history,
271
+ type
272
+ }] = useGeometrySelection();
273
+ return useMemo(() => {
274
+ var _history$zones$histor, _history$zones$histor2;
275
+
276
+ if (history.step === -1) {
277
+ return "";
278
+ }
279
+
280
+ return type === GeometrySelectionTypes.Zones ? !isEmpty((_history$zones$histor = history.zones[history.step]) == null ? void 0 : _history$zones$histor[0]) ? "SRID=3857;" + geometryToWkt((_history$zones$histor2 = history.zones[history.step]) == null ? void 0 : _history$zones$histor2[0]) : "SRID=3857;" + geometryToWkt(history.features[history.step]) : "SRID=3857;" + geometryToWkt(history.features[history.step]);
281
+ }, [history.features, history.step, history.zones, type]);
282
+ };
283
+
284
+ const useGeometrySelectionBuffer = () => {
285
+ const [{
286
+ settings: {
287
+ bufferRadius,
288
+ bufferMultiplier
289
+ },
290
+ isBuffer
291
+ }] = useGeometrySelection();
292
+ return useMemo(() => {
293
+ if (!isBuffer || !bufferRadius) {
294
+ return undefined;
295
+ }
296
+
297
+ return Number((+bufferRadius || 0) * +bufferMultiplier).toFixed(2);
298
+ }, [isBuffer, bufferRadius, bufferMultiplier]);
299
+ };
300
+
301
+ const customModes = MapboxDraw.modes;
302
+ const StaticMode = {};
303
+
304
+ StaticMode.onSetup = function () {
305
+ this.setActionableState(undefined);
306
+ return {};
307
+ };
308
+
309
+ StaticMode.toDisplayFeatures = function (state, geojson, display) {
310
+ display(geojson);
311
+ };
312
+
313
+ customModes.static = StaticMode;
314
+
315
+ const customStyles = [{
316
+ id: "gl-draw-point",
317
+ type: "circle",
318
+ filter: ["all", ["==", "$type", "Point"]],
319
+ paint: {
320
+ "circle-radius": 5,
321
+ "circle-color": "#D20C0C",
322
+ "circle-stroke-color": "#FFFFFF",
323
+ "circle-stroke-width": 3,
324
+ "circle-stroke-opacity": 0.3
325
+ }
326
+ }, {
327
+ id: "highlight-inactive-points",
328
+ type: "circle",
329
+ filter: ["all", ["==", "$type", "Point"], ["==", "meta", "feature"], ["==", "active", "false"]],
330
+ paint: {
331
+ "circle-radius": 5,
332
+ "circle-color": "#D20C0C",
333
+ "circle-stroke-color": "#FFFFFF",
334
+ "circle-stroke-width": 3,
335
+ "circle-stroke-opacity": 0.3
336
+ }
337
+ }, {
338
+ id: "highlight-active-points",
339
+ type: "circle",
340
+ filter: ["all", ["==", "$type", "Point"], ["==", "meta", "feature"], ["==", "active", "true"]],
341
+ paint: {
342
+ "circle-radius": 3,
343
+ "circle-color": "#fbb03b",
344
+ "circle-stroke-color": "#FFFFFF",
345
+ "circle-stroke-width": 1,
346
+ "circle-stroke-opacity": 0.3
347
+ }
348
+ }, {
349
+ id: "gl-draw-polygon-fill-static",
350
+ type: "fill",
351
+ filter: ["all", ["==", "$type", "Polygon"]],
352
+ paint: {
353
+ "fill-color": "#D20C0C",
354
+ "fill-outline-color": "#D20C0C",
355
+ "fill-opacity": 0.1
356
+ }
357
+ }, {
358
+ id: "gl-draw-line",
359
+ type: "line",
360
+ filter: ["all", ["==", "$type", "LineString"]],
361
+ layout: {
362
+ "line-cap": "round",
363
+ "line-join": "round"
364
+ },
365
+ paint: {
366
+ "line-color": "#D20C0C",
367
+ "line-dasharray": [0.2, 2],
368
+ "line-width": 2
369
+ }
370
+ }, {
371
+ id: "gl-draw-polygon-fill",
372
+ type: "fill",
373
+ filter: ["all", ["==", "$type", "Polygon"]],
374
+ paint: {
375
+ "fill-color": "#D20C0C",
376
+ "fill-outline-color": "#D20C0C",
377
+ "fill-opacity": 0.1
378
+ }
379
+ }, {
380
+ id: "gl-draw-polygon-midpoint",
381
+ type: "circle",
382
+ filter: ["all", ["==", "$type", "Point"], ["==", "meta", "midpoint"]],
383
+ paint: {
384
+ "circle-radius": 3,
385
+ "circle-color": "#fbb03b",
386
+ "circle-stroke-color": "#FFFFFF",
387
+ "circle-stroke-width": 1,
388
+ "circle-stroke-opacity": 0.3
389
+ }
390
+ }, {
391
+ id: "gl-draw-polygon-stroke-active",
392
+ type: "line",
393
+ filter: ["all", ["==", "$type", "Polygon"]],
394
+ layout: {
395
+ "line-cap": "round",
396
+ "line-join": "round"
397
+ },
398
+ paint: {
399
+ "line-color": "#D20C0C",
400
+ "line-dasharray": [0.2, 2],
401
+ "line-width": 2
402
+ }
403
+ }, {
404
+ id: "gl-draw-polygon-and-line-vertex-active",
405
+ type: "circle",
406
+ filter: ["all", ["==", "meta", "vertex"], ["==", "$type", "Point"]],
407
+ paint: {
408
+ "circle-radius": 3,
409
+ "circle-color": "#D20C0C",
410
+ "circle-stroke-color": "#FFFFFF",
411
+ "circle-stroke-width": 3,
412
+ "circle-stroke-opacity": 0.3
413
+ }
414
+ }];
415
+
416
+ const draw = /*#__PURE__*/new MapboxDraw({
417
+ displayControlsDefault: false,
418
+ styles: customStyles,
419
+ modes: customModes,
420
+ defaultMode: "draw_point",
421
+ controls: {
422
+ trash: true
423
+ }
424
+ });
425
+ const useMapDraw = function useMapDraw(triggerDeps) {
426
+ if (triggerDeps === void 0) {
427
+ triggerDeps = [];
428
+ }
429
+
430
+ const {
431
+ map,
432
+ draw: drawContext,
433
+ loaded,
434
+ basemapName
435
+ } = useMapContext();
436
+ useEffect(() => {
437
+ if (!loaded || !map.current) {
438
+ return;
439
+ }
440
+
441
+ drawContext.current = draw;
442
+ map.current.addControl(drawContext.current);
443
+ }, [loaded]); // eslint-disable-line
444
+
445
+ useEffect(() => {
446
+ if (map.current && map.current.hasControl(drawContext.current)) {
447
+ map.current.removeControl(drawContext.current);
448
+ map.current.addControl(drawContext.current);
449
+ }
450
+ }, [basemapName, ...triggerDeps]); // eslint-disable-line
451
+ };
452
+
453
+ const useRedrawLayer = () => {
454
+ const {
455
+ map
456
+ } = useMapContext();
457
+ return useCallback(layerName => {
458
+ const layerTileSource = map.current.getSource(layerName);
459
+ layerTileSource.setTiles(layerTileSource.tiles);
460
+ }, [map]);
461
+ };
462
+
463
+ const useSelectedFeatures = () => {
464
+ var _selectFeatures$featu;
465
+
466
+ const {
467
+ selectFeatures,
468
+ setSelectedFeatures
469
+ } = useMapContext();
470
+ const updatSelectedFeatures = useCallback(features => {
471
+ setSelectedFeatures(features);
472
+ }, [setSelectedFeatures]);
473
+ return [(_selectFeatures$featu = selectFeatures.features) != null ? _selectFeatures$featu : {}, updatSelectedFeatures];
474
+ };
475
+
476
+ const useSelectFeaturesCount = () => {
477
+ const {
478
+ selectFeatures
479
+ } = useMapContext();
480
+ return useMemo(() => {
481
+ var _selectFeatures$featu, _selectFeatures$featu2;
482
+
483
+ return (_selectFeatures$featu = (_selectFeatures$featu2 = selectFeatures.features) == null || (_selectFeatures$featu2 = _selectFeatures$featu2[selectFeatures.layerName]) == null ? void 0 : _selectFeatures$featu2.length) != null ? _selectFeatures$featu : 0;
484
+ }, [selectFeatures]);
485
+ };
486
+
487
+ const useSelectFeaturesCurrentIndex = () => {
488
+ const {
489
+ selectFeatures
490
+ } = useMapContext();
491
+ return useMemo(() => {
492
+ var _selectFeatures$featu, _selectFeatures$featu2;
493
+
494
+ return (_selectFeatures$featu = selectFeatures.features) != null && (_selectFeatures$featu = _selectFeatures$featu[selectFeatures.layerName]) != null && _selectFeatures$featu.length ? (_selectFeatures$featu2 = selectFeatures.features) == null || (_selectFeatures$featu2 = _selectFeatures$featu2[selectFeatures.layerName]) == null ? void 0 : _selectFeatures$featu2.findIndex(feature => feature.id === selectFeatures.currentId) : -1;
495
+ }, [selectFeatures]);
496
+ };
497
+
498
+ const useSelectFeaturesGeometryMasking = () => {
499
+ const {
500
+ selectFeatures,
501
+ setSelectFeaturesGeometryMasking
502
+ } = useMapContext();
503
+ const update = useCallback(state => {
504
+ setSelectFeaturesGeometryMasking(state);
505
+ }, [setSelectFeaturesGeometryMasking]);
506
+ return [selectFeatures.geometryMasking, update];
507
+ };
508
+
509
+ const useSelectFeaturesInitialized = () => {
510
+ const {
511
+ selectFeatures,
512
+ setSelectFeaturesInitialized
513
+ } = useMapContext();
514
+ const update = useCallback(state => {
515
+ setSelectFeaturesInitialized(state);
516
+ }, [setSelectFeaturesInitialized]);
517
+ return [selectFeatures.initialized, update];
518
+ };
519
+
520
+ const useSelectFeaturesLayerName = () => {
521
+ const {
522
+ selectFeatures,
523
+ setSelectFeaturesLayerName
524
+ } = useMapContext();
525
+ const update = useCallback(name => {
526
+ setSelectFeaturesLayerName(name);
527
+ }, [setSelectFeaturesLayerName]);
528
+ return [selectFeatures.layerName, update];
529
+ };
530
+
531
+ const useSelectFeaturesPagination = () => {
532
+ const {
533
+ setNextFeature,
534
+ setPrevFeature
535
+ } = useMapContext();
536
+ const onNext = useCallback(() => {
537
+ setNextFeature();
538
+ }, [setNextFeature]);
539
+ const onPrev = useCallback(() => {
540
+ setPrevFeature();
541
+ }, [setPrevFeature]);
542
+ return {
543
+ onNext,
544
+ onPrev
545
+ };
546
+ };
547
+
548
+ const useSelectFeaturesStatisticsActive = () => {
549
+ const {
550
+ selectFeatures,
551
+ setSelectFeaturesStatisticsActive
552
+ } = useMapContext();
553
+ const update = useCallback(state => {
554
+ setSelectFeaturesStatisticsActive(state);
555
+ }, [setSelectFeaturesStatisticsActive]);
556
+ return [selectFeatures.statisticsActive, update];
557
+ };
558
+
559
+ const useSelectFeaturesTotalCounts = () => {
560
+ var _selectFeatures$total;
561
+
562
+ const {
563
+ selectFeatures,
564
+ setSelectedFeaturesTotalCounts
565
+ } = useMapContext();
566
+ const update = useCallback(totalCounts => {
567
+ setSelectedFeaturesTotalCounts(totalCounts);
568
+ }, [setSelectedFeaturesTotalCounts]);
569
+ return [(_selectFeatures$total = selectFeatures.totalCounts) != null ? _selectFeatures$total : {}, update];
570
+ };
571
+
572
+ const useUpdateCurrentFeature = () => {
573
+ const {
574
+ updateCurrentFeature
575
+ } = useMapContext();
576
+ return useCallback(values => {
577
+ updateCurrentFeature(values);
578
+ }, [updateCurrentFeature]);
579
+ };
580
+
581
+ const useZoomToFeatures = () => {
582
+ const {
583
+ map
584
+ } = useMapContext();
585
+ return useCallback((features, padding) => {
586
+ if (!features) {
587
+ return;
588
+ }
589
+
590
+ const currentFeatureCenter = bbox({
591
+ type: "FeatureCollection",
592
+ features: features.map(feature => convertSpToTurfFeature(feature.geometry))
593
+ });
594
+ map.current.fitBounds(currentFeatureCenter, {
595
+ padding: padding != null ? padding : 150
596
+ });
597
+ }, [map]);
598
+ };
599
+
600
+ const DEFAULT_PADDING = 50;
601
+ const useZoomToLayer = () => {
602
+ const {
603
+ map
604
+ } = useMapContext();
605
+ return useCallback(async (bulkExtent, options) => {
606
+ var _options$padding;
607
+
608
+ if (!bulkExtent || !bulkExtent.overall) {
609
+ return;
610
+ }
611
+
612
+ map.current.fitBounds([...bulkExtent.overall.coordinates[0], ...bulkExtent.overall.coordinates[1]], {
613
+ padding: (_options$padding = options == null ? void 0 : options.padding) != null ? _options$padding : DEFAULT_PADDING
614
+ });
615
+ }, [map]);
616
+ };
617
+
618
+ const useZoomToPoint = () => {
619
+ const {
620
+ map
621
+ } = useMapContext();
622
+ return useCallback((options, callback) => {
623
+ if (map.current) {
624
+ if (callback) {
625
+ map.current.once("moveend", () => {
626
+ callback();
627
+ });
628
+ }
629
+
630
+ map.current.flyTo(options);
631
+ } else {
632
+ callback == null || callback();
633
+ }
634
+ }, [map]);
635
+ };
636
+
637
+ const useServerNotifications = (url, initialized) => {
638
+ const hubConnection = useRef(null);
639
+ const [connection, setConnection] = useState(null);
640
+ useEffect(() => {
641
+ if (!initialized) {
642
+ return;
643
+ }
644
+
645
+ hubConnection.current = new HubConnectionBuilder().withUrl(url, {
646
+ withCredentials: true
647
+ }).configureLogging(LogLevel.Information).build();
648
+ hubConnection.current.start().then(() => console.info("Серверные нотификации подключены")).catch(err => console.info("Ошибка:", err)).finally(() => setConnection(hubConnection.current));
649
+ }, [initialized]); // eslint-disable-line
650
+
651
+ useEffect(() => {
652
+ if (!connection || connection.state !== "Connected") {
653
+ return;
654
+ }
655
+
656
+ connection.invoke("SubscribeNotifications", []).then(() => console.info("Подписка `SubscribeNotifications` оформлена")).catch(err => console.info("Ошибка подписки `SubscribeNotifications`:", err));
657
+ }, [connection]);
658
+ return connection;
659
+ };
660
+
661
+ const ServerNotificationsContext = /*#__PURE__*/createContext({});
662
+
663
+ const useServerNotificationsContext = () => {
664
+ return useContext(ServerNotificationsContext);
665
+ };
666
+
667
+ var VerticalPosition;
668
+
669
+ (function (VerticalPosition) {
670
+ VerticalPosition["Top"] = "top";
671
+ VerticalPosition["Bottom"] = "bottom";
672
+ })(VerticalPosition || (VerticalPosition = {}));
673
+
674
+ var HorizontalPosition;
675
+
676
+ (function (HorizontalPosition) {
677
+ HorizontalPosition["Left"] = "left";
678
+ HorizontalPosition["Right"] = "right";
679
+ })(HorizontalPosition || (HorizontalPosition = {}));
680
+
681
+ const useResizer = (_ref) => {
682
+ let {
683
+ handleVerticalPosition,
684
+ handleHorizontalPosition,
685
+ minWidth = Number.MIN_SAFE_INTEGER,
686
+ maxWidth = Number.MAX_SAFE_INTEGER,
687
+ horizontal = true,
688
+ minHeight = Number.MIN_SAFE_INTEGER,
689
+ maxHeight = Number.MAX_SAFE_INTEGER,
690
+ vertical = true,
691
+ useResize = false,
692
+ onResize,
693
+ onResizeEnd,
694
+ onResizeStart
695
+ } = _ref;
696
+ const containerRef = useRef();
697
+ const verticalHandleRef = useRef();
698
+ const horizontalHandleRef = useRef();
699
+ const updateSizes = useCallback((width, height) => {
700
+ var _horizontalHandleRef$, _verticalHandleRef$cu;
701
+
702
+ let newWidth = width;
703
+ let newHeight = height;
704
+
705
+ if (horizontal && newWidth < minWidth) {
706
+ newWidth = minWidth;
707
+ }
708
+
709
+ if (horizontal && newWidth > Math.min(window.innerWidth - ((_horizontalHandleRef$ = horizontalHandleRef.current) == null ? void 0 : _horizontalHandleRef$.clientWidth), maxWidth)) {
710
+ newWidth = maxWidth;
711
+ }
712
+
713
+ if (vertical && newHeight < minHeight) {
714
+ newHeight = minHeight;
715
+ }
716
+
717
+ if (vertical && newHeight > Math.min(window.innerHeight - ((_verticalHandleRef$cu = verticalHandleRef.current) == null ? void 0 : _verticalHandleRef$cu.clientHeight), maxHeight)) {
718
+ newHeight = maxHeight;
719
+ }
720
+
721
+ if (horizontal) {
722
+ requestAnimationFrame(() => {
723
+ if (!isNil(containerRef.current)) {
724
+ containerRef.current.style.width = newWidth + "px";
725
+ }
726
+ });
727
+ }
728
+
729
+ if (vertical) {
730
+ requestAnimationFrame(() => {
731
+ if (!isNil(containerRef.current)) {
732
+ containerRef.current.style.height = newHeight + "px";
733
+ }
734
+ });
735
+ }
736
+
737
+ onResize == null || onResize(newWidth, newHeight);
738
+ }, [minWidth, maxWidth, minHeight, maxHeight, horizontal, vertical]);
739
+ const onPointerMove = useCallback(pointerMoveEvent => {
740
+ var _containerRef$current, _containerRef$current2, _containerRef$current3;
741
+
742
+ const {
743
+ x,
744
+ y
745
+ } = (_containerRef$current = containerRef.current) == null ? void 0 : _containerRef$current.getBoundingClientRect();
746
+ const reverseHorizontal = handleHorizontalPosition === HorizontalPosition.Right;
747
+ const reverseVertical = handleVerticalPosition === VerticalPosition.Bottom;
748
+ const newWidth = reverseHorizontal ? pointerMoveEvent.pageX - x : ((_containerRef$current2 = containerRef.current) == null ? void 0 : _containerRef$current2.offsetWidth) + x - pointerMoveEvent.pageX;
749
+ const newHeight = reverseVertical ? pointerMoveEvent.pageY - y : ((_containerRef$current3 = containerRef.current) == null ? void 0 : _containerRef$current3.offsetHeight) + y - pointerMoveEvent.pageY;
750
+ document.body.style.userSelect = "none";
751
+ updateSizes(newWidth, newHeight);
752
+ }, [updateSizes]);
753
+ const onPointerDown = useCallback(() => {
754
+ const onPointerUp = () => {
755
+ document.body.style.userSelect = "initial";
756
+ document.body.removeEventListener("pointermove", onPointerMove);
757
+
758
+ if (!isNil(containerRef.current)) {
759
+ onResizeEnd == null || onResizeEnd(containerRef.current.offsetWidth, containerRef.current.offsetHeight);
760
+ }
761
+ };
762
+
763
+ if (!isNil(containerRef.current)) {
764
+ onResizeStart == null || onResizeStart(containerRef.current.offsetWidth, containerRef.current.offsetHeight);
765
+ }
766
+
767
+ document.body.addEventListener("pointermove", onPointerMove);
768
+ document.body.addEventListener("pointerup", onPointerUp, {
769
+ once: true
770
+ });
771
+ }, [onPointerMove]); // eslint-disable-line
772
+
773
+ useLayoutEffect(() => {
774
+ if (useResize && !isNil(containerRef.current)) {
775
+ updateSizes(containerRef.current.offsetWidth, containerRef.current.offsetHeight);
776
+ }
777
+ }, [updateSizes, useResize]);
778
+ return {
779
+ containerRef,
780
+ verticalHandleRef,
781
+ horizontalHandleRef,
782
+ onPointerDown
783
+ };
784
+ };
785
+
786
+ const useToggle = initial => {
787
+ const [state, setState] = useState(initial !== undefined ? initial : false);
788
+ const toggle = useCallback(() => setState(!state), [state]);
789
+ return [state, toggle, setState];
790
+ };
791
+
792
+ const drawModeToGeometrySelectionType = mode => {
793
+ switch (mode) {
794
+ case "draw_point":
795
+ return GeometrySelectionTypes.Point;
796
+
797
+ case "draw_polygon":
798
+ return GeometrySelectionTypes.Polygon;
799
+
800
+ case "draw_line_string":
801
+ return GeometrySelectionTypes.Line;
802
+
803
+ default:
804
+ return GeometrySelectionTypes.Point;
805
+ }
806
+ };
807
+
808
+ const getGeometrySelectionTurfFeature = (coordinates, selectionType, toWgs) => {
809
+ if (toWgs) {
810
+ switch (selectionType) {
811
+ case GeometrySelectionTypes.Point:
812
+ return toWgs84(point(coordinates));
813
+
814
+ case GeometrySelectionTypes.Polygon:
815
+ return toWgs84(polygon(coordinates));
816
+
817
+ case GeometrySelectionTypes.Line:
818
+ return toWgs84(lineString(coordinates));
819
+ }
820
+ }
821
+
822
+ switch (selectionType) {
823
+ case GeometrySelectionTypes.Point:
824
+ return toMercator(point(coordinates));
825
+
826
+ case GeometrySelectionTypes.Polygon:
827
+ return toMercator(polygon(coordinates));
828
+
829
+ case GeometrySelectionTypes.Line:
830
+ return toMercator(lineString(coordinates));
831
+ }
832
+ };
833
+
834
+ export { DateFormat, HorizontalPosition, NO_CONTENT_VALUE, VerticalPosition, convertSpToTurfFeature, drawModeToGeometrySelectionType, findAttributeInExpression, formatDate, geometryToWkt, getActualExtrusionHeight, getDate, getGeometrySelectionTurfFeature, isNumeric, isObject, parseClientStyle, useCurrentSelectedFeature, useEditingFeature, useEwktGeometry, useGeometryEditor, useGeometrySelection, useGeometrySelectionBuffer, useMapContext, useMapDraw, useRedrawLayer, useResizer, useSelectFeaturesCount, useSelectFeaturesCurrentIndex, useSelectFeaturesGeometryMasking, useSelectFeaturesInitialized, useSelectFeaturesLayerName, useSelectFeaturesPagination, useSelectFeaturesStatisticsActive, useSelectFeaturesTotalCounts, useSelectedFeatures, useServerNotifications, useServerNotificationsContext, useToggle, useUpdateCurrentFeature, useZoomToFeatures, useZoomToLayer, useZoomToPoint };
53
835
  //# sourceMappingURL=react.esm.js.map