maplibre-gl-raster 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.
@@ -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;
@@ -16337,40 +16337,59 @@ var COLORMAP_OPTIONS = COLORMAP_NAMES.map((name) => ({
16337
16337
  }));
16338
16338
  //#endregion
16339
16339
  //#region src/lib/raster/repair-geokeys.ts
16340
- /**
16341
- * Repair GeoTIFFs whose projected CRS is tagged with a "user-defined" model
16342
- * type so {@link import('@developmentseed/geotiff').Overview.crs} can build it.
16343
- *
16344
- * `crsFromGeoKeys` only accepts `GTModelTypeGeoKey` of 1 (projected) or 2
16345
- * (geographic) and throws `Unsupported GeoTIFF model type: 32767` for anything
16346
- * else. Some exporters (notably ArcGIS, which writes an ESRI PE string for the
16347
- * `WGS_1984_Web_Mercator` / "Popular Visualisation CRS" auxiliary-sphere
16348
- * Mercator) emit a fully specified projected CRS via the projection geo keys
16349
- * but leave `GTModelTypeGeoKey` and `ProjectedCSTypeGeoKey` as user-defined
16350
- * (32767). COGLayer then fails to resolve the CRS and the raster never draws,
16351
- * even though the projection is completely described by the keys already
16352
- * present. See GeoLibre issue #393.
16353
- *
16354
- * When a projection coordinate-transformation method is present
16355
- * (`ProjMethodGeoKey`, exposed as `gkd.projMethod`), the CRS is unambiguously
16356
- * projected, so we set `modelType` to projected. `crsFromGeoKeys` then takes
16357
- * the projected path and builds a PROJJSON CRS from the projection keys (or
16358
- * returns the EPSG code when `ProjectedCSTypeGeoKey` carries one). Files with a
16359
- * valid model type, or user-defined geographic CRSes with no projection method,
16360
- * are left untouched.
16361
- *
16362
- * Must run before any `Overview.crs` access, which caches its result; callers
16363
- * invoke it immediately after opening the GeoTIFF and before handing it to
16364
- * COGLayer.
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.
16365
16383
  *
16366
16384
  * @param tiff - The opened GeoTIFF to repair in place.
16367
16385
  */
16368
16386
  function repairUserDefinedProjectedCrs(tiff) {
16369
- const MODEL_TYPE_PROJECTED = 1;
16370
- const MODEL_TYPE_USER_DEFINED = 32767;
16371
16387
  for (const overview of tiff.overviews) {
16372
16388
  const gkd = overview.gkd;
16373
- if ((gkd.modelType === null || gkd.modelType === MODEL_TYPE_USER_DEFINED) && gkd.projMethod !== null) gkd.modelType = MODEL_TYPE_PROJECTED;
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;
16374
16393
  }
16375
16394
  }
16376
16395
  //#endregion
@@ -19725,4 +19744,4 @@ var RasterControl = class {
19725
19744
  //#endregion
19726
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 };
19727
19746
 
19728
- //# sourceMappingURL=RasterControl-BxGg08KC.js.map
19747
+ //# sourceMappingURL=RasterControl-COXL7MI-.js.map