From c30eeb020d5366bcde3bacc0375332dee8027d23 Mon Sep 17 00:00:00 2001 From: Jean Andreani Date: Tue, 5 Mar 2024 12:27:47 +0000 Subject: [PATCH] fix/ign-tiles-fallback --- src/utils/mapAndViewer.ts | 38 +++++++++++++++++++++++--------------- src/views/HomeView.vue | 2 -- 2 files changed, 23 insertions(+), 17 deletions(-) diff --git a/src/utils/mapAndViewer.ts b/src/utils/mapAndViewer.ts index 604968d..db76efa 100644 --- a/src/utils/mapAndViewer.ts +++ b/src/utils/mapAndViewer.ts @@ -1,21 +1,29 @@ import axios from 'axios' -async function getIgnTiles(): Promise { - const { data } = await axios.get( - 'https://wxs.ign.fr/essentiels/static/vectorTiles/styles/PLAN.IGN/attenue.json' - ) - data.sources.plan_ign.scheme = 'xyz' - data.sources.plan_ign.attribution = 'Données cartographiques : © IGN' - const objIndex = data.layers.findIndex( - (el: { id: string }) => el.id === 'toponyme - parcellaire - adresse' - ) - data.layers[objIndex].layout = { - ...data.layers[objIndex].layout, - 'text-field': ['concat', ['get', 'numero'], ['get', 'indice_de_repetition']] +async function getIgnTiles(): Promise { + try { + const { data } = await axios.get( + 'https://wxs.ign.fr/essentiels/static/vectorTiles/styles/PLAN.IGN/attenue.json' + ) + data.sources.plan_ign.scheme = 'xyz' + data.sources.plan_ign.attribution = 'Données cartographiques : © IGN' + const objIndex = data.layers.findIndex( + (el: { id: string }) => el.id === 'toponyme - parcellaire - adresse' + ) + data.layers[objIndex].layout = { + ...data.layers[objIndex].layout, + 'text-field': [ + 'concat', + ['get', 'numero'], + ['get', 'indice_de_repetition'] + ] + } + // Patch tms scheme to xyz to make it compatible for Maplibre GL JS / Mapbox GL JS + // Patch num_repetition + return data + } catch (error) { + return 'https://tile-vect.openstreetmap.fr/styles/basic/style.json' } - // Patch tms scheme to xyz to make it compatible for Maplibre GL JS / Mapbox GL JS - // Patch num_repetition - return data } export { getIgnTiles } diff --git a/src/views/HomeView.vue b/src/views/HomeView.vue index 01926d3..698a485 100644 --- a/src/views/HomeView.vue +++ b/src/views/HomeView.vue @@ -8,10 +8,8 @@