[feat] add map navigation locking (unlockable!) on ML request to take advantage of image embedding re-use
Browse files
static/src/components/PagePredictionMap.vue
CHANGED
@@ -17,6 +17,13 @@
|
|
17 |
:send-m-l-request="sendMLRequest"
|
18 |
:waiting-string="waitingString"
|
19 |
/>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
20 |
</div>
|
21 |
<div id="map" class="map-predictions" />
|
22 |
<ButtonMapSendRequest
|
@@ -29,7 +36,13 @@
|
|
29 |
:send-m-l-request="sendMLRequest"
|
30 |
:waiting-string="waitingString"
|
31 |
/>
|
32 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
33 |
</div>
|
34 |
</div>
|
35 |
|
@@ -44,7 +57,6 @@
|
|
44 |
{statName: 'prompt: points/rectangles number', statValue: promptsArrayRef.length},
|
45 |
]" />
|
46 |
</div>
|
47 |
-
|
48 |
<div v-if="responseMessageRef === waitingString" />
|
49 |
<h2 v-else-if="responseMessageRef || responseMessageRef == '-'" class="text-lg text-red-600">{{ responseMessageRef }}</h2>
|
50 |
<div v-else>
|
@@ -97,11 +109,13 @@ import {
|
|
97 |
} from 'leaflet'
|
98 |
import 'leaflet-providers'
|
99 |
import '@geoman-io/leaflet-geoman-free'
|
100 |
-
import { onMounted, ref, type Ref } from 'vue'
|
101 |
import { driver } from "../../node_modules/driver.js/src/driver"
|
102 |
|
103 |
import {
|
104 |
durationRef,
|
|
|
|
|
105 |
numberOfPolygonsRef,
|
106 |
numberOfPredictedMasksRef,
|
107 |
OpenStreetMap,
|
@@ -114,6 +128,7 @@ import {
|
|
114 |
applyFnToObjectWithinArray,
|
115 |
getExtentCurrentViewMapBBox,
|
116 |
getGeoJSONRequest,
|
|
|
117 |
getSelectedPointCoordinate,
|
118 |
setGeomanControls,
|
119 |
updateMapData
|
@@ -142,6 +157,8 @@ const currentBaseMapNameRef = ref("")
|
|
142 |
const currentMapBBoxRef = ref()
|
143 |
const currentZoomRef = ref()
|
144 |
const promptsArrayRef: Ref<Array<IPointPrompt | IRectanglePrompt>> = ref([])
|
|
|
|
|
145 |
let map: LMap
|
146 |
type ServiceTiles = {
|
147 |
[key: SourceTileType]: LTileLayer;
|
@@ -175,6 +192,7 @@ const sendMLRequest = async (leafletMap: LMap, promptRequest: Array<IPointPrompt
|
|
175 |
if (map.pm.globalEditModeEnabled()) {
|
176 |
map.pm.disableGlobalEditMode()
|
177 |
}
|
|
|
178 |
const bodyRequest: IBodyLatLngPoints = {
|
179 |
bbox: getExtentCurrentViewMapBBox(leafletMap),
|
180 |
prompt: promptRequest,
|
@@ -208,9 +226,11 @@ const getCurrentBasemap = (url: string, providersArray: ServiceTiles) => {
|
|
208 |
|
209 |
onMounted(async () => {
|
210 |
const osmTile = tileLayer.provider(OpenStreetMap)
|
211 |
-
|
|
|
|
|
|
|
212 |
let localVarTerrain: SourceTileType = "nextzen.terrarium"
|
213 |
-
const satelliteTile = tileLayer.provider(localVarSatellite)
|
214 |
const terrainTile = new LTileLayer(
|
215 |
"https://s3.amazonaws.com/elevation-tiles-prod/terrarium/{z}/{x}/{y}.png", {
|
216 |
id: localVarTerrain,
|
@@ -219,14 +239,15 @@ onMounted(async () => {
|
|
219 |
"<a href='https://github.com/tilezen/joerd/blob/master/docs/attribution.md'>Mapzen Source Attributions</a>."
|
220 |
}
|
221 |
)
|
222 |
-
|
223 |
let baseMaps: ServiceTiles = { OpenStreetMap: osmTile }
|
224 |
baseMaps[localVarSatellite] = satelliteTile
|
225 |
baseMaps[localVarTerrain] = terrainTile
|
226 |
currentBaseMapNameRef.value = OpenStreetMap
|
227 |
|
228 |
map = LeafletMap('map', {
|
229 |
-
layers: [osmTile]
|
|
|
|
|
230 |
})
|
231 |
map.fitBounds(props.mapBounds)
|
232 |
map.attributionControl.setPrefix(prefix)
|
@@ -235,6 +256,7 @@ onMounted(async () => {
|
|
235 |
LeafletControl.layers(baseMaps).addTo(map)
|
236 |
setGeomanControls(map)
|
237 |
updateZoomBboxMap(map)
|
|
|
238 |
|
239 |
map.on('zoomend', (e: LEvented) => {
|
240 |
updateZoomBboxMap(map)
|
@@ -251,5 +273,23 @@ onMounted(async () => {
|
|
251 |
|
252 |
driverObj.drive();
|
253 |
})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
254 |
</script>
|
255 |
|
|
|
17 |
:send-m-l-request="sendMLRequest"
|
18 |
:waiting-string="waitingString"
|
19 |
/>
|
20 |
+
<span class="ml-2 lg:hidden">
|
21 |
+
<input type="checkbox" id="checkboxMapNavigationLocked" v-model="mapNavigationLocked" />
|
22 |
+
<span class="ml-2">
|
23 |
+
<label class="text-red-600" for="checkboxMapNavigationLocked" v-if="mapNavigationLocked">locked map navigation!</label>
|
24 |
+
<label class="text-blue-600" for="checkboxMapNavigationLocked" v-else>map navigation unlocked</label>
|
25 |
+
</span>
|
26 |
+
</span>
|
27 |
</div>
|
28 |
<div id="map" class="map-predictions" />
|
29 |
<ButtonMapSendRequest
|
|
|
36 |
:send-m-l-request="sendMLRequest"
|
37 |
:waiting-string="waitingString"
|
38 |
/>
|
39 |
+
<span class="hidden lg:block lg:ml-2">
|
40 |
+
<input type="checkbox" id="checkboxMapNavigationLocked" v-model="mapNavigationLocked" />
|
41 |
+
<span class="ml-2">
|
42 |
+
<label class="text-red-600" for="checkboxMapNavigationLocked" v-if="mapNavigationLocked">locked map navigation!</label>
|
43 |
+
<label class="text-blue-600" for="checkboxMapNavigationLocked" v-else>map navigation unlocked</label>
|
44 |
+
</span>
|
45 |
+
</span>
|
46 |
</div>
|
47 |
</div>
|
48 |
|
|
|
57 |
{statName: 'prompt: points/rectangles number', statValue: promptsArrayRef.length},
|
58 |
]" />
|
59 |
</div>
|
|
|
60 |
<div v-if="responseMessageRef === waitingString" />
|
61 |
<h2 v-else-if="responseMessageRef || responseMessageRef == '-'" class="text-lg text-red-600">{{ responseMessageRef }}</h2>
|
62 |
<div v-else>
|
|
|
109 |
} from 'leaflet'
|
110 |
import 'leaflet-providers'
|
111 |
import '@geoman-io/leaflet-geoman-free'
|
112 |
+
import { onMounted, onUpdated, ref, type Ref } from 'vue'
|
113 |
import { driver } from "../../node_modules/driver.js/src/driver"
|
114 |
|
115 |
import {
|
116 |
durationRef,
|
117 |
+
maxZoom,
|
118 |
+
minZoom,
|
119 |
numberOfPolygonsRef,
|
120 |
numberOfPredictedMasksRef,
|
121 |
OpenStreetMap,
|
|
|
128 |
applyFnToObjectWithinArray,
|
129 |
getExtentCurrentViewMapBBox,
|
130 |
getGeoJSONRequest,
|
131 |
+
getQueryParams,
|
132 |
getSelectedPointCoordinate,
|
133 |
setGeomanControls,
|
134 |
updateMapData
|
|
|
157 |
const currentMapBBoxRef = ref()
|
158 |
const currentZoomRef = ref()
|
159 |
const promptsArrayRef: Ref<Array<IPointPrompt | IRectanglePrompt>> = ref([])
|
160 |
+
const mapNavigationLocked = ref(false)
|
161 |
+
const mapOptionsDefaultRef = ref()
|
162 |
let map: LMap
|
163 |
type ServiceTiles = {
|
164 |
[key: SourceTileType]: LTileLayer;
|
|
|
192 |
if (map.pm.globalEditModeEnabled()) {
|
193 |
map.pm.disableGlobalEditMode()
|
194 |
}
|
195 |
+
mapNavigationLocked.value = true
|
196 |
const bodyRequest: IBodyLatLngPoints = {
|
197 |
bbox: getExtentCurrentViewMapBBox(leafletMap),
|
198 |
prompt: promptRequest,
|
|
|
226 |
|
227 |
onMounted(async () => {
|
228 |
const osmTile = tileLayer.provider(OpenStreetMap)
|
229 |
+
const params = getQueryParams()
|
230 |
+
let localVarSatellite: SourceTileType = params.source ? params.source : Satellite
|
231 |
+
let localVarSatelliteOptions = params.options ? params.options : {}
|
232 |
+
const satelliteTile = tileLayer.provider(localVarSatellite, localVarSatelliteOptions)
|
233 |
let localVarTerrain: SourceTileType = "nextzen.terrarium"
|
|
|
234 |
const terrainTile = new LTileLayer(
|
235 |
"https://s3.amazonaws.com/elevation-tiles-prod/terrarium/{z}/{x}/{y}.png", {
|
236 |
id: localVarTerrain,
|
|
|
239 |
"<a href='https://github.com/tilezen/joerd/blob/master/docs/attribution.md'>Mapzen Source Attributions</a>."
|
240 |
}
|
241 |
)
|
|
|
242 |
let baseMaps: ServiceTiles = { OpenStreetMap: osmTile }
|
243 |
baseMaps[localVarSatellite] = satelliteTile
|
244 |
baseMaps[localVarTerrain] = terrainTile
|
245 |
currentBaseMapNameRef.value = OpenStreetMap
|
246 |
|
247 |
map = LeafletMap('map', {
|
248 |
+
layers: [osmTile],
|
249 |
+
minZoom: minZoom,
|
250 |
+
maxZoom: maxZoom
|
251 |
})
|
252 |
map.fitBounds(props.mapBounds)
|
253 |
map.attributionControl.setPrefix(prefix)
|
|
|
256 |
LeafletControl.layers(baseMaps).addTo(map)
|
257 |
setGeomanControls(map)
|
258 |
updateZoomBboxMap(map)
|
259 |
+
mapOptionsDefaultRef.value = {...map.options}
|
260 |
|
261 |
map.on('zoomend', (e: LEvented) => {
|
262 |
updateZoomBboxMap(map)
|
|
|
273 |
|
274 |
driverObj.drive();
|
275 |
})
|
276 |
+
|
277 |
+
onUpdated(() => {
|
278 |
+
if (mapNavigationLocked.value) {
|
279 |
+
map.setMaxZoom(currentZoomRef.value)
|
280 |
+
map.setMinZoom(currentZoomRef.value)
|
281 |
+
map.options.maxBoundsViscosity = 1.0
|
282 |
+
map.setMaxBounds(map.getBounds())
|
283 |
+
}
|
284 |
+
if (!mapNavigationLocked.value) {
|
285 |
+
map.setMaxZoom(maxZoom)
|
286 |
+
map.setMinZoom(minZoom)
|
287 |
+
map.options.maxBoundsViscosity = 0.0
|
288 |
+
map.setMaxBounds([
|
289 |
+
[90, 180],
|
290 |
+
[-90, -180]
|
291 |
+
])
|
292 |
+
}
|
293 |
+
})
|
294 |
</script>
|
295 |
|
static/src/components/constants.ts
CHANGED
@@ -4,7 +4,7 @@ export const prefix = " © <a target=\"_blank\" href=\"https://leafletjs.com
|
|
4 |
export const OpenStreetMap = "OpenStreetMap"
|
5 |
export const Satellite = "OpenStreetMap.HOT"
|
6 |
export const maxZoom = 20
|
7 |
-
export const minZoom =
|
8 |
export const waitingString = "waiting..."
|
9 |
export const durationRef = ref(0)
|
10 |
export const numberOfPolygonsRef = ref(0)
|
|
|
4 |
export const OpenStreetMap = "OpenStreetMap"
|
5 |
export const Satellite = "OpenStreetMap.HOT"
|
6 |
export const maxZoom = 20
|
7 |
+
export const minZoom = 2
|
8 |
export const waitingString = "waiting..."
|
9 |
export const durationRef = ref(0)
|
10 |
export const numberOfPolygonsRef = ref(0)
|
static/src/components/helpers.ts
CHANGED
@@ -17,6 +17,12 @@ import {
|
|
17 |
} from './types.d'
|
18 |
import type { Ref } from 'vue'
|
19 |
|
|
|
|
|
|
|
|
|
|
|
|
|
20 |
|
21 |
export const applyFnToObjectWithinArray = (array: Array<IPointPrompt | IRectanglePrompt>): Array<IPointTable | IRectangleTable> => {
|
22 |
let newArray = []
|
|
|
17 |
} from './types.d'
|
18 |
import type { Ref } from 'vue'
|
19 |
|
20 |
+
export const getQueryParams = () => {
|
21 |
+
const urlSearchParams = new URLSearchParams(window.location.search);
|
22 |
+
const params = Object.fromEntries(urlSearchParams.entries());
|
23 |
+
const {source,...options} = params
|
24 |
+
return {source, options}
|
25 |
+
}
|
26 |
|
27 |
export const applyFnToObjectWithinArray = (array: Array<IPointPrompt | IRectanglePrompt>): Array<IPointTable | IRectangleTable> => {
|
28 |
let newArray = []
|