Skip to content

Commit dbef4d5

Browse files
authored
Merge pull request #446 from fschmenger/view_animation_config
Refactor ViewAnimation to accept only subconfiguration
2 parents 0c6b911 + 55ed56c commit dbef4d5

File tree

10 files changed

+35
-26
lines changed

10 files changed

+35
-26
lines changed

src/components/attributeTable/AttributeTable.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ export default {
251251
}
252252
253253
// zoom to feature
254-
const viewAnimationUtil = new ViewAnimationUtil(this.$appConfig);
254+
const viewAnimationUtil = new ViewAnimationUtil(this.$appConfig.viewAnimation);
255255
viewAnimationUtil.to(this.map.getView(), foundFeature.getGeometry());
256256
257257
// add to map selection

src/components/geocoder/Geocoder.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ export default {
187187
// Position Map on result
188188
const result = item.value;
189189
const mapProjection = this.map.getView().getProjection();
190-
const viewAnimationUtil = new ViewAnimationUtil(this.$appConfig);
190+
const viewAnimationUtil = new ViewAnimationUtil(this.$appConfig.viewAnimation);
191191
192192
// Prefer zooming to bounding box if present in result
193193
if (Object.prototype.hasOwnProperty.call(result, 'boundingbox')) {

src/components/geolocator/Geolocator.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ export default {
8383
this.map.addLayer(geolocLayer);
8484
8585
// zoom to geolocation position
86-
const viewAnimationUtil = new ViewAnimationUtil(this.$appConfig);
86+
const viewAnimationUtil = new ViewAnimationUtil(this.$appConfig.viewAnimation);
8787
viewAnimationUtil.to(this.map.getView(), currentPosGeom);
8888
} else {
8989
console.error('The map is not defined in the getCurrentPosition callback');

src/components/maxextentbutton/ZoomToMaxExtentButton.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export default {
2424
// derive correct initial zoom and center
2525
const initialCenter = this.$appConfig.mapCenter;
2626
const initalZoom = this.$appConfig.mapZoom;
27-
const viewAnimationUtil = new ViewAnimationUtil(this.$appConfig);
27+
const viewAnimationUtil = new ViewAnimationUtil(this.$appConfig.viewAnimation);
2828
viewAnimationUtil.to(this.map.getView(), initialCenter, null, {
2929
zoom: initalZoom,
3030
maxZoom: initalZoom

src/components/ol/Map.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ export default {
335335
ddSource.addFeatures(event.features);
336336
337337
if (mapDdConf.zoomToData === true) {
338-
const viewAnimationUtil = new ViewAnimationUtil(this.$appConfig);
338+
const viewAnimationUtil = new ViewAnimationUtil(this.$appConfig.viewAnimation);
339339
viewAnimationUtil.to(this.map.getView(), ddSource.getExtent());
340340
}
341341
}, this);

src/util/Layer.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,14 @@ const LayerUtil = {
4444
*
4545
* @param {ol.layer.Base} vecLayer OL vector layer
4646
* @param {ol.Map} olMap The map to perform the zoom on
47-
* @param {Object} appConfig The application config containing optional animation configuration
47+
* @param {Object} options Optional animation configuration
4848
*/
49-
zoomToLayerExtent (vecLayer, olMap, appConfig) {
49+
zoomToLayerExtent (vecLayer, olMap, options) {
5050
if (!vecLayer || !vecLayer.getSource().getExtent || !olMap) {
5151
return;
5252
}
5353
const extent = vecLayer.getSource().getExtent();
54-
const viewAnimationUtil = new ViewAnimationUtil(appConfig);
54+
const viewAnimationUtil = new ViewAnimationUtil(options);
5555
viewAnimationUtil.to(olMap.getView(), extent);
5656
}
5757
}

src/util/ViewAnimation.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,12 @@ import Geometry from 'ol/geom/Geometry';
88
*/
99
class ViewAnimationUtil {
1010
/**
11-
* Instantiates a view animation util object with current application configuration.
12-
* @param {Object} appConfig Current application configuration
11+
* Instantiates a view animation util object with the animation object
12+
* configured in the application context.
13+
* @param {Object} options Application wide animation options.
1314
*/
14-
constructor (appConfig) {
15-
this.appConfig = appConfig
15+
constructor (options) {
16+
this.options = options;
1617
}
1718

1819
/**
@@ -29,7 +30,7 @@ class ViewAnimationUtil {
2930
default: NoAnimation
3031
};
3132

32-
const animType = this.appConfig?.viewAnimation?.type;
33+
const animType = this.options?.type;
3334
return animations[animType] || animations.default;
3435
}
3536

@@ -42,7 +43,7 @@ class ViewAnimationUtil {
4243
* @private
4344
*/
4445
getOptions (options) {
45-
return options || this.appConfig?.viewAnimation?.options || {};
46+
return options || this.options?.options || {};
4647
}
4748

4849
/**

tests/unit/specs/components/geocoder/Geocoder.spec.js

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,16 @@ import { getTransform } from 'ol/proj';
1111
import axios from 'axios';
1212
import MockAdapter from 'axios-mock-adapter';
1313

14-
function createWrapper (options = {}) {
15-
return mount(Geocoder, options);
14+
function createWrapper (props = {}, $appConfig = {}) {
15+
return mount(Geocoder, {
16+
props,
17+
attachTo: document.body,
18+
global: {
19+
mocks: {
20+
$appConfig
21+
}
22+
}
23+
});
1624
}
1725

1826
describe('geocoder/Geocoder.vue', () => {
@@ -96,7 +104,7 @@ describe('geocoder/Geocoder.vue', () => {
96104
provider: 'photon'
97105
};
98106

99-
comp = createWrapper({ props: moduleProps });
107+
comp = createWrapper(moduleProps);
100108
vm = comp.vm;
101109
});
102110

@@ -123,7 +131,7 @@ describe('geocoder/Geocoder.vue', () => {
123131
provider: 'opencage'
124132
};
125133

126-
comp = createWrapper({ props: moduleProps });
134+
comp = createWrapper(moduleProps);
127135
vm = comp.vm;
128136
});
129137

@@ -149,7 +157,7 @@ describe('geocoder/Geocoder.vue', () => {
149157
maxWidth: 100
150158
};
151159

152-
comp = createWrapper({ props: moduleProps });
160+
comp = createWrapper(moduleProps);
153161
vm = comp.vm;
154162
});
155163

@@ -176,7 +184,7 @@ describe('geocoder/Geocoder.vue', () => {
176184
maxWidth: 100
177185
};
178186

179-
comp = createWrapper({ props: moduleProps });
187+
comp = createWrapper(moduleProps);
180188
vm = comp.vm;
181189
});
182190

@@ -262,7 +270,7 @@ describe('geocoder/Geocoder.vue', () => {
262270
provider: 'osm'
263271
};
264272

265-
comp = createWrapper({ props: moduleProps });
273+
comp = createWrapper(moduleProps);
266274
vm = comp.vm;
267275

268276
onQueryResultsSpy = sinon.replace(vm, 'onQueryResults', sinon.fake(vm.onQueryResults));
@@ -373,7 +381,7 @@ describe('geocoder/Geocoder.vue', () => {
373381

374382
describe('user interactions for search activation', () => {
375383
beforeEach(() => {
376-
comp = createWrapper({ attachTo: document.body });
384+
comp = createWrapper();
377385
vm = comp.vm;
378386
});
379387

tests/unit/specs/util/ViewAnimation.spec.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@ const extent = [966000, 6341000, 967000, 6342000];
1919
const coordinate = [966000, 6341000];
2020

2121
function createViewAnimationUtil (animType) {
22-
const $appConfig = {
23-
viewAnimation: { type: animType, options }
22+
const animOptions = {
23+
type: animType, options
2424
};
2525

26-
return new ViewAnimationUtil($appConfig);
26+
return new ViewAnimationUtil(animOptions);
2727
}
2828

2929
describe('ViewAnimationUtil', () => {

upgrade-notes.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ Some changes must be done if you were using those functions directly inside your
3131
> `ViewAnimationUtil.to(this.map.getView(), foundFeature.getGeometry());`
3232
3333
Should be replaced by:
34-
> const viewAnimationUtil = new ViewAnimationUtil(this.$appConfig);
34+
> const viewAnimationUtil = new ViewAnimationUtil(this.$appConfig.viewAnimation);
3535
viewAnimationUtil.to(this.map.getView(), foundFeature.getGeometry());
3636
- `Vue` instances can no longer be used to create an *event bus*. `WguEventBus` was rewritten to make use of `tiny-emitter` because of that. This should be fully transparent, however, some edge cases could be encountered if very specific usage is made of it.
3737
- `ColorTheme mixin` and `Mapable mixin` were rewritten as `composables`. What should be done to migrate those `mixins` to their `composable` counterparts is easier to see by example. Please take a look at the [ThemeSwitcher component](https://github.com/wegue-oss/wegue/blob/master/src/components/themeswitcher/ThemeSwitcher.vue) and the [BackgroundLayerSwitcher component](https://github.com/wegue-oss/wegue/blob/master/src/components/bglayerswitcher/BgLayerSwitcher.vue) respectively.

0 commit comments

Comments
 (0)