alessandro trinca tornidor commited on
Commit
d52c87f
1 Parent(s): 65803bd

[feat] PageLisaMap/PagePredictionMap: add inference polygons as overlay, refactor code

Browse files
static/src/components/PageLisaMap.vue CHANGED
@@ -95,7 +95,6 @@
95
  import {
96
  control as LeafletControl,
97
  Evented as LEvented,
98
- geoJSON as LeafletGeoJSON,
99
  type LatLng,
100
  Map as LMap,
101
  map as LeafletMap,
@@ -108,7 +107,13 @@ import { onMounted, onUpdated, ref, type Ref } from 'vue'
108
  import { driver } from "../../node_modules/@trincadev/driver.js/src/driver"
109
 
110
  import {
 
 
 
 
111
  durationRef,
 
 
112
  maxZoom,
113
  minZoom,
114
  numberOfPolygonsRef,
@@ -123,95 +128,57 @@ import {
123
  waitingString
124
  } from './constants'
125
  import {
 
126
  getExtentCurrentViewMapBBox,
127
- getGeoJSONRequest,
128
  getQueryParams,
129
  getSelectedPointCoordinate,
130
- updateMapData
 
131
  } from '@/components/helpers'
132
- import type {IBodyLatLngWithStringPoints, SourceTileType} from '@/components/types';
133
  import StatsGrid from '@/components/StatsGrid.vue';
134
  import StringArray from '@/components/StringArray.vue';
135
  import ButtonMapSendStringRequest from '@/components/buttons/ButtonMapSendStringRequest.vue';
136
 
 
 
 
 
137
  const lisaDriverObj = driver({
138
  showProgress: true,
139
  steps: [
140
- {
141
- element: 'id-prediction-map-container', popover: {
142
- title: 'SamGIS with LISA',
143
- description: 'A quick tour about functionalities of SamGIS with LISA',
144
- onNextClick: () => {
145
- detailIsOpenRef.value = true
146
- lisaDriverObj.moveNext();
147
- }
148
- }
149
- },
150
- {
151
- element: '#map',
152
- popover: {
153
- title: 'Geographic map',
154
- description: 'Choose here the map area where you can execute your machine learning prompt'
155
- }
156
- },
157
- {
158
- element: "#prompt-examples-array",
159
- popover: {title: 'Some prompt examples', description: 'A selection of prompt examples'}
160
- },
161
- {
162
- element: "#prompt-text-placeholder", popover: {
163
- title: 'Default prompt prefix',
164
- description: 'A good LLM prompt prefix tailored for photogrammetry, remote sensing and geomorphology (editable)'
165
- }
166
- },
167
- {
168
- element: "#prompt-text-llm-ref", popover: {
169
- title: 'Prompt text',
170
- description: 'Editable text area for the LLM text prompt (you can precompile it clicking on the examples)'
171
  }
172
- },
173
- {
174
- element: "#id-button-submit",
175
- popover: {title: 'LLM submit button', description: 'submit button for the LISA request'}
176
- },
177
- {
178
- element: '.leaflet-control-layers-toggle',
179
- popover: {title: 'Map provider selector', description: 'select a different map provider'}
180
- },
181
- {
182
- element: '#lisa-response-text',
183
- popover: {title: 'LISA response text', description: 'Output area with the LISA response text'}
184
- },
185
- {
186
- element: '#id-map-info', popover: {
187
- title: 'map info',
188
- description: 'Section about various map info',
189
- onNextClick: () => {
190
- detailIsOpenRef.value = false
191
- lisaDriverObj.moveNext();
192
- }
193
- }
194
- },
195
- {
196
- element: "#detail-prompt-examples-array", popover: {
197
- title: 'Detail: Array of Prompt Examples',
198
- description: 'Click here to expand the array of prompt examples (closed by default)'
199
  }
200
- },
201
- ]
 
 
 
 
 
 
 
202
  });
203
 
204
- const currentBaseMapNameRef = ref("")
205
- const currentMapBBoxRef = ref()
206
- const currentZoomRef = ref()
207
- const promptTextRef: Ref<string> = ref("")
208
- const promptTextPlaceholderRef: Ref<string> = ref(promptPlaceHolder)
209
- const detailIsOpenRef: Ref<boolean> = ref(false)
210
- const mapNavigationLocked = ref(false)
211
  let map: LMap
212
- type ServiceTiles = {
213
- [key: SourceTileType]: LTileLayer;
214
- };
215
 
216
  const props = defineProps<{
217
  mapBounds: Array<LatLng>,
@@ -234,39 +201,6 @@ const getPopupContentPoint = (leafletEvent: LEvented, label: number): HTMLDivEle
234
  return popupDiv
235
  }
236
 
237
- const sendMLStringRequest = async (leafletMap: LMap, promptRequest: string, sourceType: SourceTileType = OpenStreetMap) => {
238
- mapNavigationLocked.value = true
239
- const bodyRequest: IBodyLatLngWithStringPoints = {
240
- bbox: getExtentCurrentViewMapBBox(leafletMap),
241
- string_prompt: promptRequest,
242
- zoom: leafletMap.getZoom(),
243
- source_type: sourceType
244
- }
245
- try {
246
- const geojsonOutputOnMounted = await getGeoJSONRequest(bodyRequest, '/infer_lisa')
247
- const featureNew = LeafletGeoJSON(geojsonOutputOnMounted)
248
- leafletMap.addLayer(featureNew)
249
- } catch (errGeojsonOutputOnMounted) {
250
- console.error('sendMLRequest:: sourceType: ', sourceType)
251
- console.error('sendMLRequest:: promptRequest: ', promptRequest.length, '::', promptRequest)
252
- console.error('sendMLRequest:: bodyRequest => ', bodyRequest, "#")
253
- console.error("errGeojsonOutputOnMounted => ", errGeojsonOutputOnMounted)
254
- }
255
- }
256
-
257
- const updateZoomBboxMap = (localMap: LMap) => {
258
- currentZoomRef.value = localMap.getZoom()
259
- currentMapBBoxRef.value = getExtentCurrentViewMapBBox(localMap)
260
- }
261
-
262
- const getCurrentBasemap = (url: string, providersArray: ServiceTiles) => {
263
- for (const [key, value] of Object.entries(providersArray)) {
264
- if (value._url == url) {
265
- return key
266
- }
267
- }
268
- }
269
-
270
  onMounted(async () => {
271
  const osmTile = tileLayer.provider(OpenStreetMap)
272
  const params = getQueryParams()
@@ -296,8 +230,7 @@ onMounted(async () => {
296
  map.fitBounds(props.mapBounds)
297
  map.attributionControl.setPrefix(prefix)
298
  LeafletControl.scale({position: 'bottomleft', imperial: false, metric: true}).addTo(map)
299
-
300
- LeafletControl.layers(baseMaps).addTo(map)
301
  updateZoomBboxMap(map)
302
 
303
  map.on('zoomend', (e: LEvented) => {
 
95
  import {
96
  control as LeafletControl,
97
  Evented as LEvented,
 
98
  type LatLng,
99
  Map as LMap,
100
  map as LeafletMap,
 
107
  import { driver } from "../../node_modules/@trincadev/driver.js/src/driver"
108
 
109
  import {
110
+ currentBaseMapNameRef,
111
+ currentMapBBoxRef,
112
+ currentZoomRef,
113
+ lisaPartialDriverSteps,
114
  durationRef,
115
+ layerControlGroupLayersRef,
116
+ mapNavigationLocked,
117
  maxZoom,
118
  minZoom,
119
  numberOfPolygonsRef,
 
128
  waitingString
129
  } from './constants'
130
  import {
131
+ getCurrentBasemap,
132
  getExtentCurrentViewMapBBox,
133
+ sendMLStringRequest,
134
  getQueryParams,
135
  getSelectedPointCoordinate,
136
+ updateMapData,
137
+ updateZoomBboxMap
138
  } from '@/components/helpers'
139
+ import type { SourceTileType, ServiceTiles } from '@/components/types';
140
  import StatsGrid from '@/components/StatsGrid.vue';
141
  import StringArray from '@/components/StringArray.vue';
142
  import ButtonMapSendStringRequest from '@/components/buttons/ButtonMapSendStringRequest.vue';
143
 
144
+ const promptTextRef: Ref<string> = ref("")
145
+ const promptTextPlaceholderRef: Ref<string> = ref(promptPlaceHolder)
146
+ const detailIsOpenRef: Ref<boolean> = ref(false)
147
+
148
  const lisaDriverObj = driver({
149
  showProgress: true,
150
  steps: [
151
+ {
152
+ element: 'id-prediction-map-container', popover: {
153
+ title: 'SamGIS with LISA...',
154
+ description: 'A quick tour about functionalities of SamGIS with LISA!',
155
+ onNextClick: () => {
156
+ detailIsOpenRef.value = true
157
+ lisaDriverObj.moveNext();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
158
  }
159
+ }
160
+ },
161
+ ...lisaPartialDriverSteps,
162
+ {
163
+ element: '#id-map-info', popover: {
164
+ title: 'map info',
165
+ description: 'Section about various map info',
166
+ onNextClick: () => {
167
+ detailIsOpenRef.value = false
168
+ lisaDriverObj.moveNext();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
169
  }
170
+ }
171
+ },
172
+ {
173
+ element: "#detail-prompt-examples-array", popover: {
174
+ title: 'Detail: Array of Prompt Examples',
175
+ description: 'Click here to expand the array of prompt examples (closed by default)'
176
+ }
177
+ },
178
+ ]
179
  });
180
 
 
 
 
 
 
 
 
181
  let map: LMap
 
 
 
182
 
183
  const props = defineProps<{
184
  mapBounds: Array<LatLng>,
 
201
  return popupDiv
202
  }
203
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
204
  onMounted(async () => {
205
  const osmTile = tileLayer.provider(OpenStreetMap)
206
  const params = getQueryParams()
 
230
  map.fitBounds(props.mapBounds)
231
  map.attributionControl.setPrefix(prefix)
232
  LeafletControl.scale({position: 'bottomleft', imperial: false, metric: true}).addTo(map)
233
+ layerControlGroupLayersRef.value = LeafletControl.layers(baseMaps).addTo(map)
 
234
  updateZoomBboxMap(map)
235
 
236
  map.on('zoomend', (e: LEvented) => {
static/src/components/PagePredictionMap.vue CHANGED
@@ -100,8 +100,7 @@
100
  import {
101
  control as LeafletControl,
102
  Evented as LEvented,
103
- geoJSON as LeafletGeoJSON,
104
- type LatLng,
105
  Map as LMap,
106
  map as LeafletMap,
107
  tileLayer,
@@ -114,13 +113,21 @@ import { onMounted, onUpdated, ref, type Ref } from 'vue'
114
  import { driver } from "../../node_modules/@trincadev/driver.js/src/driver"
115
 
116
  import {
 
 
 
 
117
  durationRef,
 
 
 
118
  maxZoom,
119
  minZoom,
120
  numberOfPolygonsRef,
121
  numberOfPredictedMasksRef,
122
  OpenStreetMap,
123
  prefix,
 
124
  responseMessageRef,
125
  Satellite,
126
  waitingString
@@ -128,42 +135,25 @@ import {
128
  import {
129
  applyFnToObjectWithinArray,
130
  getExtentCurrentViewMapBBox,
131
- getGeoJSONRequest,
132
  getQueryParams,
133
  getSelectedPointCoordinate,
134
  setGeomanControls,
135
- updateMapData
 
 
136
  } from '@/components/helpers'
137
- import type { IBodyLatLngPoints, IPointPrompt, IRectanglePrompt, SourceTileType } from '@/components/types';
138
  import StatsGrid from '@/components/StatsGrid.vue';
139
  import TableGenericComponent from '@/components/TableGenericComponent.vue';
140
  import ButtonMapSendArrayRequest from '@/components/buttons/ButtonMapSendArrayRequest.vue';
141
 
142
  const driverObj = driver({
143
  showProgress: true,
144
- steps: [
145
- { element: 'id-prediction-map-container', popover: { title: 'SamGIS', description: 'A quick tour about SamGIS functionality' } },
146
- { element: '#map', popover: { title: 'Webmap for ML prompt', description: 'Add here your machine learning prompt. Pay attention about markers and polygons outside the map bounds: you could get unexpected results' } },
147
- { element: '.leaflet-pm-icon-marker-include', popover: { title: '"Include" point prompt', description: 'add "include" points prompt (label 1) for machine learning request' } },
148
- { element: '.leaflet-pm-icon-marker-exclude', popover: { title: '"Exclude" point prompt', description: 'add "exclude" points prompt (label 0) for machine learning request' } },
149
- { element: '.leaflet-pm-icon-rectangle', popover: { title: '"Include" rectangle prompt', description: 'add "include" rectangles prompt for machine learning request' } },
150
- { element: "#id-button-submit", popover: { title: 'ML submit button', description: 'Machine learning submit button' } },
151
- { element: '.leaflet-control-layers-toggle', popover: { title: 'Map provider selector', description: 'select a different map provider' } },
152
- { element: '#id-map-info', popover: { title: 'map info', description: 'Section about various map info' } },
153
- { element: '#id-ml-request-prompt', popover: { title: 'ML prompt quest', description: 'Empty at beginning, this table will contain the machine learning prompt (points and rectangles) section' } }
154
- ]
155
  });
156
 
157
- const currentBaseMapNameRef = ref("")
158
- const currentMapBBoxRef = ref()
159
- const currentZoomRef = ref()
160
- const promptsArrayRef: Ref<Array<IPointPrompt | IRectanglePrompt>> = ref([])
161
- const mapNavigationLocked = ref(false)
162
- const mapOptionsDefaultRef = ref()
163
  let map: LMap
164
- type ServiceTiles = {
165
- [key: SourceTileType]: LTileLayer;
166
- };
167
 
168
  const props = defineProps<{
169
  mapBounds: Array<LatLng>,
@@ -186,45 +176,6 @@ const getPopupContentPoint = (leafletEvent: LEvented, label: number): HTMLDivEle
186
  return popupDiv
187
  }
188
 
189
- const sendMLArrayRequest = async (leafletMap: LMap, promptRequest: Array<IPointPrompt | IRectanglePrompt>, sourceType: SourceTileType = OpenStreetMap) => {
190
- if (map.pm.globalDragModeEnabled()) {
191
- map.pm.disableGlobalDragMode()
192
- }
193
- if (map.pm.globalEditModeEnabled()) {
194
- map.pm.disableGlobalEditMode()
195
- }
196
- mapNavigationLocked.value = true
197
- const bodyRequest: IBodyLatLngPoints = {
198
- bbox: getExtentCurrentViewMapBBox(leafletMap),
199
- prompt: promptRequest,
200
- zoom: leafletMap.getZoom(),
201
- source_type: sourceType
202
- }
203
- try {
204
- const geojsonOutputOnMounted = await getGeoJSONRequest(bodyRequest, '/infer_samgis')
205
- const featureNew = LeafletGeoJSON(geojsonOutputOnMounted)
206
- leafletMap.addLayer(featureNew)
207
- } catch (errGeojsonOutputOnMounted) {
208
- console.error('sendMLRequest:: sourceType: ', sourceType)
209
- console.error('sendMLRequest:: promptRequest: ', promptRequest.length, '::', promptRequest)
210
- console.error('sendMLRequest:: bodyRequest => ', bodyRequest, "#")
211
- console.error("errGeojsonOutputOnMounted => ", errGeojsonOutputOnMounted)
212
- }
213
- }
214
-
215
- const updateZoomBboxMap = (localMap: LMap) => {
216
- currentZoomRef.value = localMap.getZoom()
217
- currentMapBBoxRef.value = getExtentCurrentViewMapBBox(localMap)
218
- }
219
-
220
- const getCurrentBasemap = (url: string, providersArray: ServiceTiles) => {
221
- for (const [key, value] of Object.entries(providersArray)) {
222
- if (value._url == url) {
223
- return key
224
- }
225
- }
226
- }
227
-
228
  onMounted(async () => {
229
  const osmTile = tileLayer.provider(OpenStreetMap)
230
  const params = getQueryParams()
@@ -253,8 +204,7 @@ onMounted(async () => {
253
  map.fitBounds(props.mapBounds)
254
  map.attributionControl.setPrefix(prefix)
255
  LeafletControl.scale({ position: 'bottomleft', imperial: false, metric: true }).addTo(map)
256
-
257
- LeafletControl.layers(baseMaps).addTo(map)
258
  setGeomanControls(map)
259
  updateZoomBboxMap(map)
260
  mapOptionsDefaultRef.value = {...map.options}
@@ -293,4 +243,3 @@ onUpdated(() => {
293
  }
294
  })
295
  </script>
296
-
 
100
  import {
101
  control as LeafletControl,
102
  Evented as LEvented,
103
+ type LatLng,
 
104
  Map as LMap,
105
  map as LeafletMap,
106
  tileLayer,
 
113
  import { driver } from "../../node_modules/@trincadev/driver.js/src/driver"
114
 
115
  import {
116
+ currentBaseMapNameRef,
117
+ currentMapBBoxRef,
118
+ currentZoomRef,
119
+ driverSteps,
120
  durationRef,
121
+ layerControlGroupLayersRef,
122
+ mapNavigationLocked,
123
+ mapOptionsDefaultRef,
124
  maxZoom,
125
  minZoom,
126
  numberOfPolygonsRef,
127
  numberOfPredictedMasksRef,
128
  OpenStreetMap,
129
  prefix,
130
+ promptsArrayRef,
131
  responseMessageRef,
132
  Satellite,
133
  waitingString
 
135
  import {
136
  applyFnToObjectWithinArray,
137
  getExtentCurrentViewMapBBox,
138
+ sendMLArrayRequest,
139
  getQueryParams,
140
  getSelectedPointCoordinate,
141
  setGeomanControls,
142
+ updateMapData,
143
+ updateZoomBboxMap,
144
+ getCurrentBasemap
145
  } from '@/components/helpers'
146
+ import type { SourceTileType, ServiceTiles } from '@/components/types';
147
  import StatsGrid from '@/components/StatsGrid.vue';
148
  import TableGenericComponent from '@/components/TableGenericComponent.vue';
149
  import ButtonMapSendArrayRequest from '@/components/buttons/ButtonMapSendArrayRequest.vue';
150
 
151
  const driverObj = driver({
152
  showProgress: true,
153
+ steps: driverSteps
 
 
 
 
 
 
 
 
 
 
154
  });
155
 
 
 
 
 
 
 
156
  let map: LMap
 
 
 
157
 
158
  const props = defineProps<{
159
  mapBounds: Array<LatLng>,
 
176
  return popupDiv
177
  }
178
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
179
  onMounted(async () => {
180
  const osmTile = tileLayer.provider(OpenStreetMap)
181
  const params = getQueryParams()
 
204
  map.fitBounds(props.mapBounds)
205
  map.attributionControl.setPrefix(prefix)
206
  LeafletControl.scale({ position: 'bottomleft', imperial: false, metric: true }).addTo(map)
207
+ layerControlGroupLayersRef.value = LeafletControl.layers(baseMaps).addTo(map)
 
208
  setGeomanControls(map)
209
  updateZoomBboxMap(map)
210
  mapOptionsDefaultRef.value = {...map.options}
 
243
  }
244
  })
245
  </script>
 
static/src/components/constants.ts CHANGED
@@ -1,4 +1,7 @@
1
- import { ref } from "vue"
 
 
 
2
 
3
  export const prefix = " &copy; <a target=\"_blank\" href=\"https://leafletjs.com\">leaflet</a>"
4
  export const OpenStreetMap = "OpenStreetMap"
@@ -11,6 +14,13 @@ export const numberOfPolygonsRef = ref(0)
11
  export const numberOfPredictedMasksRef = ref(0)
12
  export const responseMessageRef = ref("-")
13
  export const geojsonRef = ref("geojsonOutput-placeholder")
 
 
 
 
 
 
 
14
  export const responseMessageLisaRef = ref("-")
15
 
16
  export const promptPlaceHolder = "You are a skilled gis analyst with a lot of expertise " +
@@ -245,3 +255,51 @@ export const htmlStatusMessages = [
245
  phrase: 'Network Authentication Required'
246
  }
247
  ]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import { ref, type Ref } from "vue"
2
+ import {Control as LeafletControl} from 'leaflet'
3
+ import type { IPointPrompt, IRectanglePrompt } from "./types"
4
+ import { driver, type DriveStep } from "../../node_modules/@trincadev/driver.js/src/driver"
5
 
6
  export const prefix = " &copy; <a target=\"_blank\" href=\"https://leafletjs.com\">leaflet</a>"
7
  export const OpenStreetMap = "OpenStreetMap"
 
14
  export const numberOfPredictedMasksRef = ref(0)
15
  export const responseMessageRef = ref("-")
16
  export const geojsonRef = ref("geojsonOutput-placeholder")
17
+ export const currentBaseMapNameRef = ref("")
18
+ export const currentMapBBoxRef = ref()
19
+ export const currentZoomRef = ref()
20
+ export const promptsArrayRef: Ref<Array<IPointPrompt | IRectanglePrompt>> = ref([])
21
+ export const mapOptionsDefaultRef = ref()
22
+ export const layerControlGroupLayersRef = ref(new LeafletControl.Layers());
23
+ export const mapNavigationLocked = ref(false)
24
  export const responseMessageLisaRef = ref("-")
25
 
26
  export const promptPlaceHolder = "You are a skilled gis analyst with a lot of expertise " +
 
255
  phrase: 'Network Authentication Required'
256
  }
257
  ]
258
+ export const driverSteps = [
259
+ { element: 'id-prediction-map-container', popover: { title: 'SamGIS', description: 'A quick tour about SamGIS functionality' } },
260
+ { element: '#map', popover: { title: 'Webmap for ML prompt', description: 'Add here your machine learning prompt. Pay attention about markers and polygons outside the map bounds: you could get unexpected results' } },
261
+ { element: '.leaflet-pm-icon-marker-include', popover: { title: '"Include" point prompt', description: 'add "include" points prompt (label 1) for machine learning request' } },
262
+ { element: '.leaflet-pm-icon-marker-exclude', popover: { title: '"Exclude" point prompt', description: 'add "exclude" points prompt (label 0) for machine learning request' } },
263
+ { element: '.leaflet-pm-icon-rectangle', popover: { title: '"Include" rectangle prompt', description: 'add "include" rectangles prompt for machine learning request' } },
264
+ { element: "#id-button-submit", popover: { title: 'ML submit button', description: 'Machine learning submit button' } },
265
+ { element: '.leaflet-control-layers-toggle', popover: { title: 'Map provider selector', description: 'select a different map provider' } },
266
+ { element: '#id-map-info', popover: { title: 'map info', description: 'Section about various map info' } },
267
+ { element: '#id-ml-request-prompt', popover: { title: 'ML prompt quest', description: 'Empty at beginning, this table will contain the machine learning prompt (points and rectangles) section' } }
268
+ ]
269
+ export const lisaPartialDriverSteps: Array<DriveStep> = [
270
+ {
271
+ element: '#map',
272
+ popover: {
273
+ title: 'Geographic map',
274
+ description: 'Choose here the map area where you can execute your machine learning prompt'
275
+ }
276
+ },
277
+ {
278
+ element: "#prompt-examples-array",
279
+ popover: {title: 'Some prompt examples', description: 'A selection of prompt examples'}
280
+ },
281
+ {
282
+ element: "#prompt-text-placeholder", popover: {
283
+ title: 'Default prompt prefix',
284
+ description: 'A good LLM prompt prefix tailored for photogrammetry, remote sensing and geomorphology (editable)'
285
+ }
286
+ },
287
+ {
288
+ element: "#prompt-text-llm-ref", popover: {
289
+ title: 'Prompt text',
290
+ description: 'Editable text area for the LLM text prompt (you can precompile it clicking on the examples)'
291
+ }
292
+ },
293
+ {
294
+ element: "#id-button-submit",
295
+ popover: {title: 'LLM submit button', description: 'submit button for the LISA request'}
296
+ },
297
+ {
298
+ element: '.leaflet-control-layers-toggle',
299
+ popover: {title: 'Map provider selector', description: 'select a different map provider'}
300
+ },
301
+ {
302
+ element: '#lisa-response-text',
303
+ popover: {title: 'LISA response text', description: 'Output area with the LISA response text'}
304
+ }
305
+ ]
static/src/components/helpers.ts CHANGED
@@ -1,12 +1,16 @@
1
- import L, { icon, Evented as LEvented, type LatLng, Map as LMap } from 'leaflet'
2
- import 'leaflet-providers'
3
  import {
4
- responseMessageLisaRef,
5
- responseMessageRef,
6
- waitingString,
7
  durationRef,
8
  numberOfPolygonsRef,
9
- numberOfPredictedMasksRef
 
 
 
 
 
 
10
  } from './constants'
11
  import {
12
  ExcludeIncludeLabelPrompt as excludeIncludeLabelPrompt,
@@ -15,10 +19,84 @@ import {
15
  type ExcludeIncludeLabelPrompt,
16
  type IBodyLatLngPoints,
17
  type IPointPrompt,
18
- type IRectanglePrompt, type IRectangleTable, type IPointTable, type IBodyLatLngWithStringPoints
 
 
 
 
 
19
  } from './types.d'
20
- import type { Ref } from 'vue'
 
 
 
 
 
 
21
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
22
 
23
  export const getQueryParams = () => {
24
  const urlSearchParams = new URLSearchParams(window.location.search);
@@ -27,7 +105,6 @@ export const getQueryParams = () => {
27
  return {source, options}
28
  }
29
 
30
-
31
  export const applyFnToObjectWithinArray = (array: Array<IPointPrompt | IRectanglePrompt>): Array<IPointTable | IRectangleTable> => {
32
  let newArray = []
33
  for (const el of array) {
 
1
+ import L, { icon, Evented as LEvented, type LatLng, Map as LMap, geoJSON as LeafletGeoJSON, FeatureGroup, } from 'leaflet'
 
2
  import {
3
+ currentMapBBoxRef,
4
+ currentZoomRef,
 
5
  durationRef,
6
  numberOfPolygonsRef,
7
+ numberOfPredictedMasksRef,
8
+ layerControlGroupLayersRef,
9
+ mapNavigationLocked,
10
+ OpenStreetMap,
11
+ responseMessageRef,
12
+ responseMessageLisaRef,
13
+ waitingString
14
  } from './constants'
15
  import {
16
  ExcludeIncludeLabelPrompt as excludeIncludeLabelPrompt,
 
19
  type ExcludeIncludeLabelPrompt,
20
  type IBodyLatLngPoints,
21
  type IPointPrompt,
22
+ type IRectanglePrompt,
23
+ type IRectangleTable,
24
+ type IPointTable,
25
+ type SourceTileType,
26
+ type ServiceTiles,
27
+ type IBodyLatLngWithStringPoints
28
  } from './types.d'
29
+ import { type Ref } from 'vue'
30
+
31
+
32
+ export const updateZoomBboxMap = (localMap: LMap) => {
33
+ currentZoomRef.value = localMap.getZoom()
34
+ currentMapBBoxRef.value = getExtentCurrentViewMapBBox(localMap)
35
+ }
36
 
37
+ export const getCurrentBasemap = (url: string, providersArray: ServiceTiles): string => {
38
+ for (const [key, value] of Object.entries(providersArray)) {
39
+ if (value._url == url) {
40
+ return key
41
+ }
42
+ }
43
+ return "-"
44
+ }
45
+
46
+ const logErrorOnRequest = (fnName: string, errorsArgs: Object): void => {
47
+ for (const [key, value] of Object.entries(errorsArgs)) {
48
+ console.error(`error:${fnName}:: ${key}: `, value)
49
+ }
50
+ }
51
+ export const sendMLStringRequest = async (leafletMap: LMap, promptRequest: string, sourceType: SourceTileType = OpenStreetMap) => {
52
+ console.log("sendMLStringRequest:: start")
53
+ mapNavigationLocked.value = true
54
+ const bodyRequest: IBodyLatLngWithStringPoints = {
55
+ bbox: getExtentCurrentViewMapBBox(leafletMap),
56
+ string_prompt: promptRequest,
57
+ zoom: leafletMap.getZoom(),
58
+ source_type: sourceType
59
+ }
60
+ try {
61
+ await sendMLRequest('/infer_lisa', bodyRequest, leafletMap)
62
+ console.log("sendMLStringRequest:: end")
63
+ } catch (errGeojsonOutputOnMounted) {
64
+ logErrorOnRequest("sendMLStringRequest", {sourceType, promptRequest, bodyRequest, errGeojsonOutputOnMounted})
65
+ }
66
+ }
67
+ export const sendMLArrayRequest = async (
68
+ leafletMap: LMap, promptRequest: Array<IPointPrompt | IRectanglePrompt>, sourceType: SourceTileType = OpenStreetMap
69
+ ) => {
70
+ console.log("sendMLArrayRequest:: start")
71
+ if (leafletMap.pm.globalDragModeEnabled()) {
72
+ leafletMap.pm.disableGlobalDragMode()
73
+ }
74
+ if (leafletMap.pm.globalEditModeEnabled()) {
75
+ leafletMap.pm.disableGlobalEditMode()
76
+ }
77
+ mapNavigationLocked.value = true
78
+ const bodyRequest: IBodyLatLngPoints = {
79
+ bbox: getExtentCurrentViewMapBBox(leafletMap),
80
+ prompt: promptRequest,
81
+ zoom: leafletMap.getZoom(),
82
+ source_type: sourceType
83
+ }
84
+ try {
85
+ await sendMLRequest('/infer_samgis', bodyRequest, leafletMap)
86
+ console.log("sendMLArrayRequest:: end")
87
+ } catch (errGeojsonOutputOnMounted) {
88
+ logErrorOnRequest("sendMLArrayRequest", {sourceType, promptRequest, bodyRequest, errGeojsonOutputOnMounted})
89
+ }
90
+ }
91
+ const sendMLRequest = async(url: string, bodyRequest: IBodyLatLngPoints | IBodyLatLngWithStringPoints, leafletMap: LMap) => {
92
+ const geojsonOutputOnMounted = await getGeoJSONRequest(bodyRequest, url)
93
+ const featureNew = LeafletGeoJSON(geojsonOutputOnMounted)
94
+ let now = new Date(Date.now())
95
+ let nowString = now.toLocaleString('it-it')
96
+ let overlayMaps = new FeatureGroup([featureNew])
97
+ layerControlGroupLayersRef.value.addOverlay(overlayMaps, nowString)
98
+ leafletMap.addLayer(featureNew)
99
+ }
100
 
101
  export const getQueryParams = () => {
102
  const urlSearchParams = new URLSearchParams(window.location.search);
 
105
  return {source, options}
106
  }
107
 
 
108
  export const applyFnToObjectWithinArray = (array: Array<IPointPrompt | IRectanglePrompt>): Array<IPointTable | IRectangleTable> => {
109
  let newArray = []
110
  for (const el of array) {
static/src/components/types.d.ts CHANGED
@@ -54,4 +54,7 @@ export interface IBodyLatLngWithStringPoints {
54
  export type OpenStreetMap = "OpenStreetMap"
55
  export type Satellite = "Satellite"
56
  export type SourceTileType = OpenStreetMap | Satellite
57
- export type ArrayNumber = Array<number>
 
 
 
 
54
  export type OpenStreetMap = "OpenStreetMap"
55
  export type Satellite = "Satellite"
56
  export type SourceTileType = OpenStreetMap | Satellite
57
+ export type ArrayNumber = Array<number>
58
+ export type ServiceTiles = {
59
+ [key: SourceTileType]: LTileLayer;
60
+ };