Commit a13551bc authored by Michael Underwood's avatar Michael Underwood
Browse files

WIP add method to update multiple leaflet methods

parent 4826999a
Loading
Loading
Loading
Loading
+2 −7
Original line number Diff line number Diff line
@@ -11,8 +11,8 @@ import {
  propsBinder,
  debounce,
  resetWebpackIcon,
  updateLeafletMethod,
  provideLeafletPlaceholders,
  updateLeafletMethods,
} from "../utils.js";

export default {
@@ -327,12 +327,7 @@ export default {
        },
      };

      updateLeafletMethod(schematics.addLayer, methods.addLayer);
      updateLeafletMethod(schematics.removeLayer, methods.removeLayer);
      updateLeafletMethod(
        schematics.registerLayerControl,
        methods.registerLayerControl
      );
      updateLeafletMethods(schematics, methods);

      blueprint.leafletRef = map(root.value, options);

+2 −2
Original line number Diff line number Diff line
@@ -6,7 +6,7 @@ import {
  debounce,
  provideLeafletPlaceholders,
  injectLeafletMethod,
  updateLeafletMethod,
  updateLeafletMethods,
} from "../utils.js";
import { props, setup as markerSetup } from "../functions/marker";

@@ -34,7 +34,7 @@ export default {
      const { marker, DomEvent, latLng, setOptions } = await import(
        "leaflet/dist/leaflet-src.esm"
      );
      updateLeafletMethod(schematics.latLng, latLng);
      updateLeafletMethods(schematics, { latLng });

      leafletRef.value = marker(props.latLng, options);

+2 −3
Original line number Diff line number Diff line
@@ -2,7 +2,7 @@ import { onUnmounted } from "vue";
import {
  provideLeafletPlaceholders,
  injectLeafletMethod,
  updateLeafletMethod,
  updateLeafletMethods,
} from "../utils";

export const props = {
@@ -94,8 +94,7 @@ export const setup = (props, leafletRef, context) => {
    "bindTooltip",
    "unbindTooltip",
  ]);
  updateLeafletMethod(schematics.bindTooltip, methods.bindTooltip);
  updateLeafletMethod(schematics.unbindTooltip, methods.unbindTooltip);
  updateLeafletMethods(schematics, methods);

  onUnmounted(() => {
    methods.unbindPopup();
+17 −2
Original line number Diff line number Diff line
@@ -89,8 +89,23 @@ export const provideLeafletMethods = (methods) => {
  }
};

export const updateLeafletMethod = (methodRef, updateMethod) => {
  methodRef.value = updateMethod;
/**
 * Update any or all of the leaflet method references originally created
 * by provideLeafletMethods.
 *
 * Each key that exists in the updateMethods object will replace the Leaflet
 * method with the same name in methodRefs, if it exists. Methods that are
 * not already part of methodRefs will not be added.
 *
 * @param {*} methodRefs
 * @param {*} updateMethods
 */
export const updateLeafletMethods = (methodRefs, updateMethods) => {
  for (const methodName in updateMethods) {
    if (methodRefs[methodName]) {
      methodRefs[methodName].value = updateMethods[methodName];
    }
  }
};

export const injectLeafletMethod = (methodName) => {