[refactor] move some functions and ref from PagePredictionMap.vue
Browse files
static/src/components/PagePredictionMap.vue
CHANGED
@@ -100,13 +100,11 @@
|
|
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,
|
108 |
-
TileLayer as LTileLayer
|
109 |
-
FeatureGroup
|
110 |
} from 'leaflet'
|
111 |
import 'leaflet-providers'
|
112 |
import '@geoman-io/leaflet-geoman-free'
|
@@ -115,57 +113,47 @@ import { onMounted, onUpdated, ref, type Ref } from 'vue'
|
|
115 |
import { driver } from "../../node_modules/@trincadev/driver.js/src/driver"
|
116 |
|
117 |
import {
|
|
|
|
|
|
|
|
|
118 |
durationRef,
|
|
|
|
|
|
|
119 |
maxZoom,
|
120 |
minZoom,
|
121 |
numberOfPolygonsRef,
|
122 |
numberOfPredictedMasksRef,
|
123 |
OpenStreetMap,
|
124 |
prefix,
|
|
|
125 |
responseMessageRef,
|
126 |
Satellite,
|
127 |
-
waitingString
|
128 |
} from './constants'
|
129 |
import {
|
130 |
applyFnToObjectWithinArray,
|
131 |
getExtentCurrentViewMapBBox,
|
132 |
-
|
133 |
getQueryParams,
|
134 |
getSelectedPointCoordinate,
|
135 |
setGeomanControls,
|
136 |
-
updateMapData
|
|
|
|
|
137 |
} from '@/components/helpers'
|
138 |
-
import type {
|
139 |
import StatsGrid from '@/components/StatsGrid.vue';
|
140 |
import TableGenericComponent from '@/components/TableGenericComponent.vue';
|
141 |
import ButtonMapSendRequest from '@/components/buttons/ButtonMapSendRequest.vue';
|
142 |
|
143 |
const driverObj = driver({
|
144 |
showProgress: true,
|
145 |
-
steps:
|
146 |
-
{ element: 'id-prediction-map-container', popover: { title: 'SamGIS', description: 'A quick tour about SamGIS functionality' } },
|
147 |
-
{ 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' } },
|
148 |
-
{ element: '.leaflet-pm-icon-marker-include', popover: { title: '"Include" point prompt', description: 'add "include" points prompt (label 1) for machine learning request' } },
|
149 |
-
{ element: '.leaflet-pm-icon-marker-exclude', popover: { title: '"Exclude" point prompt', description: 'add "exclude" points prompt (label 0) for machine learning request' } },
|
150 |
-
{ element: '.leaflet-pm-icon-rectangle', popover: { title: '"Include" rectangle prompt', description: 'add "include" rectangles prompt for machine learning request' } },
|
151 |
-
{ element: "#id-button-submit", popover: { title: 'ML submit button', description: 'Machine learning submit button' } },
|
152 |
-
{ element: '.leaflet-control-layers-toggle', popover: { title: 'Map provider selector', description: 'select a different map provider' } },
|
153 |
-
{ element: '#id-map-info', popover: { title: 'map info', description: 'Section about various map info' } },
|
154 |
-
{ 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' } }
|
155 |
-
]
|
156 |
});
|
157 |
|
158 |
-
const currentBaseMapNameRef = ref("")
|
159 |
-
const currentMapBBoxRef = ref()
|
160 |
-
const currentZoomRef = ref()
|
161 |
-
const promptsArrayRef: Ref<Array<IPointPrompt | IRectanglePrompt>> = ref([])
|
162 |
-
const mapNavigationLocked = ref(false)
|
163 |
-
const mapOptionsDefaultRef = ref()
|
164 |
-
const layerControlGroupLayersRef = ref(LeafletControl.layers());
|
165 |
let map: LMap
|
166 |
-
type ServiceTiles = {
|
167 |
-
[key: SourceTileType]: LTileLayer;
|
168 |
-
};
|
169 |
|
170 |
const props = defineProps<{
|
171 |
mapBounds: Array<LatLng>,
|
@@ -188,51 +176,6 @@ const getPopupContentPoint = (leafletEvent: LEvented, label: number): HTMLDivEle
|
|
188 |
return popupDiv
|
189 |
}
|
190 |
|
191 |
-
const sendMLRequest = async (
|
192 |
-
leafletMap: LMap, promptRequest: Array<IPointPrompt | IRectanglePrompt>, sourceType: SourceTileType = OpenStreetMap
|
193 |
-
) => {
|
194 |
-
if (map.pm.globalDragModeEnabled()) {
|
195 |
-
map.pm.disableGlobalDragMode()
|
196 |
-
}
|
197 |
-
if (map.pm.globalEditModeEnabled()) {
|
198 |
-
map.pm.disableGlobalEditMode()
|
199 |
-
}
|
200 |
-
mapNavigationLocked.value = true
|
201 |
-
const bodyRequest: IBodyLatLngPoints = {
|
202 |
-
bbox: getExtentCurrentViewMapBBox(leafletMap),
|
203 |
-
prompt: promptRequest,
|
204 |
-
zoom: leafletMap.getZoom(),
|
205 |
-
source_type: sourceType
|
206 |
-
}
|
207 |
-
try {
|
208 |
-
const geojsonOutputOnMounted = await getGeoJSONRequest(bodyRequest, '/infer_samgis')
|
209 |
-
const featureNew = LeafletGeoJSON(geojsonOutputOnMounted)
|
210 |
-
let now = new Date(Date.now())
|
211 |
-
let nowString = now.toLocaleString('it-it', )
|
212 |
-
let overlayMaps = new FeatureGroup([featureNew])
|
213 |
-
layerControlGroupLayersRef.value.addOverlay(overlayMaps, nowString)
|
214 |
-
leafletMap.addLayer(featureNew)
|
215 |
-
} catch (errGeojsonOutputOnMounted) {
|
216 |
-
console.error('sendMLRequest:: sourceType: ', sourceType)
|
217 |
-
console.error('sendMLRequest:: promptRequest: ', promptRequest.length, '::', promptRequest)
|
218 |
-
console.error('sendMLRequest:: bodyRequest => ', bodyRequest, "#")
|
219 |
-
console.error("errGeojsonOutputOnMounted => ", errGeojsonOutputOnMounted)
|
220 |
-
}
|
221 |
-
}
|
222 |
-
|
223 |
-
const updateZoomBboxMap = (localMap: LMap) => {
|
224 |
-
currentZoomRef.value = localMap.getZoom()
|
225 |
-
currentMapBBoxRef.value = getExtentCurrentViewMapBBox(localMap)
|
226 |
-
}
|
227 |
-
|
228 |
-
const getCurrentBasemap = (url: string, providersArray: ServiceTiles) => {
|
229 |
-
for (const [key, value] of Object.entries(providersArray)) {
|
230 |
-
if (value._url == url) {
|
231 |
-
return key
|
232 |
-
}
|
233 |
-
}
|
234 |
-
}
|
235 |
-
|
236 |
onMounted(async () => {
|
237 |
const osmTile = tileLayer.provider(OpenStreetMap)
|
238 |
const params = getQueryParams()
|
@@ -300,4 +243,3 @@ onUpdated(() => {
|
|
300 |
}
|
301 |
})
|
302 |
</script>
|
303 |
-
|
|
|
100 |
import {
|
101 |
control as LeafletControl,
|
102 |
Evented as LEvented,
|
|
|
103 |
type LatLng,
|
104 |
Map as LMap,
|
105 |
map as LeafletMap,
|
106 |
tileLayer,
|
107 |
+
TileLayer as LTileLayer
|
|
|
108 |
} from 'leaflet'
|
109 |
import 'leaflet-providers'
|
110 |
import '@geoman-io/leaflet-geoman-free'
|
|
|
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,
|
134 |
} from './constants'
|
135 |
import {
|
136 |
applyFnToObjectWithinArray,
|
137 |
getExtentCurrentViewMapBBox,
|
138 |
+
sendMLRequest,
|
139 |
getQueryParams,
|
140 |
getSelectedPointCoordinate,
|
141 |
setGeomanControls,
|
142 |
+
updateMapData,
|
143 |
+
updateZoomBboxMap,
|
144 |
+
getCurrentBasemap
|
145 |
} from '@/components/helpers'
|
146 |
+
import type { ServiceTiles, SourceTileType } from '@/components/types';
|
147 |
import StatsGrid from '@/components/StatsGrid.vue';
|
148 |
import TableGenericComponent from '@/components/TableGenericComponent.vue';
|
149 |
import ButtonMapSendRequest from '@/components/buttons/ButtonMapSendRequest.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()
|
|
|
243 |
}
|
244 |
})
|
245 |
</script>
|
|
static/src/components/constants.ts
CHANGED
@@ -1,4 +1,6 @@
|
|
1 |
-
import { ref } from "vue"
|
|
|
|
|
2 |
|
3 |
export const prefix = " © <a target=\"_blank\" href=\"https://leafletjs.com\">leaflet</a>"
|
4 |
export const OpenStreetMap = "OpenStreetMap"
|
@@ -11,6 +13,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 |
// modified from https://github.com/for-GET/know-your-http-well/blob/master/json/status-codes.json
|
15 |
export const htmlStatusMessages = [
|
16 |
{
|
@@ -234,3 +243,14 @@ export const htmlStatusMessages = [
|
|
234 |
phrase: 'Network Authentication Required'
|
235 |
}
|
236 |
]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import { ref, type Ref } from "vue"
|
2 |
+
import L, {Control as LeafletControl} from 'leaflet'
|
3 |
+
import type { IPointPrompt, IRectanglePrompt } from "./types"
|
4 |
|
5 |
export const prefix = " © <a target=\"_blank\" href=\"https://leafletjs.com\">leaflet</a>"
|
6 |
export const OpenStreetMap = "OpenStreetMap"
|
|
|
13 |
export const numberOfPredictedMasksRef = ref(0)
|
14 |
export const responseMessageRef = ref("-")
|
15 |
export const geojsonRef = ref("geojsonOutput-placeholder")
|
16 |
+
export const currentBaseMapNameRef = ref("")
|
17 |
+
export const currentMapBBoxRef = ref()
|
18 |
+
export const currentZoomRef = ref()
|
19 |
+
export const promptsArrayRef: Ref<Array<IPointPrompt | IRectanglePrompt>> = ref([])
|
20 |
+
export const mapOptionsDefaultRef = ref()
|
21 |
+
export const layerControlGroupLayersRef = ref(new LeafletControl.Layers());
|
22 |
+
export const mapNavigationLocked = ref(false)
|
23 |
// modified from https://github.com/for-GET/know-your-http-well/blob/master/json/status-codes.json
|
24 |
export const htmlStatusMessages = [
|
25 |
{
|
|
|
243 |
phrase: 'Network Authentication Required'
|
244 |
}
|
245 |
]
|
246 |
+
export const driverSteps = [
|
247 |
+
{ element: 'id-prediction-map-container', popover: { title: 'SamGIS', description: 'A quick tour about SamGIS functionality' } },
|
248 |
+
{ 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' } },
|
249 |
+
{ element: '.leaflet-pm-icon-marker-include', popover: { title: '"Include" point prompt', description: 'add "include" points prompt (label 1) for machine learning request' } },
|
250 |
+
{ element: '.leaflet-pm-icon-marker-exclude', popover: { title: '"Exclude" point prompt', description: 'add "exclude" points prompt (label 0) for machine learning request' } },
|
251 |
+
{ element: '.leaflet-pm-icon-rectangle', popover: { title: '"Include" rectangle prompt', description: 'add "include" rectangles prompt for machine learning request' } },
|
252 |
+
{ element: "#id-button-submit", popover: { title: 'ML submit button', description: 'Machine learning submit button' } },
|
253 |
+
{ element: '.leaflet-control-layers-toggle', popover: { title: 'Map provider selector', description: 'select a different map provider' } },
|
254 |
+
{ element: '#id-map-info', popover: { title: 'map info', description: 'Section about various map info' } },
|
255 |
+
{ 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' } }
|
256 |
+
]
|
static/src/components/helpers.ts
CHANGED
@@ -1,10 +1,15 @@
|
|
1 |
-
import L, { icon, Evented as LEvented, type LatLng, Map as LMap } from 'leaflet'
|
2 |
import {
|
3 |
-
|
4 |
-
|
5 |
durationRef,
|
6 |
numberOfPolygonsRef,
|
7 |
-
numberOfPredictedMasksRef
|
|
|
|
|
|
|
|
|
|
|
8 |
} from './constants'
|
9 |
import {
|
10 |
ExcludeIncludeLabelPrompt as excludeIncludeLabelPrompt,
|
@@ -13,9 +18,59 @@ import {
|
|
13 |
type ExcludeIncludeLabelPrompt,
|
14 |
type IBodyLatLngPoints,
|
15 |
type IPointPrompt,
|
16 |
-
type IRectanglePrompt,
|
|
|
|
|
|
|
|
|
17 |
} from './types.d'
|
18 |
-
import type
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
19 |
|
20 |
export const getQueryParams = () => {
|
21 |
const urlSearchParams = new URLSearchParams(window.location.search);
|
|
|
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 |
+
waitingString
|
13 |
} from './constants'
|
14 |
import {
|
15 |
ExcludeIncludeLabelPrompt as excludeIncludeLabelPrompt,
|
|
|
18 |
type ExcludeIncludeLabelPrompt,
|
19 |
type IBodyLatLngPoints,
|
20 |
type IPointPrompt,
|
21 |
+
type IRectanglePrompt,
|
22 |
+
type IRectangleTable,
|
23 |
+
type IPointTable,
|
24 |
+
type SourceTileType,
|
25 |
+
type ServiceTiles
|
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)
|
32 |
+
}
|
33 |
+
|
34 |
+
export const getCurrentBasemap = (url: string, providersArray: ServiceTiles): string => {
|
35 |
+
for (const [key, value] of Object.entries(providersArray)) {
|
36 |
+
if (value._url == url) {
|
37 |
+
return key
|
38 |
+
}
|
39 |
+
}
|
40 |
+
return "-"
|
41 |
+
}
|
42 |
+
|
43 |
+
export const sendMLRequest = async (
|
44 |
+
leafletMap: LMap, promptRequest: Array<IPointPrompt | IRectanglePrompt>, sourceType: SourceTileType = OpenStreetMap
|
45 |
+
) => {
|
46 |
+
if (leafletMap.pm.globalDragModeEnabled()) {
|
47 |
+
leafletMap.pm.disableGlobalDragMode()
|
48 |
+
}
|
49 |
+
if (leafletMap.pm.globalEditModeEnabled()) {
|
50 |
+
leafletMap.pm.disableGlobalEditMode()
|
51 |
+
}
|
52 |
+
mapNavigationLocked.value = true
|
53 |
+
const bodyRequest: IBodyLatLngPoints = {
|
54 |
+
bbox: getExtentCurrentViewMapBBox(leafletMap),
|
55 |
+
prompt: promptRequest,
|
56 |
+
zoom: leafletMap.getZoom(),
|
57 |
+
source_type: sourceType
|
58 |
+
}
|
59 |
+
try {
|
60 |
+
const geojsonOutputOnMounted = await getGeoJSONRequest(bodyRequest, '/infer_samgis')
|
61 |
+
const featureNew = LeafletGeoJSON(geojsonOutputOnMounted)
|
62 |
+
let now = new Date(Date.now())
|
63 |
+
let nowString = now.toLocaleString('it-it', )
|
64 |
+
let overlayMaps = new FeatureGroup([featureNew])
|
65 |
+
layerControlGroupLayersRef.value.addOverlay(overlayMaps, nowString)
|
66 |
+
leafletMap.addLayer(featureNew)
|
67 |
+
} catch (errGeojsonOutputOnMounted) {
|
68 |
+
console.error('sendMLRequest:: sourceType: ', sourceType)
|
69 |
+
console.error('sendMLRequest:: promptRequest: ', promptRequest.length, '::', promptRequest)
|
70 |
+
console.error('sendMLRequest:: bodyRequest => ', bodyRequest, "#")
|
71 |
+
console.error("errGeojsonOutputOnMounted => ", errGeojsonOutputOnMounted)
|
72 |
+
}
|
73 |
+
}
|
74 |
|
75 |
export const getQueryParams = () => {
|
76 |
const urlSearchParams = new URLSearchParams(window.location.search);
|
static/src/components/types.d.ts
CHANGED
@@ -47,4 +47,8 @@ export interface IBodyLatLngPoints {
|
|
47 |
export type OpenStreetMap = "OpenStreetMap"
|
48 |
export type Satellite = "Satellite"
|
49 |
export type SourceTileType = OpenStreetMap | Satellite
|
50 |
-
export type ArrayNumber = Array<number>
|
|
|
|
|
|
|
|
|
|
47 |
export type OpenStreetMap = "OpenStreetMap"
|
48 |
export type Satellite = "Satellite"
|
49 |
export type SourceTileType = OpenStreetMap | Satellite
|
50 |
+
export type ArrayNumber = Array<number>
|
51 |
+
export type ServiceTiles = {
|
52 |
+
[key: SourceTileType]: LTileLayer;
|
53 |
+
};
|
54 |
+
|