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