@m4l/components 0.2.4 → 0.2.6

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 (97) hide show
  1. package/components/DataGrid/{index.8fbcf147.js → index.d14640ca.js} +5 -5
  2. package/components/DataGrid/subcomponents/Actions/{index.bad681dc.js → index.3afb1664.js} +1 -1
  3. package/components/DynamicFilter/{index.cd7691e0.js → index.118c9d62.js} +1 -1
  4. package/components/ObjectLogs/{index.9c353020.js → index.070914d9.js} +2 -2
  5. package/components/PropertyValue/{index.37d91d0c.js → index.3b5c9ac7.js} +1 -1
  6. package/components/areas/components/AreasAdmin/{index.a14ba797.js → index.27c6d03e.js} +1 -1
  7. package/components/areas/components/AreasViewer/{index.c4545f2d.js → index.374d105d.js} +3 -3
  8. package/components/areas/contexts/AreasContext/{index.54893ef7.js → index.287ec96e.js} +2 -2
  9. package/components/areas/hooks/useAreas/{index.a15b3d9c.js → index.66c6cf2f.js} +1 -1
  10. package/components/hook-form/RHFRadioGroup/{index.7deb4e48.js → index.3b17819b.js} +1 -1
  11. package/components/index.d.ts +0 -1
  12. package/components/mui_extended/Accordion/{index.b9b427d7.js → index.22b4a776.js} +1 -1
  13. package/components/mui_extended/Tab/{index.724d5948.js → index.32349e95.js} +5 -5
  14. package/hooks/useTab/{index.991b13a7.js → index.f24a704c.js} +1 -1
  15. package/index.js +35 -52
  16. package/package.json +1 -1
  17. package/{vendor.8f8b0ac9.js → vendor.632361a1.js} +11 -13
  18. package/components/hook-form/HelperError/index.66bbcac3.js +0 -30
  19. package/components/hook-form/RHFHelperError/index.d.ts +0 -4
  20. package/components/maps/components/GpsTools/GpsTools.d.ts +0 -1
  21. package/components/maps/components/GpsTools/classes/index.d.ts +0 -4
  22. package/components/maps/components/GpsTools/classes/types.d.ts +0 -20
  23. package/components/maps/components/GpsTools/constants.d.ts +0 -8
  24. package/components/maps/components/GpsTools/contexts/GpsToolsContext/index.d.ts +0 -19
  25. package/components/maps/components/GpsTools/contexts/GpsToolsContext/store.d.ts +0 -16
  26. package/components/maps/components/GpsTools/contexts/GpsToolsContext/types.d.ts +0 -173
  27. package/components/maps/components/GpsTools/dictionary.d.ts +0 -64
  28. package/components/maps/components/GpsTools/hooks/useLayers/index.d.ts +0 -1
  29. package/components/maps/components/GpsTools/hooks/useMapTools/index.d.ts +0 -2
  30. package/components/maps/components/GpsTools/icons.d.ts +0 -15
  31. package/components/maps/components/GpsTools/index.889b0c39.js +0 -2313
  32. package/components/maps/components/GpsTools/index.d.ts +0 -2
  33. package/components/maps/components/GpsTools/subcomponents/TabTools/index.d.ts +0 -9
  34. package/components/maps/components/GpsTools/subcomponents/TabTools/subcomponents/GeofencesTool/constants.d.ts +0 -7
  35. package/components/maps/components/GpsTools/subcomponents/TabTools/subcomponents/GeofencesTool/hooks/useCheckedFeatures.d.ts +0 -9
  36. package/components/maps/components/GpsTools/subcomponents/TabTools/subcomponents/GeofencesTool/hooks/useCheckedGeofences.d.ts +0 -4
  37. package/components/maps/components/GpsTools/subcomponents/TabTools/subcomponents/GeofencesTool/hooks/useColumns.d.ts +0 -9
  38. package/components/maps/components/GpsTools/subcomponents/TabTools/subcomponents/GeofencesTool/hooks/useMaster.d.ts +0 -20
  39. package/components/maps/components/GpsTools/subcomponents/TabTools/subcomponents/GeofencesTool/hooks/useRowActionsGetter.d.ts +0 -9
  40. package/components/maps/components/GpsTools/subcomponents/TabTools/subcomponents/GeofencesTool/index.d.ts +0 -1
  41. package/components/maps/components/GpsTools/subcomponents/TabTools/subcomponents/GeofencesTool/model.d.ts +0 -122
  42. package/components/maps/components/GpsTools/subcomponents/TabTools/subcomponents/GeofencesTool/subcomponents/ColumnSetCheckFormatter/index.d.ts +0 -8
  43. package/components/maps/components/GpsTools/subcomponents/TabTools/subcomponents/GeofencesTool/subcomponents/ColumnSetCheckFormatter/types.d.ts +0 -5
  44. package/components/maps/components/GpsTools/subcomponents/TabTools/subcomponents/GeofencesTool/subcomponents/GeofenceAddEdit/constants.d.ts +0 -20
  45. package/components/maps/components/GpsTools/subcomponents/TabTools/subcomponents/GeofencesTool/subcomponents/GeofenceAddEdit/helpers.d.ts +0 -7
  46. package/components/maps/components/GpsTools/subcomponents/TabTools/subcomponents/GeofencesTool/subcomponents/GeofenceAddEdit/hooks/useDrawing.d.ts +0 -11
  47. package/components/maps/components/GpsTools/subcomponents/TabTools/subcomponents/GeofencesTool/subcomponents/GeofenceAddEdit/hooks/useSubmit.d.ts +0 -8
  48. package/components/maps/components/GpsTools/subcomponents/TabTools/subcomponents/GeofencesTool/subcomponents/GeofenceAddEdit/hooks/useSumbitErrorsFocus.d.ts +0 -5
  49. package/components/maps/components/GpsTools/subcomponents/TabTools/subcomponents/GeofencesTool/subcomponents/GeofenceAddEdit/hooks/useValidation.d.ts +0 -22
  50. package/components/maps/components/GpsTools/subcomponents/TabTools/subcomponents/GeofencesTool/subcomponents/GeofenceAddEdit/index.d.ts +0 -1
  51. package/components/maps/components/GpsTools/subcomponents/TabTools/subcomponents/GeofencesTool/subcomponents/GeofenceAddEdit/subcomponents/ConfigData/index.d.ts +0 -1
  52. package/components/maps/components/GpsTools/subcomponents/TabTools/subcomponents/GeofencesTool/subcomponents/GeofenceAddEdit/subcomponents/ConfigData/types.d.ts +0 -6
  53. package/components/maps/components/GpsTools/subcomponents/TabTools/subcomponents/GeofencesTool/subcomponents/GeofenceAddEdit/subcomponents/ConfigData/validations.d.ts +0 -5
  54. package/components/maps/components/GpsTools/subcomponents/TabTools/subcomponents/GeofencesTool/subcomponents/GeofenceAddEdit/subcomponents/GeneralData/index.d.ts +0 -1
  55. package/components/maps/components/GpsTools/subcomponents/TabTools/subcomponents/GeofencesTool/subcomponents/GeofenceAddEdit/subcomponents/GeneralData/types.d.ts +0 -7
  56. package/components/maps/components/GpsTools/subcomponents/TabTools/subcomponents/GeofencesTool/subcomponents/GeofenceAddEdit/subcomponents/GeneralData/validations.d.ts +0 -6
  57. package/components/maps/components/GpsTools/subcomponents/TabTools/subcomponents/GeofencesTool/subcomponents/GeofenceAddEdit/subcomponents/MyActions/index.d.ts +0 -1
  58. package/components/maps/components/GpsTools/subcomponents/TabTools/subcomponents/GeofencesTool/subcomponents/GeofenceAddEdit/subcomponents/MyTabs/index.d.ts +0 -1
  59. package/components/maps/components/GpsTools/subcomponents/TabTools/subcomponents/GeofencesTool/subcomponents/GeofenceAddEdit/subcomponents/StyleData/index.d.ts +0 -1
  60. package/components/maps/components/GpsTools/subcomponents/TabTools/subcomponents/GeofencesTool/subcomponents/GeofenceAddEdit/subcomponents/StyleData/subcomponents/FillData/index.d.ts +0 -1
  61. package/components/maps/components/GpsTools/subcomponents/TabTools/subcomponents/GeofencesTool/subcomponents/GeofenceAddEdit/subcomponents/StyleData/subcomponents/StrokeData/index.d.ts +0 -1
  62. package/components/maps/components/GpsTools/subcomponents/TabTools/subcomponents/GeofencesTool/subcomponents/GeofenceAddEdit/subcomponents/StyleData/types.d.ts +0 -10
  63. package/components/maps/components/GpsTools/subcomponents/TabTools/subcomponents/GeofencesTool/subcomponents/GeofenceAddEdit/types.d.ts +0 -25
  64. package/components/maps/components/GpsTools/subcomponents/TabTools/subcomponents/GeofencesTool/subcomponents/GeofencesList/index.d.ts +0 -1
  65. package/components/maps/components/GpsTools/subcomponents/TabTools/subcomponents/GeofencesTool/subcomponents/GeofencesList/subcomponents/Filter/index.d.ts +0 -7
  66. package/components/maps/components/GpsTools/subcomponents/TabTools/subcomponents/GeofencesTool/subcomponents/PolylineWithArrows/index.d.ts +0 -9
  67. package/components/maps/components/GpsTools/subcomponents/TabTools/subcomponents/MeasureTool/constants.d.ts +0 -30
  68. package/components/maps/components/GpsTools/subcomponents/TabTools/subcomponents/MeasureTool/hooks/useMeasure.d.ts +0 -31
  69. package/components/maps/components/GpsTools/subcomponents/TabTools/subcomponents/MeasureTool/hooks/useValidation.d.ts +0 -10
  70. package/components/maps/components/GpsTools/subcomponents/TabTools/subcomponents/MeasureTool/index.d.ts +0 -1
  71. package/components/maps/components/GpsTools/subcomponents/TabTools/subcomponents/MeasureTool/subcomponents/MeasureData/index.d.ts +0 -1
  72. package/components/maps/components/GpsTools/subcomponents/TabTools/subcomponents/MeasureTool/subcomponents/MeasureData/types.d.ts +0 -6
  73. package/components/maps/components/GpsTools/subcomponents/TabTools/subcomponents/MeasureTool/subcomponents/MeasureData/validations.d.ts +0 -2
  74. package/components/maps/components/GpsTools/subcomponents/TabTools/subcomponents/MeasureTool/subcomponents/MyActions/index.d.ts +0 -1
  75. package/components/maps/components/GpsTools/subcomponents/TabTools/subcomponents/MeasureTool/types.d.ts +0 -9
  76. package/components/maps/components/GpsTools/types.d.ts +0 -34
  77. package/components/maps/components/Map/Map.d.ts +0 -2
  78. package/components/maps/components/Map/classes/index.d.ts +0 -5
  79. package/components/maps/components/Map/classes/types.d.ts +0 -19
  80. package/components/maps/components/Map/constants.d.ts +0 -10
  81. package/components/maps/components/Map/contexts/MapContext/MapContext.d.ts +0 -19
  82. package/components/maps/components/Map/contexts/MapContext/helper.d.ts +0 -8
  83. package/components/maps/components/Map/contexts/MapContext/index.d.ts +0 -2
  84. package/components/maps/components/Map/contexts/MapContext/store.d.ts +0 -16
  85. package/components/maps/components/Map/contexts/MapContext/types.d.ts +0 -354
  86. package/components/maps/components/Map/hooks/useMapStore/index.d.ts +0 -3
  87. package/components/maps/components/Map/index.665e5c5d.js +0 -474
  88. package/components/maps/components/Map/index.d.ts +0 -5
  89. package/components/maps/components/Map/subcomponents/LayersContainer/index.d.ts +0 -2
  90. package/components/maps/components/Map/subcomponents/LeafletLayer/index.d.ts +0 -3
  91. package/components/maps/components/Map/subcomponents/LeafletLayer/types.d.ts +0 -2
  92. package/components/maps/components/Map/subcomponents/MainTools/index.d.ts +0 -2
  93. package/components/maps/components/Map/subcomponents/MainTools/types.d.ts +0 -5
  94. package/components/maps/components/Map/types.d.ts +0 -28
  95. package/components/maps/index.d.ts +0 -3
  96. package/hooks/useFormReadyForUpdate/index.d.ts +0 -6
  97. package/hooks/useFormReadyForUpdate/index.f60f500e.js +0 -20
@@ -1,2313 +0,0 @@
1
- import { createContext, useRef, useEffect, useState, useMemo, useCallback } from "react";
2
- import { createStore, useStore } from "zustand";
3
- import { shallow } from "zustand/shallow";
4
- import { useResponsiveDesktop, useFirstRender } from "@m4l/graphics";
5
- import { useModuleDictionary, useModuleSkeleton, useEnvironment, useNetwork, useModulePrivileges, useHostTools, usePaginate } from "@m4l/core";
6
- import { devtools } from "zustand/middleware";
7
- import { immer } from "zustand/middleware/immer";
8
- import { enableMapSet } from "immer";
9
- import { jsx, jsxs, Fragment } from "react/jsx-runtime";
10
- import { D as DynamicFilter } from "../../../DynamicFilter/index.cd7691e0.js";
11
- import { S as SelectCellFormatter } from "../../../../react-data-grid.c5377916.js";
12
- import { e as columnDateFormatter, c as DataGrid } from "../../../DataGrid/index.8fbcf147.js";
13
- import { u as useMapToolsStore, a as useMapStore, m as mapClasses, M as MAP_ZINDEX_DEFAULT, b as MAP_ZINDEX_OVER_MAP } from "../Map/index.665e5c5d.js";
14
- import { u as useModal } from "../../../../hooks/useModal/index.abdc0962.js";
15
- import { W as WindowConfirm } from "../../../modal/WindowConfirm.19ddbd5d.js";
16
- import { generateUtilityClasses } from "@mui/material";
17
- import "@mui/base";
18
- import { S as Stack } from "../../../mui_extended/Stack/index.0e53197c.js";
19
- import { B as Button } from "../../../mui_extended/Button/index.570fd3a4.js";
20
- import { useFormContext, useWatch } from "react-hook-form";
21
- import { H as HelperError } from "../../../hook-form/HelperError/index.66bbcac3.js";
22
- import { A as Actions } from "../../../CommonActions/components/Actions/index.2f6286eb.js";
23
- import { A as ActionFormIntro } from "../../../CommonActions/components/ActionFormIntro/index.5a719043.js";
24
- import { useMap, Polyline, Polygon, Popup, Circle } from "react-leaflet";
25
- import { u as useFormReadyForUpdate } from "../../../../hooks/useFormReadyForUpdate/index.f60f500e.js";
26
- import * as L from "leaflet";
27
- import L__default from "leaflet";
28
- import { u as useTab } from "../../../../hooks/useTab/index.991b13a7.js";
29
- import { P as PaperForm } from "../../../PaperForm/index.7ea3883f.js";
30
- import { R as RHFAutocomplete } from "../../../hook-form/RHFAutocomplete/index.0ce87ac3.js";
31
- import { R as RHFTextField } from "../../../hook-form/RHFTextField/index.80cc07e0.js";
32
- import { P as PropertyValue } from "../../../PropertyValue/index.37d91d0c.js";
33
- import { R as RHFColorPicker } from "../../../hook-form/RHFColorPicker/index.d00a2b53.js";
34
- import clsx from "clsx";
35
- import { T as Tabs, a as Tab, b as TabContent, c as TabProvider } from "../../../mui_extended/Tab/index.724d5948.js";
36
- import { T as Tooltip } from "../../../mui_extended/Tooltip/index.24a2bc3f.js";
37
- import * as Yup from "yup";
38
- import { u as useFormAddEdit } from "../../../../hooks/useFormAddEdit/index.32aa4f64.js";
39
- import { R as RHFormProvider } from "../../../../contexts/RHFormContext/index.7769076a.js";
40
- import { R as RHFAutocompleteAsync } from "../../../hook-form/RHFAutocompleteAsync/index.57789d3a.js";
41
- import "leaflet-polylinedecorator";
42
- import "@geoman-io/leaflet-geoman-free/dist/leaflet-geoman.css";
43
- import "@geoman-io/leaflet-geoman-free";
44
- import { styled } from "@mui/material/styles";
45
- import { createPortal } from "react-dom";
46
- enableMapSet();
47
- const createMapToolsStore = (initProps) => {
48
- const startProps = {
49
- currentTabTool: "measure",
50
- geofenceState: {
51
- currentGeofenceTool: "add_edit",
52
- rows: [],
53
- checkedGeofences: /* @__PURE__ */ new Set(),
54
- checkedCrossingFeatures: /* @__PURE__ */ new Set(),
55
- checkedInternalFeatures: /* @__PURE__ */ new Set(),
56
- hashGeofences: {}
57
- },
58
- ...initProps
59
- };
60
- return createStore(
61
- devtools(
62
- immer((set, get) => ({
63
- ...startProps,
64
- mapToolsActions: {
65
- init: () => {
66
- set((state) => {
67
- state.ownerState.status = "ready";
68
- });
69
- },
70
- setMapToolsState: (status) => {
71
- set((state) => {
72
- state.ownerState.status = status;
73
- });
74
- },
75
- setHandlerGetLabel: (newHandler) => {
76
- set((state) => {
77
- state.getLabel = newHandler;
78
- });
79
- },
80
- setExternalState: (newExternalState) => {
81
- set((state) => {
82
- state.ownerState = { ...state.ownerState, ...newExternalState };
83
- });
84
- },
85
- setCurrentTabTool: (newTabTool) => {
86
- set((state) => {
87
- state.currentTabTool = newTabTool;
88
- });
89
- }
90
- },
91
- geofenceActions: {
92
- goToAddEdit: (geofenceId) => {
93
- set((state) => {
94
- state.geofenceState.currentGeofenceTool = "add_edit";
95
- state.geofenceState.geofenceId = geofenceId;
96
- });
97
- },
98
- goToList: (geofenceId) => {
99
- set((state) => {
100
- state.geofenceState.currentGeofenceTool = "list";
101
- state.geofenceState.geofenceId = geofenceId;
102
- });
103
- },
104
- addGeofence: (geofenceId, geofence) => {
105
- set((state) => {
106
- state.geofenceState.hashGeofences[geofenceId] = geofence;
107
- });
108
- },
109
- updatePartialGeofence: (geofenceId, geofence) => {
110
- set((state) => {
111
- state.geofenceState.hashGeofences[geofenceId] = { ...state.geofenceState.hashGeofences[geofenceId], ...geofence };
112
- });
113
- },
114
- updateRows: (newRows) => {
115
- set((state) => {
116
- state.geofenceState.rows = newRows;
117
- });
118
- },
119
- setCheckedGeofences: (newGeofences) => {
120
- set((state) => {
121
- state.geofenceState.checkedGeofences = new Set(newGeofences);
122
- });
123
- },
124
- setCheckedCrossingFeatures: (newFeatures) => {
125
- set((state) => {
126
- state.geofenceState.checkedCrossingFeatures = new Set(newFeatures);
127
- });
128
- },
129
- setCheckedInternalFeatures: (newFeatures) => {
130
- set((state) => {
131
- state.geofenceState.checkedInternalFeatures = new Set(newFeatures);
132
- });
133
- }
134
- }
135
- })),
136
- { name: `Map Tools Store` }
137
- )
138
- );
139
- };
140
- const GpsToolsContext = createContext(null);
141
- function GpsToolsProvider(props) {
142
- const {
143
- children
144
- } = props;
145
- const {
146
- getLabel
147
- } = useModuleDictionary();
148
- const isDesktop = useResponsiveDesktop();
149
- const isSkeleton = useModuleSkeleton();
150
- const isFirstRender = useFirstRender([getLabel]);
151
- const mapStoreRef = useRef();
152
- if (!mapStoreRef.current) {
153
- mapStoreRef.current = createMapToolsStore({
154
- getLabel,
155
- ownerState: {
156
- status: "init",
157
- isMobile: !isDesktop,
158
- isSkeleton,
159
- focus: false
160
- }
161
- });
162
- }
163
- const {
164
- setHandlerGetLabel,
165
- setExternalState
166
- } = useStore(mapStoreRef.current, (state) => state.mapToolsActions, shallow);
167
- useEffect(() => {
168
- if (!isFirstRender) {
169
- setHandlerGetLabel(getLabel);
170
- }
171
- }, [getLabel]);
172
- useEffect(() => {
173
- if (isFirstRender) {
174
- return;
175
- }
176
- setExternalState({
177
- isMobile: !isDesktop,
178
- isSkeleton
179
- });
180
- }, [isDesktop, isSkeleton]);
181
- return /* @__PURE__ */ jsx(GpsToolsContext.Provider, {
182
- value: mapStoreRef.current,
183
- children
184
- });
185
- }
186
- const DICCTIONARY = {
187
- LABEL_TAB_GEO: "label_tab_geo",
188
- TAB_GENERAL_CONFIG_TOOLTIP: "tab_general_config_tooltip",
189
- PAPER_GENERAL: "paper_general",
190
- LABEL_ID: "label_id",
191
- LABEL_NAME: "label_name",
192
- LABEL_GEOMETRY_TYPE: "label_geometry_type",
193
- LABEL_GEOMETRY_CIRCLE: "label_geometry_circle",
194
- LABEL_GEOMETRY_RECTANGLE: "label_geometry_rectangle",
195
- LABEL_GEOMETRY_POLYGON: "label_geometry_polygon",
196
- LABEL_DRAW: "label_draw",
197
- LABEL_FINISH: "label_finish",
198
- PAPER_CONFIG: "paper_config",
199
- LABEL_ALIAS: "label_alias",
200
- LABEL_CUSTOMER_ID: "label_customer_id",
201
- LABEL_TIME_MIN_IN_SECONDS: "label_time_min_in_seconds",
202
- LABEL_TIME_MIN_OUT_SECONDS: "label_time_min_out_seconds",
203
- TAB_STYLE_CONFIG_TOOLTIP: "tab_style_tooltip",
204
- PAPER_STROKE: "paper_stroke",
205
- LABEL_COLOR: "label_color",
206
- LABEL_OPACITY: "label_opacity",
207
- LABEL_WEIGHT: "label_weight",
208
- LABEL_DASH_ARRAY: "label_dash_array",
209
- LABEL_DASH_OFFSET: "label_dash_offset",
210
- LABEL_RADIUS: "label_radius",
211
- LABEL_LAT: "label_lat",
212
- LABEL_LON: "label_lon",
213
- LABEL_PLACE_MARKER: "label_place_marker",
214
- LABEL_FIRST_VERTEX: "label_first_vertex",
215
- LABEL_CONTINUE_LINE: "label_continue_line",
216
- LABEL_FINISH_LINE: "label_finish_line",
217
- LABEL_FINISH_POLY: "label_finish_poly",
218
- LABEL_FINISH_RECT: "label_finish_rect",
219
- LABEL_START_CIRCLE: "label_start_circle",
220
- LABEL_FINISH_CIRCLE: "label_finish_circle",
221
- LABEL_PLACE_CIRCLE_MARKER: "label_place_circle_marker",
222
- VALIDATION_GEOMETRY_REQUIRED: "validation_geometry_required",
223
- VALIDATION_FIELD_REQUIRED: "validation_field_required",
224
- VALIDATION_FIELD_TYPE_NUMBER_ERROR: "validation_field_type_number_error",
225
- LABEL_VIEW_TRANSIT_FEATURES: "label_view_crossing_features",
226
- LABEL_VIEW_INTERNAL_FEATURES: "label_view_internal_features",
227
- LABEL_CREATED_AT: "label_created_at",
228
- LABEL_UPDATED_AT: "label_updated_at",
229
- MODAL_DELETE_GEO_TITLE: "modal_delete_geo_title",
230
- MODAL_DELETE_GEO_MESSAGE: "modal_delete_geo_message",
231
- MODAL_DISABLE_GEO_TITLE: "modal_disable_geo_title",
232
- MODAL_DISABLE_MESSAGE: "modal_disable_geo_message",
233
- ROW_ACTION_GEO_EDIT: "row_action_geo_edit",
234
- ROW_ACTION_GEO_ENABLE: "row_action_geo_enable",
235
- ROW_ACTION_GEO_DISABLE: "row_action_geo_disable",
236
- ROW_ACTION_GEO_DELETE: "row_action_geo_delete",
237
- LABEL_TAB_MEASURE: "label_tab_measure",
238
- PAPER_MEASURE: "paper_measure",
239
- LABEL_MEASURE_START: "label_measure_start",
240
- LABEL_MEASURE_RESTART: "label_measure_restart",
241
- LABEL_MEASURE_DISTANCE: "label_measure_distance",
242
- LABEL_MEASURE_AREA: "label_measure_area",
243
- LABEL_MEASURE_UNIT: "label_measure_unit",
244
- LABEL_MEASURE_UNIT_BASE_KILOMETERS: "label_measure_unit_base_kilometers",
245
- LABEL_MEASURE_REMOVE_POINT: "label_measure_remove_point"
246
- };
247
- const COMPONENT_CLASS_NAME = "M4LGpsTools";
248
- const COMPONENT_MAP_TOOLS_ID = "gps_tools";
249
- const STYLE_OPACITIES = [
250
- {
251
- value: 0,
252
- label: "0%"
253
- },
254
- {
255
- value: 0.1,
256
- label: "10%"
257
- },
258
- {
259
- value: 0.2,
260
- label: "20%"
261
- },
262
- {
263
- value: 0.3,
264
- label: "30%"
265
- },
266
- {
267
- value: 0.4,
268
- label: "40%"
269
- },
270
- {
271
- value: 0.5,
272
- label: "50%"
273
- },
274
- {
275
- value: 1,
276
- label: "100%"
277
- }
278
- ];
279
- const STYLE_WHEIGHTS = [
280
- {
281
- value: 0,
282
- label: "0px"
283
- },
284
- {
285
- value: 1,
286
- label: "1px"
287
- },
288
- {
289
- value: 2,
290
- label: "2px"
291
- },
292
- {
293
- value: 3,
294
- label: "3px"
295
- },
296
- {
297
- value: 4,
298
- label: "4px"
299
- }
300
- ];
301
- const STYLE_PATTERNS = [
302
- {
303
- value: "",
304
- label: "------"
305
- },
306
- {
307
- value: "4 1 2",
308
- label: "-- - - --"
309
- }
310
- ];
311
- const icons = {
312
- GEOMETRY_CIRCLE: "geometry_circle.svg",
313
- GEOMETRY_RECTANGLE: "geometry_rectangle.svg",
314
- GEOMETRY_POLYGON: "geometry_polygon.svg",
315
- ADD: "add.svg",
316
- MEASURE: "measure.svg",
317
- GENERAL: "general.svg",
318
- CONFIG: "config.svg",
319
- STROKE: "stroke.svg",
320
- FILL: "fill.svg",
321
- EDIT: "edit.svg",
322
- DELETE: "delete.svg",
323
- ACTIVE: "active.svg",
324
- NAME: "name.svg"
325
- };
326
- function Filter(props) {
327
- const {
328
- refresh,
329
- setBackendQueryParams
330
- } = props;
331
- const {
332
- host_static_assets,
333
- environment_assets
334
- } = useEnvironment();
335
- const [initialFilter] = useState(() => {
336
- return [];
337
- });
338
- const onChangeFilter = (initialFilters, rawFilters) => {
339
- setBackendQueryParams({
340
- f: rawFilters
341
- });
342
- refresh();
343
- };
344
- return /* @__PURE__ */ jsx(DynamicFilter, {
345
- withAllField: true,
346
- onChangeFilters: onChangeFilter,
347
- fields: [{
348
- name: "id",
349
- dictionaryId: DICCTIONARY.LABEL_ID,
350
- type: "number",
351
- multiple: true,
352
- presence: "optional",
353
- urlIcon: `${host_static_assets}/${environment_assets}/components/${COMPONENT_MAP_TOOLS_ID}/assets/icons/${icons.ACTIVE}`,
354
- defaultOperand1: true
355
- }, {
356
- name: "name",
357
- dictionaryId: DICCTIONARY.LABEL_NAME,
358
- type: "string",
359
- multiple: true,
360
- presence: "optional",
361
- urlIcon: `${host_static_assets}/${environment_assets}/components/${COMPONENT_MAP_TOOLS_ID}/assets/icons/${icons.NAME}`
362
- }],
363
- initialApplyedFilters: initialFilter
364
- });
365
- }
366
- function ColumnSetCheckFormatter(parameters) {
367
- const {
368
- field,
369
- rowKeyGetter,
370
- useHook
371
- } = parameters;
372
- const formatter = (props) => {
373
- const {
374
- row
375
- } = props;
376
- const [checkedRows, setCheckedRows] = useHook(field);
377
- const onChange = (checked, _isShiftClick) => {
378
- const newCheckedRows = new Set(checkedRows);
379
- if (checked) {
380
- newCheckedRows.add(rowKeyGetter(props.row));
381
- } else {
382
- newCheckedRows.delete(rowKeyGetter(props.row));
383
- }
384
- setCheckedRows(newCheckedRows);
385
- };
386
- return /* @__PURE__ */ jsx(SelectCellFormatter, {
387
- value: checkedRows.has(rowKeyGetter(row)) || false,
388
- isCellSelected: props.isCellSelected,
389
- onChange,
390
- "aria-label": "Select"
391
- });
392
- };
393
- return formatter;
394
- }
395
- function useColumns(props) {
396
- const {
397
- rowKeyGetter
398
- } = props;
399
- const {
400
- getLabel
401
- } = useModuleDictionary();
402
- const useHook = (field) => {
403
- return useMapToolsStore((state) => {
404
- return field === "CrossingFeatures" ? [state.geofenceState.checkedCrossingFeatures, state.geofenceActions.setCheckedCrossingFeatures] : [state.geofenceState.checkedInternalFeatures, state.geofenceActions.setCheckedInternalFeatures];
405
- }, shallow);
406
- };
407
- const columns = useMemo(() => [{
408
- key: "id",
409
- name: getLabel(DICCTIONARY.LABEL_ID),
410
- type: "number",
411
- width: 40,
412
- visible: false
413
- }, {
414
- key: "name",
415
- name: getLabel(DICCTIONARY.LABEL_NAME),
416
- type: "string",
417
- width: 300
418
- }, {
419
- key: "checkedCrossingFeatures",
420
- name: getLabel(DICCTIONARY.LABEL_VIEW_TRANSIT_FEATURES),
421
- width: 80,
422
- type: "boolean",
423
- formatter: ColumnSetCheckFormatter({
424
- field: "CrossingFeatures",
425
- rowKeyGetter,
426
- useHook
427
- }),
428
- cellClass: "rdg-cell-align-center"
429
- }, {
430
- key: "checkedInternalFeatures",
431
- name: getLabel(DICCTIONARY.LABEL_VIEW_INTERNAL_FEATURES),
432
- width: 80,
433
- type: "boolean",
434
- formatter: ColumnSetCheckFormatter({
435
- field: "InternalFeatures",
436
- rowKeyGetter,
437
- useHook
438
- }),
439
- cellClass: "rdg-cell-align-center"
440
- }, {
441
- key: "created_at",
442
- name: getLabel(DICCTIONARY.LABEL_CREATED_AT),
443
- type: "date",
444
- formatter: columnDateFormatter({
445
- presentationType: "datetime",
446
- fieldValue: "row.created_at"
447
- })
448
- }, {
449
- key: "updated_at",
450
- name: getLabel(DICCTIONARY.LABEL_UPDATED_AT),
451
- type: "date",
452
- formatter: columnDateFormatter({
453
- presentationType: "datetime",
454
- fieldValue: "row.updated_at"
455
- })
456
- }], [getLabel]);
457
- return {
458
- columns
459
- };
460
- }
461
- const ENDPOINT_GEOFENCE_GET = "geofences";
462
- const ENDPOINT_GEOFENCE_NEW_EDIT = "geofences";
463
- var GeofencesFeaturesLayers = /* @__PURE__ */ ((GeofencesFeaturesLayers2) => {
464
- GeofencesFeaturesLayers2["LAYER_GEOFENCES"] = "geofences";
465
- GeofencesFeaturesLayers2["LAYER_GEOFENCES_TRANSIT_FEATURES"] = "geofencesCrossingFeatures";
466
- GeofencesFeaturesLayers2["LAYER_GEOFENCES_INTERNAL_FEATURES"] = "geofencesInternalFeatures";
467
- return GeofencesFeaturesLayers2;
468
- })(GeofencesFeaturesLayers || {});
469
- function useRowActionsGetter(props) {
470
- const {
471
- fullRefresh
472
- } = props;
473
- const {
474
- networkOperation
475
- } = useNetwork();
476
- const {
477
- openModal,
478
- closeModal
479
- } = useModal();
480
- const {
481
- getLabel
482
- } = useModuleDictionary();
483
- const {
484
- hasPrivilege
485
- } = useModulePrivileges();
486
- const {
487
- host_static_assets,
488
- environment_assets
489
- } = useEnvironment();
490
- const {
491
- goToAddEdit
492
- } = useMapToolsStore((state) => state.geofenceActions, shallow);
493
- const {
494
- removeFeature
495
- } = useMapStore((state) => state.mapActions, shallow);
496
- const {
497
- toast
498
- } = useHostTools();
499
- const isDesktop = useResponsiveDesktop();
500
- const [urlIconEdit] = useState(`${host_static_assets}/${environment_assets}/frontend/components/maptools/assets/icons/${icons.EDIT}`);
501
- const [urlIconDelete] = useState(`${host_static_assets}/${environment_assets}/frontend/domain/microfrontends/maptools/assets/icons/${icons.DELETE}`);
502
- const goEdit = useCallback((objectId) => {
503
- goToAddEdit(objectId);
504
- removeFeature(GeofencesFeaturesLayers.LAYER_GEOFENCES, objectId);
505
- }, [getLabel]);
506
- const onDelete = useCallback((row) => {
507
- openModal({
508
- window: /* @__PURE__ */ jsx(WindowConfirm, {
509
- title: getLabel(DICCTIONARY.MODAL_DELETE_GEO_TITLE),
510
- msg: getLabel(DICCTIONARY.MODAL_DELETE_GEO_MESSAGE),
511
- onClickIntro: () => onConfirmDelete(row)
512
- }),
513
- variant: "delete",
514
- initialWidth: 300,
515
- initialHeigth: 350
516
- });
517
- }, [getLabel]);
518
- const onConfirmDelete = useCallback((row) => {
519
- networkOperation({
520
- method: "DELETE",
521
- endPoint: `geofences/${row.id}`
522
- }).then((response) => {
523
- toast(response.message, {
524
- type: "success"
525
- });
526
- fullRefresh();
527
- });
528
- closeModal();
529
- }, []);
530
- const rowActionsGetter = useCallback((row) => {
531
- const conditionalItems = [];
532
- conditionalItems.push({
533
- urlIcon: urlIconEdit,
534
- dictionaryId: DICCTIONARY.ROW_ACTION_GEO_EDIT,
535
- onClick: () => {
536
- goEdit(row.id);
537
- },
538
- disabled: !row.authUserOptions.edit
539
- });
540
- return conditionalItems;
541
- }, [hasPrivilege, goEdit, onDelete, urlIconDelete, urlIconEdit, isDesktop]);
542
- return {
543
- rowActionsGetter
544
- };
545
- }
546
- function useCheckedGeofences() {
547
- const [checkedGeofences, hashGeofences] = useMapToolsStore((state) => [state.geofenceState.checkedGeofences, state.geofenceState.hashGeofences], shallow);
548
- const {
549
- setCheckedGeofences,
550
- updatePartialGeofence
551
- } = useMapToolsStore((state) => state.geofenceActions, shallow);
552
- const {
553
- setFeatureData,
554
- removeFeature,
555
- getFeatureIds
556
- } = useMapStore((state) => state.mapActions, shallow);
557
- const {
558
- networkOperation
559
- } = useNetwork();
560
- useEffect(() => {
561
- const mapFeatureIds = getFeatureIds(GeofencesFeaturesLayers.LAYER_GEOFENCES);
562
- checkedGeofences.forEach((chkRow) => {
563
- const geofence = hashGeofences[chkRow];
564
- if (!geofence) {
565
- return;
566
- }
567
- if (!mapFeatureIds.includes(chkRow) || !geofence.hasRenderizedGeofence) {
568
- if (!geofence.geometry) {
569
- networkOperation({
570
- method: "GET",
571
- endPoint: `geofences/${geofence.id}`,
572
- isRemote: false,
573
- responseToCamelCase: true
574
- }).then((response) => {
575
- console.log("onCheckedRowsChange response:", response.data);
576
- const geoLoaded = {
577
- geometry: response.data.geometry,
578
- properties: response.data.properties,
579
- countCrossingFeatures: response.data.countCrossingFeatures,
580
- hasRenderizedGeofence: false
581
- };
582
- if (geoLoaded.geometry) {
583
- if (checkedGeofences.has(geofence.id)) {
584
- setFeatureData("geofences", chkRow, geoLoaded.geometry, geoLoaded.properties);
585
- geoLoaded.hasRenderizedGeofence = true;
586
- }
587
- }
588
- updatePartialGeofence(geofence.id, geoLoaded);
589
- });
590
- } else {
591
- setFeatureData(GeofencesFeaturesLayers.LAYER_GEOFENCES, chkRow, geofence.geometry, geofence.properties);
592
- updatePartialGeofence(geofence.id, {
593
- hasRenderizedGeofence: true
594
- });
595
- }
596
- }
597
- });
598
- mapFeatureIds.forEach((mapFeatureId) => {
599
- if (!checkedGeofences.has(Number(mapFeatureId))) {
600
- removeFeature(GeofencesFeaturesLayers.LAYER_GEOFENCES, mapFeatureId);
601
- }
602
- });
603
- return () => {
604
- };
605
- }, [checkedGeofences]);
606
- return {
607
- checkedGeofences,
608
- setCheckedGeofences
609
- };
610
- }
611
- function useCheckedFeatures(layerId, featuresType, endpoint) {
612
- const [checkedFeatures, setCheckedFeatures, hashGeofences] = useMapToolsStore((state) => {
613
- return featuresType === "CrossingFeatures" ? [state.geofenceState.checkedCrossingFeatures, state.geofenceActions.setCheckedCrossingFeatures, state.geofenceState.hashGeofences] : [state.geofenceState.checkedInternalFeatures, state.geofenceActions.setCheckedInternalFeatures, state.geofenceState.hashGeofences];
614
- }, shallow);
615
- const {
616
- setFeatureData,
617
- removeFeature,
618
- getFeatureIds
619
- } = useMapStore((state) => state.mapActions, shallow);
620
- const {
621
- networkOperation
622
- } = useNetwork();
623
- useEffect(() => {
624
- const mapFeatureIds = getFeatureIds(layerId);
625
- checkedFeatures.forEach((chkRow) => {
626
- const geofence = hashGeofences[chkRow];
627
- if (!geofence) {
628
- return;
629
- }
630
- if (!mapFeatureIds.find((fId) => fId.toString().includes(`geo_${geofence.id}_fid`)) || !geofence[`hasRenderized${featuresType}`]) {
631
- const currentGeofenceLoadedFeatures = geofence[`loaded${featuresType}`];
632
- if (!currentGeofenceLoadedFeatures) {
633
- networkOperation({
634
- method: "GET",
635
- endPoint: `geofences/${geofence.id}/${endpoint}`,
636
- isRemote: false,
637
- responseToCamelCase: true
638
- }).then((response) => {
639
- console.log("onCheckedGeometriesChange response:", response.data);
640
- geofence[`loaded${featuresType}`] = response.data;
641
- const newGeofenceLoadedFeatures = geofence[`loaded${featuresType}`];
642
- if (newGeofenceLoadedFeatures && Array.isArray(geofence[`loaded${featuresType}`])) {
643
- if (checkedFeatures.has(geofence.id)) {
644
- newGeofenceLoadedFeatures.forEach((feature) => {
645
- setFeatureData(layerId, `geo_${geofence.id}_fid_${feature.id}`, feature.geometry, feature.properties);
646
- });
647
- geofence[`hasRenderized${featuresType}`] = true;
648
- }
649
- }
650
- }).catch(() => {
651
- });
652
- } else {
653
- currentGeofenceLoadedFeatures.forEach((feature) => {
654
- setFeatureData(layerId, `geo_${geofence.id}_fid_${feature.id}`, feature.geometry, feature.properties);
655
- });
656
- geofence[`hasRenderized${featuresType}`] = true;
657
- }
658
- }
659
- });
660
- mapFeatureIds.forEach((mapFeatureId) => {
661
- const featureId = Number(mapFeatureId.toString().split("_")[1]);
662
- if (!checkedFeatures.has(featureId)) {
663
- removeFeature(layerId, mapFeatureId);
664
- }
665
- });
666
- return () => {
667
- };
668
- }, [checkedFeatures]);
669
- return [checkedFeatures, setCheckedFeatures];
670
- }
671
- function useMaster() {
672
- const {
673
- goToAddEdit
674
- } = useMapToolsStore((state) => state.geofenceActions, shallow);
675
- const [checkedGeofences, hashGeofences, initialRows] = useMapToolsStore((state) => [state.geofenceState.checkedGeofences, state.geofenceState.hashGeofences, state.geofenceState.rows], shallow);
676
- const {
677
- setCheckedGeofences,
678
- addGeofence,
679
- updatePartialGeofence,
680
- updateRows
681
- } = useMapToolsStore((state) => state.geofenceActions, shallow);
682
- useCheckedGeofences();
683
- const [checkedCrossingFeatures, setCheckedCrossingFeatures] = useCheckedFeatures(GeofencesFeaturesLayers.LAYER_GEOFENCES_TRANSIT_FEATURES, "CrossingFeatures", "crossing_features");
684
- const [checkedInternalFeatures, setCheckedInternalFeatures] = useCheckedFeatures(GeofencesFeaturesLayers.LAYER_GEOFENCES_INTERNAL_FEATURES, "InternalFeatures", "internal_features");
685
- const rowKeyGetter = useCallback((row) => row.id, []);
686
- const [selectedRows, setSelectedRows] = useState(/* @__PURE__ */ new Set());
687
- const [backendQueryParams, setBackendQueryParams] = useState({});
688
- const {
689
- columns
690
- } = useColumns({
691
- rowKeyGetter
692
- });
693
- const {
694
- pagerState,
695
- rows,
696
- onPageChange,
697
- onRowsPerPageChange,
698
- Refresh,
699
- setRows
700
- } = usePaginate({
701
- endPoint: "geofences",
702
- fireOnChangeParms: false,
703
- fireOnFirstLoad: false,
704
- queryParams: backendQueryParams,
705
- isRemote: false,
706
- responseToCamelCase: true,
707
- initialRows
708
- });
709
- const onSelectedRowsChange = (newRowsSelectSet) => {
710
- setSelectedRows(newRowsSelectSet);
711
- };
712
- const fullRefresh = useCallback((id) => {
713
- Refresh();
714
- }, []);
715
- useEffect(() => {
716
- const newCheckedGeofences = new Set(checkedGeofences);
717
- const newCheckedCrossingFeatures = new Set(checkedCrossingFeatures);
718
- const newCheckedInternalFeatures = new Set(checkedInternalFeatures);
719
- let updatedCheckedGeofences = false;
720
- let updatedCheckedCrossingFeatures = false;
721
- let updatedCheckedInternalFeatures = false;
722
- newCheckedGeofences.forEach((chkRow) => {
723
- if (rows.findIndex((row) => row.id === chkRow) === -1) {
724
- newCheckedGeofences.delete(chkRow);
725
- }
726
- });
727
- newCheckedCrossingFeatures.forEach((chkTF) => {
728
- if (rows.findIndex((row) => row.id === chkTF) === -1) {
729
- newCheckedCrossingFeatures.delete(chkTF);
730
- }
731
- });
732
- newCheckedInternalFeatures.forEach((chkIF) => {
733
- if (rows.findIndex((row) => row.id === chkIF) === -1) {
734
- newCheckedInternalFeatures.delete(chkIF);
735
- }
736
- });
737
- rows.forEach((row) => {
738
- let hasGeo = hashGeofences[row.id];
739
- if (!hasGeo) {
740
- hasGeo = {
741
- ...row,
742
- hasRenderizedGeofence: false,
743
- loadedCrossingFeatures: null,
744
- loadedInternalFeatures: null,
745
- hasRenderizedCrossingFeatures: false,
746
- hasRenderizedInternalFeatures: false,
747
- createdAt: row.createdAt
748
- };
749
- addGeofence(row.id, hasGeo);
750
- return;
751
- }
752
- if (row.updatedAt && row.updatedAt !== hasGeo.updatedAt) {
753
- updatePartialGeofence(row.id, {
754
- updatedAt: row.updatedAt,
755
- geometry: null,
756
- hasRenderizedGeofence: false,
757
- hasRenderizedCrossingFeatures: false,
758
- hasRenderizedInternalFeatures: false,
759
- loadedCrossingFeatures: null,
760
- loadedInternalFeatures: null
761
- });
762
- updatedCheckedGeofences = true;
763
- updatedCheckedCrossingFeatures = true;
764
- updatedCheckedInternalFeatures = true;
765
- }
766
- });
767
- if (newCheckedGeofences.size !== checkedGeofences.size || updatedCheckedGeofences) {
768
- setCheckedGeofences(newCheckedGeofences);
769
- }
770
- if (newCheckedCrossingFeatures.size !== checkedCrossingFeatures.size || updatedCheckedCrossingFeatures) {
771
- setCheckedCrossingFeatures(newCheckedCrossingFeatures);
772
- }
773
- if (newCheckedInternalFeatures.size !== checkedInternalFeatures.size || updatedCheckedInternalFeatures) {
774
- setCheckedInternalFeatures(newCheckedInternalFeatures);
775
- }
776
- onSelectedRowsChange(selectedRows);
777
- updateRows(rows);
778
- }, [rows]);
779
- const {
780
- rowActionsGetter
781
- } = useRowActionsGetter({
782
- fullRefresh
783
- });
784
- return {
785
- rowKeyGetter,
786
- columns,
787
- refresh: Refresh,
788
- setBackendQueryParams,
789
- pagerState,
790
- rows,
791
- onPageChange,
792
- onRowsPerPageChange,
793
- rowActionsGetter,
794
- selectedRows,
795
- onSelectedRowsChange,
796
- checkedRows: checkedGeofences,
797
- onCheckedRowsChange: setCheckedGeofences,
798
- setRows,
799
- goToAddEdit
800
- };
801
- }
802
- const mapToolsClasses = generateUtilityClasses(COMPONENT_CLASS_NAME, [
803
- "root",
804
- "tabToolsRoot",
805
- "tabContentRoot",
806
- "toolGeofences",
807
- "toolGeofencesList",
808
- "toolGeofencesAddEdit",
809
- "toolGeofencesAddEditGeneral",
810
- "toolGeofencesAddEditStyle",
811
- "toolMeasureFormValue",
812
- "toolMeasureFormValueDistance",
813
- "toolMeasureFormValueSymbol",
814
- "toolMeasure",
815
- "toolMeausureLabel",
816
- "toolMeausureLabelDistance",
817
- "toolMeausureLabelSymbol",
818
- "visible",
819
- "hidden"
820
- ]);
821
- function GeofencesList() {
822
- const {
823
- refresh,
824
- setBackendQueryParams,
825
- columns,
826
- rows,
827
- rowActionsGetter,
828
- selectedRows,
829
- onSelectedRowsChange,
830
- pagerState,
831
- onPageChange,
832
- onRowsPerPageChange,
833
- checkedRows,
834
- onCheckedRowsChange,
835
- setRows,
836
- rowKeyGetter,
837
- goToAddEdit
838
- } = useMaster();
839
- return /* @__PURE__ */ jsxs(Stack, {
840
- direction: "column",
841
- gap: "4px",
842
- className: mapToolsClasses.toolGeofencesList,
843
- children: [/* @__PURE__ */ jsx(Button, {
844
- onClick: () => goToAddEdit(),
845
- children: "Agregar geocerca"
846
- }), /* @__PURE__ */ jsx(Filter, {
847
- refresh,
848
- setBackendQueryParams
849
- }), /* @__PURE__ */ jsx(DataGrid, {
850
- id: "geofences",
851
- columns,
852
- rows,
853
- onRowsChange: setRows,
854
- checkedRows,
855
- onCheckedRowsChange,
856
- rowActionsGetter,
857
- rowKeyGetter,
858
- selectedRows,
859
- onSelectedRowsChange,
860
- withActions: true,
861
- actionsProps: {
862
- withPager: true,
863
- withLocalFilters: true,
864
- pagerOptions: {
865
- records: rows.length,
866
- totalRecords: pagerState.totalRecords,
867
- rowsPerPageOptions: [1, 2, 3, 4, 5, 10, 25],
868
- page: pagerState.page,
869
- rowsPerPage: pagerState.rowsPerPage,
870
- onPageChange,
871
- onRowsPerPageChange
872
- }
873
- }
874
- }, "list")]
875
- });
876
- }
877
- function MyActions$1() {
878
- const {
879
- control
880
- } = useFormContext();
881
- const inEdition = useWatch({
882
- control,
883
- name: "inEdition"
884
- });
885
- const {
886
- goToList
887
- } = useMapToolsStore((state) => state.geofenceActions);
888
- return /* @__PURE__ */ jsxs(Actions, {
889
- children: [/* @__PURE__ */ jsx(HelperError, {
890
- name: "geometry"
891
- }), /* @__PURE__ */ jsx(Button, {
892
- onClick: () => {
893
- goToList();
894
- },
895
- disabled: inEdition,
896
- children: "Cancelar"
897
- }), /* @__PURE__ */ jsx(ActionFormIntro, {
898
- disabled: inEdition
899
- })]
900
- });
901
- }
902
- const STROKE_COLOR_DEFAULT = "#aaccaa";
903
- const STROKE_OPACITY_DEFAULT = { value: 1, label: "100%" };
904
- const STROKE_WHEIGTH_DEFAULT = { value: 1, label: "1 px" };
905
- const STROKE_DASH_ARRAY_DEFAULT = { value: "", label: "-----" };
906
- const FILL_COLOR_DEFAULT = "#aa3000";
907
- const FILL_OPACITY_DEFAULT = { value: 0.2, label: "20%" };
908
- const initialValues = {
909
- name: "",
910
- geofenceType: null,
911
- alias: null,
912
- customerId: null,
913
- timeMinInSeconds: 5,
914
- timeMinOutSeconds: 5,
915
- inEdition: false,
916
- geometry: null,
917
- lat: null,
918
- lng: null,
919
- properties: {
920
- radius: null,
921
- strokeColor: STROKE_COLOR_DEFAULT,
922
- strokeOpacity: STROKE_OPACITY_DEFAULT,
923
- strokeWeight: STROKE_WHEIGTH_DEFAULT,
924
- strokeDashArray: STROKE_DASH_ARRAY_DEFAULT,
925
- fillColor: FILL_COLOR_DEFAULT,
926
- fillOpacity: FILL_OPACITY_DEFAULT
927
- }
928
- };
929
- const formatDataEnpoint = (response) => {
930
- try {
931
- const { data } = response;
932
- const obRet = {
933
- ...initialValues,
934
- inEdition: false,
935
- name: data.name,
936
- geometry: data.geometry,
937
- geofenceType: { id: data.type.id, name: data.type.name, url: "" },
938
- properties: {
939
- strokeColor: data.properties.strokeColor || STROKE_COLOR_DEFAULT,
940
- strokeOpacity: data.properties.strokeOpacity || STROKE_OPACITY_DEFAULT,
941
- strokeWeight: data.properties.strokeWeight || STROKE_WHEIGTH_DEFAULT,
942
- strokeDashArray: data.properties.strokeDashArray || STROKE_DASH_ARRAY_DEFAULT,
943
- fillColor: data.properties.fillColor || FILL_COLOR_DEFAULT,
944
- fillOpacity: data.properties.fillOpacity || FILL_OPACITY_DEFAULT
945
- }
946
- };
947
- if (obRet.geofenceType?.id === "gt_circle") {
948
- if (data.properties.radius) {
949
- obRet.properties.radius = data.properties.radius;
950
- }
951
- if (data.geometry && data.geometry.type === "Point") {
952
- obRet.lng = data.geometry.coordinates[0];
953
- obRet.lat = data.geometry.coordinates[1];
954
- }
955
- }
956
- return obRet;
957
- } catch (error) {
958
- return { ...initialValues };
959
- }
960
- };
961
- const getLayerFromGeometry = (geometry, geofenceTypeId, radius) => {
962
- if (geometry) {
963
- if (geofenceTypeId === "gt_circle" && geometry.type === "Point") {
964
- return L.circle([geometry.coordinates[1], geometry.coordinates[0]], radius || 0);
965
- } else if (geofenceTypeId === "gt_polygon" && geometry.type === "Polygon") {
966
- const coordinates = geometry.coordinates.map(
967
- (ring) => ring.map((position) => [position[1], position[0]])
968
- );
969
- return L.polygon(coordinates);
970
- } else if (geofenceTypeId === "gt_rectangle" && geometry.type === "Polygon") {
971
- const latLngs = geometry.coordinates[0].map((coord) => [coord[1], coord[0]]);
972
- const lats = latLngs.map((coord) => coord);
973
- const lngs = latLngs.map((coord) => coord);
974
- const southWest = [Math.min(...lats), Math.min(...lngs)];
975
- const northEast = [Math.max(...lats), Math.max(...lngs)];
976
- return L.rectangle([southWest, northEast]);
977
- }
978
- }
979
- return null;
980
- };
981
- function useDrawing() {
982
- const { getLabel } = useModuleDictionary();
983
- const readyToUpdate = useFormReadyForUpdate();
984
- const map = useMap();
985
- const { control, setValue } = useFormContext();
986
- const fieldsWatch = useWatch({
987
- control,
988
- name: [
989
- "geofenceType",
990
- "inEdition",
991
- "properties.strokeColor",
992
- "properties.strokeOpacity",
993
- "properties.strokeWeight",
994
- "properties.strokeDashArray",
995
- "properties.fillColor",
996
- "properties.fillOpacity",
997
- "geometry",
998
- "properties.radius"
999
- ]
1000
- });
1001
- const geofenceTypeId = fieldsWatch[0]?.id;
1002
- const inEdition = fieldsWatch[1];
1003
- const strokeColor = fieldsWatch[2];
1004
- const strokeOpacity = fieldsWatch[3].value;
1005
- const strokeWeight = fieldsWatch[4].value;
1006
- const strokeDashArray = fieldsWatch[5].value;
1007
- const fillColor = fieldsWatch[6];
1008
- const fillOpacity = fieldsWatch[7].value;
1009
- const geometry = fieldsWatch[8];
1010
- const radius = fieldsWatch[9];
1011
- const [drawing, setDrawing] = useState(false);
1012
- const currentLayer = useRef(null);
1013
- const [geometrTypeIdCached, setgeofenceTypeIdCached] = useState(geofenceTypeId);
1014
- useEffect(() => {
1015
- if (geometry) {
1016
- currentLayer.current = getLayerFromGeometry(geometry, geofenceTypeId, radius);
1017
- if (currentLayer.current) {
1018
- map.addLayer(currentLayer.current);
1019
- }
1020
- }
1021
- return () => {
1022
- if (currentLayer.current) {
1023
- currentLayer.current.remove();
1024
- }
1025
- };
1026
- }, [map]);
1027
- useEffect(() => {
1028
- if (currentLayer.current) {
1029
- currentLayer.current.setStyle({
1030
- color: strokeColor,
1031
- opacity: strokeOpacity,
1032
- weight: strokeWeight,
1033
- dashArray: strokeDashArray,
1034
- fillColor,
1035
- fillOpacity
1036
- });
1037
- }
1038
- }, [strokeColor, strokeOpacity, strokeWeight, strokeDashArray, fillColor, fillOpacity]);
1039
- useEffect(() => {
1040
- map.pm.setLang("en", {
1041
- tooltips: {
1042
- placeMarker: void 0,
1043
- firstVertex: getLabel(DICCTIONARY.LABEL_FIRST_VERTEX),
1044
- continueLine: getLabel(DICCTIONARY.LABEL_CONTINUE_LINE),
1045
- finishLine: getLabel(DICCTIONARY.LABEL_FINISH_LINE),
1046
- finishPoly: getLabel(DICCTIONARY.LABEL_FINISH_POLY),
1047
- finishRect: getLabel(DICCTIONARY.LABEL_FINISH_RECT),
1048
- startCircle: getLabel(DICCTIONARY.LABEL_START_CIRCLE),
1049
- finishCircle: getLabel(DICCTIONARY.LABEL_FINISH_CIRCLE),
1050
- placeCircleMarker: getLabel(DICCTIONARY.LABEL_PLACE_CIRCLE_MARKER)
1051
- }
1052
- });
1053
- }, [map, getLabel]);
1054
- useEffect(() => {
1055
- if (map) {
1056
- let shape = "Circle";
1057
- if (geometrTypeIdCached === "gt_polygon") {
1058
- shape = "Polygon";
1059
- } else if (geometrTypeIdCached === "gt_rectangle") {
1060
- shape = "Rectangle";
1061
- }
1062
- if (drawing) {
1063
- if (!currentLayer.current) {
1064
- setValue("inEdition", true);
1065
- if (shape === "Circle") {
1066
- map.on("pm:drawstart", ({ workingLayer }) => {
1067
- workingLayer.on("pm:centerplaced", (e) => {
1068
- var layer = e.workingLayer;
1069
- layer.setStyle(
1070
- {
1071
- color: strokeColor,
1072
- opacity: strokeOpacity,
1073
- weight: strokeWeight,
1074
- dashArray: strokeDashArray,
1075
- fillColor,
1076
- fillOpacity
1077
- }
1078
- );
1079
- setValue("lat", layer.getLatLng().lat);
1080
- setValue("lng", layer.getLatLng().lng);
1081
- layer.on("pm:change", (e2) => {
1082
- setValue("properties.radius", layer.getRadius());
1083
- });
1084
- });
1085
- });
1086
- setValue("properties.subType", shape);
1087
- } else if (shape === "Polygon") {
1088
- map.on("pm:drawstart", ({ workingLayer }) => {
1089
- workingLayer.on("pm:vertexadded", (e) => {
1090
- var layer = e.workingLayer;
1091
- layer.setStyle(
1092
- {
1093
- color: strokeColor,
1094
- opacity: strokeOpacity,
1095
- weight: strokeWeight,
1096
- dashArray: strokeDashArray,
1097
- fillColor,
1098
- fillOpacity
1099
- }
1100
- );
1101
- });
1102
- });
1103
- }
1104
- map.pm.enableDraw(shape);
1105
- map.pm.setPathOptions(
1106
- {
1107
- color: strokeColor,
1108
- opacity: strokeOpacity,
1109
- weight: strokeWeight,
1110
- dashArray: strokeDashArray,
1111
- fillColor,
1112
- fillOpacity
1113
- }
1114
- );
1115
- map.on("pm:create", (e) => {
1116
- currentLayer.current = e.layer;
1117
- setValue("geometry", currentLayer.current.toGeoJSON()?.geometry, {
1118
- shouldTouch: false,
1119
- shouldValidate: true
1120
- });
1121
- setValue("inEdition", false);
1122
- setDrawing(false);
1123
- });
1124
- } else {
1125
- currentLayer.current.pm.enable();
1126
- setValue("inEdition", true);
1127
- currentLayer.current.on("pm:disable", (e) => {
1128
- currentLayer.current = e.layer;
1129
- console.log("Geometr\xEDa editada **", currentLayer.current.toGeoJSON());
1130
- setValue("geometry", currentLayer.current.toGeoJSON()?.geometry, {
1131
- shouldTouch: false,
1132
- shouldValidate: true
1133
- });
1134
- setValue("inEdition", false);
1135
- setDrawing(false);
1136
- });
1137
- if (shape === "Circle") {
1138
- currentLayer.current.on("pm:change", (e) => {
1139
- currentLayer.current = e.layer;
1140
- setValue("properties.radius", currentLayer.current.getRadius());
1141
- });
1142
- }
1143
- }
1144
- } else {
1145
- map.pm.disableDraw("Polygon");
1146
- map.off("pm:create");
1147
- map.off("pm:edit");
1148
- map.off("pm:drawstart");
1149
- }
1150
- }
1151
- }, [map, drawing]);
1152
- const handleDraw = useCallback(() => {
1153
- setDrawing(true);
1154
- }, []);
1155
- const handleFinish = useCallback(() => {
1156
- if (currentLayer.current) {
1157
- currentLayer.current.pm.disable();
1158
- currentLayer.current.setStyle({ color: "#ff0000", fillColor: "#ff0000" });
1159
- }
1160
- }, []);
1161
- useEffect(() => {
1162
- if (!readyToUpdate)
1163
- return;
1164
- if (geofenceTypeId) {
1165
- if (geofenceTypeId !== geometrTypeIdCached) {
1166
- setgeofenceTypeIdCached(geofenceTypeId);
1167
- if (geometrTypeIdCached !== "gt_circle") {
1168
- setValue("properties.radius", null);
1169
- setValue("lat", null);
1170
- setValue("lng", null);
1171
- }
1172
- setValue("geometry", null);
1173
- if (currentLayer.current) {
1174
- currentLayer.current.remove();
1175
- currentLayer.current = null;
1176
- }
1177
- }
1178
- }
1179
- }, [geofenceTypeId]);
1180
- return { inEdition, handleDraw, handleFinish, geometrTypeIdCached };
1181
- }
1182
- function useSumbitErrorsFocus() {
1183
- const {
1184
- setFocus,
1185
- formState: { isSubmitted, errors }
1186
- } = useFormContext();
1187
- const { handleChange } = useTab();
1188
- useEffect(() => {
1189
- if (isSubmitted) {
1190
- const firstError = Object.keys(errors).reduce((field, a) => {
1191
- const fieldKey = field;
1192
- return !!errors[fieldKey] ? fieldKey : a;
1193
- }, null);
1194
- if (firstError) {
1195
- let found = ["name", "geometry", "geofenceType", "timeMinInSeconds", "timeMinOutSeconds"].some((field) => field.includes(firstError));
1196
- if (found) {
1197
- handleChange(null, "general");
1198
- }
1199
- if (firstError) {
1200
- setFocus(firstError);
1201
- }
1202
- }
1203
- }
1204
- }, [isSubmitted, errors]);
1205
- }
1206
- function GeneralData() {
1207
- const {
1208
- getLabel
1209
- } = useModuleDictionary();
1210
- const {
1211
- host_static_assets,
1212
- environment_assets
1213
- } = useEnvironment();
1214
- const {
1215
- inEdition,
1216
- handleDraw,
1217
- handleFinish,
1218
- geometrTypeIdCached
1219
- } = useDrawing();
1220
- useSumbitErrorsFocus();
1221
- const urlIcon = `${host_static_assets}/${environment_assets}/frontend/domain/components/map/assets/icons/${icons.GENERAL}`;
1222
- const geofencesTypes = useMemo(() => {
1223
- return [{
1224
- id: "gt_circle",
1225
- name: getLabel(DICCTIONARY.LABEL_GEOMETRY_CIRCLE),
1226
- url: `${host_static_assets}/${environment_assets}/frontend/domain/components/map/assets/icons/${icons.GEOMETRY_CIRCLE}`
1227
- }, {
1228
- id: "gt_polygon",
1229
- name: getLabel(DICCTIONARY.LABEL_GEOMETRY_POLYGON),
1230
- url: `${host_static_assets}/${environment_assets}/frontend/domain/components/map/assets/icons/${icons.GEOMETRY_POLYGON}`
1231
- }, {
1232
- id: "gt_rectangle",
1233
- name: getLabel(DICCTIONARY.LABEL_GEOMETRY_RECTANGLE),
1234
- url: `${host_static_assets}/${environment_assets}/frontend/domain/components/map/assets/icons/${icons.GEOMETRY_RECTANGLE}`
1235
- }];
1236
- }, [getLabel]);
1237
- return /* @__PURE__ */ jsxs(PaperForm, {
1238
- urlIcon,
1239
- title: getLabel(DICCTIONARY.PAPER_GENERAL),
1240
- children: [/* @__PURE__ */ jsx(RHFTextField, {
1241
- name: "name",
1242
- disabled: false,
1243
- type: "text",
1244
- label: getLabel(`${DICCTIONARY.LABEL_NAME}`)
1245
- }), /* @__PURE__ */ jsxs(Stack, {
1246
- direction: "column",
1247
- spacing: 1,
1248
- alignItems: "center",
1249
- children: [/* @__PURE__ */ jsxs(Stack, {
1250
- direction: "row",
1251
- spacing: 1,
1252
- alignItems: "center",
1253
- children: [/* @__PURE__ */ jsx(RHFAutocomplete, {
1254
- name: "geofenceType",
1255
- autoComplete: "off",
1256
- options: geofencesTypes,
1257
- getOptionLabel: (option) => option.name,
1258
- isOptionEqualToValue: (option, value) => option.id === value.id,
1259
- getOptionUrlImage: (option) => option.url,
1260
- imageHeight: "12px",
1261
- imageWidth: "12px",
1262
- label: getLabel(DICCTIONARY.LABEL_GEOMETRY_TYPE)
1263
- }), /* @__PURE__ */ jsx(Button, {
1264
- onClick: handleDraw,
1265
- disabled: inEdition || !geometrTypeIdCached,
1266
- children: getLabel(DICCTIONARY.LABEL_DRAW)
1267
- }), /* @__PURE__ */ jsx(Button, {
1268
- onClick: handleFinish,
1269
- disabled: !inEdition,
1270
- children: getLabel(DICCTIONARY.LABEL_FINISH)
1271
- })]
1272
- }), geometrTypeIdCached && geometrTypeIdCached === "gt_circle" && /* @__PURE__ */ jsxs(Stack, {
1273
- direction: "row",
1274
- spacing: 1,
1275
- alignItems: "center",
1276
- children: [/* @__PURE__ */ jsx(RHFTextField, {
1277
- name: "properties.radius",
1278
- label: getLabel(DICCTIONARY.LABEL_RADIUS),
1279
- autoComplete: "on",
1280
- skeletonWidth: "70%",
1281
- skeletonHeight: "18px",
1282
- disabled: true,
1283
- size: "medium"
1284
- }), /* @__PURE__ */ jsx(RHFTextField, {
1285
- name: "lat",
1286
- label: getLabel(DICCTIONARY.LABEL_LAT),
1287
- autoComplete: "on",
1288
- skeletonWidth: "70%",
1289
- skeletonHeight: "18px",
1290
- disabled: true,
1291
- size: "medium"
1292
- }), /* @__PURE__ */ jsx(RHFTextField, {
1293
- name: "lng",
1294
- label: getLabel(DICCTIONARY.LABEL_LON),
1295
- autoComplete: "on",
1296
- skeletonWidth: "70%",
1297
- skeletonHeight: "18px",
1298
- disabled: true,
1299
- size: "medium"
1300
- })]
1301
- })]
1302
- })]
1303
- });
1304
- }
1305
- function ConfigData() {
1306
- const {
1307
- getLabel
1308
- } = useModuleDictionary();
1309
- const {
1310
- host_static_assets,
1311
- environment_assets
1312
- } = useEnvironment();
1313
- const urlIcon = `${host_static_assets}/${environment_assets}/frontend/domain/components/map/assets/icons/${icons.CONFIG}`;
1314
- return /* @__PURE__ */ jsxs(PaperForm, {
1315
- urlIcon,
1316
- title: getLabel(DICCTIONARY.PAPER_CONFIG),
1317
- children: [/* @__PURE__ */ jsx(RHFTextField, {
1318
- name: "alias",
1319
- disabled: false,
1320
- type: "text",
1321
- label: getLabel(`${DICCTIONARY.LABEL_ALIAS}`)
1322
- }), /* @__PURE__ */ jsx(RHFTextField, {
1323
- name: "customerId",
1324
- disabled: false,
1325
- type: "text",
1326
- label: getLabel(`${DICCTIONARY.LABEL_CUSTOMER_ID}`)
1327
- }), /* @__PURE__ */ jsx(RHFTextField, {
1328
- name: "timeMinInSeconds",
1329
- disabled: false,
1330
- type: "number",
1331
- label: getLabel(`${DICCTIONARY.LABEL_TIME_MIN_IN_SECONDS}`)
1332
- }), /* @__PURE__ */ jsx(RHFTextField, {
1333
- name: "timeMinOutSeconds",
1334
- disabled: false,
1335
- type: "number",
1336
- label: getLabel(`${DICCTIONARY.LABEL_TIME_MIN_OUT_SECONDS}`)
1337
- })]
1338
- });
1339
- }
1340
- function FillData() {
1341
- const {
1342
- getLabel
1343
- } = useModuleDictionary();
1344
- const {
1345
- host_static_assets,
1346
- environment_assets
1347
- } = useEnvironment();
1348
- const urlIcon = `${host_static_assets}/${environment_assets}/frontend/domain/components/map/assets/icons/${icons.FILL}`;
1349
- return /* @__PURE__ */ jsxs(PaperForm, {
1350
- urlIcon,
1351
- title: getLabel(DICCTIONARY.PAPER_STROKE),
1352
- children: [/* @__PURE__ */ jsx(PropertyValue, {
1353
- property: getLabel(`${DICCTIONARY.LABEL_COLOR}`),
1354
- isForm: true,
1355
- propertyWidth: 150,
1356
- value: /* @__PURE__ */ jsx(RHFColorPicker, {
1357
- name: "properties.fillColor"
1358
- })
1359
- }, "properties.fillColor"), /* @__PURE__ */ jsx(PropertyValue, {
1360
- property: getLabel(`${DICCTIONARY.LABEL_OPACITY}`),
1361
- isForm: true,
1362
- propertyWidth: 150,
1363
- value: /* @__PURE__ */ jsx(RHFAutocomplete, {
1364
- name: "properties.fillOpacity",
1365
- autoComplete: "off",
1366
- options: STYLE_OPACITIES,
1367
- getOptionLabel: (option) => option.label,
1368
- isOptionEqualToValue: (option, value) => option.value === value.value,
1369
- label: "ssss"
1370
- })
1371
- }, "properties.fillOpacity")]
1372
- });
1373
- }
1374
- function StrokeData() {
1375
- const {
1376
- getLabel
1377
- } = useModuleDictionary();
1378
- const {
1379
- host_static_assets,
1380
- environment_assets
1381
- } = useEnvironment();
1382
- const urlIcon = `${host_static_assets}/${environment_assets}/frontend/domain/components/map/assets/icons/${icons.STROKE}`;
1383
- return /* @__PURE__ */ jsxs(PaperForm, {
1384
- urlIcon,
1385
- title: getLabel(DICCTIONARY.PAPER_STROKE),
1386
- children: [/* @__PURE__ */ jsx(PropertyValue, {
1387
- property: getLabel(`${DICCTIONARY.LABEL_COLOR}`),
1388
- isForm: true,
1389
- propertyWidth: 150,
1390
- value: /* @__PURE__ */ jsx(RHFColorPicker, {
1391
- name: "properties.strokeColor"
1392
- })
1393
- }, "properties.strokeColor"), /* @__PURE__ */ jsx(PropertyValue, {
1394
- property: getLabel(`${DICCTIONARY.LABEL_OPACITY}`),
1395
- isForm: true,
1396
- propertyWidth: 150,
1397
- value: /* @__PURE__ */ jsx(RHFAutocomplete, {
1398
- name: "properties.strokeOpacity",
1399
- autoComplete: "off",
1400
- options: STYLE_OPACITIES,
1401
- getOptionLabel: (option) => option.label,
1402
- isOptionEqualToValue: (option, value) => option.value === value.value,
1403
- label: "ssss"
1404
- })
1405
- }, "properties.strokeOpacity"), /* @__PURE__ */ jsx(PropertyValue, {
1406
- property: getLabel(`${DICCTIONARY.LABEL_WEIGHT}`),
1407
- isForm: true,
1408
- propertyWidth: 150,
1409
- value: /* @__PURE__ */ jsx(RHFAutocomplete, {
1410
- name: "properties.strokeWeight",
1411
- autoComplete: "off",
1412
- options: STYLE_WHEIGHTS,
1413
- getOptionLabel: (option) => option.label,
1414
- isOptionEqualToValue: (option, value) => option.value === value.value,
1415
- label: "ssss"
1416
- })
1417
- }, "properties.strokeWeight"), /* @__PURE__ */ jsx(PropertyValue, {
1418
- property: getLabel(`${DICCTIONARY.LABEL_DASH_ARRAY}`),
1419
- isForm: true,
1420
- propertyWidth: 150,
1421
- value: /* @__PURE__ */ jsx(RHFAutocomplete, {
1422
- name: "properties.strokeDashArray",
1423
- autoComplete: "off",
1424
- options: STYLE_PATTERNS,
1425
- getOptionLabel: (option) => option.label,
1426
- isOptionEqualToValue: (option, value) => option.value === value.value,
1427
- label: "ssss"
1428
- })
1429
- }, "properties.strokeDashArray")]
1430
- });
1431
- }
1432
- function StyleData() {
1433
- return /* @__PURE__ */ jsxs(Fragment, {
1434
- children: [/* @__PURE__ */ jsx(StrokeData, {}), /* @__PURE__ */ jsx(FillData, {})]
1435
- });
1436
- }
1437
- function MyTabs() {
1438
- const {
1439
- getLabel
1440
- } = useModuleDictionary();
1441
- const {
1442
- currentTab,
1443
- handleChange
1444
- } = useTab();
1445
- const geofenceAddEditTabs = useMemo(() => {
1446
- return [{
1447
- value: "general",
1448
- icon: void 0,
1449
- components: /* @__PURE__ */ jsxs(Fragment, {
1450
- children: [/* @__PURE__ */ jsx(GeneralData, {}), /* @__PURE__ */ jsx(ConfigData, {})]
1451
- }),
1452
- toolTip: getLabel(DICCTIONARY.TAB_GENERAL_CONFIG_TOOLTIP),
1453
- className: mapToolsClasses.toolGeofencesAddEditGeneral
1454
- }, {
1455
- value: "style",
1456
- icon: void 0,
1457
- components: /* @__PURE__ */ jsx(StyleData, {}),
1458
- toolTip: getLabel(DICCTIONARY.TAB_STYLE_CONFIG_TOOLTIP),
1459
- className: mapToolsClasses.toolGeofencesAddEditStyle
1460
- }];
1461
- }, [getLabel]);
1462
- console.log("MyTabs", currentTab);
1463
- return /* @__PURE__ */ jsxs(Stack, {
1464
- direction: "column",
1465
- children: [/* @__PURE__ */ jsx(Tabs, {
1466
- value: currentTab,
1467
- scrollButtons: "auto",
1468
- variant: "scrollable",
1469
- allowScrollButtonsMobile: true,
1470
- onChange: (_e, newValue) => handleChange(_e, newValue),
1471
- children: geofenceAddEditTabs.map((tab) => /* @__PURE__ */ jsx(Tab, {
1472
- value: tab.value,
1473
- icon: tab.icon,
1474
- label: /* @__PURE__ */ jsx(Tooltip, {
1475
- title: tab.toolTip,
1476
- children: /* @__PURE__ */ jsx("span", {
1477
- children: tab.toolTip
1478
- })
1479
- }),
1480
- SKTWidth: "100px",
1481
- SKTHeight: "14px"
1482
- }, tab.value))
1483
- }), geofenceAddEditTabs.map((tab) => {
1484
- const isMatched = tab.value === currentTab;
1485
- return /* @__PURE__ */ jsx(TabContent, {
1486
- className: clsx(mapToolsClasses.tabContentRoot, tab.className, isMatched ? mapToolsClasses.visible : mapToolsClasses.hidden),
1487
- children: tab.components
1488
- }, tab.value);
1489
- })]
1490
- });
1491
- }
1492
- function GeneralDataValidation(getLabel) {
1493
- return {
1494
- name: Yup.string().required(getLabel(DICCTIONARY.VALIDATION_FIELD_REQUIRED)),
1495
- geometry: Yup.object().nullable().required(getLabel(DICCTIONARY.VALIDATION_GEOMETRY_REQUIRED)),
1496
- geofenceType: Yup.object().nullable().required(getLabel(DICCTIONARY.VALIDATION_FIELD_REQUIRED))
1497
- };
1498
- }
1499
- function ConfigDataValidation(getLabel) {
1500
- return {
1501
- timeMinInSeconds: Yup.number().required(getLabel(DICCTIONARY.VALIDATION_FIELD_REQUIRED)).typeError(getLabel(DICCTIONARY.VALIDATION_FIELD_TYPE_NUMBER_ERROR)),
1502
- timeMinOutSeconds: Yup.number().required(getLabel(DICCTIONARY.VALIDATION_FIELD_REQUIRED)).typeError(getLabel(DICCTIONARY.VALIDATION_FIELD_TYPE_NUMBER_ERROR))
1503
- };
1504
- }
1505
- function useValidation$1() {
1506
- const { getLabel } = useModuleDictionary();
1507
- const validationSchema = useMemo(
1508
- () => Yup.object().shape({
1509
- ...GeneralDataValidation(getLabel),
1510
- ...ConfigDataValidation(getLabel)
1511
- }),
1512
- [getLabel]
1513
- );
1514
- return { validationSchema };
1515
- }
1516
- const getSummitData = (values, geofenceId) => {
1517
- const newEditObj = {
1518
- name: values.name,
1519
- typeId: values.geofenceType.id,
1520
- geometry: values.geometry,
1521
- properties: {
1522
- strokeColor: values.properties.fillColor,
1523
- strokeOpacity: values.properties.strokeOpacity.value,
1524
- strokeWeight: values.properties.strokeWeight.value,
1525
- strokeDashArray: values.properties.strokeDashArray.value,
1526
- fillColor: values.properties.fillColor,
1527
- fillOpacity: values.properties.fillOpacity.value
1528
- },
1529
- timeMinInSeconds: values.timeMinInSeconds,
1530
- timeMinOutSeconds: values.timeMinOutSeconds,
1531
- alias: values.alias,
1532
- customerId: values.customerId,
1533
- ...geofenceId ? { geofenceId } : {}
1534
- };
1535
- if (values.geofenceType.id === "gt_circle") {
1536
- newEditObj.properties.radius = values.properties.radius;
1537
- }
1538
- return newEditObj;
1539
- };
1540
- function useSubmit(props) {
1541
- const { objectId } = props;
1542
- const { toast } = useHostTools();
1543
- const { goToList } = useMapToolsStore((state) => state.geofenceActions);
1544
- const { networkOperation } = useNetwork();
1545
- const onSubmit = async (data) => {
1546
- await networkOperation({
1547
- method: objectId ? "PUT" : "POST",
1548
- endPoint: `${ENDPOINT_GEOFENCE_NEW_EDIT}${objectId ? `/${objectId}` : ""}`,
1549
- data: getSummitData(data, objectId),
1550
- toastError: true,
1551
- toastSuccess: false,
1552
- bodyToSnakeCase: true,
1553
- isRemote: false
1554
- }).then((response) => {
1555
- toast(
1556
- response.message,
1557
- { type: "success" }
1558
- );
1559
- goToList();
1560
- }).catch((error) => {
1561
- });
1562
- };
1563
- return { onSubmit };
1564
- }
1565
- function GeofenceAddEdit() {
1566
- const [geofenceId, finalInitalValues, omitCallEnpoint] = useMapToolsStore((state) => {
1567
- if (state.geofenceState.geofenceId === void 0) {
1568
- return [void 0, initialValues, false];
1569
- }
1570
- const geofence = state.geofenceState.hashGeofences[state.geofenceState.geofenceId];
1571
- if (geofence?.geometry) {
1572
- const emulateResponse = {
1573
- data: {
1574
- type: geofence.type,
1575
- name: geofence.name,
1576
- id: geofence.id,
1577
- active: false,
1578
- geometry: geofence.geometry,
1579
- properties: geofence.properties,
1580
- countCrossingFeatures: geofence.countCrossingFeatures,
1581
- countInternalFeatures: geofence.countInternalFeatures,
1582
- createdAt: geofence.createdAt,
1583
- updatedAt: geofence.updatedAt,
1584
- timeMinInSeconds: geofence.timeMinInSeconds,
1585
- timeMinOutSeconds: geofence.timeMinOutSeconds,
1586
- alias: geofence.alias,
1587
- customerId: geofence.customerId
1588
- }
1589
- };
1590
- return [state.geofenceState.geofenceId, formatDataEnpoint(emulateResponse), true];
1591
- } else {
1592
- return [state.geofenceState.geofenceId, initialValues, false];
1593
- }
1594
- });
1595
- const {
1596
- formValues,
1597
- statusLoad
1598
- } = useFormAddEdit({
1599
- objectId: geofenceId,
1600
- formatDataEnpoint,
1601
- initialValues: finalInitalValues,
1602
- endPoint: ENDPOINT_GEOFENCE_GET,
1603
- isRemote: false,
1604
- omitCallEnpoint
1605
- });
1606
- const {
1607
- validationSchema
1608
- } = useValidation$1();
1609
- const {
1610
- onSubmit
1611
- } = useSubmit({
1612
- objectId: geofenceId
1613
- });
1614
- return /* @__PURE__ */ jsxs(RHFormProvider, {
1615
- statusLoad,
1616
- onSubmit,
1617
- values: formValues,
1618
- validationSchema,
1619
- className: mapToolsClasses.toolGeofencesAddEditGeneral,
1620
- children: [/* @__PURE__ */ jsx(Stack, {
1621
- direction: "column",
1622
- children: /* @__PURE__ */ jsx(TabProvider, {
1623
- initialValue: "general",
1624
- children: /* @__PURE__ */ jsx(MyTabs, {})
1625
- })
1626
- }), /* @__PURE__ */ jsx(MyActions$1, {})]
1627
- });
1628
- }
1629
- function GeofencesTool() {
1630
- const currentGeofenceTool = useMapToolsStore((state) => state.geofenceState.currentGeofenceTool, shallow);
1631
- return /* @__PURE__ */ jsxs(Stack, {
1632
- direction: "column",
1633
- gap: "4px",
1634
- className: mapToolsClasses.toolGeofences,
1635
- children: [currentGeofenceTool === "list" && /* @__PURE__ */ jsx(GeofencesList, {}), currentGeofenceTool === "add_edit" && /* @__PURE__ */ jsx(GeofenceAddEdit, {})]
1636
- });
1637
- }
1638
- function MyActions() {
1639
- const {
1640
- control,
1641
- setValue
1642
- } = useFormContext();
1643
- const {
1644
- getLabel
1645
- } = useModuleDictionary();
1646
- const fieldsWatch = useWatch({
1647
- control,
1648
- name: ["statusEdition", "reInits"]
1649
- });
1650
- const statusEdition = fieldsWatch[0];
1651
- const reInits = fieldsWatch[1];
1652
- const initDraw = () => {
1653
- if (statusEdition === "initial") {
1654
- setValue("statusEdition", "draw");
1655
- } else if (statusEdition === "draw") {
1656
- setValue("reInits", reInits + 1);
1657
- }
1658
- };
1659
- return /* @__PURE__ */ jsx(Actions, {
1660
- children: /* @__PURE__ */ jsx(Button, {
1661
- onClick: initDraw,
1662
- children: statusEdition === "initial" ? getLabel(DICCTIONARY.LABEL_MEASURE_START) : getLabel(DICCTIONARY.LABEL_MEASURE_RESTART)
1663
- })
1664
- });
1665
- }
1666
- function MeasureDataValidation(getLabel) {
1667
- return {};
1668
- }
1669
- function useValidation() {
1670
- const { getLabel } = useModuleDictionary();
1671
- const validationSchema = useMemo(
1672
- () => Yup.object().shape({
1673
- ...MeasureDataValidation()
1674
- }),
1675
- [getLabel]
1676
- );
1677
- return { validationSchema };
1678
- }
1679
- const INITIAL_FORM_VALUES = {
1680
- statusLoad: "ready",
1681
- reInits: 0,
1682
- value: "0",
1683
- measureTypeId: "distance",
1684
- magnitudFactor: { id: "m_kilometers", name: "Kilometers", symbol: "k", factor_x0: 0, factor_x1: 1, factor_x2: 0 },
1685
- unitArea: null,
1686
- statusEdition: "initial"
1687
- };
1688
- const STYLE_MEASURE_OPTIONS = {
1689
- strokeLineColor: "#1E96DC",
1690
- strokeLineWeight: 5,
1691
- markerHeight: 37,
1692
- markerWidth: 26,
1693
- labelMarkerHeight: 0,
1694
- labelMarkerWidth: 0,
1695
- labelMarkerAnchorY: 0,
1696
- labelMarkerAnchorX: 0
1697
- };
1698
- function useMeasure() {
1699
- const { getLabel } = useModuleDictionary();
1700
- const readyToUpdate = useFormReadyForUpdate();
1701
- const map = useMap();
1702
- const { control, setValue } = useFormContext();
1703
- const fieldsWatch = useWatch({
1704
- control,
1705
- name: [
1706
- "statusEdition",
1707
- "value",
1708
- "magnitudFactor",
1709
- "reInits"
1710
- ]
1711
- });
1712
- const statusEdition = fieldsWatch[0];
1713
- const value = fieldsWatch[1];
1714
- const magnitudFactor = fieldsWatch[2];
1715
- const reInits = fieldsWatch[3];
1716
- const [magnitudFactorCached, setMagnitudFactorCached] = useState(magnitudFactor);
1717
- const currentMeasure = useRef({ measurePoints: [], addMarker: false, magnitudFactor, dragging: false });
1718
- const clearMeasure = useCallback(() => {
1719
- currentMeasure.current.measurePoints.forEach((measurePoint) => {
1720
- measurePoint.marker.remove();
1721
- measurePoint.labelMarker.remove();
1722
- });
1723
- currentMeasure.current.measurePoints = [];
1724
- setValue("value", measureDistante());
1725
- }, []);
1726
- const getFormatFactorDistance = useCallback((distance, withSymbol = false) => {
1727
- if (distance === void 0) {
1728
- return void 0;
1729
- }
1730
- const cMagnitudeFactor = currentMeasure.current.magnitudFactor;
1731
- return (cMagnitudeFactor.factor_x0 + distance * cMagnitudeFactor.factor_x1 + (distance ^ 2 * cMagnitudeFactor.factor_x2)).toFixed(2) + (withSymbol ? ` ${cMagnitudeFactor.symbol}` : "");
1732
- }, []);
1733
- const measureDistante = useCallback(() => {
1734
- var totalDistance = 0;
1735
- const measurePoints = currentMeasure.current.measurePoints;
1736
- if (currentMeasure.current.layerLine) {
1737
- if (measurePoints.length < 2) {
1738
- currentMeasure.current.layerLine.remove();
1739
- currentMeasure.current.layerLine = void 0;
1740
- } else {
1741
- currentMeasure.current.layerLine.setLatLngs(measurePoints.map((measurePoint) => measurePoint.marker.getLatLng()));
1742
- }
1743
- } else {
1744
- if (measurePoints.length > 1) {
1745
- currentMeasure.current.layerLine = L.polyline(
1746
- measurePoints.map((measurePoint) => measurePoint.marker.getLatLng()),
1747
- {
1748
- color: STYLE_MEASURE_OPTIONS.strokeLineColor,
1749
- weight: STYLE_MEASURE_OPTIONS.strokeLineWeight,
1750
- interactive: false
1751
- }
1752
- ).addTo(map);
1753
- }
1754
- }
1755
- for (let i = 0; i < measurePoints.length - 1; i++) {
1756
- totalDistance += measurePoints[i].marker.getLatLng().distanceTo(measurePoints[i + 1].marker.getLatLng());
1757
- }
1758
- if (measurePoints.length > 0 && measurePoints[0].formatDistanceFromPrevious !== void 0) {
1759
- measurePoints[0].formatDistanceFromPrevious = void 0;
1760
- }
1761
- for (let i = 1; i < measurePoints.length; i++) {
1762
- const formatDistanceFromPrevious = getFormatFactorDistance(measurePoints[i - 1].marker.getLatLng().distanceTo(measurePoints[i].marker.getLatLng()), true);
1763
- if (measurePoints[i].formatDistanceFromPrevious !== formatDistanceFromPrevious) {
1764
- measurePoints[i].formatDistanceFromPrevious = formatDistanceFromPrevious;
1765
- measurePoints[i].labelMarker.setIcon(getLabelMarkerPointIcon(formatDistanceFromPrevious));
1766
- addClickListenerForRemove(measurePoints[i].labelMarker);
1767
- }
1768
- }
1769
- return getFormatFactorDistance(totalDistance);
1770
- }, [map]);
1771
- const getMarkerPointIcon = useCallback((position) => {
1772
- return L.divIcon({
1773
- className: mapClasses.measureMarkerRoot,
1774
- html: `<div class="${mapClasses.measureMarkerContainer}">
1775
- <div class="${mapClasses.measureMarkerContainerRhomb}">
1776
- </div>
1777
- <div class="${mapClasses.measureMarkerContainerSlot}">
1778
- <div class="${mapClasses.measureMarkerContainerSlotNumber}">
1779
- ${position}
1780
- </div>
1781
- </div>
1782
- </div>
1783
- `,
1784
- iconSize: [STYLE_MEASURE_OPTIONS.markerWidth, STYLE_MEASURE_OPTIONS.markerHeight],
1785
- iconAnchor: [STYLE_MEASURE_OPTIONS.markerWidth / 2, STYLE_MEASURE_OPTIONS.markerHeight]
1786
- });
1787
- }, []);
1788
- const getLabelMarkerPointIcon = useCallback((distance) => {
1789
- return L.divIcon({
1790
- className: mapClasses.measureLabelMarkerRoot,
1791
- html: `<div class="${mapClasses.measureLabelMarkerContainer}">
1792
- ${distance ? `<span class="${mapClasses.measureLabelMarkerDistance}">${distance}</span>` : ""}
1793
- <div class="${mapClasses.measureLabelMarkerRemove}">${getLabel(DICCTIONARY.LABEL_MEASURE_REMOVE_POINT)}</div>
1794
- </div>`,
1795
- iconSize: [STYLE_MEASURE_OPTIONS.labelMarkerWidth, STYLE_MEASURE_OPTIONS.labelMarkerHeight],
1796
- iconAnchor: [STYLE_MEASURE_OPTIONS.labelMarkerAnchorX, STYLE_MEASURE_OPTIONS.labelMarkerAnchorY]
1797
- });
1798
- }, [getLabel]);
1799
- const onClickRemovePoint = useCallback((labelMarker) => {
1800
- return (e) => {
1801
- e.stopPropagation();
1802
- if (!currentMeasure.current.dragging) {
1803
- var markIndex = currentMeasure.current.measurePoints.findIndex((searchElement) => {
1804
- return searchElement.labelMarker === labelMarker;
1805
- });
1806
- if (markIndex !== -1) {
1807
- var measurePoint = currentMeasure.current.measurePoints[markIndex];
1808
- measurePoint.marker.remove();
1809
- measurePoint.labelMarker.remove();
1810
- currentMeasure.current.measurePoints.splice(markIndex, 1);
1811
- setValue("value", measureDistante());
1812
- currentMeasure.current.addMarker = true;
1813
- }
1814
- currentMeasure.current.measurePoints.forEach((measurePoint2, index) => {
1815
- measurePoint2.marker.setIcon(getMarkerPointIcon(index + 1));
1816
- });
1817
- }
1818
- };
1819
- }, []);
1820
- const addClickListenerForRemove = useCallback((labelMarker) => {
1821
- var element = labelMarker.getElement();
1822
- if (element) {
1823
- var elements = element.getElementsByClassName("M4L-MapTool-MeasureToolTip-Remove");
1824
- element = elements[0];
1825
- if (element) {
1826
- element.addEventListener("click", onClickRemovePoint(labelMarker));
1827
- }
1828
- }
1829
- }, []);
1830
- const onClickMap = useCallback((e) => {
1831
- var lat = e.latlng.lat;
1832
- var lng = e.latlng.lng;
1833
- var formatDistanceFromPrevious = void 0;
1834
- if (currentMeasure.current.addMarker === false) {
1835
- return;
1836
- }
1837
- if (currentMeasure.current.measurePoints.length > 0) {
1838
- formatDistanceFromPrevious = getFormatFactorDistance(currentMeasure.current.measurePoints[currentMeasure.current.measurePoints.length - 1].marker.getLatLng().distanceTo(e.latlng));
1839
- }
1840
- var marker = L.marker([lat, lng], {
1841
- draggable: true,
1842
- riseOnHover: true,
1843
- autoPan: true,
1844
- icon: getMarkerPointIcon(currentMeasure.current.measurePoints.length + 1),
1845
- zIndexOffset: MAP_ZINDEX_DEFAULT
1846
- }).addTo(map);
1847
- marker.on("moveend", function(e2) {
1848
- var latlng = marker.getLatLng();
1849
- labelMarker.setLatLng(latlng);
1850
- setValue("value", measureDistante());
1851
- });
1852
- marker.on("mouseover", function(e2) {
1853
- currentMeasure.current.addMarker = false;
1854
- });
1855
- marker.on("mouseout", function(e2) {
1856
- currentMeasure.current.addMarker = true;
1857
- });
1858
- var labelMarker = L.marker([lat, lng], {
1859
- draggable: true,
1860
- riseOnHover: true,
1861
- icon: getLabelMarkerPointIcon(formatDistanceFromPrevious),
1862
- zIndexOffset: MAP_ZINDEX_DEFAULT
1863
- }).addTo(map);
1864
- labelMarker.on("moveend", function(e2) {
1865
- var latlng = labelMarker.getLatLng();
1866
- marker.setLatLng(latlng);
1867
- setValue("value", measureDistante());
1868
- });
1869
- labelMarker.on("mouseover", function(e2) {
1870
- currentMeasure.current.addMarker = false;
1871
- });
1872
- labelMarker.on("mouseout", function(e2) {
1873
- currentMeasure.current.addMarker = true;
1874
- });
1875
- labelMarker.on("dragstart", function(e2) {
1876
- currentMeasure.current.dragging = true;
1877
- });
1878
- labelMarker.on("dragend", function(e2) {
1879
- setTimeout(function() {
1880
- currentMeasure.current.dragging = false;
1881
- }, 10);
1882
- });
1883
- addClickListenerForRemove(labelMarker);
1884
- currentMeasure.current.measurePoints.push({
1885
- marker,
1886
- labelMarker,
1887
- formatDistanceFromPrevious
1888
- });
1889
- setValue("value", measureDistante());
1890
- }, [map, measureDistante, setValue]);
1891
- const onMouseMoveMap = useCallback(() => {
1892
- map.getContainer().style.cursor = "crosshair";
1893
- }, [map]);
1894
- const onMouseOutMap = useCallback(() => {
1895
- map.getContainer().style.cursor = "default";
1896
- }, [map]);
1897
- useEffect(() => {
1898
- if (map) {
1899
- if (statusEdition === "initial") {
1900
- return;
1901
- } else {
1902
- currentMeasure.current.addMarker = true;
1903
- map.on("mousemove", onMouseMoveMap);
1904
- map.on("mouseout", onMouseOutMap);
1905
- map.on("click", onClickMap);
1906
- }
1907
- }
1908
- }, [map, statusEdition]);
1909
- useEffect(() => {
1910
- console.log("useEffect magnitudFactor", readyToUpdate, magnitudFactor);
1911
- if (!readyToUpdate)
1912
- return;
1913
- if (magnitudFactor.id !== magnitudFactorCached.id) {
1914
- console.log("useEffect magnitudFactor CAMBIO");
1915
- setMagnitudFactorCached({ ...magnitudFactor });
1916
- currentMeasure.current.magnitudFactor = magnitudFactor;
1917
- setValue("value", measureDistante());
1918
- }
1919
- }, [magnitudFactor]);
1920
- useEffect(() => {
1921
- console.log("useEffect reInits", readyToUpdate, reInits);
1922
- if (!readyToUpdate)
1923
- return;
1924
- clearMeasure();
1925
- }, [reInits]);
1926
- useEffect(() => {
1927
- return () => {
1928
- map.off("mousemove", onMouseMoveMap);
1929
- map.off("mouseout", onMouseOutMap);
1930
- map.off("click", onClickMap);
1931
- map.getContainer().style.cursor = "default";
1932
- clearMeasure();
1933
- console.debug("DESMONTAJES MARCAS Y EVENTOS");
1934
- };
1935
- }, []);
1936
- return { statusEdition, magnitudFactor, value };
1937
- }
1938
- const DevTool = process.env.NODE_ENV === "development" ? require("@hookform/devtools").DevTool : () => null;
1939
- function MeasureData() {
1940
- const {
1941
- getLabel
1942
- } = useModuleDictionary();
1943
- const {
1944
- host_static_assets,
1945
- environment_assets
1946
- } = useEnvironment();
1947
- const {
1948
- control
1949
- } = useFormContext();
1950
- const {
1951
- value,
1952
- magnitudFactor
1953
- } = useMeasure();
1954
- const urlIcon = `${host_static_assets}/${environment_assets}/frontend/domain/components/map/assets/icons/${icons.MEASURE}`;
1955
- return /* @__PURE__ */ jsxs(PaperForm, {
1956
- urlIcon,
1957
- title: getLabel(DICCTIONARY.PAPER_MEASURE),
1958
- children: [/* @__PURE__ */ jsx(RHFAutocompleteAsync, {
1959
- endPoint: "magnitudes/factors?origin_unit_reference_id=m_kilometers",
1960
- name: "magnitudFactor",
1961
- autoComplete: "off",
1962
- getOptionLabel: (option) => option.name,
1963
- isOptionEqualToValue: (option, value2) => option.id === value2.id,
1964
- label: getLabel(DICCTIONARY.LABEL_MEASURE_UNIT),
1965
- isRemote: false
1966
- }), /* @__PURE__ */ jsxs(Stack, {
1967
- direction: "row",
1968
- spacing: 2,
1969
- className: mapToolsClasses.toolMeasureFormValue,
1970
- children: [/* @__PURE__ */ jsx("span", {
1971
- className: mapToolsClasses.toolMeasureFormValueDistance,
1972
- children: value
1973
- }), /* @__PURE__ */ jsx("span", {
1974
- className: mapToolsClasses.toolMeasureFormValueSymbol,
1975
- children: magnitudFactor.symbol
1976
- })]
1977
- }), process.env.NODE_ENV === "development" && /* @__PURE__ */ jsx(DevTool, {
1978
- control
1979
- })]
1980
- });
1981
- }
1982
- function MeasureTool() {
1983
- const {
1984
- getLabel
1985
- } = useModuleDictionary();
1986
- const finalInitalValues = {
1987
- ...INITIAL_FORM_VALUES
1988
- };
1989
- if (finalInitalValues?.magnitudFactor?.name) {
1990
- finalInitalValues.magnitudFactor.name = getLabel(DICCTIONARY.LABEL_MEASURE_UNIT_BASE_KILOMETERS);
1991
- }
1992
- const {
1993
- validationSchema
1994
- } = useValidation();
1995
- const onSubmit = () => {
1996
- };
1997
- return /* @__PURE__ */ jsxs(RHFormProvider, {
1998
- statusLoad: INITIAL_FORM_VALUES.statusLoad,
1999
- onSubmit,
2000
- values: finalInitalValues,
2001
- validationSchema,
2002
- children: [/* @__PURE__ */ jsx(Stack, {
2003
- direction: "column",
2004
- children: /* @__PURE__ */ jsx(MeasureData, {})
2005
- }), /* @__PURE__ */ jsx(MyActions, {})]
2006
- });
2007
- }
2008
- const PolylineWithArrows = ({
2009
- positions,
2010
- enableEdit,
2011
- ...other
2012
- }) => {
2013
- const map = useMap();
2014
- const polylineRef = useRef(null);
2015
- const decoratorRef = useRef(null);
2016
- useEffect(() => {
2017
- if (polylineRef.current) {
2018
- const decorator = L__default.polylineDecorator(polylineRef.current, {
2019
- patterns: [{
2020
- repeat: 50,
2021
- symbol: L__default.Symbol.arrowHead({
2022
- pixelSize: 4,
2023
- polygon: false,
2024
- pathOptions: {
2025
- stroke: true,
2026
- color: "#ffffff",
2027
- weight: 2
2028
- }
2029
- })
2030
- }]
2031
- }).addTo(map);
2032
- decoratorRef.current = decorator;
2033
- if (enableEdit) {
2034
- polylineRef.current.pm.enable();
2035
- } else {
2036
- polylineRef.current.pm.disable();
2037
- }
2038
- polylineRef.current.on("pm:change", () => {
2039
- if (decoratorRef.current) {
2040
- map.removeLayer(decoratorRef.current);
2041
- }
2042
- if (polylineRef.current) {
2043
- decoratorRef.current = L__default.polylineDecorator(polylineRef.current, {
2044
- patterns: [{
2045
- repeat: 40,
2046
- symbol: L__default.Symbol.arrowHead({
2047
- pixelSize: 4,
2048
- polygon: false,
2049
- pathOptions: {
2050
- stroke: true,
2051
- color: "#cc0000",
2052
- weight: 2
2053
- }
2054
- })
2055
- }]
2056
- }).addTo(map);
2057
- }
2058
- });
2059
- return () => {
2060
- if (decoratorRef.current) {
2061
- map.removeLayer(decoratorRef.current);
2062
- }
2063
- };
2064
- }
2065
- }, [map, enableEdit]);
2066
- return /* @__PURE__ */ jsx(Polyline, {
2067
- positions,
2068
- ref: polylineRef,
2069
- ...other
2070
- });
2071
- };
2072
- const PolylineWithArrows$1 = PolylineWithArrows;
2073
- function useLayers() {
2074
- const {
2075
- addLayer,
2076
- removeLayer
2077
- } = useMapStore((state) => state.mapActions, shallow);
2078
- const {
2079
- init
2080
- } = useMapToolsStore((state) => state.mapToolsActions, shallow);
2081
- const renderByEachFeature = useCallback((props) => {
2082
- const {
2083
- id,
2084
- layerId
2085
- } = props;
2086
- const feature = useMapStore((state) => {
2087
- const gObject = state.hashLayers[layerId].geoJsonObject;
2088
- if (!gObject) {
2089
- return null;
2090
- }
2091
- if (gObject.object.type === "Feature") {
2092
- return {
2093
- geometry: gObject.object.geometry,
2094
- properties: gObject.object.properties
2095
- };
2096
- } else {
2097
- const feat = gObject.object.features.find((f) => f.id === id);
2098
- if (feat) {
2099
- return {
2100
- geometry: feat.geometry,
2101
- properties: feat.properties
2102
- };
2103
- }
2104
- return null;
2105
- }
2106
- }, shallow);
2107
- const refFeature = useRef(null);
2108
- if (!feature) {
2109
- return null;
2110
- }
2111
- useEffect(() => {
2112
- if (refFeature.current)
2113
- ;
2114
- }, [refFeature.current]);
2115
- console.log(`renderByEachFeature *** ${feature.geometry?.type}: ${id}`);
2116
- if (feature.geometry?.type === "LineString") {
2117
- const polylinePositions = feature.geometry.coordinates.map((coord) => [coord[1], coord[0]]);
2118
- return /* @__PURE__ */ jsx(
2119
- PolylineWithArrows$1,
2120
- {
2121
- positions: polylinePositions,
2122
- stroke: true,
2123
- weight: 10,
2124
- ...feature.properties,
2125
- dashArray: "20 30"
2126
- },
2127
- Math.random()
2128
- );
2129
- }
2130
- if (feature.geometry?.type === "Polygon") {
2131
- const polygonPositions = feature.geometry.coordinates.map((ring) => ring.map(([lng, lat]) => [lat, lng]));
2132
- return /* @__PURE__ */ jsx(
2133
- Polygon,
2134
- {
2135
- ref: refFeature,
2136
- positions: polygonPositions,
2137
- opacity: 1,
2138
- ...feature.properties,
2139
- children: /* @__PURE__ */ jsx(Popup, {})
2140
- },
2141
- Math.random()
2142
- );
2143
- }
2144
- if (feature.geometry?.type === "Point") {
2145
- if (feature.properties?.subType === "Circle" && feature.properties?.radius) {
2146
- const {
2147
- subType,
2148
- radius,
2149
- ...styleProperties
2150
- } = feature.properties;
2151
- const [lng, lat] = feature.geometry.coordinates;
2152
- return /* @__PURE__ */ jsx(Circle, {
2153
- center: {
2154
- lat,
2155
- lng
2156
- },
2157
- radius: feature.properties?.radius,
2158
- ...styleProperties
2159
- }, Math.random());
2160
- }
2161
- }
2162
- return null;
2163
- }, []);
2164
- useEffect(() => {
2165
- addLayer({
2166
- layerId: GeofencesFeaturesLayers.LAYER_GEOFENCES,
2167
- description: "Geocercas",
2168
- renderFeature: renderByEachFeature,
2169
- geoJsonObject: {
2170
- object: {
2171
- type: "FeatureCollection",
2172
- features: []
2173
- }
2174
- }
2175
- });
2176
- addLayer({
2177
- layerId: GeofencesFeaturesLayers.LAYER_GEOFENCES_TRANSIT_FEATURES,
2178
- description: "Geometr\xEDas de tr\xE1nsito",
2179
- renderFeature: renderByEachFeature,
2180
- geoJsonObject: {
2181
- object: {
2182
- type: "FeatureCollection",
2183
- features: []
2184
- }
2185
- }
2186
- });
2187
- addLayer({
2188
- layerId: GeofencesFeaturesLayers.LAYER_GEOFENCES_INTERNAL_FEATURES,
2189
- description: "Geometr\xEDas internas",
2190
- renderFeature: renderByEachFeature,
2191
- geoJsonObject: {
2192
- object: {
2193
- type: "FeatureCollection",
2194
- features: []
2195
- }
2196
- }
2197
- });
2198
- init();
2199
- return () => {
2200
- removeLayer(GeofencesFeaturesLayers.LAYER_GEOFENCES);
2201
- removeLayer(GeofencesFeaturesLayers.LAYER_GEOFENCES_INTERNAL_FEATURES);
2202
- removeLayer(GeofencesFeaturesLayers.LAYER_GEOFENCES_TRANSIT_FEATURES);
2203
- };
2204
- }, []);
2205
- }
2206
- const TabToolsRoot = styled("div")`
2207
- display:flex;
2208
- flex-direction:column;
2209
- right:10px;
2210
- width:600px;
2211
- top:10px;
2212
- bottom:10px;
2213
- position:absolute;
2214
- height:unset;
2215
- z-index:${MAP_ZINDEX_OVER_MAP};
2216
-
2217
-
2218
- .${mapToolsClasses.tabContentRoot}.${mapToolsClasses.hidden} {
2219
- height:0px;
2220
- width:0px;
2221
- overflow:hidden;
2222
- opacity:0;
2223
- visibility:hidden;
2224
- }
2225
-
2226
-
2227
- .${mapToolsClasses.toolMeasureFormValue} {
2228
- justify-content: center;
2229
- }
2230
-
2231
- .${mapToolsClasses.toolMeasureFormValueDistance} {
2232
- border: 1px solid white;
2233
-
2234
- margin: 0 5px;
2235
- }
2236
- .${mapToolsClasses.toolMeasureFormValueSymbol} {
2237
- border: 1px solid white;
2238
-
2239
- margin: 0 5px;
2240
- }
2241
-
2242
- ${(props) => props.theme.components?.M4LGpsTools?.styleOverrides}
2243
- `;
2244
- function TabTools() {
2245
- const {
2246
- getLabel
2247
- } = useModuleDictionary();
2248
- const status = useMapToolsStore((state) => state.ownerState.status, shallow);
2249
- const currentTabTool = useMapToolsStore((state) => state.currentTabTool, shallow);
2250
- const {
2251
- setCurrentTabTool
2252
- } = useMapToolsStore((state) => state.mapToolsActions, shallow);
2253
- const toolTabs = useMemo(() => {
2254
- return [
2255
- {
2256
- id: "geofences",
2257
- icon: void 0,
2258
- component: /* @__PURE__ */ jsx(GeofencesTool, {}),
2259
- label: getLabel(DICCTIONARY.LABEL_TAB_GEO),
2260
- className: mapToolsClasses.toolGeofences
2261
- },
2262
- {
2263
- id: "measure",
2264
- icon: void 0,
2265
- component: /* @__PURE__ */ jsx(MeasureTool, {}),
2266
- label: getLabel(DICCTIONARY.LABEL_TAB_MEASURE),
2267
- className: mapToolsClasses.toolMeasure
2268
- }
2269
- ];
2270
- }, [getLabel]);
2271
- useLayers();
2272
- if (status !== "ready") {
2273
- return null;
2274
- }
2275
- return createPortal(/* @__PURE__ */ jsxs(
2276
- TabToolsRoot,
2277
- {
2278
- children: [/* @__PURE__ */ jsx(Tabs, {
2279
- value: currentTabTool,
2280
- scrollButtons: "auto",
2281
- variant: "scrollable",
2282
- allowScrollButtonsMobile: true,
2283
- onChange: (_e, value) => setCurrentTabTool(value),
2284
- children: toolTabs.map((tab) => /* @__PURE__ */ jsx(Tab, {
2285
- value: tab.id,
2286
- icon: tab.icon,
2287
- label: tab.label,
2288
- SKTWidth: "100px",
2289
- SKTHeight: "14px"
2290
- }, tab.id))
2291
- }), toolTabs.map((tab) => {
2292
- const isMatched = tab.id === currentTabTool;
2293
- if (!isMatched && tab.id === "measure") {
2294
- return null;
2295
- }
2296
- return /* @__PURE__ */ jsx(TabContent, {
2297
- className: clsx(mapToolsClasses.tabContentRoot, tab.className, isMatched ? mapToolsClasses.visible : mapToolsClasses.hidden),
2298
- children: tab.component
2299
- }, tab.id);
2300
- })]
2301
- }
2302
- ), document.body);
2303
- }
2304
- function GpsTools() {
2305
- const isSkeleton = useModuleSkeleton();
2306
- return /* @__PURE__ */ jsx(GpsToolsProvider, {
2307
- children: !isSkeleton && /* @__PURE__ */ jsx(TabTools, {})
2308
- });
2309
- }
2310
- export {
2311
- GpsToolsContext as G,
2312
- GpsTools as a
2313
- };