Skip to content

Commit 441735f

Browse files
Merge pull request #259 from studiometa/bugfix/js-error-on-control-removal
[Bugfix] JS error on control removal
2 parents 5acb49e + 12ae5a9 commit 441735f

File tree

3 files changed

+30
-1
lines changed

3 files changed

+30
-1
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file. The format
44

55
## [Unreleased]
66

7+
### Fixed
8+
9+
- Fix Mapbox trying to remove controls already removed ([#249](https://github.com/studiometa/vue-mapbox-gl/issues/249), [#259](https://github.com/studiometa/vue-mapbox-gl/pull/259), [0bfaea6](https://github.com/studiometa/vue-mapbox-gl/commit/0bfaea6))
10+
711
## [v2.7.1](https://github.com/studiometa/vue-mapbox-gl/compare/2.7.0...2.7.1) (2025-02-04)
812

913
### Changed

packages/demo/pages/issue-249.vue

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<script setup>
2+
import { ref } from 'vue';
3+
import { MapboxMap, MapboxGeocoder } from '@studiometa/vue-mapbox-gl';
4+
import 'mapbox-gl/dist/mapbox-gl.css';
5+
import '@mapbox/mapbox-gl-geocoder/lib/mapbox-gl-geocoder.css';
6+
7+
const config = useRuntimeConfig();
8+
const showMap = ref(true);
9+
</script>
10+
11+
<template>
12+
<div>
13+
<label>
14+
<input v-model="showMap" type="checkbox" />
15+
toggle map
16+
</label>
17+
<MapboxMap
18+
v-if="showMap"
19+
style="height: 60vh"
20+
:access-token="config.public.accessToken"
21+
map-style="mapbox://styles/mapbox/streets-v11">
22+
<MapboxGeocoder />
23+
</MapboxMap>
24+
</div>
25+
</template>

packages/vue-mapbox-gl/composables/useControl.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ export function useControl(ControlConstructor, { propsConfig, props, emit, event
6262
});
6363

6464
onUnmounted(() => {
65-
if (unref(control) && unref(map)) {
65+
if (unref(control) && unref(map) && unref(map).hasControl(unref(control))) {
6666
unref(map).removeControl(unref(control));
6767
}
6868
});

0 commit comments

Comments
 (0)