Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 26 additions & 1 deletion src/components/GlobalDataPanel.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<script setup lang="ts">
import useSettings from '../composables/useSettings'
import { computed, onMounted, onUnmounted, ref } from 'vue'
import useSettings, { GLOBAL_DATA_MAP_FIELD_START_ZOOM_LEVEL } from '../composables/useSettings'
import useMap from '../composables/useMap'
import useAreaOfInterest from '../composables/useAreaOfInterest'
import type { PlaceResult } from '../composables/useAreaOfInterest'
Expand All @@ -13,6 +14,21 @@ const { map } = useMap()
const { fitToExtent } = useAreaOfInterest()
const { showError } = useNotifier()

const zoom = ref(0)
const onZoomChange = () => {
zoom.value = map.value?.getView()?.getZoom() ?? 0
}
onMounted(() => {
if (map.value) {
onZoomChange()
map.value.getView().on('change:resolution', onZoomChange)
}
})
onUnmounted(() => {
map.value?.getView()?.un('change:resolution', onZoomChange)
})
const fieldBoundariesDisabled = computed(() => zoom.value < GLOBAL_DATA_MAP_FIELD_START_ZOOM_LEVEL)

const handleLocationSelected = (place: PlaceResult) => {
Comment thread
m-mohr marked this conversation as resolved.
if (!map.value) return
if (!place.boundingbox) {
Expand Down Expand Up @@ -52,6 +68,15 @@ const handleLocationSelected = (place: PlaceResult) => {
thumb-color="teal"
hide-details
/>
<v-checkbox
v-model="settings.showFieldBoundaries"
label="Show field boundaries"
density="compact"
hide-details
color="teal"
class="mt-2"
:disabled="fieldBoundariesDisabled"
/>
<h3 class="group legend">Legend</h3>
<MapLegend />
</v-col>
Expand Down
9 changes: 9 additions & 0 deletions src/composables/useMap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,19 @@ watch(
}

globalPredictionsLayer.value = createGlobalPredictionsLayer(settings.value)
globalPredictionsLayer.value.setVisible(settings.value.showFieldBoundaries)
map.value.addLayer(globalPredictionsLayer.value)
}
},
)

watch(
() => settings.value.showFieldBoundaries,
(visible) => {
globalPredictionsLayer.value?.setVisible(visible)
},
)

const initCloudlessLayer = () => {
if (!map.value) {
return
Expand Down Expand Up @@ -170,6 +178,7 @@ const updateLayers = () => {
if (!globalPredictionsLayer.value) {
// Only handle first initialization here, year changes are handled by a watcher on year above
globalPredictionsLayer.value = createGlobalPredictionsLayer(settings.value)
globalPredictionsLayer.value.setVisible(settings.value.showFieldBoundaries)
map.value.addLayer(globalPredictionsLayer.value)
}
if (!globalOverviewLayer.value) {
Expand Down
2 changes: 2 additions & 0 deletions src/composables/useSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export interface Settings {
expertMode: boolean
mode: string
threshold: number
showFieldBoundaries: boolean
}

export interface ModelInfo {
Expand Down Expand Up @@ -57,6 +58,7 @@ const defaultSettings: Settings = {
expertMode: false,
mode: defaultMode,
threshold: 0.4,
showFieldBoundaries: true,
}

const defaultModel = computed(() => {
Expand Down
Loading