|
12 | 12 | :icon="mdiChevronDown" |
13 | 13 | > |
14 | 14 | </v-icon> |
15 | | - <span class="text-white title"> Results ({{ geoJsonResults.length }}) </span> |
| 15 | + <span class="text-white title">Results ({{ geoJsonResults.length }})</span> |
16 | 16 | </div> |
17 | 17 | <span v-else class="text-white title">Results</span> |
18 | 18 | <v-spacer /> |
|
102 | 102 | </template> |
103 | 103 |
|
104 | 104 | <script setup lang="ts"> |
105 | | -import { ref, onMounted, onUnmounted, onBeforeUnmount, computed, watch } from 'vue' |
| 105 | +import { ref, computed, watch } from 'vue' |
106 | 106 | import useMap from '../composables/useMap' |
107 | 107 | import useNotifier from '../composables/useNotifier' |
108 | 108 | import useAreaOfInterest from '../composables/useAreaOfInterest' |
@@ -137,7 +137,20 @@ const hasMoreResults = computed(() => { |
137 | 137 |
|
138 | 138 | watch( |
139 | 139 | () => props.geoJsonResults, |
140 | | - (results) => (isOpen.value = results.length > 0), |
| 140 | + (results) => { |
| 141 | + const hasResults = results.length > 0 |
| 142 | + isOpen.value = hasResults |
| 143 | + // |
| 144 | + if (!hasResults) { |
| 145 | + selectedFeature.value = null |
| 146 | + } |
| 147 | + // Map click handler to detect feature clicks and show properties |
| 148 | + if (map.value) { |
| 149 | + const action = hasResults ? 'on' : 'un' |
| 150 | + map.value[action]('singleclick', handleMapClick) |
| 151 | + } |
| 152 | + }, |
| 153 | + { immediate: true }, |
141 | 154 | ) |
142 | 155 |
|
143 | 156 | const sortedResults = computed(() => { |
@@ -278,24 +291,6 @@ const fitMapToResult = (result: Feature) => { |
278 | 291 | fitToExtent(map.value!, extent, null) |
279 | 292 | } |
280 | 293 |
|
281 | | -onMounted(() => { |
282 | | - // Add map click handler to detect feature clicks and show properties |
283 | | - if (map.value) { |
284 | | - map.value.on('singleclick', handleMapClick) |
285 | | - } |
286 | | -}) |
287 | | -
|
288 | | -onBeforeUnmount(() => { |
289 | | - selectedFeature.value = null |
290 | | -}) |
291 | | -
|
292 | | -// Clean up map click handler when component is unmounted |
293 | | -onUnmounted(() => { |
294 | | - if (map.value) { |
295 | | - map.value.un('singleclick', handleMapClick) |
296 | | - } |
297 | | -}) |
298 | | -
|
299 | 294 | const clearResultsHandler = () => { |
300 | 295 | // Clear results and zoom back to S2 grid |
301 | 296 | clearResults(map.value!) |
|
0 commit comments