diff --git a/components/FicheDetail.vue b/components/FicheDetail.vue index ccae59b..6fc027a 100644 --- a/components/FicheDetail.vue +++ b/components/FicheDetail.vue @@ -297,9 +297,8 @@ async function initMap(el: HTMLElement) { if (mapInit || !hasCoords.value) return mapInit = true - const L = (await import('leaflet')).default - // La feuille Leaflet n'est plus globale (socle perf) : chargée ici, avant la carte. - await import('leaflet/dist/leaflet.css') + // Leaflet et sa feuille, chargés une fois pour toutes les cartes (useLeaflet, B4a). + const L = await useLeaflet() const lat = props.org.latitude as number const lng = props.org.longitude as number diff --git a/components/NavMap.vue b/components/NavMap.vue deleted file mode 100644 index 87fc8ca..0000000 --- a/components/NavMap.vue +++ /dev/null @@ -1,296 +0,0 @@ - - - diff --git a/components/carte/CarteUnifiee.vue b/components/carte/CarteUnifiee.vue new file mode 100644 index 0000000..7823425 --- /dev/null +++ b/components/carte/CarteUnifiee.vue @@ -0,0 +1,171 @@ + + + + diff --git a/components/carte/EncartsOutremer.vue b/components/carte/EncartsOutremer.vue new file mode 100644 index 0000000..e366bea --- /dev/null +++ b/components/carte/EncartsOutremer.vue @@ -0,0 +1,178 @@ + + + + + + diff --git a/composables/useLeaflet.ts b/composables/useLeaflet.ts new file mode 100644 index 0000000..6f1f7c4 --- /dev/null +++ b/composables/useLeaflet.ts @@ -0,0 +1,49 @@ +/** + * useLeaflet — B4a-M2. Charge Leaflet une seule fois côté client et rend `L`. + * + * La séquence « import Leaflet, sa feuille, le plugin de cluster » vivait recopiée dans + * quatre composants (NavMap, NavMapV2, OutremerMap, FicheDetail ; dette du socle perf du + * 29/10). Elle vit ici : imports dynamiques (Leaflet reste hors du premier chargement), + * promesses mémorisées au niveau du module (deux cartes montées ensemble ne chargent rien + * deux fois), `window.L` posé AVANT le plugin (leaflet.markercluster lit `window.L` à son + * chargement). + * + * const L = await useLeaflet({ cluster: true }) // carte à clusters + * const L = await useLeaflet() // mini-carte, encart + * + * Côté serveur : la promesse est rejetée (une carte ne se monte que dans ou + * `onMounted`). + */ +let base: Promise | null = null +let avecCluster: Promise | null = null + +async function chargerBase(): Promise { + const mod: any = await import('leaflet') + const L = mod.default || mod + await import('leaflet/dist/leaflet.css') + return L +} + +async function chargerCluster(): Promise { + const L = await useLeaflet() + await Promise.all([ + // @ts-ignore — feuilles du plugin, sans types + import('leaflet.markercluster/dist/MarkerCluster.css'), + // @ts-ignore + import('leaflet.markercluster/dist/MarkerCluster.Default.css'), + ]) + ;(window as any).L = L + // @ts-ignore — étend L.MarkerClusterGroup en effet de bord + await import('leaflet.markercluster') + return L +} + +export function useLeaflet(options: { cluster?: boolean } = {}): Promise { + if (import.meta.server) return Promise.reject(new Error('useLeaflet : côté client seulement')) + if (options.cluster) { + avecCluster ??= chargerCluster().catch((e) => { avecCluster = null; throw e }) + return avecCluster + } + base ??= chargerBase().catch((e) => { base = null; throw e }) + return base +} diff --git a/pages/index.vue b/pages/index.vue index adcc1d1..a52a1bd 100644 --- a/pages/index.vue +++ b/pages/index.vue @@ -20,34 +20,34 @@ :lien-page="(f) => `/fiche/${f.id}`" >