Skip to content

Commit dd23868

Browse files
committed
refactor(ol-layerswitcher-control): migrate to script setup
1 parent 560e795 commit dd23868

File tree

5 files changed

+84
-72
lines changed

5 files changed

+84
-72
lines changed

src/components/mapControls/LayerSwitcherControl.vue

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

src/components/mapControls/LayerSwitcherImageControl.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55
<script>
66
import LayerSwitcherImage from "ol-ext/control/LayerSwitcherImage";
77
import useControl from "@/composables/useControl";
8-
import LayerSwitcherControl from "./LayerSwitcherControl.vue";
8+
import OlLayerSwitcherControl from "./OlLayerSwitcherControl.vue";
99
export default {
1010
name: "ol-layerswitcherimage-control",
11-
extends: LayerSwitcherControl,
11+
extends: OlLayerSwitcherControl,
1212
setup(props, context) {
1313
const { control } = useControl(LayerSwitcherImage, props, context);
1414
return {
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
<template lang="">
2+
<div v-if="false"></div>
3+
</template>
4+
5+
<script setup>
6+
import LayerSwitcher from "ol-ext/control/LayerSwitcher";
7+
import useControl from "@/composables/useControl";
8+
import { useAttrs } from "vue";
9+
10+
const props = defineProps({
11+
selection: {
12+
type: Boolean,
13+
},
14+
displayInLayerSwitcher: {
15+
type: Function,
16+
},
17+
show_progress: {
18+
type: Boolean,
19+
default: false,
20+
},
21+
mouseover: {
22+
type: Boolean,
23+
default: false,
24+
},
25+
reordering: {
26+
type: Boolean,
27+
default: true,
28+
},
29+
trash: {
30+
type: Boolean,
31+
default: false,
32+
},
33+
oninfo: {
34+
type: Function,
35+
},
36+
extent: {
37+
type: Boolean,
38+
},
39+
onextent: {
40+
type: Function,
41+
},
42+
drawDelay: {
43+
type: Number,
44+
},
45+
collapsed: {
46+
type: Boolean,
47+
default: true,
48+
},
49+
layerGroup: {
50+
type: Object,
51+
},
52+
noScroll: {
53+
type: Boolean,
54+
default: false,
55+
},
56+
});
57+
58+
const attrs = useAttrs();
59+
const { control } = useControl(LayerSwitcher, props, { attrs });
60+
61+
defineExpose({
62+
control,
63+
});
64+
</script>
65+
66+
<style lang=""></style>

src/components/mapControls/index.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import SwipeControl from "./SwipeControl.vue";
1414
import ToggleControl from "./ToggleControl.vue";
1515
import PrintDialog from "./PrintDialog.vue";
1616
import VideoRecorderControl from "./VideoRecorderControl.vue";
17-
import LayerSwitcherControl from "./LayerSwitcherControl.vue";
17+
import OlLayerSwitcherControl from "./OlLayerSwitcherControl.vue";
1818
import LayerSwitcherImageControl from "./LayerSwitcherImageControl.vue";
1919
import ZoneControl from "./ZoneControl.vue";
2020

@@ -41,7 +41,7 @@ function install(app) {
4141
app.component("ol-button-control", OlButtonControl);
4242
app.component(PrintDialog.name, PrintDialog);
4343
app.component(VideoRecorderControl.name, VideoRecorderControl);
44-
app.component(LayerSwitcherControl.name, LayerSwitcherControl);
44+
app.component("ol-layerswitcher-control", OlLayerSwitcherControl);
4545
app.component(LayerSwitcherImageControl.name, LayerSwitcherImageControl);
4646
app.component(ZoneControl.name, ZoneControl);
4747
}
@@ -55,6 +55,7 @@ export {
5555
OlContextMenuControl,
5656
OlControlBar,
5757
OlFullScreenControl,
58+
OlLayerSwitcherControl,
5859
MousePositionControl,
5960
OverviewMapControl,
6061
ScaleLineControl,
@@ -66,7 +67,6 @@ export {
6667
ToggleControl,
6768
PrintDialog,
6869
VideoRecorderControl,
69-
LayerSwitcherControl,
7070
LayerSwitcherImageControl,
7171
ZoneControl,
7272
};

src/demos/MapControlDemo.vue

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,14 @@
4949
<input type="checkbox" id="swipecontrol" v-model="showSwipeControl" />
5050
<label for="swipecontrol">swipe-control</label>
5151
</li>
52+
<li>
53+
<input
54+
type="checkbox"
55+
id="layerswitchercontrol"
56+
v-model="showLayerSwitcherControl"
57+
/>
58+
<label for="layerswitchercontrol">layerswitcher-control</label>
59+
</li>
5260
</ul>
5361

5462
<ol-map
@@ -91,6 +99,10 @@
9199
:layerList="layerList"
92100
/>
93101

102+
<ol-layerswitcher-control
103+
v-if="showLayerSwitcherControl && layerList.length > 0"
104+
/>
105+
94106
<ol-tile-layer ref="jawgLayer" title="JAWG">
95107
<ol-source-xyz
96108
crossOrigin="anonymous"
@@ -125,6 +137,7 @@ const overviewmapcontrol = ref(true);
125137
const mousepositioncontrol = ref(true);
126138
const rotatecontrol = ref(true);
127139
const showSwipeControl = ref(true);
140+
const showLayerSwitcherControl = ref(true);
128141
129142
onMounted(() => {
130143
layerList.value.push(jawgLayer.value.tileLayer);

0 commit comments

Comments
 (0)