diff options
author | Guilhem Moulin <guilhem@fripost.org> | 2025-07-22 19:41:49 +0200 |
---|---|---|
committer | Guilhem Moulin <guilhem@fripost.org> | 2025-07-23 01:28:09 +0200 |
commit | 439267dc4afea300a4251693054da6313d1ed169 (patch) | |
tree | 7efa46773014340a0a84857230cabd172e3c6607 /main.js | |
parent | ffffdc0cd1d29c3f3a3449f26c9fec4c85ff6c8e (diff) |
Diffstat (limited to 'main.js')
-rw-r--r-- | main.js | 68 |
1 files changed, 34 insertions, 34 deletions
@@ -497,21 +497,18 @@ if (window.location === window.parent.location) { infoMetadataAccordions.forEach((x) => x.element.replaceChildren()); modal.show(); Promise.allSettled(Object.entries(mapLayers).map(function([grp,lyr]) { - if (lyr?.getSource() instanceof VectorTile) { - const url = lyr.getSource().getUrls()[0]; - if (url == null || url.length <= 16 || url.substr(url.length - 16) !== '/{z}/{x}/{y}.pbf') { - return new Promise(() => { throw new Error(`Invalid URL ${url}`); }); - } - return fetch(url.substr(0, url.length - 16) + '/metadata.json') - .then(function(resp0) { - if (resp0.status === 200) { - return resp0.json().then((x) => [grp,x]); - } else { - throw new Error(`${resp0.url} [${resp0.status}]`); - } - }); + const baseurl = lyr?.getSource?.()?.get?.('baseurl'); + if (baseurl == null) { + return new Promise(() => { throw new Error(`Unknown source for "${grp}"`); }); } - return new Promise(() => { throw new Error(`Unknown source for "${grp}"`); }); + return fetch(new URL('metadata.json', baseurl)) + .then(function(resp0) { + if (resp0.status === 200) { + return resp0.json().then((x) => [grp,x]); + } else { + throw new Error(`${resp0.url} [${resp0.status}]`); + } + }); })) .then(function(rs) { const metadata = Object.fromEntries(rs.filter(function(r) { @@ -2777,8 +2774,6 @@ MAP.getView().on('change', function(event) { /* add layers to the map */ const mapLayers = (function() { - const baseurl = '/'; - const xyz = '/{z}/{x}/{y}.pbf'; const tileGrid = createXYZ({ extent: EXTENT, tileSize: 1024, @@ -2803,19 +2798,21 @@ const mapLayers = (function() { rasterLayers.forEach((k) => ret[k] = null); } else { rasterLayers.forEach(function(k) { + const baseurl = new URL('/raster/' + k + '/', window.location.toString()).toString(); + const source = new GeoTIFF({ + sources: [{ url: baseurl + encodeURIComponent(k) + '.tiff' }], + normalize: false, + convertToRGB: false, + wrapX: false, + interpolate: false, + /* use the projection found in the source's metadata */ + }); + /* GeoTIFF doesn't allow retrieving the URL later, so we manually store the baseurl instead */ + source.set('baseurl', baseurl, true); ret[k] = new TileLayerGL({ /* Naturvårdsverket has a WMS server we could use instead, but by serving it ourselves * we can filter on he various kskog classes */ - source: new GeoTIFF({ - sources: [{ - url: baseurl + 'raster/' + k + '.tiff', - }], - normalize: false, - convertToRGB: false, - wrapX: false, - interpolate: false, - /* use the projection found in the source's metadata */ - }), + source: source, visible: false, style: null, /* filled later */ }); @@ -2826,15 +2823,18 @@ const mapLayers = (function() { vectorLayers.forEach(function(k) { const canFilterByAge0 = canFilterByAge.includes(k); const styles = STYLES[k]; + const baseurl = new URL('/tiles/' + k + '/', window.location.toString()).toString(); + const source = new VectorTile({ + url: baseurl + '{z}/{x}/{y}.pbf', + format: new MVT(), + projection: PROJECTION, + wrapX: false, + transition: 0, + tileGrid: tileGrid, + }); + source.set('baseurl', baseurl, true); ret[k] = new VectorTileLayer({ - source: new VectorTile({ - url: baseurl + 'tiles/' + k + xyz, - format: new MVT(), - projection: PROJECTION, - wrapX: false, - transition: 0, - tileGrid: tileGrid, - }), + source: source, /* XXX switch to 'hybrid' if there are perf issues; but that seems to * put lines above points regardless of their respective z-index */ renderMode: 'hybrid', |