Skip to content

Commit 254235f

Browse files
committed
[Front] Zoom out with transition at drawer close.
1 parent 853b218 commit 254235f

File tree

1 file changed

+19
-3
lines changed

1 file changed

+19
-3
lines changed

frontend/src/components/AnomalyMap.vue

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ import { Fill, Stroke, Style } from 'ol/style';
7676
import type MapRef from 'ol/Map';
7777
import { getCssVar, useQuasar } from 'quasar';
7878
import { ANOMALY_COLORS } from 'src/constants/colors';
79-
import { computed, inject, onMounted, ref, watch, watchEffect } from 'vue';
79+
import { computed, inject, onMounted, onUnmounted, ref, watch, watchEffect } from 'vue';
8080
import { Layer } from 'ol/layer';
8181
import { useMapStore } from 'src/stores/mapStore';
8282
import { FeatureLike } from 'ol/Feature';
@@ -107,7 +107,7 @@ const $q = useQuasar();
107107
*/
108108
const projection = ref('EPSG:3857');
109109
const center = ref(fromLonLat([-3.6, 40.0], projection.value));
110-
const zoom = ref(7);
110+
const zoom = ref(6.8);
111111
const maxZoom = ref(17);
112112
113113
// * Map layers
@@ -151,6 +151,17 @@ onMounted(() => {
151151
}
152152
});
153153
154+
onUnmounted(() => {
155+
const map = mapRef.value?.map;
156+
if (!map) {
157+
return;
158+
}
159+
map.removeOverlay(hoverOverlay);
160+
161+
// .clear();
162+
mapStore.selectedFeatures = [];
163+
});
164+
154165
/**
155166
* Select and hover features
156167
*/
@@ -221,8 +232,13 @@ watchEffect(() => {
221232
padding: [250, 250, 250, 250], //Padding around the feature
222233
duration: 600, // duration of the zoom animation in milliseconds
223234
});
235+
} else if (viewRef.value && !mapStore.isRegionSelected) {
236+
viewRef.value.view.animate({
237+
center: center.value,
238+
zoom: zoom.value,
239+
duration: 600, // duration of the zoom animation in milliseconds
240+
});
224241
}
225-
// # TODO: Zoom out if selected feature is cleared
226242
});
227243
228244
watch(hoveredFeatures, () => {

0 commit comments

Comments
 (0)