cog-tiler-wasm 0.2.2 → 0.2.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/cog-tiler.js CHANGED
@@ -147,6 +147,24 @@ function fitSize(extW, extH, maxSize, width, height) {
147
147
  : [Math.max(1, Math.round(max * ar)), max];
148
148
  }
149
149
 
150
+ /**
151
+ * Read a TIFF tag from a geotiff.js image across major versions. geotiff v2
152
+ * exposes tags as direct `fileDirectory` properties; v3 defers them behind
153
+ * `fileDirectory.loadValue()` (large arrays such as ColorMap are not actualized
154
+ * eagerly), so a direct property read returns undefined there. Returns the tag
155
+ * value, or undefined when the tag is absent.
156
+ */
157
+ async function readTiffTag(img, name) {
158
+ const fd = img.fileDirectory;
159
+ if (fd && fd[name] !== undefined) return fd[name]; // geotiff v2
160
+ if (typeof fd?.loadValue === "function") {
161
+ // geotiff v3: skip the load when the tag is absent so loadValue doesn't throw.
162
+ if (typeof fd.hasTag === "function" && !fd.hasTag(name)) return undefined;
163
+ return fd.loadValue(name);
164
+ }
165
+ return undefined;
166
+ }
167
+
150
168
  /** Build a 256-entry RGBA palette from a TIFF ColorMap (16-bit R,G,B blocks). */
151
169
  function buildPalette(colorMap) {
152
170
  if (!colorMap) return null;
@@ -248,7 +266,7 @@ export async function openCog(source) {
248
266
  if (stream.epsg !== 3857 || multiBand) {
249
267
  tiff = await openTiff();
250
268
  img = await tiff.getImage();
251
- planar = multiBand && img.fileDirectory.PlanarConfiguration === 2;
269
+ planar = multiBand && (await readTiffTag(img, "PlanarConfiguration")) === 2;
252
270
  }
253
271
  const base = { url: label, range, stream, levels, gt, nodata: stream.nodata, tiff, planar };
254
272
 
@@ -268,7 +286,7 @@ export async function openCog(source) {
268
286
  if (!srcDef) throw new Error("could not derive source CRS from GeoTIFF geokeys");
269
287
  const toSource = proj4("EPSG:3857", srcDef); // forward: mercator -> source
270
288
  const toLonLat = proj4(srcDef, "EPSG:4326"); // forward: source -> lon/lat
271
- const palette = buildPalette(img.fileDirectory.ColorMap);
289
+ const palette = buildPalette(await readTiffTag(img, "ColorMap"));
272
290
 
273
291
  // fitBounds bounds: transform the source corners to lon/lat.
274
292
  const fw = levels[0].width, fh = levels[0].height;
Binary file
package/package.json CHANGED
@@ -5,7 +5,7 @@
5
5
  "Qiusheng Wu <giswqs@gmail.com>"
6
6
  ],
7
7
  "description": "Serverless Cloud Optimized GeoTIFF (COG) dynamic tiling in WebAssembly. TiTiler-style XYZ tiles, no backend.",
8
- "version": "0.2.2",
8
+ "version": "0.2.3",
9
9
  "license": "MIT",
10
10
  "repository": {
11
11
  "type": "git",