diff --git a/src/js/data-layer/layers-config.json b/src/js/data-layer/layers-config.json index 0f2fb82e..900d218b 100644 --- a/src/js/data-layer/layers-config.json +++ b/src/js/data-layer/layers-config.json @@ -4719,6 +4719,12 @@ "name": "standard", "title": "Style standard", "current": true, + "url": "https://ignf.github.io/cartes-ign-app/plan-ign-interactif-style.json" + }, + { + "name": "fallback", + "title": "Style standard", + "current": true, "url": "data/plan-ign-interactif-style.json" } ], @@ -4764,6 +4770,12 @@ "name": "standard", "title": "Style standard", "current": true, + "url": "https://ignf.github.io/cartes-ign-app/mixte.json" + }, + { + "name": "fallback", + "title": "Style standard", + "current": true, "url": "data/mixte.json" } ], @@ -4806,6 +4818,12 @@ "name": "standard", "title": "Style standard", "current": true, + "url": "https://ignf.github.io/cartes-ign-app/poi-osm-style.json" + }, + { + "name": "fallback", + "title": "Style standard", + "current": true, "url": "data/poi-osm-style.json" } ], diff --git a/src/js/layer-manager/layer-config.js b/src/js/layer-manager/layer-config.js index 39b7de55..0c1b94f7 100644 --- a/src/js/layer-manager/layer-config.js +++ b/src/js/layer-manager/layer-config.js @@ -82,6 +82,10 @@ const getLayerProps = (id) => { if (!style) { style = props.styles[0]; } + var fallbackStyle = ""; + if (isVector) { + fallbackStyle = props.styles[1]; + } var format = props.formats.length ? props.formats.find((f) => { return f.current === true; }) : ""; if (!format) { format = props.formats[0]; @@ -103,6 +107,7 @@ const getLayerProps = (id) => { maj: props.maj || "", type: (isVector) ? "vector" : "raster", style: (isVector) ? style.url : style.name || "normal", + fallbackStyle: (isVector) ? fallbackStyle.url : style.name || "normal", format: format.name || "", url: props.serviceParams.serverUrl[key], minNativeZoom: minNativeZoom, diff --git a/src/js/layer-manager/layer-switcher.js b/src/js/layer-manager/layer-switcher.js index f3ce5945..b5e577c3 100644 --- a/src/js/layer-manager/layer-switcher.js +++ b/src/js/layer-manager/layer-switcher.js @@ -561,6 +561,7 @@ class LayerSwitcher extends EventTarget { var type = this.layers[id].type; var style = []; + var fallback = []; if (type === "raster") { style.push({ id : id, @@ -569,6 +570,7 @@ class LayerSwitcher extends EventTarget { }); } else if (type === "vector") { style = this.layers[id].style; // url ! + fallback = this.layers[id].fallbackStyle; // url !; } else { // ex. geojson this.layers[id].error = true; @@ -588,11 +590,10 @@ class LayerSwitcher extends EventTarget { }); } else { // Vecteur - promise = fetch(style) - .then((response) => { - return response.json(); - }) - .then((data) => { + var fetchStyle = async (style, fallback) => { + try { + const response = await fetch(style); + const data = await response.json(); // INFO // on ajoute les sources ! // les sources des couches tuiles vectorielles ne sont pas pré chargées @@ -602,32 +603,33 @@ class LayerSwitcher extends EventTarget { if (Object.hasOwnProperty.call(data.sources, key)) { const source = data.sources[key]; // on ne peut pas ajouter la même source ! - if (! this.map.getStyle().sources[key]) { + if (!this.map.getStyle().sources[key]) { this.map.addSource(key, source); } } } - return data; - }) - .then((data) => { + const data_1 = data; // les sprites et les glyphs sont uniques sinon exceptions ! // mais, normalement, on ajoute que des couches IGN, on mutualise sur ces informations. // FIXME comment gerer les exceptions ? - if (!data.sprite.startsWith("http")) { - data.sprite = document.URL + data.sprite; + if (!data_1.sprite.startsWith("http")) { + data_1.sprite = document.URL + data_1.sprite; } - this.map.setSprite(data.sprite); - this.map.setGlyphs(data.glyphs); - return data; - }) - .then((data) => { - LayersGroup.addGroup(id, data.layers, layerIdBefore); - this.layers[id].style = data.layers; // sauvegarde ! - }) - .catch((e) => { - this.layers[id].error = true; - throw new Error(e); - }); + this.map.setSprite(data_1.sprite); + this.map.setGlyphs(data_1.glyphs); + const data_2 = data_1; + LayersGroup.addGroup(id, data_2.layers, layerIdBefore); + this.layers[id].style = data_2.layers; // sauvegarde ! + } catch (e) { + if (fallback) { + fetchStyle(fallback, null); + } else { + this.layers[id].error = true; + throw new Error(e); + } + } + }; + promise = fetchStyle(style, fallback); } return promise; @@ -655,6 +657,7 @@ class LayerSwitcher extends EventTarget { title: props.title, quickLookUrl: LayersAdditional.getQuickLookUrl(id.split("$")[0]), style: props.style, + fallbackStyle: props.fallbackStyle, type: props.type, base: props.base, opacity: layerOptions.opacity, diff --git a/src/js/map-interactivity/gfi-rules.js b/src/js/map-interactivity/gfi-rules.js index 4a3a8a43..853b2c3e 100644 --- a/src/js/map-interactivity/gfi-rules.js +++ b/src/js/map-interactivity/gfi-rules.js @@ -5,6 +5,13 @@ */ import InseeCommWiki from "../data-layer/com_wiki.json"; +let inseeCommWiki; +try { + const resp = await fetch("https://ignf.github.io/cartes-ign-app/com_wiki.json"); + inseeCommWiki = await resp.json(); +} catch (e) { + inseeCommWiki = InseeCommWiki; +} const gfiRules = { "TRANSPORTS.DRONES.RESTRICTIONS$GEOPORTAIL:OGC:WMTS": { @@ -290,7 +297,7 @@ const gfiRules = { if (!featureProperties["insee_com"]) { return ""; } - featureProperties[match[1]] = InseeCommWiki[featureProperties["insee_com"]]; + featureProperties[match[1]] = inseeCommWiki[featureProperties["insee_com"]]; if (!featureProperties[match[1]]) { return ""; } diff --git a/www/data/mixte.json b/www/data/mixte.json index de8eafc7..96e6d892 100644 --- a/www/data/mixte.json +++ b/www/data/mixte.json @@ -43,7 +43,7 @@ "line-join": "round" }, "filter": [ - "==", + "in", "symbo", "PISTE_CYCLABLE_SOU", "VOIE_VERTE_SOU" @@ -2019,19 +2019,13 @@ "line-join": "round" }, "filter": [ - "==", + "in", "symbo", "PISTE_CYCLABLE", "VOIE_VERTE" ], "paint": { - "line-color": [ - "step", - [ - "zoom" - ], - "#9B5CCC" - ], + "line-color": "#9B5CCC", "line-opacity": { "stops": [ [ @@ -2091,13 +2085,7 @@ "ESCALIER" ], "paint": { - "line-color": [ - "step", - [ - "zoom" - ], - "#8C7274" - ], + "line-color": "#8C7274", "line-opacity": { "stops": [ [ @@ -2205,13 +2193,7 @@ "RUE_PIETONNE" ], "paint": { - "line-color": [ - "step", - [ - "zoom" - ], - "#8C7274" - ], + "line-color": "#8C7274", "line-opacity": { "stops": [ [ @@ -2271,13 +2253,7 @@ "SENTIER" ], "paint": { - "line-color": [ - "step", - [ - "zoom" - ], - "#8C7274" - ], + "line-color": "#8C7274", "line-opacity": { "stops": [ [ @@ -2337,13 +2313,7 @@ "CHEMIN" ], "paint": { - "line-color": [ - "step", - [ - "zoom" - ], - "#8C7274" - ], + "line-color": "#8C7274", "line-opacity": { "stops": [ [ @@ -2594,13 +2564,7 @@ "NON_CLASSEE_RESTREINT" ], "paint": { - "line-color": [ - "step", - [ - "zoom" - ], - "#969696" - ], + "line-color": "#969696", "line-opacity": { "stops": [ [ @@ -2652,13 +2616,7 @@ "NON_CLASSEE" ], "paint": { - "line-color": [ - "step", - [ - "zoom" - ], - "#969696" - ], + "line-color": "#969696", "line-opacity": { "stops": [ [ @@ -2974,13 +2932,7 @@ "PRINCIPALE_1" ], "paint": { - "line-color": [ - "step", - [ - "zoom" - ], - "#E2A52A" - ], + "line-color": "#E2A52A", "line-opacity": { "stops": [ [ @@ -4569,7 +4521,7 @@ "line-join": "round" }, "filter": [ - "==", + "in", "symbo", "PISTE_CYCLABLE_SUP", "VOIE_VERTE_SUP" @@ -4641,13 +4593,7 @@ "ESCALIER_SUP" ], "paint": { - "line-color": [ - "step", - [ - "zoom" - ], - "#8C7274" - ], + "line-color": "#8C7274", "line-opacity": { "stops": [ [ @@ -4755,13 +4701,7 @@ "RUE_PIETONNE_SUP" ], "paint": { - "line-color": [ - "step", - [ - "zoom" - ], - "#8C7274" - ], + "line-color": "#8C7274", "line-opacity": { "stops": [ [ @@ -4821,13 +4761,7 @@ "SENTIER_SUP" ], "paint": { - "line-color": [ - "step", - [ - "zoom" - ], - "#8C7274" - ], + "line-color": "#8C7274", "line-opacity": { "stops": [ [ @@ -4887,13 +4821,7 @@ "CHEMIN_SUP" ], "paint": { - "line-color": [ - "step", - [ - "zoom" - ], - "#8C7274" - ], + "line-color": "#8C7274", "line-opacity": { "stops": [ [ @@ -5144,13 +5072,7 @@ "NON_CLASSEE_RESTREINT_SUP" ], "paint": { - "line-color": [ - "step", - [ - "zoom" - ], - "#969696" - ], + "line-color": "#969696", "line-opacity": { "stops": [ [ @@ -5202,13 +5124,7 @@ "NON_CLASSEE_SUP" ], "paint": { - "line-color": [ - "step", - [ - "zoom" - ], - "#969696" - ], + "line-color": "#969696", "line-opacity": { "stops": [ [ @@ -5523,13 +5439,7 @@ "PRINCIPALE_1_SUP" ], "paint": { - "line-color": [ - "step", - [ - "zoom" - ], - "#E2A52A" - ], + "line-color": "#E2A52A", "line-opacity": { "stops": [ [ @@ -7568,75 +7478,6 @@ "text-color": "#FFFFFF" } }, - { - "id": "toponyme chateau ge zoom 16 a 17", - "type": "symbol", - "source": "plan_ign", - "source-layer": "toponyme_bati_ponc", - "minzoom": 15, - "maxzoom": 17, - "filter": [ - "all", - [ - "==", - "txt_typo", - "divers_bati_ge" - ], - [ - "==", - "symbo", - "CHATEAU" - ] - ], - "layout": { - "visibility": "visible", - "symbol-placement": "point", - "text-field": "{designation}", - "text-size": 11, - "text-allow-overlap": false, - "text-padding": 1, - "text-font": [ - "Source Sans Pro Italic" - ] - }, - "paint": { - "text-color": "#FFFFFF" - } - }, - { - "id": "toponyme chateau ge zoom 18 à 19", - "type": "symbol", - "source": "plan_ign", - "source-layer": "toponyme_bati_ponc", - "minzoom": 17, - "filter": [ - "all", - [ - "==", - "txt_typo", - "divers_bati_ge" - ], - [ - "==", - "symbo", - "CHATEAU" - ] - ], - "layout": { - "visibility": "visible", - "symbol-placement": "point", - "text-field": "{texte}", - "text-size": 11, - "text-allow-overlap": false, - "text-padding": 1, - "text-font": [ - "Source Sans Pro Italic" - ] - }, - "paint": { - "text-color": "#FFFFFF" - } - }, { "id": "toponyme station epuration, de pompage, usine de production eau", "type": "symbol", @@ -11503,4 +11344,4 @@ } } ] -} \ No newline at end of file +}