Skip to content

Commit

Permalink
added support for .palettename.txt
Browse files Browse the repository at this point in the history
  • Loading branch information
morandd committed Nov 26, 2024
1 parent 2c81b2b commit a1e7471
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 1 deletion.
9 changes: 9 additions & 0 deletions public/favicon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 6 additions & 1 deletion src/components/Map.astro
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down
21 changes: 21 additions & 0 deletions src/scripts/parseQGISColorfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit a1e7471

Please sign in to comment.