@@ -12,7 +12,7 @@ import type { Options as AttributionOptions } from "ol/control/Attribution";
12
12
import type Control from "ol/control/Control" ;
13
13
import type ContextMenu from "ol-contextmenu" ;
14
14
import type { Options as OlContextmenuOptions } from "ol-contextmenu/dist/types" ;
15
- import type Bar from "ol-ext/control/Bar" ;
15
+ import Bar from "ol-ext/control/Bar" ;
16
16
import type { Options as BarOptions } from "ol-ext/control/Bar" ;
17
17
import type Button from "ol-ext/control/Button" ;
18
18
import type { Options as ButtonOptions } from "ol-ext/control/Button" ;
@@ -103,15 +103,25 @@ export default function useControl<T extends InnerControlType>(
103
103
control . value . set ( "order" , attrs . order === undefined ? 0 : attrs . order ) ;
104
104
105
105
watch ( control , ( newVal , oldVal ) => {
106
- if ( parent && parent instanceof Map ) {
107
- parent . removeControl ( oldVal ) ;
108
- parent . addControl ( newVal ) ;
106
+ if ( parent ) {
107
+ if ( parent instanceof Map ) {
108
+ parent . removeControl ( oldVal ) ;
109
+ parent . addControl ( newVal ) ;
110
+ } else if ( parent instanceof Bar ) {
111
+ if ( parent ?. controls_ ) {
112
+ const index = parent ?. controls_ . findIndex ( ( a ) => a === control . value ) ;
113
+ if ( index ) {
114
+ parent ?. controls_ . splice ( index , 1 ) ;
115
+ }
116
+ }
117
+ parent . addControl ( newVal ) ;
118
+ }
109
119
map ?. changed ( ) ;
110
120
}
111
121
} ) ;
112
122
113
123
onMounted ( ( ) => {
114
- if ( parent && parent instanceof Map ) {
124
+ if ( parent && ( parent instanceof Map || parent instanceof Bar ) ) {
115
125
parent . addControl ( control . value ) ;
116
126
}
117
127
@@ -123,7 +133,7 @@ export default function useControl<T extends InnerControlType>(
123
133
124
134
parent . controls_ = [ ] ;
125
135
126
- if ( parent instanceof Map ) {
136
+ if ( parent && ( parent instanceof Map || parent instanceof Bar ) ) {
127
137
sortedControls . forEach ( ( c ) => {
128
138
parent . addControl ( c ) ;
129
139
} ) ;
@@ -153,8 +163,8 @@ export default function useControl<T extends InnerControlType>(
153
163
parent ?. controls_ . splice ( index , 1 ) ;
154
164
}
155
165
}
156
- control . value . dispose ( ) ;
157
166
}
167
+ control . value . dispose ( ) ;
158
168
map ?. changed ( ) ;
159
169
} ) ;
160
170
0 commit comments