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

Merge pull request #90 from juan267/feature/add-before-map-mount-hook

Add option to run a beforeMapMount hook and also save the leaflet instance on window or global
parents 83837c5b 8433a898
Loading
Loading
Loading
Loading
+25 −9
Original line number Diff line number Diff line
@@ -21,13 +21,13 @@ import {
  setup as componentSetup,
} from "../functions/component";

const WINDOW_OR_GLOBAL =
  (typeof self === "object" && self.self === self && self) ||
  (typeof global === "object" && global.global === global && global) ||
  undefined;

export default {
  emits: [
    'ready',
    'update:zoom',
    'update:center',
    'update:bounds',
  ],
  emits: ["ready", "update:zoom", "update:center", "update:bounds"],
  props: {
    ...componentProps,
    /**
@@ -219,9 +219,25 @@ export default {
    };

    onMounted(async () => {
      const { map, CRS, Icon, latLngBounds, latLng, DomEvent } = await import(
        "leaflet/dist/leaflet-src.esm"
      const {
        map,
        CRS,
        Icon,
        latLngBounds,
        latLng,
        DomEvent,
      } = options.useGlobalLeaflet
        ? (WINDOW_OR_GLOBAL.L = WINDOW_OR_GLOBAL.L || (await import("leaflet")))
        : await import("leaflet/dist/leaflet-src.esm");

      try {
        options.beforeMapMount && (await options.beforeMapMount());
      } catch (error) {
        console.error(
          `The following error occurred running the provided beforeMapMount hook ${error.message}`
        );
      }

      await resetWebpackIcon(Icon);

      const optionsCrs =
+1 −1
Original line number Diff line number Diff line
export const props = {
  options: {
    type: Object,
    default: () => ({}),
    default: () => ({ useGlobalLeaflet: false }),
  },
};

+1713 −1642

File changed.

Preview size limit exceeded, changes collapsed.