Skip to content

Commit

Permalink
feat: create tooltip component
Browse files Browse the repository at this point in the history
  • Loading branch information
DonNicoJs committed Oct 3, 2020
1 parent 7649900 commit 054ac05
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions src/components/LTooltip.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<script>
import { onMounted, ref, inject, h } from "vue";
import { propsBinder, remapEvents } from "../utils.js";
import { setup as tooltipSetup, props } from "../functions/tooltip";
/**
* Display a tooltip on the map
*/
export default {
name: "LTooltip",
props,
setup(props, context) {
const mapRef = ref({});
const root = ref(null);
const lMethods = inject("leafLetMethods");
const { options, methods } = tooltipSetup(props, mapRef, context, lMethods);
onMounted(async () => {
const { tooltip, DomEvent, setOptions } = await import(
"leaflet/dist/leaflet-src.esm"
);
mapRef.value = tooltip(options);
propsBinder(methods, mapRef.value, props, setOptions);
const listeners = remapEvents(context.attrs);
DomEvent.on(mapRef.value, listeners);
mapRef.value.setContent(props.content || root.value);
lMethods.bindTooltip({ mapObject: mapRef.value });
});
return { root };
},
render() {
if (this.$slots.default) {
return h("div", { ref: "root" }, this.$slots.default());
}
return null;
},
};
</script>

0 comments on commit 054ac05

Please sign in to comment.