Skip to content

Commit

Permalink
Expose remove function to the popup.
Browse files Browse the repository at this point in the history
  • Loading branch information
francois2metz committed Sep 25, 2024
1 parent bec966b commit a40dcc4
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
10 changes: 9 additions & 1 deletion docs/examples/popup.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@
>
<mgl-navigation-control />
<mgl-marker :coordinates="coordinates">
<mgl-popup>
<mgl-popup ref="popup">
<h1>Hello</h1>
<p>HTML content</p>
<a href="#" @click="closePopup">Close popup</a>
</mgl-popup>
</mgl-marker>
</mgl-map>
Expand All @@ -25,11 +26,18 @@ import {
MglMarker,
MglPopup,
} from '@indoorequal/vue-maplibre-gl';
import { useTemplateRef } from 'vue'
const style = 'https://api.maptiler.com/maps/streets/style.json?key=cQX2iET1gmOW38bedbUh';
const center = [12.550343, 55.665957];
const zoom = 8;
const coordinates = [12.550343, 55.665957];
const popupRef = useTemplateRef('popup')
const closePopup = () => {
popupRef.value.remove()
};
</script>

<style lang="scss">
Expand Down
14 changes: 13 additions & 1 deletion lib/components/popup.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ export default defineComponent({
*/
"close",
],
expose: [
/**
* Close the popup
*/
"remove",
],
props: {
/**
* The geographical location of the popup's anchor.
Expand Down Expand Up @@ -124,7 +130,7 @@ export default defineComponent({
required: false,
},
},
setup(props, { slots, emit }) {
setup(props, { slots, emit, expose }) {
const map = inject(mapSymbol);
const marker = inject(markerSymbol);
const root = ref();
Expand Down Expand Up @@ -152,6 +158,12 @@ export default defineComponent({
emitEvent("open");
emitEvent("close");

expose({
remove() {
popup.remove();
},
});

watch(
() => props.coordinates,
(v) => {
Expand Down

0 comments on commit a40dcc4

Please sign in to comment.