@m4l/components 0.2.5 → 0.2.7

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