From a1e74710d529cddd01107d83d120c370895e8d1c Mon Sep 17 00:00:00 2001 From: Dan Moran MBA15 Date: Tue, 26 Nov 2024 11:14:17 +0100 Subject: [PATCH] added support for .palettename.txt --- public/favicon.svg | 9 +++++++++ src/components/Map.astro | 7 ++++++- src/scripts/parseQGISColorfile.js | 21 +++++++++++++++++++++ 3 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 public/favicon.svg diff --git a/public/favicon.svg b/public/favicon.svg new file mode 100644 index 0000000..f157bd1 --- /dev/null +++ b/public/favicon.svg @@ -0,0 +1,9 @@ + + + + diff --git a/src/components/Map.astro b/src/components/Map.astro index 7625093..88b1d7d 100644 --- a/src/components/Map.astro +++ b/src/components/Map.astro @@ -18,7 +18,7 @@ import { getInterpolateBand1AsColor } from '../scripts/palette.js'; import { transformExtent, Projection, get as getProjection, fromLonLat } from 'ol/proj'; import {register,fromEPSGCode} from 'ol/proj/proj4'; import proj4 from 'proj4' -import {getQGISColorfile} from '../scripts/parseQGISColorfile.js'; +import {getQGISColorfile, getPalettenameFile} from '../scripts/parseQGISColorfile.js'; let source : any = null; @@ -117,6 +117,11 @@ async function buildMapForGeotiff() { } }); + // Launch an async function to try and get a .palettename.txt for this URL + // This will trigger a "newpalette" event if found + getPalettenameFile(); + + // Launch an async function to try and get a QGIS colorfile for the palette // This will trigger a "newpalette" event if a QGIS colorfile is found getQGISColorfile(); diff --git a/src/scripts/parseQGISColorfile.js b/src/scripts/parseQGISColorfile.js index af7aff0..809698d 100644 --- a/src/scripts/parseQGISColorfile.js +++ b/src/scripts/parseQGISColorfile.js @@ -45,6 +45,27 @@ export async function getQGISColorfile(){ } } + +/** + * Try and get the .palettename.txt file for the URL + * This will trigger a "newpalette" event if found + * @returns + */ +export async function getPalettenameFile(){ + const url = localStorage.getItem('url'); + if (!url) return null; + try { + const palettenameurl = url.replace('.tif', '.palettename.txt'); + const response = await fetch(palettenameurl); + if (!response.ok) return null; + const text = await response.text(); + localStorage.setItem('palettename', text); + document.dispatchEvent(new Event('newpalette')); + } catch (e) { + } +} + + /** * Returns a function which accepts a value in the domain * of the QGISColorfile and returns a color.