Commit 3fc04ba8 authored by Michael Underwood's avatar Michael Underwood
Browse files

fix: Use injected methods instead of `this` in layer

Fixes #165
parent 852a1807
Loading
Loading
Loading
Loading
+16 −0
Original line number Diff line number Diff line
@@ -182,8 +182,12 @@ export default {
      markerZoomAnimation: props.markerZoomAnimation,
    };

    const getAttributionControl = () => blueprint.leafletRef.attributionControl;

    const addLayer = provideLeafletWrapper("addLayer");
    const removeLayer = provideLeafletWrapper("removeLayer");
    const addAttribution = provideLeafletWrapper("addAttribution");
    const removeAttribution = provideLeafletWrapper("removeAttribution");
    const registerControl = provideLeafletWrapper("registerControl");
    const registerLayerControl = provideLeafletWrapper("registerLayerControl");
    provide(GLOBAL_LEAFLET_OPT, props.useGlobalLeaflet);
@@ -368,10 +372,22 @@ export default {
            });
          }
        },

        addAttribution(attribution) {
          const control = getAttributionControl();
          control && control.addAttribution(attribution);
        },

        removeAttribution(attribution) {
          const control = getAttributionControl();
          control && control.removeAttribution(attribution);
        },
      };

      updateLeafletWrapper(addLayer, methods.addLayer);
      updateLeafletWrapper(removeLayer, methods.removeLayer);
      updateLeafletWrapper(addAttribution, methods.addAttribution);
      updateLeafletWrapper(removeAttribution, methods.removeAttribution);
      updateLeafletWrapper(registerControl, methods.registerControl);
      updateLeafletWrapper(registerLayerControl, methods.registerLayerControl);

+4 −2
Original line number Diff line number Diff line
@@ -32,6 +32,8 @@ export const props = {
export const setup = (props, leafletRef, context) => {
  const addLayer = inject("addLayer");
  const removeLayer = inject("removeLayer");
  const addAttribution = inject("addAttribution");
  const removeAttribution = inject("removeAttribution");
  const {
    options: componentOptions,
    methods: componentMethods,
@@ -50,8 +52,8 @@ export const setup = (props, leafletRef, context) => {
  const methods = {
    ...componentMethods,
    setAttribution(val, old) {
      const attributionControl = this.$parent.leafletObject.attributionControl;
      attributionControl.removeAttribution(old).addAttribution(val);
      removeAttribution(old);
      addAttribution(val);
    },
    setName() {
      removeThisLayer();