diff options
| author | Guilhem Moulin <guilhem@fripost.org> | 2025-06-08 17:21:19 +0200 | 
|---|---|---|
| committer | Guilhem Moulin <guilhem@fripost.org> | 2025-06-09 13:47:39 +0200 | 
| commit | 6ef5462f388ebb5e3263f9c5baac6aecf3c480a5 (patch) | |
| tree | 276effd2c72a1776f98d29be4d435ac544fd90ba | |
| parent | a0156f862704d1f9cc858b93e0d61f9bd58c2cc8 (diff) | |
JS: Minor refactorining of the OL layer creation logic.
Also, don't define a projection for raster layers and let OL get it from
the source's metadata instead.
| -rw-r--r-- | main.js | 90 | 
1 files changed, 46 insertions, 44 deletions
@@ -4409,54 +4409,56 @@ const [mapLayers, featureOverlayLayer] = (function() {    if (!canWebGL2) {      rasterLayers.forEach((k) => ret[k] = null);    } else { -    rasterLayers.forEach((k) => 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, +    rasterLayers.forEach(function(k) { +      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 */ +        }), +        visible: false, +        style: null, /* filled later */ +      }); +      map.addLayer(ret[k]); +    }); +  } + +  vectorLayers.forEach(function(k) { +    ret[k] = new VectorTileLayer({ +      source: new VectorTile({ +        url: baseurl + 'tiles/' + k + xyz, +        format: new MVT(),          projection: projection,          wrapX: false, -        interpolate: false, +        transition: 0, +        tileGrid: tileGrid,        }), -      visible: false, -      style: null, /* filled later */ -    })); -    rasterLayers.forEach((k) => map.addLayer(ret[k])); -  } - -  vectorLayers.forEach((k) => ret[k] = new VectorTileLayer({ -    source: new VectorTile({ -      url: baseurl + 'tiles/' + k + xyz, -      format: new MVT(), -      projection: projection, -      wrapX: false, -      transition: 0, -      tileGrid: tileGrid, -    }), -    /* 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', -    declutter: false, -    visible: isVisible(k), -    style: function(feature, resolution) { -      const style = styles[k + '.' + feature.getProperties().layer]; -      if (!Array.isArray(style)) { -        return style; -      } else { -        const maxi = style.length - 1; -        const z = 10 /* Math.log2(maxResolution) */ - Math.log2(resolution); -        /* use Math.floor() as VectorTile.js calls getZForResolution(resolution, 1) */ -        const i = z <= 0 ? 0 : z >= maxi ? maxi : Math.floor(z); -        // console.log(`resolution=${resolution}, z=${z}, i=${i}`); -        return style[i]; +      /* 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', +      declutter: false, +      visible: isVisible(k), +      style: function(feature, resolution) { +        const style = styles[k + '.' + feature.getProperties().layer]; +        if (!Array.isArray(style)) { +          return style; +        } else { +          const maxi = style.length - 1; +          const z = 10 /* Math.log2(maxResolution) */ - Math.log2(resolution); +          /* use Math.floor() as VectorTile.js calls getZForResolution(resolution, 1) */ +          const i = z <= 0 ? 0 : z >= maxi ? maxi : Math.floor(z); +          // console.log(`resolution=${resolution}, z=${z}, i=${i}`); +          return style[i]; +        }        } -    } -  })); -  vectorLayers.forEach(function(k) { +    });      ret[k].set('layerGroup', k, true);      map.addLayer(ret[k]);    });  | 
