Unverified Commit ea85db7c authored by Nicolò Maria Mezzopera's avatar Nicolò Maria Mezzopera Committed by GitHub
Browse files

Merge pull request #143 from vue-leaflet/resolve-141

Resolve 141 by ensuring expected functions can be called before using them
parents ac85ef06 e635396b
Loading
Loading
Loading
Loading
+27 −4
Original line number Diff line number Diff line
import { onUnmounted, provide, inject, h } from "vue";
import { props as componentProps, setup as componentSetup } from "./component";
import { isFunction } from "../utils";

export const props = {
  ...componentProps,
@@ -74,20 +75,42 @@ export const setup = (props, leafletRef, context) => {
      }
    },
    bindPopup({ leafletObject }) {
      if (!leafletRef.value || !isFunction(leafletRef.value.bindPopup)) {
        console.warn(
          "Attempt to bind popup before bindPopup method available on layer."
        );

        return;
      }

      leafletRef.value.bindPopup(leafletObject);
    },
    bindTooltip({ leafletObject }) {
      if (!leafletRef.value || !isFunction(leafletRef.value.bindTooltip)) {
        console.warn(
          "Attempt to bind tooltip before bindTooltip method available on layer."
        );

        return;
      }

      leafletRef.value.bindTooltip(leafletObject);
    },
    unbindTooltip() {
      const tooltip = leafletRef.value ? leafletRef.value.getTooltip() : null;
      if (tooltip) {
      const tooltip =
        leafletRef.value && isFunction(leafletRef.value.getTooltip)
          ? leafletRef.value.getTooltip()
          : null;
      if (tooltip && isFunction(tooltip.unbindTooltip)) {
        tooltip.unbindTooltip();
      }
    },
    unbindPopup() {
      const popup = leafletRef.value ? leafletRef.value.getPopup() : null;
      if (popup) {
      const popup =
        leafletRef.value && isFunction(leafletRef.value.getPopup)
          ? leafletRef.value.getPopup()
          : null;
      if (popup && isFunction(popup.unbindPopup)) {
        popup.unbindPopup();
      }
    },
+2 −0
Original line number Diff line number Diff line
@@ -22,6 +22,8 @@ export const capitalizeFirstLetter = (string) => {
  return string.charAt(0).toUpperCase() + string.slice(1);
};

export const isFunction = (x) => typeof x === "function";

export const propsBinder = (methods, leafletElement, props) => {
  for (const key in props) {
    const setMethodName = "set" + capitalizeFirstLetter(key);