Commit 31345c2d authored by Michael Underwood's avatar Michael Underwood
Browse files

Revert add/rm attr in favour of whole layer

The original idea of swapping out the old attribution for the new
instead of completely removing and re-adding the layer had merit, but
led to incorrect attributions on the map if other layer properties were
also changed. Specifically, if props changed attribution "A" to "B" and
name "layer A" to "layer B", then:
* Attribution "A" would be remove and "B" added.
* The layer would be removed from the map entirely.
* The layer would be added back, _with its original options.attribution_
  still equal to "A".
* Attribution on the map would read "A, B".

This updated approach resolves that by changing the option on the layer
object before re-adding it to the map, and otherwise letting Leaflet
take care of adding and removing attributions as the layer is changed.
parent 3fc04ba8
Loading
Loading
Loading
Loading
+0 −16
Original line number Diff line number Diff line
@@ -182,12 +182,8 @@ 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);
@@ -372,22 +368,10 @@ 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);

+6 −5
Original line number Diff line number Diff line
@@ -32,8 +32,6 @@ 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,
@@ -51,9 +49,12 @@ export const setup = (props, leafletRef, context) => {

  const methods = {
    ...componentMethods,
    setAttribution(val, old) {
      removeAttribution(old);
      addAttribution(val);
    setAttribution(val) {
      removeThisLayer();
      leafletRef.value.options.attribution = val;
      if (props.visible) {
        addThisLayer();
      }
    },
    setName() {
      removeThisLayer();