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

Merge pull request #54 from vue-leaflet/resolve-51

Pass leaflet object correctly to add and remove layer functions
parents 4a3f9eb4 20bb2e6a
Loading
Loading
Loading
Loading
+11 −7
Original line number Diff line number Diff line
@@ -34,29 +34,33 @@ export const setup = (props, leafletRef, context) => {
    pane: props.pane,
  };

  const addThisLayer = () => addLayer({ leafletObject: leafletRef.value });
  const removeThisLayer = () =>
    removeLayer({ leafletObject: leafletRef.value });

  const methods = {
    setAttribution(val, old) {
      const attributionControl = this.$parent.leafletObject.attributionControl;
      attributionControl.removeAttribution(old).addAttribution(val);
    },
    setName() {
      removeLayer(leafletRef.value);
      removeThisLayer();
      if (props.visible) {
        addLayer(leafletRef.value);
        addThisLayer();
      }
    },
    setLayerType() {
      removeLayer(leafletRef.value);
      removeThisLayer();
      if (props.visible) {
        addLayer(leafletRef.value);
        addThisLayer();
      }
    },
    setVisible(isVisible) {
      if (leafletRef.value) {
        if (isVisible) {
          addLayer(leafletRef.value);
          addThisLayer();
        } else {
          removeLayer(leafletRef.value);
          removeThisLayer();
        }
      }
    },
@@ -96,7 +100,7 @@ export const setup = (props, leafletRef, context) => {
  onUnmounted(() => {
    methods.unbindPopup();
    methods.unbindTooltip();
    removeLayer({ leafletObject: leafletRef.value });
    removeThisLayer();
  });

  return { options, methods };
+1 −1
Original line number Diff line number Diff line
@@ -150,7 +150,7 @@ export const setup = (props, leafletRef, context) => {
  };

  onBeforeUnmount(() => {
    removeLayer();
    removeLayer({ leafletObject: leafletRef.value });
  });

  return { options, methods };