Skip to content

Commit 846c0ed

Browse files
committed
refactor(ol-animation-shake): migrate to script setup
1 parent 60d0fa4 commit 846c0ed

File tree

5 files changed

+56
-85
lines changed

5 files changed

+56
-85
lines changed

docs/componentsguide/animations/shake/index.md

Lines changed: 9 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import ShakeAnimation from "@demos/ShakeAnimation.vue"
1515
<ol-map
1616
:loadTilesWhileAnimating="true"
1717
:loadTilesWhileInteracting="true"
18-
style="height:700px"
18+
style="height: 700px"
1919
>
2020
<ol-view
2121
ref="view"
@@ -53,27 +53,16 @@ import ShakeAnimation from "@demos/ShakeAnimation.vue"
5353
</ol-map>
5454
</template>
5555
56-
<script>
56+
<script setup>
5757
import { ref } from "vue";
5858
import starIcon from "@/assets/star.png";
59-
export default {
60-
setup() {
61-
const center = ref([40, 40]);
62-
const projection = ref("EPSG:4326");
63-
const zoom = ref(6);
64-
const rotation = ref(0);
65-
const getRandomInRange = (from, to, fixed) => {
66-
return (Math.random() * (to - from) + from).toFixed(fixed) * 1;
67-
};
68-
return {
69-
center,
70-
projection,
71-
zoom,
72-
rotation,
73-
getRandomInRange,
74-
starIcon,
75-
};
76-
},
59+
60+
const center = ref([40, 40]);
61+
const projection = ref("EPSG:4326");
62+
const zoom = ref(6);
63+
const rotation = ref(0);
64+
const getRandomInRange = (from, to, fixed) => {
65+
return (Math.random() * (to - from) + from).toFixed(fixed) * 1;
7766
};
7867
</script>
7968
```
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<template lang="">
2+
<slot></slot>
3+
</template>
4+
5+
<script setup>
6+
import Shake from "ol-ext/featureanimation/Shake";
7+
import useAnimation from "@/composables/useAnimation";
8+
import useAnimationProps from "@/composables/useAnimationProps";
9+
10+
const props = defineProps({
11+
...useAnimationProps(),
12+
bounce: {
13+
type: Number,
14+
default: 6,
15+
},
16+
amplitude: {
17+
type: Number,
18+
default: 40,
19+
},
20+
horizontal: {
21+
type: Boolean,
22+
default: false,
23+
},
24+
});
25+
26+
const { map, vectorLayer, properties, animation } = useAnimation(Shake, props);
27+
28+
defineExpose({
29+
map,
30+
vectorLayer,
31+
properties,
32+
animation,
33+
});
34+
</script>
35+
36+
<style lang=""></style>

src/components/animations/ShakeAnimation.vue

Lines changed: 0 additions & 43 deletions
This file was deleted.

src/components/animations/index.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import OLAnimationDrop from "./OLAnimationDrop.vue";
22
import OlAnimationFade from "./OlAnimationFade.vue";
33
import OlAnimationFeature from "./OlAnimationFeature.vue";
44
import OlAnimationPath from "./OlAnimationPath.vue";
5-
import ShakeAnimation from "./ShakeAnimation.vue";
5+
import OlAnimationShake from "./OlAnimationShake.vue";
66
import ZoomAnimation from "./ZoomAnimation.vue";
77
import TeleportAnimation from "./TeleportAnimation.vue";
88
import SlideAnimation from "./SlideAnimation.vue";
@@ -18,7 +18,7 @@ function install(app) {
1818
app.component("ol-animation-fade", OlAnimationFade);
1919
app.component("ol-animation-feature", OlAnimationFeature);
2020
app.component("ol-animation-path", OlAnimationPath);
21-
app.component(ShakeAnimation.name, ShakeAnimation);
21+
app.component("ol-animation-shake", OlAnimationShake);
2222
app.component(ZoomAnimation.name, ZoomAnimation);
2323
app.component(TeleportAnimation.name, TeleportAnimation);
2424
app.component(SlideAnimation.name, SlideAnimation);
@@ -32,7 +32,7 @@ export {
3232
OlAnimationFade,
3333
OlAnimationFeature,
3434
OlAnimationPath,
35-
ShakeAnimation,
35+
OlAnimationShake,
3636
ZoomAnimation,
3737
TeleportAnimation,
3838
SlideAnimation,

src/demos/ShakeAnimation.vue

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -40,26 +40,15 @@
4040
</ol-map>
4141
</template>
4242

43-
<script>
43+
<script setup>
4444
import { ref } from "vue";
4545
import starIcon from "@/assets/star.png";
46-
export default {
47-
setup() {
48-
const center = ref([40, 40]);
49-
const projection = ref("EPSG:4326");
50-
const zoom = ref(6);
51-
const rotation = ref(0);
52-
const getRandomInRange = (from, to, fixed) => {
53-
return (Math.random() * (to - from) + from).toFixed(fixed) * 1;
54-
};
55-
return {
56-
center,
57-
projection,
58-
zoom,
59-
rotation,
60-
getRandomInRange,
61-
starIcon,
62-
};
63-
},
46+
47+
const center = ref([40, 40]);
48+
const projection = ref("EPSG:4326");
49+
const zoom = ref(6);
50+
const rotation = ref(0);
51+
const getRandomInRange = (from, to, fixed) => {
52+
return (Math.random() * (to - from) + from).toFixed(fixed) * 1;
6453
};
6554
</script>

0 commit comments

Comments
 (0)