@@ -76,7 +76,7 @@ import { Fill, Stroke, Style } from 'ol/style';
7676import type MapRef from ' ol/Map' ;
7777import { getCssVar , useQuasar } from ' quasar' ;
7878import { 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' ;
8080import { Layer } from ' ol/layer' ;
8181import { useMapStore } from ' src/stores/mapStore' ;
8282import { FeatureLike } from ' ol/Feature' ;
@@ -107,7 +107,7 @@ const $q = useQuasar();
107107 */
108108const projection = ref (' EPSG:3857' );
109109const center = ref (fromLonLat ([- 3.6 , 40.0 ], projection .value ));
110- const zoom = ref (7 );
110+ const zoom = ref (6.8 );
111111const 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
228244watch (hoveredFeatures , () => {
0 commit comments