Skip to content

Commit a603a20

Browse files
committed
refactor(ol-view): migrate to script setup
1 parent 2ca9d7d commit a603a20

File tree

5 files changed

+153
-179
lines changed

5 files changed

+153
-179
lines changed

docs/componentsguide/view/index.md

Lines changed: 25 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ See also documentation of ol-map component
2121

2222
```vue
2323
<template>
24-
<ol-map style="height:400px">
24+
<ol-map style="height: 400px">
2525
<ol-view
2626
ref="view"
2727
:center="center"
@@ -45,45 +45,31 @@ See also documentation of ol-map component
4545
</div>
4646
</template>
4747
48-
<script>
48+
<script setup>
4949
import { ref } from "vue";
50-
export default {
51-
setup() {
52-
const center = ref([40, 40]);
53-
const projection = ref("EPSG:4326");
54-
const zoom = ref(8);
55-
const rotation = ref(0);
56-
57-
return {
58-
center,
59-
projection,
60-
zoom,
61-
rotation,
62-
};
63-
},
64-
data() {
65-
return {
66-
currentCenter: this.center,
67-
currentZoom: this.zoom,
68-
currentResolution: this.resolution,
69-
currentRotation: this.rotation,
70-
};
71-
},
72-
methods: {
73-
zoomChanged(currentZoom) {
74-
this.currentZoom = currentZoom;
75-
},
76-
resolutionChanged(resolution) {
77-
this.currentResolution = resolution;
78-
},
79-
centerChanged(center) {
80-
this.currentCenter = center;
81-
},
82-
rotationChanged(rotation) {
83-
this.currentRotation = rotation;
84-
},
85-
},
86-
};
50+
51+
const center = ref([40, 40]);
52+
const projection = ref("EPSG:4326");
53+
const zoom = ref(8);
54+
const rotation = ref(0);
55+
56+
const currentCenter = ref(0);
57+
const currentZoom = ref(0);
58+
const currentResolution = ref(0);
59+
const currentRotation = ref(0);
60+
61+
function zoomChanged(z) {
62+
currentZoom.value = z;
63+
}
64+
function resolutionChanged(r) {
65+
currentResolution.value = r;
66+
}
67+
function centerChanged(c) {
68+
currentCenter.value = c;
69+
}
70+
function rotationChanged(r) {
71+
currentRotation.value = r;
72+
}
8773
</script>
8874
```
8975

src/components/map/OlView.vue

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
<template lang="">
2+
<div v-if="false"></div>
3+
</template>
4+
5+
<script setup>
6+
import useView from "@/composables/useView";
7+
8+
const props = defineProps({
9+
center: {
10+
type: Array,
11+
default: () => [0, 0],
12+
},
13+
constrainRotation: {
14+
type: Boolean,
15+
default: true,
16+
},
17+
enableRotation: {
18+
type: Boolean,
19+
default: true,
20+
},
21+
extent: {
22+
type: Array,
23+
},
24+
constrainOnlyCenter: {
25+
type: Boolean,
26+
default: false,
27+
},
28+
smoothExtentConstraint: {
29+
type: Boolean,
30+
default: true,
31+
},
32+
maxResolution: {
33+
type: Number,
34+
},
35+
minResolution: {
36+
type: Number,
37+
},
38+
maxZoom: {
39+
type: Number,
40+
default: 28,
41+
},
42+
minZoom: {
43+
type: Number,
44+
default: 0,
45+
},
46+
multiWorld: {
47+
type: Boolean,
48+
default: false,
49+
},
50+
constrainResolution: {
51+
type: Boolean,
52+
default: false,
53+
},
54+
smoothResolutionConstraint: {
55+
type: Boolean,
56+
default: true,
57+
},
58+
showFullExtent: {
59+
type: Boolean,
60+
default: false,
61+
},
62+
projection: {
63+
type: [String, Object],
64+
default: "EPSG:3857",
65+
},
66+
resolution: {
67+
type: Number,
68+
},
69+
resolutions: {
70+
type: Array,
71+
},
72+
rotation: {
73+
type: Number,
74+
},
75+
zoom: {
76+
type: Number,
77+
default: 0,
78+
},
79+
zoomFactor: {
80+
type: Number,
81+
default: 2,
82+
},
83+
padding: {
84+
type: Array,
85+
default: () => [0, 0, 0, 0],
86+
},
87+
});
88+
89+
const emit = defineEmits([
90+
"centerChanged",
91+
"zoomChanged",
92+
"resolutionChanged",
93+
"rotationChanged",
94+
]);
95+
const view = useView(props, emit);
96+
97+
defineExpose({
98+
...view,
99+
});
100+
</script>
101+
102+
<style lang=""></style>

src/components/map/View.vue

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

src/components/map/index.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import OlGeoLocation from "./OlGeoLocation.vue";
33
import OlMap from "./OlMap.vue";
44
import OlOverlay from "./OlOverlay.vue";
55
import OlProjectionRegister from "./OlProjectionRegister.vue";
6-
import View from "./View.vue";
6+
import OlView from "./OlView.vue";
77

88
function install(app) {
99
if (install.installed) {
@@ -17,7 +17,7 @@ function install(app) {
1717
app.component("ol-map", OlMap);
1818
app.component("ol-overlay", OlOverlay);
1919
app.component("ol-projection-register", OlProjectionRegister);
20-
app.component(View.name, View);
20+
app.component("ol-view", OlView);
2121
}
2222

2323
export default install;
@@ -29,5 +29,5 @@ export {
2929
OlMap,
3030
OlOverlay,
3131
OlProjectionRegister,
32-
View,
32+
OlView,
3333
};

src/demos/ViewDemo.vue

Lines changed: 23 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -23,43 +23,29 @@
2323
</div>
2424
</template>
2525

26-
<script>
26+
<script setup>
2727
import { ref } from "vue";
28-
export default {
29-
setup() {
30-
const center = ref([40, 40]);
31-
const projection = ref("EPSG:4326");
32-
const zoom = ref(8);
33-
const rotation = ref(0);
3428
35-
return {
36-
center,
37-
projection,
38-
zoom,
39-
rotation,
40-
};
41-
},
42-
data() {
43-
return {
44-
currentCenter: this.center,
45-
currentZoom: this.zoom,
46-
currentResolution: this.resolution,
47-
currentRotation: this.rotation,
48-
};
49-
},
50-
methods: {
51-
zoomChanged(currentZoom) {
52-
this.currentZoom = currentZoom;
53-
},
54-
resolutionChanged(resolution) {
55-
this.currentResolution = resolution;
56-
},
57-
centerChanged(center) {
58-
this.currentCenter = center;
59-
},
60-
rotationChanged(rotation) {
61-
this.currentRotation = rotation;
62-
},
63-
},
64-
};
29+
const center = ref([40, 40]);
30+
const projection = ref("EPSG:4326");
31+
const zoom = ref(8);
32+
const rotation = ref(0);
33+
34+
const currentCenter = ref(0);
35+
const currentZoom = ref(0);
36+
const currentResolution = ref(0);
37+
const currentRotation = ref(0);
38+
39+
function zoomChanged(z) {
40+
currentZoom.value = z;
41+
}
42+
function resolutionChanged(r) {
43+
currentResolution.value = r;
44+
}
45+
function centerChanged(c) {
46+
currentCenter.value = c;
47+
}
48+
function rotationChanged(r) {
49+
currentRotation.value = r;
50+
}
6551
</script>

0 commit comments

Comments
 (0)