alessandro trinca tornidor commited on
Commit
ca78a2e
Β·
1 Parent(s): 52a7159

style(frontend): add section headers to helpers.ts for readability

Browse files

Organize 22 functions into 10 logical sections with single-line
comment headers: Map State, ML Inference, URL Params, Prompt
Transformation, Leaflet UI, Coordinate Extraction, API Communication,
Prompt Builders, Geoman Events, UI Feedback.

Files changed (1) hide show
  1. static/src/components/helpers.ts +10 -0
static/src/components/helpers.ts CHANGED
@@ -26,6 +26,7 @@ import {
26
  } from './types.d'
27
  import { type Ref } from 'vue'
28
 
 
29
  export const updateZoomBboxMap = (localMap: LMap) => {
30
  currentZoomRef.value = localMap.getZoom()
31
  currentMapBBoxRef.value = getExtentCurrentViewMapBBox(localMap)
@@ -40,6 +41,7 @@ export const getCurrentBasemap = (url: string, providersArray: ServiceTiles): st
40
  return "-"
41
  }
42
 
 
43
  export const sendMLRequest = async (
44
  leafletMap: LMap, promptRequest: Array<IPointPrompt | IRectanglePrompt>, sourceType: SourceTileType = OpenStreetMap
45
  ) => {
@@ -72,6 +74,7 @@ export const sendMLRequest = async (
72
  }
73
  }
74
 
 
75
  export const getQueryParams = () => {
76
  const urlSearchParams = new URLSearchParams(window.location.search);
77
  const params = Object.fromEntries(urlSearchParams.entries());
@@ -79,6 +82,7 @@ export const getQueryParams = () => {
79
  return {source, options}
80
  }
81
 
 
82
  export const applyFnToObjectWithinArray = (array: Array<IPointPrompt | IRectanglePrompt>): Array<IPointTable | IRectangleTable> => {
83
  const newArray: Array<IPointTable | IRectangleTable> = []
84
  for (const el of array) {
@@ -103,6 +107,7 @@ const getUpdatedRectangle = (obj: IRectanglePrompt): IRectangleTable => {
103
  }
104
  }
105
 
 
106
  /** get a custom icon given a PNG path with its anchor/size values */
107
  export const getCustomIconMarker = (
108
  iconUrlNoExt: string,
@@ -189,6 +194,7 @@ export function setGeomanControls(localMap: LMap) {
189
  })
190
  }
191
 
 
192
  /** get the selected rectangle layer bounding box coordinate */
193
  export const getSelectedRectangleCoordinatesBBox = (leafletEvent: LEvented): BboxLatLng => {
194
  const { _northEast, _southWest } = leafletEvent.layer._bounds
@@ -209,6 +215,7 @@ export const getExtentCurrentViewMapBBox = (leafletMap: LMap): BboxLatLng => {
209
  return { ne: boundaries.getNorthEast(), sw: boundaries.getSouthWest() }
210
  }
211
 
 
212
  /** send the ML request to the backend API through the cloudflare proxy function */
213
  export const getGeoJSONRequest = async (
214
  requestBody: IBodyLatLngPoints,
@@ -259,6 +266,7 @@ export const getGeoJSONRequest = async (
259
  }
260
  }
261
 
 
262
  /** populate a single point ML request prompt, by type (exclude or include), see type ExcludeIncludeLabelPrompt */
263
  export const getPointPromptElement = (e: LEvented, elementType: ExcludeIncludeLabelPrompt): IPointPrompt|IRectanglePrompt => {
264
  const currentPointLayer: LatLng = getSelectedPointCoordinate(e)
@@ -279,6 +287,7 @@ export const getRectanglePromptElement = (e: LEvented) => {
279
  }
280
  }
281
 
 
282
  /** handle different event/layer types (rectangle, point: IncludeMarkerPrompt, ExcludeMarkerPrompt) */
283
  const updateLayerOnCreateOrEditEvent = (
284
  event: LEvented,
@@ -325,6 +334,7 @@ export const removeEventFromArrayByIndex = (arr: Array<LEvented>, e: LEvented) =
325
  })
326
  }
327
 
 
328
  /** build an HTML popup div showing lat, lng, label and leaflet id for a point marker */
329
  export const getPopupContentPoint = (leafletEvent: LEvented, label: number): HTMLDivElement => {
330
  const popupContent: HTMLDivElement = document.createElement('div')
 
26
  } from './types.d'
27
  import { type Ref } from 'vue'
28
 
29
+ // ── Map State & View ────────────────────────────────────────────────
30
  export const updateZoomBboxMap = (localMap: LMap) => {
31
  currentZoomRef.value = localMap.getZoom()
32
  currentMapBBoxRef.value = getExtentCurrentViewMapBBox(localMap)
 
41
  return "-"
42
  }
43
 
44
+ // ── ML Inference Workflow ───────────────────────────────────────────
45
  export const sendMLRequest = async (
46
  leafletMap: LMap, promptRequest: Array<IPointPrompt | IRectanglePrompt>, sourceType: SourceTileType = OpenStreetMap
47
  ) => {
 
74
  }
75
  }
76
 
77
+ // ── URL & Query Parameters ──────────────────────────────────────────
78
  export const getQueryParams = () => {
79
  const urlSearchParams = new URLSearchParams(window.location.search);
80
  const params = Object.fromEntries(urlSearchParams.entries());
 
82
  return {source, options}
83
  }
84
 
85
+ // ── Prompt Data Transformation ──────────────────────────────────────
86
  export const applyFnToObjectWithinArray = (array: Array<IPointPrompt | IRectanglePrompt>): Array<IPointTable | IRectangleTable> => {
87
  const newArray: Array<IPointTable | IRectangleTable> = []
88
  for (const el of array) {
 
107
  }
108
  }
109
 
110
+ // ── Leaflet UI Components (Geoman) ──────────────────────────────────
111
  /** get a custom icon given a PNG path with its anchor/size values */
112
  export const getCustomIconMarker = (
113
  iconUrlNoExt: string,
 
194
  })
195
  }
196
 
197
+ // ── Coordinate Extraction ───────────────────────────────────────────
198
  /** get the selected rectangle layer bounding box coordinate */
199
  export const getSelectedRectangleCoordinatesBBox = (leafletEvent: LEvented): BboxLatLng => {
200
  const { _northEast, _southWest } = leafletEvent.layer._bounds
 
215
  return { ne: boundaries.getNorthEast(), sw: boundaries.getSouthWest() }
216
  }
217
 
218
+ // ── API Communication ───────────────────────────────────────────────
219
  /** send the ML request to the backend API through the cloudflare proxy function */
220
  export const getGeoJSONRequest = async (
221
  requestBody: IBodyLatLngPoints,
 
266
  }
267
  }
268
 
269
+ // ── Prompt Object Builders ──────────────────────────────────────────
270
  /** populate a single point ML request prompt, by type (exclude or include), see type ExcludeIncludeLabelPrompt */
271
  export const getPointPromptElement = (e: LEvented, elementType: ExcludeIncludeLabelPrompt): IPointPrompt|IRectanglePrompt => {
272
  const currentPointLayer: LatLng = getSelectedPointCoordinate(e)
 
287
  }
288
  }
289
 
290
+ // ── Geoman Event Handling & Layer Management ────────────────────────
291
  /** handle different event/layer types (rectangle, point: IncludeMarkerPrompt, ExcludeMarkerPrompt) */
292
  const updateLayerOnCreateOrEditEvent = (
293
  event: LEvented,
 
334
  })
335
  }
336
 
337
+ // ── UI Feedback (Popups) ────────────────────────────────────────────
338
  /** build an HTML popup div showing lat, lng, label and leaflet id for a point marker */
339
  export const getPopupContentPoint = (leafletEvent: LEvented, label: number): HTMLDivElement => {
340
  const popupContent: HTMLDivElement = document.createElement('div')