maplibre-gl-raster 0.2.1 → 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.
@@ -6578,9 +6578,9 @@ var SourceMemory = class SourceMemory {
6578
6578
  //#endregion
6579
6579
  //#region node_modules/@developmentseed/geotiff/dist/crs.js
6580
6580
  var PROJJSON_SCHEMA = "https://proj.org/schemas/v0.7/projjson.schema.json";
6581
- var MODEL_TYPE_PROJECTED = 1;
6581
+ var MODEL_TYPE_PROJECTED$1 = 1;
6582
6582
  var MODEL_TYPE_GEOGRAPHIC = 2;
6583
- var USER_DEFINED = 32767;
6583
+ var USER_DEFINED$1 = 32767;
6584
6584
  var CT_TRANSVERSE_MERCATOR = 1;
6585
6585
  var CT_TRANSVERSE_MERCATOR_SOUTH = 2;
6586
6586
  var CT_OBLIQUE_MERCATOR = 3;
@@ -6633,31 +6633,31 @@ var LINEAR_UNIT = {
6633
6633
  */
6634
6634
  function crsFromGeoKeys(gkd) {
6635
6635
  const modelType = gkd.modelType;
6636
- if (modelType === MODEL_TYPE_PROJECTED) return _projectedCrs(gkd);
6636
+ if (modelType === MODEL_TYPE_PROJECTED$1) return _projectedCrs(gkd);
6637
6637
  if (modelType === MODEL_TYPE_GEOGRAPHIC) return _geographicCrs(gkd);
6638
6638
  throw new Error(`Unsupported GeoTIFF model type: ${modelType}`);
6639
6639
  }
6640
6640
  function _geographicCrs(gkd) {
6641
6641
  const epsg = gkd.geodeticCRS;
6642
- if (epsg !== null && epsg !== USER_DEFINED) return epsg;
6642
+ if (epsg !== null && epsg !== USER_DEFINED$1) return epsg;
6643
6643
  return _buildGeographicCrs(gkd, PROJJSON_SCHEMA);
6644
6644
  }
6645
6645
  function _projectedCrs(gkd) {
6646
6646
  const epsg = gkd.projectedCRS;
6647
- if (epsg !== null && epsg !== USER_DEFINED) return epsg;
6647
+ if (epsg !== null && epsg !== USER_DEFINED$1) return epsg;
6648
6648
  return _buildProjectedCrs(gkd);
6649
6649
  }
6650
6650
  function _buildGeographicCrs(gkd, schema) {
6651
6651
  const ellipsoid = _buildEllipsoid(gkd);
6652
6652
  let pmName = "Greenwich";
6653
6653
  let pmLongitude = 0;
6654
- if (gkd.primeMeridian !== null && gkd.primeMeridian !== USER_DEFINED) pmName = `EPSG:${gkd.primeMeridian}`;
6654
+ if (gkd.primeMeridian !== null && gkd.primeMeridian !== USER_DEFINED$1) pmName = `EPSG:${gkd.primeMeridian}`;
6655
6655
  else if (gkd.primeMeridianLongitude !== null) {
6656
6656
  pmLongitude = gkd.primeMeridianLongitude;
6657
6657
  pmName = "User-defined";
6658
6658
  }
6659
6659
  let datum;
6660
- if (gkd.geodeticDatum !== null && gkd.geodeticDatum !== USER_DEFINED) datum = {
6660
+ if (gkd.geodeticDatum !== null && gkd.geodeticDatum !== USER_DEFINED$1) datum = {
6661
6661
  type: "GeodeticReferenceFrame",
6662
6662
  name: `Unknown datum based upon EPSG ${gkd.geodeticDatum} ellipsoid`
6663
6663
  };
@@ -6693,7 +6693,7 @@ function _buildProjectedCrs(gkd) {
6693
6693
  };
6694
6694
  }
6695
6695
  function _buildEllipsoid(gkd) {
6696
- if (gkd.ellipsoid !== null && gkd.ellipsoid !== USER_DEFINED) {
6696
+ if (gkd.ellipsoid !== null && gkd.ellipsoid !== USER_DEFINED$1) {
6697
6697
  const ellipsoid = { name: `EPSG ellipsoid ${gkd.ellipsoid}` };
6698
6698
  if (gkd.ellipsoidSemiMajorAxis !== null) ellipsoid.semi_major_axis = gkd.ellipsoidSemiMajorAxis;
6699
6699
  if (gkd.ellipsoidInvFlattening !== null) ellipsoid.inverse_flattening = gkd.ellipsoidInvFlattening;
@@ -16336,6 +16336,63 @@ var COLORMAP_OPTIONS = COLORMAP_NAMES.map((name) => ({
16336
16336
  rowIndex: COLORMAP_INDEX[name]
16337
16337
  }));
16338
16338
  //#endregion
16339
+ //#region src/lib/raster/repair-geokeys.ts
16340
+ var MODEL_TYPE_PROJECTED = 1;
16341
+ var USER_DEFINED = 32767;
16342
+ var EPSG_WEB_MERCATOR = 3857;
16343
+ var WEB_MERCATOR_ALIASES = new Set([
16344
+ 3785,
16345
+ 900913,
16346
+ 102100,
16347
+ 102113
16348
+ ]);
16349
+ var WEB_MERCATOR_CITATION = /web[ _]?mercator|pseudo[ _-]?mercator|popular[ _]?vis|auxiliary[ _]?sphere/i;
16350
+ function citationText(gkd) {
16351
+ return [
16352
+ gkd.citation,
16353
+ gkd.projectedCitation,
16354
+ gkd.geodeticCitation
16355
+ ].filter((value) => typeof value === "string").join(" ");
16356
+ }
16357
+ /**
16358
+ * Repair GeoTIFF CRS geo keys so {@link import('@developmentseed/geotiff').Overview.crs}
16359
+ * resolves them to the right projection, in place. Two problems are fixed:
16360
+ *
16361
+ * 1. **User-defined model type for a projected CRS.** `crsFromGeoKeys` only
16362
+ * accepts `GTModelTypeGeoKey` 1 (projected) or 2 (geographic) and throws
16363
+ * `Unsupported GeoTIFF model type: 32767` otherwise, so the raster never
16364
+ * draws. ArcGIS exports the ESRI Web Mercator with a fully specified
16365
+ * projection but leaves `GTModelTypeGeoKey` (and `ProjectedCSTypeGeoKey`)
16366
+ * user-defined. When a projection method is present (`ProjMethodGeoKey`, i.e.
16367
+ * `gkd.projMethod`) the CRS is unambiguously projected, so the model type is
16368
+ * set to projected and the CRS is built from the keys (or the EPSG code in
16369
+ * `ProjectedCSTypeGeoKey`). This is projection-agnostic.
16370
+ *
16371
+ * 2. **Spherical Web Mercator written as an ellipsoidal CRS.** ESRI's "Web
16372
+ * Mercator Auxiliary Sphere" (a.k.a. Popular Visualisation CRS, EPSG:3857)
16373
+ * projects on a sphere of radius 6378137, but the geo keys can only declare
16374
+ * the WGS84 ellipsoid (the sphere lives only in the citation). Building the
16375
+ * CRS from those keys yields an *ellipsoidal* Mercator, which misplaces the
16376
+ * raster by kilometres in latitude. When the projected CRS is a Web Mercator
16377
+ * alias code, or is user-defined with a Web-Mercator citation, it is replaced
16378
+ * with EPSG:3857 so proj4's correct spherical definition is used.
16379
+ *
16380
+ * Files with a valid model type and a non-Web-Mercator EPSG/projection are left
16381
+ * untouched. Must run before any `Overview.crs` access (which caches its
16382
+ * result), so callers invoke it immediately after opening the GeoTIFF.
16383
+ *
16384
+ * @param tiff - The opened GeoTIFF to repair in place.
16385
+ */
16386
+ function repairUserDefinedProjectedCrs(tiff) {
16387
+ for (const overview of tiff.overviews) {
16388
+ const gkd = overview.gkd;
16389
+ const projectedIsUserDefined = gkd.projectedCRS === null || gkd.projectedCRS === USER_DEFINED;
16390
+ if (gkd.projectedCRS !== null && WEB_MERCATOR_ALIASES.has(gkd.projectedCRS)) gkd.projectedCRS = EPSG_WEB_MERCATOR;
16391
+ else if (projectedIsUserDefined && gkd.projMethod !== null && WEB_MERCATOR_CITATION.test(citationText(gkd))) gkd.projectedCRS = EPSG_WEB_MERCATOR;
16392
+ if ((gkd.modelType === null || gkd.modelType === USER_DEFINED) && gkd.projMethod !== null) gkd.modelType = MODEL_TYPE_PROJECTED;
16393
+ }
16394
+ }
16395
+ //#endregion
16339
16396
  //#region src/lib/raster/load-geotiff.ts
16340
16397
  /**
16341
16398
  * COG access pattern is hundreds of distinct Range requests against the
@@ -16414,10 +16471,12 @@ function loadGeoTIFF(url) {
16414
16471
  const promise = (async () => {
16415
16472
  const source = new CorsSafeSourceHttp(url, {});
16416
16473
  const view = new SourceView(source, [new SourceChunk({ size: CHUNK_SIZE }), new SourceCache({ size: CACHE_SIZE })]);
16417
- return await GeoTIFF.open({
16474
+ const tiff = await GeoTIFF.open({
16418
16475
  dataSource: source,
16419
16476
  headerSource: view
16420
16477
  });
16478
+ repairUserDefinedProjectedCrs(tiff);
16479
+ return tiff;
16421
16480
  })();
16422
16481
  inflight.set(url, promise);
16423
16482
  promise.finally(() => inflight.delete(url)).catch(() => {});
@@ -19685,4 +19744,4 @@ var RasterControl = class {
19685
19744
  //#endregion
19686
19745
  export { colormaps_default as _, debounce as a, throttle as c, percentileFromHistogram as d, readBandNames as f, COLORMAP_ROW_COUNT as g, COLORMAP_OPTIONS as h, classNames as i, MAX_SAMPLE_TILES as l, COLORMAP_NAMES as m, PALETTE_COLORMAP as n, formatNumericValue as o, loadGeoTIFF as p, clamp as r, generateId as s, RasterControl as t, computeAutoStats as u, createResilientEpsgResolver as v };
19687
19746
 
19688
- //# sourceMappingURL=RasterControl-DNAVxbPt.js.map
19747
+ //# sourceMappingURL=RasterControl-COXL7MI-.js.map