@nika-js/onlymap 0.5.9 → 0.5.11
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/README.md +5 -2
- package/THIRD-PARTY-LICENSES.md +238 -0
- package/dist/{LercDecode.es-C0sNWzF8.js → LercDecode.es-DgVQ-yzp.js} +1 -1
- package/dist/attribute-resolution.d.ts +27 -0
- package/dist/{basemap-8hhWmvHS.js → basemap-Q6WD4W1c.js} +1 -1
- package/dist/blosc-D1xNXZJs.js +719 -0
- package/dist/chunk-INHXZS53-DiyuLb3Z.js +14 -0
- package/dist/{geoparquet-DMnv5yzR.js → geoparquet-BUR3VCqE.js} +1 -1
- package/dist/{index-CZeGkc2B.js → index-B59kDhQV.js} +2 -2
- package/dist/{index--M5J0eSx.js → index-BtVjjBff.js} +1 -1
- package/dist/{index-COoJesma.js → index-DBsR-e_U.js} +1 -1
- package/dist/{index-CAlZChhH.js → index-DTRXxe7D.js} +11960 -11519
- package/dist/{index-BC-t0qL6.js → index-E2LluXDY.js} +1 -1
- package/dist/{lerc-CRVtSMWE.js → lerc-Bl4IMkfo.js} +2 -2
- package/dist/lz4-1Ws5oVWR.js +640 -0
- package/dist/onlymap.standalone.js +86791 -78874
- package/dist/onlymapjs.js +1 -1
- package/dist/programmatic.d.ts +4 -0
- package/dist/raster-B5dIvmBr.js +3614 -0
- package/dist/raster-pipeline-Dzo5h6YY.js +1585 -0
- package/dist/raster-pipeline.d.ts +44 -0
- package/dist/raster.d.ts +3 -42
- package/dist/version.d.ts +1 -1
- package/dist/zarr-DHOOSvXD.js +5506 -0
- package/dist/zarr.d.ts +87 -0
- package/dist/zstd-C4EcZnjq.js +603 -0
- package/llms.txt +2 -0
- package/onlymapjs.html-data.json +27 -0
- package/package.json +2 -1
- package/skills/onlymapjs/SKILL.md +3 -1
- package/skills/onlymapjs/references/syntax.md +42 -3
- package/dist/raster-7fiRE9GO.js +0 -5179
|
@@ -0,0 +1,3614 @@
|
|
|
1
|
+
import { c as re, t as Ae, i as nt, a as Re, s as rt, C as ot, b as it, F as at, A as st, d as lt, R as he, e as ct, p as ut, m as dt, f as ht, g as pt, h as gt } from "./raster-pipeline-Dzo5h6YY.js";
|
|
2
|
+
import pe from "./index-CW1n5LdO.js";
|
|
3
|
+
function mt(e, t) {
|
|
4
|
+
const n = e.length / 3, r = new Uint8ClampedArray(n * 4), o = 0, i = n, a = n * 2;
|
|
5
|
+
for (let s = 0; s < n; s++)
|
|
6
|
+
r[4 * s + 0] = e[o + s] >> 8, r[4 * s + 1] = e[i + s] >> 8, r[4 * s + 2] = e[a + s] >> 8, r[4 * s + 3] = 255;
|
|
7
|
+
return new ImageData(r, n, 1);
|
|
8
|
+
}
|
|
9
|
+
var q;
|
|
10
|
+
(function(e) {
|
|
11
|
+
e[e.Big = 19789] = "Big", e[e.Little = 18761] = "Little";
|
|
12
|
+
})(q || (q = {}));
|
|
13
|
+
var J;
|
|
14
|
+
(function(e) {
|
|
15
|
+
e[e.ReducedImage = 1] = "ReducedImage", e[e.Page = 2] = "Page", e[e.Mask = 4] = "Mask";
|
|
16
|
+
})(J || (J = {}));
|
|
17
|
+
var ge;
|
|
18
|
+
(function(e) {
|
|
19
|
+
e[e.TopLeft = 1] = "TopLeft", e[e.TopRight = 2] = "TopRight", e[e.BottomRight = 3] = "BottomRight", e[e.BottomLeft = 4] = "BottomLeft", e[e.LeftTop = 5] = "LeftTop", e[e.RightTOP = 6] = "RightTOP", e[e.RightBottom = 7] = "RightBottom", e[e.LeftBottom = 8] = "LeftBottom";
|
|
20
|
+
})(ge || (ge = {}));
|
|
21
|
+
var T;
|
|
22
|
+
(function(e) {
|
|
23
|
+
e[e.PixelIsArea = 1] = "PixelIsArea", e[e.PixelIsPoint = 2] = "PixelIsPoint";
|
|
24
|
+
})(T || (T = {}));
|
|
25
|
+
var M;
|
|
26
|
+
(function(e) {
|
|
27
|
+
e[e.Unknown = 0] = "Unknown", e[e.Projected = 1] = "Projected", e[e.Geographic = 2] = "Geographic", e[e.Geocentric = 3] = "Geocentric", e[e.UserDefined = 32767] = "UserDefined";
|
|
28
|
+
})(M || (M = {}));
|
|
29
|
+
var me;
|
|
30
|
+
(function(e) {
|
|
31
|
+
e[e.Image = 1] = "Image", e[e.ReducedImage = 2] = "ReducedImage", e[e.Page = 3] = "Page";
|
|
32
|
+
})(me || (me = {}));
|
|
33
|
+
var m;
|
|
34
|
+
(function(e) {
|
|
35
|
+
e[e.None = 1] = "None", e[e.Ccittrle = 2] = "Ccittrle", e[e.CcittT4 = 3] = "CcittT4", e[e.CcittT6 = 4] = "CcittT6", e[e.Lzw = 5] = "Lzw", e[e.Jpeg6 = 6] = "Jpeg6", e[e.Jpeg = 7] = "Jpeg", e[e.DeflateOther = 8] = "DeflateOther", e[e.T85 = 9] = "T85", e[e.T43 = 10] = "T43", e[e.Next = 32766] = "Next", e[e.Ccittrlew = 32771] = "Ccittrlew", e[e.PackBits = 32773] = "PackBits", e[e.ThunderScan = 32809] = "ThunderScan", e[e.It8ctpad = 32895] = "It8ctpad", e[e.It8lw = 32896] = "It8lw", e[e.It8mp = 32897] = "It8mp", e[e.It8bl = 32898] = "It8bl", e[e.PixarFilm = 32908] = "PixarFilm", e[e.PixarLog = 32909] = "PixarLog", e[e.Deflate = 32946] = "Deflate", e[e.Dcs = 32947] = "Dcs", e[e.Jbig = 34661] = "Jbig", e[e.SgiLog = 34676] = "SgiLog", e[e.SgiLog24 = 34677] = "SgiLog24", e[e.Jp2000 = 34712] = "Jp2000", e[e.Lerc = 34887] = "Lerc", e[e.Lzma = 34925] = "Lzma", e[e.Zstd = 5e4] = "Zstd", e[e.Webp = 50001] = "Webp", e[e.JpegXl = 50002] = "JpegXl", e[e.JpegXlDng17 = 52546] = "JpegXlDng17";
|
|
36
|
+
})(m || (m = {}));
|
|
37
|
+
var U;
|
|
38
|
+
(function(e) {
|
|
39
|
+
e[e.Contig = 1] = "Contig", e[e.Separate = 2] = "Separate";
|
|
40
|
+
})(U || (U = {}));
|
|
41
|
+
var _;
|
|
42
|
+
(function(e) {
|
|
43
|
+
e[e.None = 1] = "None", e[e.Horizontal = 2] = "Horizontal", e[e.FloatingPoint = 3] = "FloatingPoint";
|
|
44
|
+
})(_ || (_ = {}));
|
|
45
|
+
var F;
|
|
46
|
+
(function(e) {
|
|
47
|
+
e[e.Uint = 1] = "Uint", e[e.Int = 2] = "Int", e[e.Float = 3] = "Float", e[e.Void = 4] = "Void", e[e.ComplexInt = 5] = "ComplexInt", e[e.ComplexFloat = 6] = "ComplexFloat";
|
|
48
|
+
})(F || (F = {}));
|
|
49
|
+
var E;
|
|
50
|
+
(function(e) {
|
|
51
|
+
e[e.MinIsWhite = 0] = "MinIsWhite", e[e.MinIsBlack = 1] = "MinIsBlack", e[e.Rgb = 2] = "Rgb", e[e.Palette = 3] = "Palette", e[e.Mask = 4] = "Mask", e[e.Separated = 5] = "Separated", e[e.Ycbcr = 6] = "Ycbcr", e[e.Cielab = 8] = "Cielab", e[e.Icclab = 9] = "Icclab", e[e.Itulab = 10] = "Itulab", e[e.Cfa = 32803] = "Cfa", e[e.Logl = 32844] = "Logl", e[e.Logluv = 32845] = "Logluv";
|
|
52
|
+
})(E || (E = {}));
|
|
53
|
+
var u;
|
|
54
|
+
(function(e) {
|
|
55
|
+
e[e.SubFileType = 254] = "SubFileType", e[e.OldSubFileType = 255] = "OldSubFileType", e[e.ImageWidth = 256] = "ImageWidth", e[e.ImageHeight = 257] = "ImageHeight", e[e.BitsPerSample = 258] = "BitsPerSample", e[e.SampleFormat = 339] = "SampleFormat", e[e.Compression = 259] = "Compression", e[e.Photometric = 262] = "Photometric", e[e.TileWidth = 322] = "TileWidth", e[e.TileHeight = 323] = "TileHeight", e[e.TileOffsets = 324] = "TileOffsets", e[e.TileByteCounts = 325] = "TileByteCounts", e[e.JpegTables = 347] = "JpegTables", e[e.StripOffsets = 273] = "StripOffsets", e[e.StripByteCounts = 279] = "StripByteCounts", e[e.GdalMetadata = 42112] = "GdalMetadata", e[e.GdalNoData = 42113] = "GdalNoData", e[e.ModelPixelScale = 33550] = "ModelPixelScale", e[e.ModelTiePoint = 33922] = "ModelTiePoint", e[e.ModelTransformation = 34264] = "ModelTransformation", e[e.GeoKeyDirectory = 34735] = "GeoKeyDirectory", e[e.GeoDoubleParams = 34736] = "GeoDoubleParams", e[e.GeoAsciiParams = 34737] = "GeoAsciiParams", e[e.LercParameters = 50674] = "LercParameters", e[e.PlanarConfiguration = 284] = "PlanarConfiguration", e[e.CellLength = 265] = "CellLength", e[e.CellWidth = 264] = "CellWidth", e[e.ColorMap = 320] = "ColorMap", e[e.Copyright = 33432] = "Copyright", e[e.DateTime = 306] = "DateTime", e[e.ExtraSamples = 338] = "ExtraSamples", e[e.FillOrder = 266] = "FillOrder", e[e.FreeByteCounts = 289] = "FreeByteCounts", e[e.FreeOffsets = 288] = "FreeOffsets", e[e.GrayResponseCurve = 291] = "GrayResponseCurve", e[e.GrayResponseUnit = 290] = "GrayResponseUnit", e[e.HostComputer = 316] = "HostComputer", e[e.ImageDescription = 270] = "ImageDescription", e[e.Make = 271] = "Make", e[e.MaxSampleValue = 281] = "MaxSampleValue", e[e.MinSampleValue = 280] = "MinSampleValue", e[e.Model = 272] = "Model", e[e.Orientation = 274] = "Orientation", e[e.ResolutionUnit = 296] = "ResolutionUnit", e[e.RowsPerStrip = 278] = "RowsPerStrip", e[e.SamplesPerPixel = 277] = "SamplesPerPixel", e[e.Software = 305] = "Software", e[e.Threshholding = 263] = "Threshholding", e[e.XResolution = 282] = "XResolution", e[e.YResolution = 283] = "YResolution", e[e.BadFaxLines = 326] = "BadFaxLines", e[e.CleanFaxData = 327] = "CleanFaxData", e[e.ClipPath = 343] = "ClipPath", e[e.ConsecutiveBadFaxLines = 328] = "ConsecutiveBadFaxLines", e[e.Decode = 433] = "Decode", e[e.DefaultImageColor = 434] = "DefaultImageColor", e[e.DocumentName = 269] = "DocumentName", e[e.DotRange = 336] = "DotRange", e[e.HalftoneHints = 321] = "HalftoneHints", e[e.Indexed = 346] = "Indexed", e[e.PageName = 285] = "PageName", e[e.PageNumber = 297] = "PageNumber", e[e.Predictor = 317] = "Predictor", e[e.PrimaryChromaticities = 319] = "PrimaryChromaticities", e[e.ReferenceBlackWhite = 532] = "ReferenceBlackWhite", e[e.SMinSampleValue = 340] = "SMinSampleValue", e[e.SMaxSampleValue = 341] = "SMaxSampleValue", e[e.StripRowCounts = 559] = "StripRowCounts", e[e.SubIFDs = 330] = "SubIFDs", e[e.T4Options = 292] = "T4Options", e[e.T6Options = 293] = "T6Options", e[e.TransferFunction = 301] = "TransferFunction", e[e.WhitePoint = 318] = "WhitePoint", e[e.XClipPathUnits = 344] = "XClipPathUnits", e[e.XPosition = 286] = "XPosition", e[e.YCbCrCoefficients = 529] = "YCbCrCoefficients", e[e.YCbCrPositioning = 531] = "YCbCrPositioning", e[e.YCbCrSubSampling = 530] = "YCbCrSubSampling", e[e.YClipPathUnits = 345] = "YClipPathUnits", e[e.YPosition = 287] = "YPosition", e[e.ApertureValue = 37378] = "ApertureValue", e[e.ColorSpace = 40961] = "ColorSpace", e[e.DateTimeDigitized = 36868] = "DateTimeDigitized", e[e.DateTimeOriginal = 36867] = "DateTimeOriginal", e[e.ExifIFD = 34665] = "ExifIFD", e[e.ExifVersion = 36864] = "ExifVersion", e[e.ExposureTime = 33434] = "ExposureTime", e[e.FileSource = 41728] = "FileSource", e[e.Flash = 37385] = "Flash", e[e.FlashpixVersion = 40960] = "FlashpixVersion", e[e.FNumber = 33437] = "FNumber", e[e.ImageUniqueID = 42016] = "ImageUniqueID", e[e.LightSource = 37384] = "LightSource", e[e.MakerNote = 37500] = "MakerNote", e[e.ShutterSpeedValue = 37377] = "ShutterSpeedValue", e[e.UserComment = 37510] = "UserComment", e[e.IPTC = 33723] = "IPTC", e[e.ICCProfile = 34675] = "ICCProfile", e[e.XMP = 700] = "XMP";
|
|
56
|
+
})(u || (u = {}));
|
|
57
|
+
var p;
|
|
58
|
+
(function(e) {
|
|
59
|
+
e[e.GTModelTypeGeoKey = 1024] = "GTModelTypeGeoKey", e[e.GTRasterTypeGeoKey = 1025] = "GTRasterTypeGeoKey", e[e.GTCitationGeoKey = 1026] = "GTCitationGeoKey", e[e.GeodeticCRSGeoKey = 2048] = "GeodeticCRSGeoKey", e[e.GeodeticCitationGeoKey = 2049] = "GeodeticCitationGeoKey", e[e.GeodeticDatumGeoKey = 2050] = "GeodeticDatumGeoKey", e[e.PrimeMeridianGeoKey = 2051] = "PrimeMeridianGeoKey", e[e.GeogLinearUnitsGeoKey = 2052] = "GeogLinearUnitsGeoKey", e[e.GeogLinearUnitSizeGeoKey = 2053] = "GeogLinearUnitSizeGeoKey", e[e.GeogAngularUnitsGeoKey = 2054] = "GeogAngularUnitsGeoKey", e[e.GeogAngularUnitSizeGeoKey = 2055] = "GeogAngularUnitSizeGeoKey", e[e.EllipsoidGeoKey = 2056] = "EllipsoidGeoKey", e[e.EllipsoidSemiMajorAxisGeoKey = 2057] = "EllipsoidSemiMajorAxisGeoKey", e[e.EllipsoidSemiMinorAxisGeoKey = 2058] = "EllipsoidSemiMinorAxisGeoKey", e[e.EllipsoidInvFlatteningGeoKey = 2059] = "EllipsoidInvFlatteningGeoKey", e[e.PrimeMeridianLongitudeGeoKey = 2061] = "PrimeMeridianLongitudeGeoKey", e[e.GeogTOWGS84GeoKey = 2062] = "GeogTOWGS84GeoKey", e[e.GeogAzimuthUnitsGeoKey = 2060] = "GeogAzimuthUnitsGeoKey", e[e.ProjectedCRSGeoKey = 3072] = "ProjectedCRSGeoKey", e[e.ProjectedCitationGeoKey = 3073] = "ProjectedCitationGeoKey", e[e.ProjectionGeoKey = 3074] = "ProjectionGeoKey", e[e.ProjMethodGeoKey = 3075] = "ProjMethodGeoKey", e[e.ProjLinearUnitsGeoKey = 3076] = "ProjLinearUnitsGeoKey", e[e.ProjLinearUnitSizeGeoKey = 3077] = "ProjLinearUnitSizeGeoKey", e[e.ProjStdParallel1GeoKey = 3078] = "ProjStdParallel1GeoKey", e[e.ProjStdParallel2GeoKey = 3079] = "ProjStdParallel2GeoKey", e[e.ProjNatOriginLongGeoKey = 3080] = "ProjNatOriginLongGeoKey", e[e.ProjNatOriginLatGeoKey = 3081] = "ProjNatOriginLatGeoKey", e[e.ProjFalseEastingGeoKey = 3082] = "ProjFalseEastingGeoKey", e[e.ProjFalseNorthingGeoKey = 3083] = "ProjFalseNorthingGeoKey", e[e.ProjFalseOriginLongGeoKey = 3084] = "ProjFalseOriginLongGeoKey", e[e.ProjFalseOriginLatGeoKey = 3085] = "ProjFalseOriginLatGeoKey", e[e.ProjFalseOriginEastingGeoKey = 3086] = "ProjFalseOriginEastingGeoKey", e[e.ProjFalseOriginNorthingGeoKey = 3087] = "ProjFalseOriginNorthingGeoKey", e[e.ProjCenterLongGeoKey = 3088] = "ProjCenterLongGeoKey", e[e.ProjCenterLatGeoKey = 3089] = "ProjCenterLatGeoKey", e[e.ProjCenterEastingGeoKey = 3090] = "ProjCenterEastingGeoKey", e[e.ProjCenterNorthingGeoKey = 3091] = "ProjCenterNorthingGeoKey", e[e.ProjScaleAtNatOriginGeoKey = 3092] = "ProjScaleAtNatOriginGeoKey", e[e.ProjScaleAtCenterGeoKey = 3093] = "ProjScaleAtCenterGeoKey", e[e.ProjAzimuthAngleGeoKey = 3094] = "ProjAzimuthAngleGeoKey", e[e.ProjStraightVertPoleLongGeoKey = 3095] = "ProjStraightVertPoleLongGeoKey", e[e.ProjRectifiedGridAngleGeoKey = 3096] = "ProjRectifiedGridAngleGeoKey", e[e.VerticalGeoKey = 4096] = "VerticalGeoKey", e[e.VerticalCitationGeoKey = 4097] = "VerticalCitationGeoKey", e[e.VerticalDatumGeoKey = 4098] = "VerticalDatumGeoKey", e[e.VerticalUnitsGeoKey = 4099] = "VerticalUnitsGeoKey";
|
|
60
|
+
})(p || (p = {}));
|
|
61
|
+
var fe;
|
|
62
|
+
(function(e) {
|
|
63
|
+
e[e.Radian = 9101] = "Radian", e[e.Degree = 9102] = "Degree", e[e.ArcMinute = 9103] = "ArcMinute", e[e.ArcDegree = 9104] = "ArcDegree", e[e.Grad = 9105] = "Grad", e[e.Gon = 9106] = "Gon", e[e.Dms = 9107] = "Dms";
|
|
64
|
+
})(fe || (fe = {}));
|
|
65
|
+
var ye;
|
|
66
|
+
(function(e) {
|
|
67
|
+
e[e.Metre = 9001] = "Metre", e[e.Foot = 9002] = "Foot", e[e.FootUsSurvey = 9003] = "FootUsSurvey", e[e.FootModifiedAmerican = 9004] = "FootModifiedAmerican", e[e.FootClarke = 9005] = "FootClarke", e[e.FootIndian = 9006] = "FootIndian", e[e.Link = 9007] = "Link", e[e.LinkBenoit = 9008] = "LinkBenoit", e[e.LinkSears = 9009] = "LinkSears", e[e.ChainBenoit = 9010] = "ChainBenoit", e[e.ChainSears = 9011] = "ChainSears", e[e.YardSears = 9012] = "YardSears", e[e.YardIndian = 9013] = "YardIndian", e[e.Fathom = 9014] = "Fathom", e[e.MileInternationalNautical = 9015] = "MileInternationalNautical";
|
|
68
|
+
})(ye || (ye = {}));
|
|
69
|
+
const ft = {
|
|
70
|
+
[u.TileByteCounts]: !0,
|
|
71
|
+
[u.TileOffsets]: !0,
|
|
72
|
+
[u.StripOffsets]: !0,
|
|
73
|
+
[u.StripByteCounts]: !0,
|
|
74
|
+
[u.BitsPerSample]: !0,
|
|
75
|
+
[u.SampleFormat]: !0,
|
|
76
|
+
[u.GeoKeyDirectory]: !0,
|
|
77
|
+
[u.GeoDoubleParams]: !0
|
|
78
|
+
};
|
|
79
|
+
var w;
|
|
80
|
+
(function(e) {
|
|
81
|
+
e.None = "application/octet-stream", e.Jbig = "image/jbig", e.Dcs = "image/x-kodak-dcs", e.PackBits = "application/packbits", e.Jpeg = "image/jpeg", e.Jp2000 = "image/jp2", e.JpegXl = "image/jpegxl", e.Webp = "image/webp", e.Zstd = "application/zstd", e.Lzw = "application/lzw", e.Deflate = "application/deflate", e.Lerc = "application/lerc", e.Lzma = "application/x-lzma";
|
|
82
|
+
})(w || (w = {}));
|
|
83
|
+
const ve = {
|
|
84
|
+
[m.None]: w.None,
|
|
85
|
+
[m.Lzw]: w.Lzw,
|
|
86
|
+
[m.Jpeg6]: w.Jpeg,
|
|
87
|
+
[m.Jpeg]: w.Jpeg,
|
|
88
|
+
[m.DeflateOther]: w.Deflate,
|
|
89
|
+
[m.Deflate]: w.Deflate,
|
|
90
|
+
[m.Lerc]: w.Lerc,
|
|
91
|
+
[m.Lzma]: w.Lzma,
|
|
92
|
+
[m.Jp2000]: w.Jp2000,
|
|
93
|
+
[m.Zstd]: w.Zstd,
|
|
94
|
+
[m.Webp]: w.Webp,
|
|
95
|
+
[m.JpegXl]: w.JpegXl,
|
|
96
|
+
[m.Ccittrle]: w.None,
|
|
97
|
+
[m.CcittT4]: w.None,
|
|
98
|
+
[m.CcittT6]: w.None,
|
|
99
|
+
[m.T85]: w.Jbig,
|
|
100
|
+
[m.T43]: w.Jbig,
|
|
101
|
+
[m.Next]: w.None,
|
|
102
|
+
[m.Ccittrlew]: w.None,
|
|
103
|
+
[m.PackBits]: w.PackBits,
|
|
104
|
+
[m.ThunderScan]: w.None,
|
|
105
|
+
[m.It8ctpad]: w.None,
|
|
106
|
+
[m.It8lw]: w.None,
|
|
107
|
+
[m.It8mp]: w.None,
|
|
108
|
+
[m.It8bl]: w.None,
|
|
109
|
+
[m.PixarFilm]: w.None,
|
|
110
|
+
[m.PixarLog]: w.None,
|
|
111
|
+
[m.Dcs]: w.Dcs,
|
|
112
|
+
[m.Jbig]: w.Jbig,
|
|
113
|
+
[m.SgiLog]: w.None,
|
|
114
|
+
[m.SgiLog24]: w.None,
|
|
115
|
+
[m.JpegXlDng17]: w.JpegXl
|
|
116
|
+
};
|
|
117
|
+
function yt(e) {
|
|
118
|
+
return e == null ? null : ve[e];
|
|
119
|
+
}
|
|
120
|
+
var y;
|
|
121
|
+
(function(e) {
|
|
122
|
+
e[e.Uint8 = 1] = "Uint8", e[e.Ascii = 2] = "Ascii", e[e.Uint16 = 3] = "Uint16", e[e.Uint32 = 4] = "Uint32", e[e.Rational = 5] = "Rational", e[e.Int8 = 6] = "Int8", e[e.Undefined = 7] = "Undefined", e[e.Int16 = 8] = "Int16", e[e.Int32 = 9] = "Int32", e[e.SignedRational = 10] = "SignedRational", e[e.Float32 = 11] = "Float32", e[e.Float64 = 12] = "Float64", e[e.Ifd = 13] = "Ifd", e[e.Uint64 = 16] = "Uint64", e[e.Int64 = 17] = "Int64", e[e.Ifd8 = 18] = "Ifd8";
|
|
123
|
+
})(y || (y = {}));
|
|
124
|
+
var v;
|
|
125
|
+
(function(e) {
|
|
126
|
+
e[e.BigTiff = 43] = "BigTiff", e[e.Tiff = 42] = "Tiff";
|
|
127
|
+
})(v || (v = {}));
|
|
128
|
+
function N(e) {
|
|
129
|
+
switch (e) {
|
|
130
|
+
case y.Uint8:
|
|
131
|
+
case y.Ascii:
|
|
132
|
+
case y.Int8:
|
|
133
|
+
case y.Undefined:
|
|
134
|
+
return 1;
|
|
135
|
+
case y.Uint16:
|
|
136
|
+
case y.Int16:
|
|
137
|
+
return 2;
|
|
138
|
+
case y.Uint32:
|
|
139
|
+
case y.Int32:
|
|
140
|
+
case y.Float32:
|
|
141
|
+
case y.Ifd:
|
|
142
|
+
return 4;
|
|
143
|
+
case y.Rational:
|
|
144
|
+
case y.SignedRational:
|
|
145
|
+
case y.Float64:
|
|
146
|
+
case y.Uint64:
|
|
147
|
+
case y.Int64:
|
|
148
|
+
case y.Ifd8:
|
|
149
|
+
return 8;
|
|
150
|
+
default:
|
|
151
|
+
throw new Error(`Invalid fieldType ${String(e)}`);
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
var we;
|
|
155
|
+
(function(e) {
|
|
156
|
+
e[e.Double = 8] = "Double", e[e.Float32 = 4] = "Float32";
|
|
157
|
+
})(we || (we = {}));
|
|
158
|
+
var L;
|
|
159
|
+
(function(e) {
|
|
160
|
+
e[e.UInt64 = 8] = "UInt64", e[e.UInt32 = 4] = "UInt32", e[e.UInt16 = 2] = "UInt16", e[e.UInt8 = 1] = "UInt8";
|
|
161
|
+
})(L || (L = {}));
|
|
162
|
+
const Se = 2 ** 32;
|
|
163
|
+
function Ue(e, t, n) {
|
|
164
|
+
const r = e.getUint32(t, n), o = e.getUint32(t + 4, n), i = n ? r + Se * o : Se * r + o;
|
|
165
|
+
if (!Number.isSafeInteger(i))
|
|
166
|
+
throw new Error(i + " exceeds MAX_SAFE_INTEGER. Precision may is lost");
|
|
167
|
+
return i;
|
|
168
|
+
}
|
|
169
|
+
function K(e, t, n, r) {
|
|
170
|
+
switch (n) {
|
|
171
|
+
case L.UInt8:
|
|
172
|
+
return e.getUint8(t);
|
|
173
|
+
case L.UInt16:
|
|
174
|
+
return e.getUint16(t, r);
|
|
175
|
+
case L.UInt32:
|
|
176
|
+
return e.getUint32(t, r);
|
|
177
|
+
case L.UInt64:
|
|
178
|
+
return Ue(e, t, r);
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
function Y(e, t, n) {
|
|
182
|
+
return !(t < e.sourceOffset || e.sourceOffset + e.byteLength < t + n);
|
|
183
|
+
}
|
|
184
|
+
const Oe = new ArrayBuffer(4), wt = new Uint32Array(Oe), St = new Uint8Array(Oe);
|
|
185
|
+
wt[0] = 1;
|
|
186
|
+
const Pe = St[0] === 1;
|
|
187
|
+
function Ce(e, t, n, r) {
|
|
188
|
+
switch (e) {
|
|
189
|
+
case y.Ascii:
|
|
190
|
+
return String.fromCharCode(t.getUint8(n));
|
|
191
|
+
case y.Undefined:
|
|
192
|
+
case y.Uint8:
|
|
193
|
+
return t.getUint8(n);
|
|
194
|
+
case y.Int8:
|
|
195
|
+
return t.getInt8(n);
|
|
196
|
+
case y.Uint16:
|
|
197
|
+
return t.getUint16(n, r);
|
|
198
|
+
case y.Int16:
|
|
199
|
+
return t.getInt16(n, r);
|
|
200
|
+
case y.Uint32:
|
|
201
|
+
case y.Ifd:
|
|
202
|
+
return t.getUint32(n, r);
|
|
203
|
+
case y.Int32:
|
|
204
|
+
return t.getInt32(n, r);
|
|
205
|
+
case y.Rational:
|
|
206
|
+
return [t.getUint32(n, r), t.getUint32(n + 4, r)];
|
|
207
|
+
case y.SignedRational:
|
|
208
|
+
return [t.getInt32(n, r), t.getInt32(n + 4, r)];
|
|
209
|
+
case y.Float64:
|
|
210
|
+
return t.getFloat64(n, r);
|
|
211
|
+
case y.Float32:
|
|
212
|
+
return t.getFloat32(n, r);
|
|
213
|
+
case y.Uint64:
|
|
214
|
+
return Ue(t, n, r);
|
|
215
|
+
default:
|
|
216
|
+
throw new Error(`Unknown read type "${e}" "${y[e]}"`);
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
function Me(e, t, n, r, o) {
|
|
220
|
+
switch (o) {
|
|
221
|
+
case y.Uint8:
|
|
222
|
+
return new Uint8Array(t.buffer.slice(t.byteOffset + n, t.byteOffset + n + r));
|
|
223
|
+
case y.Uint16:
|
|
224
|
+
return e.isLittleEndian !== Pe ? null : new Uint16Array(t.buffer.slice(t.byteOffset + n, t.byteOffset + n + r));
|
|
225
|
+
case y.Uint32:
|
|
226
|
+
return e.isLittleEndian !== Pe ? null : new Uint32Array(t.buffer.slice(t.byteOffset + n, t.byteOffset + n + r));
|
|
227
|
+
}
|
|
228
|
+
return null;
|
|
229
|
+
}
|
|
230
|
+
function x(e, t, n, r, o, i) {
|
|
231
|
+
const a = N(o), s = i * a;
|
|
232
|
+
if (i === 1) {
|
|
233
|
+
const c = Ce(o, n, r, e.isLittleEndian);
|
|
234
|
+
return t && ft[t] ? [c] : c;
|
|
235
|
+
}
|
|
236
|
+
switch (o) {
|
|
237
|
+
case y.Ascii:
|
|
238
|
+
return String.fromCharCode.apply(null, new Uint8Array(n.buffer, r, s - 1));
|
|
239
|
+
}
|
|
240
|
+
if (t === u.TileOffsets || t === u.TileByteCounts || t === u.StripOffsets || t === u.StripByteCounts) {
|
|
241
|
+
const c = Me(e, n, r, s, o);
|
|
242
|
+
if (c)
|
|
243
|
+
return c;
|
|
244
|
+
}
|
|
245
|
+
const l = [];
|
|
246
|
+
for (let c = 0; c < s; c += a)
|
|
247
|
+
l.push(Ce(o, n, r + c, e.isLittleEndian));
|
|
248
|
+
return l;
|
|
249
|
+
}
|
|
250
|
+
function Pt(e, t, n) {
|
|
251
|
+
const r = t.getUint16(n + 0, e.isLittleEndian), o = t.getUint16(n + 2, e.isLittleEndian), i = K(t, n + 4, e.ifdConfig.pointer, e.isLittleEndian), s = N(o) * i;
|
|
252
|
+
if (s <= e.ifdConfig.pointer) {
|
|
253
|
+
const c = x(e, r, t, n + 4 + e.ifdConfig.pointer, o, i);
|
|
254
|
+
return { type: "inline", id: r, name: u[r], count: i, value: c, dataType: o, tagOffset: n };
|
|
255
|
+
}
|
|
256
|
+
const l = K(t, n + 4 + e.ifdConfig.pointer, e.ifdConfig.pointer, e.isLittleEndian);
|
|
257
|
+
switch (r) {
|
|
258
|
+
case u.TileOffsets:
|
|
259
|
+
case u.TileByteCounts:
|
|
260
|
+
case u.StripByteCounts:
|
|
261
|
+
case u.StripOffsets:
|
|
262
|
+
const c = {
|
|
263
|
+
type: "offset",
|
|
264
|
+
id: r,
|
|
265
|
+
name: u[r],
|
|
266
|
+
count: i,
|
|
267
|
+
dataType: o,
|
|
268
|
+
dataOffset: l,
|
|
269
|
+
isLoaded: !1,
|
|
270
|
+
value: [],
|
|
271
|
+
tagOffset: n
|
|
272
|
+
};
|
|
273
|
+
if (Y(t, l, s)) {
|
|
274
|
+
const d = Me(e, t, l - t.sourceOffset, s, o);
|
|
275
|
+
d ? (c.value = d, c.isLoaded = !0) : bt(c, t);
|
|
276
|
+
}
|
|
277
|
+
return c;
|
|
278
|
+
}
|
|
279
|
+
if (Y(t, l, s)) {
|
|
280
|
+
const c = x(e, r, t, l - t.sourceOffset, o, i);
|
|
281
|
+
return { type: "inline", id: r, name: u[r], count: i, value: c, dataType: o, tagOffset: n };
|
|
282
|
+
}
|
|
283
|
+
return { type: "lazy", id: r, name: u[r], count: i, dataOffset: l, dataType: o, tagOffset: n };
|
|
284
|
+
}
|
|
285
|
+
async function Ct(e, t, n) {
|
|
286
|
+
if (e.value != null)
|
|
287
|
+
return e.value;
|
|
288
|
+
const o = N(e.dataType) * e.count, i = await t.source.fetch(e.dataOffset, o, n), a = new DataView(i);
|
|
289
|
+
return e.value = x(t, e.id, a, 0, e.dataType, e.count), e.value;
|
|
290
|
+
}
|
|
291
|
+
async function Lt(e, t, n) {
|
|
292
|
+
const r = N(t.dataType);
|
|
293
|
+
if (t.view == null) {
|
|
294
|
+
const o = await e.source.fetch(t.dataOffset, r * t.count, n);
|
|
295
|
+
t.view = new DataView(o), t.view.sourceOffset = t.dataOffset;
|
|
296
|
+
}
|
|
297
|
+
return t.value = x(e, t.id, t.view, 0, t.dataType, t.count), t.view = void 0, t.isLoaded = !0, t.value;
|
|
298
|
+
}
|
|
299
|
+
function bt(e, t) {
|
|
300
|
+
const n = N(e.dataType), r = t.byteOffset + e.dataOffset - t.sourceOffset;
|
|
301
|
+
e.view = new DataView(t.buffer.slice(r, r + n * e.count)), e.view.sourceOffset = e.dataOffset;
|
|
302
|
+
}
|
|
303
|
+
async function It(e, t, n, r) {
|
|
304
|
+
if (n > t.count || n < 0)
|
|
305
|
+
throw new Error("TagOffset: out of bounds :" + n);
|
|
306
|
+
if (t.value[n] != null)
|
|
307
|
+
return t.value[n];
|
|
308
|
+
const o = N(t.dataType);
|
|
309
|
+
if (t.view == null) {
|
|
310
|
+
const a = await e.source.fetch(t.dataOffset + n * o, o, r), s = new DataView(a), l = x(e, void 0, s, 0, t.dataType, 1);
|
|
311
|
+
if (typeof l != "number")
|
|
312
|
+
throw new Error("Value is not a number");
|
|
313
|
+
return t.value[n] = l, l;
|
|
314
|
+
}
|
|
315
|
+
const i = x(e, void 0, t.view, n * o, t.dataType, 1);
|
|
316
|
+
if (typeof i != "number")
|
|
317
|
+
throw new Error("Value is not a number");
|
|
318
|
+
return t.value[n] = i, i;
|
|
319
|
+
}
|
|
320
|
+
function Gt(e, t, n) {
|
|
321
|
+
if (n > t.count || n < 0)
|
|
322
|
+
throw new Error("TagOffset: out of bounds :" + n);
|
|
323
|
+
if (t.value[n] != null)
|
|
324
|
+
return t.value[n];
|
|
325
|
+
if (t.view == null)
|
|
326
|
+
return null;
|
|
327
|
+
const r = N(t.dataType), o = x(e, void 0, t.view, n * r, t.dataType, 1);
|
|
328
|
+
if (typeof o != "number")
|
|
329
|
+
throw new Error("Value is not a number");
|
|
330
|
+
return t.value[n] = o, o;
|
|
331
|
+
}
|
|
332
|
+
const Le = 32767, jt = /* @__PURE__ */ new Set([
|
|
333
|
+
u.Compression,
|
|
334
|
+
u.ImageHeight,
|
|
335
|
+
u.ImageWidth,
|
|
336
|
+
u.ModelPixelScale,
|
|
337
|
+
u.ModelTiePoint,
|
|
338
|
+
u.ModelTransformation,
|
|
339
|
+
u.TileHeight,
|
|
340
|
+
u.TileWidth
|
|
341
|
+
]), Et = /* @__PURE__ */ new Set([u.GeoKeyDirectory, u.GeoAsciiParams, u.GeoDoubleParams]);
|
|
342
|
+
class Ft {
|
|
343
|
+
/**
|
|
344
|
+
* Id of the tif image, generally the image index inside the tif
|
|
345
|
+
* where 0 is the root image, and every sub image is +1
|
|
346
|
+
*
|
|
347
|
+
* @example 0, 1, 2
|
|
348
|
+
*/
|
|
349
|
+
id;
|
|
350
|
+
/** Reference to the TIFF that owns this image */
|
|
351
|
+
tiff;
|
|
352
|
+
/** Has loadGeoTiffTags been called */
|
|
353
|
+
isGeoTagsLoaded = !1;
|
|
354
|
+
/** Sub tags stored in TiffTag.GeoKeyDirectory */
|
|
355
|
+
tagsGeo = /* @__PURE__ */ new Map();
|
|
356
|
+
/** All IFD tags that have been read for the image */
|
|
357
|
+
tags;
|
|
358
|
+
constructor(t, n, r) {
|
|
359
|
+
this.tiff = t, this.id = n, this.tags = r;
|
|
360
|
+
}
|
|
361
|
+
/**
|
|
362
|
+
* Force loading of important tags if they have not already been loaded
|
|
363
|
+
*
|
|
364
|
+
* @param loadGeoTags Whether to load the GeoKeyDirectory and unpack it
|
|
365
|
+
*/
|
|
366
|
+
async init(t = !0, n) {
|
|
367
|
+
const r = [];
|
|
368
|
+
jt.forEach((o) => {
|
|
369
|
+
r.push(this.fetch(o, n));
|
|
370
|
+
}), t && Et.forEach((o) => {
|
|
371
|
+
r.push(this.fetch(o, n));
|
|
372
|
+
}), await Promise.all(r), t && await this.loadGeoTiffTags();
|
|
373
|
+
}
|
|
374
|
+
/**
|
|
375
|
+
* Get the value of a TiffTag if it has been loaded, null otherwise.
|
|
376
|
+
*
|
|
377
|
+
* If the value is not loaded use {@link TiffImage.fetch} to load the value
|
|
378
|
+
* Or use {@link TiffImage.has} to check if the tag exists
|
|
379
|
+
*
|
|
380
|
+
*
|
|
381
|
+
* @returns value if loaded, null otherwise
|
|
382
|
+
*/
|
|
383
|
+
value(t) {
|
|
384
|
+
const n = this.tags.get(t);
|
|
385
|
+
return n == null || n.type === "offset" && n.isLoaded === !1 ? null : n.value;
|
|
386
|
+
}
|
|
387
|
+
/**
|
|
388
|
+
* Does the tag exist
|
|
389
|
+
*
|
|
390
|
+
* @example
|
|
391
|
+
* ```typescript
|
|
392
|
+
* img.has(TiffTag.ImageWidth) // true
|
|
393
|
+
* ```
|
|
394
|
+
*
|
|
395
|
+
* @param tag Tag to check
|
|
396
|
+
* @returns true if the tag exists, false otherwise
|
|
397
|
+
*/
|
|
398
|
+
has(t) {
|
|
399
|
+
return this.tags.has(t);
|
|
400
|
+
}
|
|
401
|
+
/**
|
|
402
|
+
* Load a tag.
|
|
403
|
+
*
|
|
404
|
+
* If it is not currently loaded, fetch the required data for the tag.
|
|
405
|
+
*
|
|
406
|
+
* @example
|
|
407
|
+
* ```typescript
|
|
408
|
+
* await img.fetch(TiffTag.ImageWidth) // 512 (px)
|
|
409
|
+
* ```
|
|
410
|
+
*
|
|
411
|
+
* @param tag tag to fetch
|
|
412
|
+
*/
|
|
413
|
+
async fetch(t, n) {
|
|
414
|
+
const r = this.tags.get(t);
|
|
415
|
+
if (r == null)
|
|
416
|
+
return null;
|
|
417
|
+
if (r.type === "inline")
|
|
418
|
+
return r.value;
|
|
419
|
+
if (r.type === "lazy")
|
|
420
|
+
return Ct(r, this.tiff, n);
|
|
421
|
+
if (r.isLoaded)
|
|
422
|
+
return r.value;
|
|
423
|
+
if (r.type === "offset")
|
|
424
|
+
return Lt(this.tiff, r, n);
|
|
425
|
+
throw new Error("Cannot fetch:" + t);
|
|
426
|
+
}
|
|
427
|
+
/**
|
|
428
|
+
* Get the associated TiffTagGeo
|
|
429
|
+
*
|
|
430
|
+
* @example
|
|
431
|
+
* ```typescript
|
|
432
|
+
* image.valueGeo(TiffTagGeo.GTRasterTypeGeoKey)
|
|
433
|
+
* ```
|
|
434
|
+
* @throws if {@link loadGeoTiffTags} has not been called
|
|
435
|
+
*/
|
|
436
|
+
valueGeo(t) {
|
|
437
|
+
if (this.isGeoTagsLoaded === !1)
|
|
438
|
+
throw new Error("loadGeoTiffTags() has not been called");
|
|
439
|
+
return this.tagsGeo.get(t);
|
|
440
|
+
}
|
|
441
|
+
/**
|
|
442
|
+
* Load and parse the GDAL_NODATA Tifftag
|
|
443
|
+
*
|
|
444
|
+
* @throws if the tag is not loaded
|
|
445
|
+
* @returns null if the tag does not exist
|
|
446
|
+
*/
|
|
447
|
+
get noData() {
|
|
448
|
+
const t = this.tags.get(u.GdalNoData);
|
|
449
|
+
if (t == null)
|
|
450
|
+
return null;
|
|
451
|
+
if (t.value != null)
|
|
452
|
+
return Number(t.value);
|
|
453
|
+
throw new Error("GdalNoData tag is not loaded");
|
|
454
|
+
}
|
|
455
|
+
/**
|
|
456
|
+
* Load and unpack the GeoKeyDirectory
|
|
457
|
+
*
|
|
458
|
+
* @see {TiffTag.GeoKeyDirectory}
|
|
459
|
+
*/
|
|
460
|
+
async loadGeoTiffTags() {
|
|
461
|
+
if (this.isGeoTagsLoaded)
|
|
462
|
+
return;
|
|
463
|
+
const t = this.tags.get(u.GeoKeyDirectory);
|
|
464
|
+
if (t == null) {
|
|
465
|
+
this.isGeoTagsLoaded = !0;
|
|
466
|
+
return;
|
|
467
|
+
}
|
|
468
|
+
if (t.type === "lazy" && t.value == null && await Promise.all([
|
|
469
|
+
this.fetch(u.GeoKeyDirectory),
|
|
470
|
+
this.fetch(u.GeoAsciiParams),
|
|
471
|
+
this.fetch(u.GeoDoubleParams)
|
|
472
|
+
]), this.isGeoTagsLoaded = !0, t.value == null)
|
|
473
|
+
return;
|
|
474
|
+
const n = t.value;
|
|
475
|
+
if (typeof n == "number")
|
|
476
|
+
throw new Error("Invalid geo tags found");
|
|
477
|
+
for (let r = 4; r <= n[3] * 4; r += 4) {
|
|
478
|
+
const o = n[r], i = n[r + 1], a = n[r + 3];
|
|
479
|
+
if (i === 0) {
|
|
480
|
+
this.tagsGeo.set(o, a);
|
|
481
|
+
continue;
|
|
482
|
+
}
|
|
483
|
+
const s = this.tags.get(i);
|
|
484
|
+
if (s == null || s.value == null)
|
|
485
|
+
continue;
|
|
486
|
+
const l = n[r + 2];
|
|
487
|
+
if (typeof s.value == "string")
|
|
488
|
+
this.tagsGeo.set(o, s.value.slice(a, a + l - 1).trim());
|
|
489
|
+
else if (Array.isArray(s.value))
|
|
490
|
+
l === 1 ? this.tagsGeo.set(o, s.value[a]) : this.tagsGeo.set(o, s.value.slice(a, a + l));
|
|
491
|
+
else
|
|
492
|
+
throw new Error("Failed to extract GeoTiffTags");
|
|
493
|
+
}
|
|
494
|
+
}
|
|
495
|
+
/**
|
|
496
|
+
* Get the origin point for the image
|
|
497
|
+
*
|
|
498
|
+
* @returns origin point of the image
|
|
499
|
+
*/
|
|
500
|
+
get origin() {
|
|
501
|
+
const t = this.value(u.ModelTiePoint);
|
|
502
|
+
if (t != null && t.length === 6)
|
|
503
|
+
return [t[3], t[4], t[5]];
|
|
504
|
+
const n = this.value(u.ModelTransformation);
|
|
505
|
+
if (n != null)
|
|
506
|
+
return [n[3], n[7], n[11]];
|
|
507
|
+
if (this.value(u.SubFileType) === J.ReducedImage && this.id !== 0)
|
|
508
|
+
return this.tiff.images[0].origin;
|
|
509
|
+
throw new Error("Image does not have a geo transformation.");
|
|
510
|
+
}
|
|
511
|
+
/** Is there enough geo information on this image to figure out where its actually located */
|
|
512
|
+
get isGeoLocated() {
|
|
513
|
+
return this.value(u.ModelPixelScale) != null || this.value(u.ModelTransformation) != null ? !0 : this.isSubImage && this.id !== 0 ? this.tiff.images[0].isGeoLocated : !1;
|
|
514
|
+
}
|
|
515
|
+
/**
|
|
516
|
+
* Get the resolution of the image
|
|
517
|
+
*
|
|
518
|
+
* @returns [x,y,z] pixel scale
|
|
519
|
+
*/
|
|
520
|
+
get resolution() {
|
|
521
|
+
const t = this.value(u.ModelPixelScale);
|
|
522
|
+
if (t != null)
|
|
523
|
+
return [t[0], -t[1], t[2]];
|
|
524
|
+
const n = this.value(u.ModelTransformation);
|
|
525
|
+
if (n != null)
|
|
526
|
+
return [n[0], n[5], n[10]];
|
|
527
|
+
if (this.isSubImage && this.id !== 0) {
|
|
528
|
+
const r = this.tiff.images[0], [o, i, a] = r.resolution, s = r.size, l = this.size;
|
|
529
|
+
return [o * s.width / l.width, i * s.height / l.height, a];
|
|
530
|
+
}
|
|
531
|
+
throw new Error("Image does not have a geo transformation.");
|
|
532
|
+
}
|
|
533
|
+
/**
|
|
534
|
+
* Is this image a reduced size image
|
|
535
|
+
* @see {@link TiffTag.SubFileType}
|
|
536
|
+
* @returns true if SubFileType is Reduces image, false otherwise
|
|
537
|
+
*/
|
|
538
|
+
get isSubImage() {
|
|
539
|
+
return this.value(u.SubFileType) === J.ReducedImage;
|
|
540
|
+
}
|
|
541
|
+
/**
|
|
542
|
+
* Bounding box of the image
|
|
543
|
+
*
|
|
544
|
+
* @returns [minX, minY, maxX, maxY] bounding box
|
|
545
|
+
*/
|
|
546
|
+
get bbox() {
|
|
547
|
+
const t = this.size, n = this.origin, r = this.resolution;
|
|
548
|
+
if (n == null || t == null || r == null)
|
|
549
|
+
throw new Error("Unable to calculate bounding box");
|
|
550
|
+
const o = n[0], i = n[1], a = o + r[0] * t.width, s = i + r[1] * t.height;
|
|
551
|
+
return [Math.min(o, a), Math.min(i, s), Math.max(o, a), Math.max(i, s)];
|
|
552
|
+
}
|
|
553
|
+
/**
|
|
554
|
+
* Get the compression used by the tile
|
|
555
|
+
*
|
|
556
|
+
* @see {@link TiffCompressionMimeType}
|
|
557
|
+
*
|
|
558
|
+
* @returns Compression type eg webp
|
|
559
|
+
*/
|
|
560
|
+
get compression() {
|
|
561
|
+
const t = this.value(u.Compression);
|
|
562
|
+
return t == null ? null : ve[t];
|
|
563
|
+
}
|
|
564
|
+
/**
|
|
565
|
+
* Attempt to read the EPSG Code from TiffGeoTags
|
|
566
|
+
*
|
|
567
|
+
* looks at TiffTagGeo.ProjectionGeoKey, TiffTagGeo.ProjectedCRSGeoKey and TiffTagGeo.GeodeticCRSGeoKey
|
|
568
|
+
*
|
|
569
|
+
* @returns EPSG Code if it exists and is not user defined.
|
|
570
|
+
*/
|
|
571
|
+
get epsg() {
|
|
572
|
+
const t = this.valueGeo(p.ProjectionGeoKey);
|
|
573
|
+
if (t != null && t !== Le)
|
|
574
|
+
return t;
|
|
575
|
+
let n = null;
|
|
576
|
+
switch (this.valueGeo(p.GTModelTypeGeoKey)) {
|
|
577
|
+
case M.Unknown:
|
|
578
|
+
return null;
|
|
579
|
+
case M.Projected:
|
|
580
|
+
n = this.valueGeo(p.ProjectedCRSGeoKey);
|
|
581
|
+
break;
|
|
582
|
+
case M.Geographic:
|
|
583
|
+
n = this.valueGeo(p.GeodeticCRSGeoKey);
|
|
584
|
+
break;
|
|
585
|
+
case M.Geocentric:
|
|
586
|
+
n = this.valueGeo(p.GeodeticCRSGeoKey);
|
|
587
|
+
break;
|
|
588
|
+
case M.UserDefined:
|
|
589
|
+
return null;
|
|
590
|
+
}
|
|
591
|
+
return n === Le ? null : n;
|
|
592
|
+
}
|
|
593
|
+
/**
|
|
594
|
+
* Get the size of the image
|
|
595
|
+
*
|
|
596
|
+
* @returns Size in pixels
|
|
597
|
+
*/
|
|
598
|
+
get size() {
|
|
599
|
+
const t = this.value(u.ImageWidth), n = this.value(u.ImageHeight);
|
|
600
|
+
if (t == null || n == null)
|
|
601
|
+
throw new Error("Tiff has no height or width");
|
|
602
|
+
return { width: t, height: n };
|
|
603
|
+
}
|
|
604
|
+
/**
|
|
605
|
+
* Determine if this image is tiled
|
|
606
|
+
*/
|
|
607
|
+
isTiled() {
|
|
608
|
+
return this.value(u.TileWidth) !== null;
|
|
609
|
+
}
|
|
610
|
+
/**
|
|
611
|
+
* Get size of individual tiles
|
|
612
|
+
*/
|
|
613
|
+
get tileSize() {
|
|
614
|
+
const t = this.value(u.TileWidth), n = this.value(u.TileHeight);
|
|
615
|
+
if (t == null || n == null)
|
|
616
|
+
throw new Error("Tiff is not tiled");
|
|
617
|
+
return { width: t, height: n };
|
|
618
|
+
}
|
|
619
|
+
/**
|
|
620
|
+
* Number of tiles used to create this image
|
|
621
|
+
*/
|
|
622
|
+
get tileCount() {
|
|
623
|
+
const t = this.size, n = this.tileSize, r = Math.ceil(t.width / n.width), o = Math.ceil(t.height / n.height);
|
|
624
|
+
return { x: r, y: o };
|
|
625
|
+
}
|
|
626
|
+
/**
|
|
627
|
+
* Get the pointer to where the tiles start in the Tiff file
|
|
628
|
+
*
|
|
629
|
+
* @remarks Used to read tiled tiffs
|
|
630
|
+
*
|
|
631
|
+
* @returns file offset to where the tiffs are stored
|
|
632
|
+
*/
|
|
633
|
+
get tileOffset() {
|
|
634
|
+
const t = this.tags.get(u.TileOffsets);
|
|
635
|
+
if (t == null)
|
|
636
|
+
throw new Error("No tile offsets found");
|
|
637
|
+
return t;
|
|
638
|
+
}
|
|
639
|
+
/**
|
|
640
|
+
* Get the number of strip's inside this tiff
|
|
641
|
+
*
|
|
642
|
+
* @remarks Used to read striped tiffs
|
|
643
|
+
*
|
|
644
|
+
* @returns number of strips present
|
|
645
|
+
*/
|
|
646
|
+
get stripCount() {
|
|
647
|
+
return this.tags.get(u.StripByteCounts)?.count ?? 0;
|
|
648
|
+
}
|
|
649
|
+
// Clamp the bounds of the output image to the size of the image, as sometimes the edge tiles are not full tiles
|
|
650
|
+
getTileBounds(t, n) {
|
|
651
|
+
const { size: r, tileSize: o } = this, i = n * o.height, a = t * o.width, s = a + o.width >= r.width ? r.width - a : o.width, l = i + o.height >= r.height ? r.height - i : o.height;
|
|
652
|
+
return { x: a, y: i, width: s, height: l };
|
|
653
|
+
}
|
|
654
|
+
/**
|
|
655
|
+
* Read a strip into a ArrayBuffer
|
|
656
|
+
*
|
|
657
|
+
* Image has to be striped see {@link stripCount}
|
|
658
|
+
*
|
|
659
|
+
* @param index Strip index to read
|
|
660
|
+
*/
|
|
661
|
+
async getStrip(t, n) {
|
|
662
|
+
if (this.isTiled())
|
|
663
|
+
throw new Error("Cannot read stripes, tiff is tiled: " + t);
|
|
664
|
+
const r = this.tags.get(u.StripByteCounts), o = this.tags.get(u.StripOffsets);
|
|
665
|
+
if (t >= r.count)
|
|
666
|
+
throw new Error("Cannot read strip, index out of bounds");
|
|
667
|
+
const [i, a] = await Promise.all([
|
|
668
|
+
$(this.tiff, o, t, n),
|
|
669
|
+
$(this.tiff, r, t, n)
|
|
670
|
+
]);
|
|
671
|
+
return this.getBytes(i, a, n);
|
|
672
|
+
}
|
|
673
|
+
/** The jpeg header is stored in the IFD, read the JPEG header and adjust the byte array to include it */
|
|
674
|
+
getJpegHeader(t) {
|
|
675
|
+
const n = this.value(u.JpegTables);
|
|
676
|
+
if (n == null)
|
|
677
|
+
throw new Error("Unable to find Jpeg header");
|
|
678
|
+
const r = n.slice(0, n.length - 2), o = new Uint8Array(t.byteLength + r.length - 2);
|
|
679
|
+
return o.set(r, 0), o.set(new Uint8Array(t).slice(2), r.length), o.buffer.slice(o.byteOffset, o.byteOffset + o.byteLength);
|
|
680
|
+
}
|
|
681
|
+
/** Read image bytes at the given offset */
|
|
682
|
+
async getBytes(t, n, r) {
|
|
683
|
+
if (n === 0)
|
|
684
|
+
return null;
|
|
685
|
+
const o = await this.tiff.source.fetch(t, n, r);
|
|
686
|
+
if (o.byteLength < n)
|
|
687
|
+
throw new Error(`Failed to fetch bytes from offset:${t} wanted:${n} got:${o.byteLength}`);
|
|
688
|
+
let i = this.value(u.Compression);
|
|
689
|
+
i == null && (i = m.None);
|
|
690
|
+
const a = yt(i) ?? w.None;
|
|
691
|
+
return i === m.Jpeg ? { mimeType: a, bytes: this.getJpegHeader(o), compression: i } : { mimeType: a, bytes: o, compression: i };
|
|
692
|
+
}
|
|
693
|
+
/**
|
|
694
|
+
* Load a tile into a ArrayBuffer
|
|
695
|
+
*
|
|
696
|
+
* if the tile compression is JPEG, This will also apply the JPEG compression tables to the resulting ArrayBuffer see {@link getJpegHeader}
|
|
697
|
+
*
|
|
698
|
+
* @param x Tile x offset
|
|
699
|
+
* @param y Tile y offset
|
|
700
|
+
*/
|
|
701
|
+
async getTile(t, n, r) {
|
|
702
|
+
const o = this.size, i = this.tileSize;
|
|
703
|
+
if (i == null)
|
|
704
|
+
throw new Error("Tiff is not tiled");
|
|
705
|
+
const a = Math.ceil(o.height / i.height), s = Math.ceil(o.width / i.width);
|
|
706
|
+
if (t >= s || n >= a)
|
|
707
|
+
throw new Error(`Tile index is outside of range x:${t} >= ${s} or y:${n} >= ${a}`);
|
|
708
|
+
const l = n * s + t, c = s * a;
|
|
709
|
+
if (l >= c)
|
|
710
|
+
throw new Error(`Tile index is outside of tile range: ${l} >= ${c}`);
|
|
711
|
+
const { offset: d, imageSize: h } = await this.getTileSize(l, r);
|
|
712
|
+
return this.getBytes(d, h, r);
|
|
713
|
+
}
|
|
714
|
+
/**
|
|
715
|
+
* Does this tile exist in the tiff and does it actually have a value
|
|
716
|
+
*
|
|
717
|
+
* Sparse tiffs can have a lot of empty tiles, they set the tile size to `0 bytes` when the tile is empty
|
|
718
|
+
* this checks the tile byte size to validate if it actually has any data.
|
|
719
|
+
*
|
|
720
|
+
* @param x Tile x offset
|
|
721
|
+
* @param y Tile y offset
|
|
722
|
+
*
|
|
723
|
+
* @returns if the tile exists and has data
|
|
724
|
+
*/
|
|
725
|
+
async hasTile(t, n, r) {
|
|
726
|
+
const o = this.tileSize, i = this.size;
|
|
727
|
+
if (o == null)
|
|
728
|
+
throw new Error("Tiff is not tiled");
|
|
729
|
+
const a = Math.ceil(i.height / o.height), s = Math.ceil(i.width / o.width);
|
|
730
|
+
if (t >= s || n >= a)
|
|
731
|
+
return !1;
|
|
732
|
+
const l = n * s + t;
|
|
733
|
+
return (await this.getTileSize(l, r)).offset > 0;
|
|
734
|
+
}
|
|
735
|
+
/**
|
|
736
|
+
* Load the offset and byteCount of a tile
|
|
737
|
+
*
|
|
738
|
+
* if the tiff is sparse, offset and byteCount will be zero if the tile is empty
|
|
739
|
+
*
|
|
740
|
+
* @param index index in the tile array
|
|
741
|
+
* @returns Offset and byteCount for the tile
|
|
742
|
+
*/
|
|
743
|
+
async getTileSize(t, n) {
|
|
744
|
+
const r = this.tags.get(u.TileByteCounts), o = ee(this.tiff, this.tileOffset, t), i = ee(this.tiff, r, t);
|
|
745
|
+
if (o != null && i != null)
|
|
746
|
+
return { offset: o, imageSize: i };
|
|
747
|
+
const a = this.tiff.options?.tileLeaderByteSize;
|
|
748
|
+
if (a) {
|
|
749
|
+
const c = o ?? await $(this.tiff, this.tileOffset, t, n);
|
|
750
|
+
if (c === 0)
|
|
751
|
+
return { offset: 0, imageSize: 0 };
|
|
752
|
+
const d = await this.tiff.source.fetch(c - a, a, n);
|
|
753
|
+
return { offset: c, imageSize: K(new DataView(d), 0, a, this.tiff.isLittleEndian) };
|
|
754
|
+
}
|
|
755
|
+
if (r == null)
|
|
756
|
+
throw new Error("No tile byte counts found");
|
|
757
|
+
const [s, l] = await Promise.all([
|
|
758
|
+
o ?? $(this.tiff, this.tileOffset, t, n),
|
|
759
|
+
i ?? $(this.tiff, r, t, n)
|
|
760
|
+
]);
|
|
761
|
+
return { offset: s, imageSize: l };
|
|
762
|
+
}
|
|
763
|
+
}
|
|
764
|
+
function $(e, t, n, r) {
|
|
765
|
+
const o = ee(e, t, n);
|
|
766
|
+
return o != null ? Promise.resolve(o) : It(e, t, n, r);
|
|
767
|
+
}
|
|
768
|
+
function ee(e, t, n) {
|
|
769
|
+
if (n < 0)
|
|
770
|
+
throw new Error(`Tiff: ${e.source.url.href} out of bounds ${u[t.id]} index:${n} total:${t.count}`);
|
|
771
|
+
return n >= t.count ? 0 : t.type === "inline" || t.isLoaded ? t.value[n] : Gt(e, t, n);
|
|
772
|
+
}
|
|
773
|
+
var z;
|
|
774
|
+
(function(e) {
|
|
775
|
+
e.GdalStructuralMetadataSize = "GDAL_STRUCTURAL_METADATA_SIZE", e.Layout = "LAYOUT", e.BlockOrder = "BLOCK_ORDER", e.BlockLeader = "BLOCK_LEADER", e.BlockTrailer = "BLOCK_TRAILER", e.KnownIncompatibleEdition = "KNOWN_INCOMPATIBLE_EDITION", e.MaskInterleavedWithImagery = "MASK_INTERLEAVED_WITH_IMAGERY";
|
|
776
|
+
})(z || (z = {}));
|
|
777
|
+
var be;
|
|
778
|
+
(function(e) {
|
|
779
|
+
e.RowMajor = "ROW_MAJOR";
|
|
780
|
+
})(be || (be = {}));
|
|
781
|
+
var te;
|
|
782
|
+
(function(e) {
|
|
783
|
+
e.uint32 = "SIZE_AS_UINT4";
|
|
784
|
+
})(te || (te = {}));
|
|
785
|
+
class At {
|
|
786
|
+
options = /* @__PURE__ */ new Map();
|
|
787
|
+
/**
|
|
788
|
+
* Has GDAL optimized this tiff
|
|
789
|
+
*/
|
|
790
|
+
get isCogOptimized() {
|
|
791
|
+
return this.isBroken ? !1 : this.options.get(z.Layout) === "IFDS_BEFORE_DATA";
|
|
792
|
+
}
|
|
793
|
+
/**
|
|
794
|
+
* Has GDAL determined this tiff is now broken
|
|
795
|
+
*/
|
|
796
|
+
get isBroken() {
|
|
797
|
+
return this.options.get(z.KnownIncompatibleEdition) === "YES";
|
|
798
|
+
}
|
|
799
|
+
/**
|
|
800
|
+
* Load the ghost options from a source
|
|
801
|
+
* @param bytes the ghost header bytes
|
|
802
|
+
*/
|
|
803
|
+
process(t, n, r) {
|
|
804
|
+
let o = "", i = "", a = !1;
|
|
805
|
+
for (let s = 0; s < r; s++) {
|
|
806
|
+
const l = t.getUint8(n + s);
|
|
807
|
+
if (l === 0)
|
|
808
|
+
break;
|
|
809
|
+
const c = String.fromCharCode(l);
|
|
810
|
+
c === `
|
|
811
|
+
` ? (this.options.set(o.trim(), i.trim()), o = "", i = "", a = !1) : c === "=" ? a = !0 : a ? i += c : o += c;
|
|
812
|
+
}
|
|
813
|
+
}
|
|
814
|
+
/**
|
|
815
|
+
* If the tile leader is set, how many bytes are allocated to the tile size
|
|
816
|
+
*/
|
|
817
|
+
get tileLeaderByteSize() {
|
|
818
|
+
switch (this.options.get(z.BlockLeader)) {
|
|
819
|
+
case te.uint32:
|
|
820
|
+
return L.UInt32;
|
|
821
|
+
default:
|
|
822
|
+
return null;
|
|
823
|
+
}
|
|
824
|
+
}
|
|
825
|
+
get isMaskInterleaved() {
|
|
826
|
+
return this.options.get(z.MaskInterleavedWithImagery) === "YES";
|
|
827
|
+
}
|
|
828
|
+
}
|
|
829
|
+
const Ke = {
|
|
830
|
+
version: v.Tiff,
|
|
831
|
+
pointer: L.UInt32,
|
|
832
|
+
offset: L.UInt16,
|
|
833
|
+
/**
|
|
834
|
+
* Each tag entry is specified as
|
|
835
|
+
* UInt16:TagCode
|
|
836
|
+
* UInt16:TagType
|
|
837
|
+
* UInt32:TagCount
|
|
838
|
+
* UInt32:Pointer To Value or value
|
|
839
|
+
*/
|
|
840
|
+
ifd: L.UInt16 + L.UInt16 + 2 * L.UInt32
|
|
841
|
+
}, De = {
|
|
842
|
+
version: v.BigTiff,
|
|
843
|
+
/** Size of most pointers */
|
|
844
|
+
pointer: L.UInt64,
|
|
845
|
+
/** Size of offsets */
|
|
846
|
+
offset: L.UInt64,
|
|
847
|
+
/**
|
|
848
|
+
* Each tag entry is specified as
|
|
849
|
+
* UInt16:TagCode
|
|
850
|
+
* UInt16:TagType
|
|
851
|
+
* UInt64:TagCount
|
|
852
|
+
* UInt64:Pointer To Value or value
|
|
853
|
+
*/
|
|
854
|
+
ifd: L.UInt16 + L.UInt16 + 2 * L.UInt64
|
|
855
|
+
};
|
|
856
|
+
v.BigTiff + "", v.Tiff + "";
|
|
857
|
+
function Rt(e, t = 4, n = !0) {
|
|
858
|
+
const r = e.toString(16).padStart(t, "0");
|
|
859
|
+
return n ? "0x" + r : r;
|
|
860
|
+
}
|
|
861
|
+
class B {
|
|
862
|
+
/** Read 16KB blocks at a time */
|
|
863
|
+
static DefaultReadSize = 16 * 1024;
|
|
864
|
+
/** Read 16KB blocks at a time */
|
|
865
|
+
defaultReadSize = B.DefaultReadSize;
|
|
866
|
+
/** Where this cog is fetching its data from */
|
|
867
|
+
source;
|
|
868
|
+
/** Big or small Tiff */
|
|
869
|
+
version = v.Tiff;
|
|
870
|
+
/** List of images, o is the base image */
|
|
871
|
+
images = [];
|
|
872
|
+
/** Ghost header options */
|
|
873
|
+
options;
|
|
874
|
+
/** Configuration for the size of the IFD */
|
|
875
|
+
ifdConfig = Ke;
|
|
876
|
+
/** Is the tiff being read is little Endian */
|
|
877
|
+
isLittleEndian = !1;
|
|
878
|
+
/** Has init() been called */
|
|
879
|
+
isInitialized = !1;
|
|
880
|
+
_initPromise;
|
|
881
|
+
/** A Tiff constructed from a source will not be pre-initialized with {@link init}. */
|
|
882
|
+
constructor(t, n = { defaultReadSize: B.DefaultReadSize }) {
|
|
883
|
+
this.source = t, this.defaultReadSize = n.defaultReadSize;
|
|
884
|
+
}
|
|
885
|
+
/** Create a tiff and initialize it by reading the tiff headers */
|
|
886
|
+
static create(t, n = { defaultReadSize: B.DefaultReadSize }) {
|
|
887
|
+
return new B(t, n).init(n);
|
|
888
|
+
}
|
|
889
|
+
/**
|
|
890
|
+
* Initialize the tiff loading in the header and all image headers.
|
|
891
|
+
*
|
|
892
|
+
* This is only required if the Tiff was created with the constructor, if you
|
|
893
|
+
* used {@link create} this will have already been called.
|
|
894
|
+
*/
|
|
895
|
+
init(t) {
|
|
896
|
+
return this.isInitialized ? Promise.resolve(this) : this._initPromise ? this._initPromise : (this._initPromise = this.readHeader(t), this._initPromise);
|
|
897
|
+
}
|
|
898
|
+
/**
|
|
899
|
+
* Find a image which has a resolution similar to the provided resolution
|
|
900
|
+
*
|
|
901
|
+
* @param resolution resolution to find
|
|
902
|
+
*/
|
|
903
|
+
getImageByResolution(t) {
|
|
904
|
+
const n = this.images[0], r = n.size, [o] = n.resolution, i = o * r.width;
|
|
905
|
+
for (let a = this.images.length - 1; a > 0; a--) {
|
|
906
|
+
const s = this.images[a], l = s.size;
|
|
907
|
+
if (i / l.width - t <= 0.01)
|
|
908
|
+
return s;
|
|
909
|
+
}
|
|
910
|
+
return n;
|
|
911
|
+
}
|
|
912
|
+
/** Read the Starting header and all Image headers from the source */
|
|
913
|
+
async readHeader(t) {
|
|
914
|
+
if (this.isInitialized)
|
|
915
|
+
return this;
|
|
916
|
+
const n = new DataView(await this.source.fetch(0, Ie(this.source, 0, this.defaultReadSize), t));
|
|
917
|
+
if (n.byteLength === 0)
|
|
918
|
+
throw new Error("Unable to read empty tiff");
|
|
919
|
+
n.sourceOffset = 0;
|
|
920
|
+
let r = 0;
|
|
921
|
+
const o = n.getUint16(r, this.isLittleEndian);
|
|
922
|
+
r += 2, this.isLittleEndian = o === q.Little, this.version = n.getUint16(r, this.isLittleEndian), r += 2;
|
|
923
|
+
let i;
|
|
924
|
+
if (this.version === v.BigTiff) {
|
|
925
|
+
this.ifdConfig = De;
|
|
926
|
+
const s = n.getUint16(r, this.isLittleEndian);
|
|
927
|
+
if (r += 2, s !== 8)
|
|
928
|
+
throw new Error("Only 8byte pointers are supported");
|
|
929
|
+
const l = n.getUint16(r, this.isLittleEndian);
|
|
930
|
+
if (r += 2, l !== 0)
|
|
931
|
+
throw new Error("Invalid big tiff header");
|
|
932
|
+
i = K(n, r, this.ifdConfig.pointer, this.isLittleEndian), r += this.ifdConfig.pointer;
|
|
933
|
+
} else if (this.version === v.Tiff)
|
|
934
|
+
i = K(n, r, this.ifdConfig.pointer, this.isLittleEndian), r += this.ifdConfig.pointer;
|
|
935
|
+
else
|
|
936
|
+
throw new Error(`Only tiff supported version:${String(this.version)}`);
|
|
937
|
+
const a = i - r;
|
|
938
|
+
for (a > 0 && a < 16 * 1024 && (this.options = new At(), this.options.process(n, r, a)); i !== 0; ) {
|
|
939
|
+
let s = n;
|
|
940
|
+
if (!Y(s, i, 1024)) {
|
|
941
|
+
const l = await this.source.fetch(i, Ie(this.source, i, this.defaultReadSize), t);
|
|
942
|
+
s = new DataView(l), s.sourceOffset = i;
|
|
943
|
+
}
|
|
944
|
+
i = this.readIfd(i, s);
|
|
945
|
+
}
|
|
946
|
+
return await Promise.all(this.images.map((s) => s.init(!0, t))), this.isInitialized = !0, this;
|
|
947
|
+
}
|
|
948
|
+
/**
|
|
949
|
+
* Read a IFD at a the provided offset
|
|
950
|
+
*
|
|
951
|
+
* @param offset file offset to read the header from
|
|
952
|
+
* @param view offset that contains the bytes for the header
|
|
953
|
+
*/
|
|
954
|
+
readIfd(t, n) {
|
|
955
|
+
const r = t - n.sourceOffset, o = K(n, r, this.ifdConfig.offset, this.isLittleEndian), i = /* @__PURE__ */ new Map(), a = o * this.ifdConfig.ifd;
|
|
956
|
+
if (!Y(n, t, a))
|
|
957
|
+
throw new Error("IFD out of range @ " + Rt(t) + " IFD" + this.images.length);
|
|
958
|
+
const s = this.ifdConfig.ifd, l = r + this.ifdConfig.offset;
|
|
959
|
+
for (let c = 0; c < o; c++) {
|
|
960
|
+
const d = Pt(this, n, l + c * s);
|
|
961
|
+
i.set(d.id, d);
|
|
962
|
+
}
|
|
963
|
+
return this.images.push(new Ft(this, this.images.length, i)), K(n, l + o * s, this.ifdConfig.pointer, this.isLittleEndian);
|
|
964
|
+
}
|
|
965
|
+
}
|
|
966
|
+
function Ie(e, t, n) {
|
|
967
|
+
const r = e.metadata?.size;
|
|
968
|
+
return r == null || r < 0 ? n : t + n > r ? r - t : n;
|
|
969
|
+
}
|
|
970
|
+
async function oe(e, t) {
|
|
971
|
+
const n = new Blob([e]), r = await createImageBitmap(n), o = new OffscreenCanvas(r.width, r.height), i = o.getContext("2d");
|
|
972
|
+
i.drawImage(r, 0, 0), r.close();
|
|
973
|
+
const { width: a, height: s } = o, c = i.getImageData(0, 0, a, s).data, d = t.samplesPerPixel;
|
|
974
|
+
if (d === 4)
|
|
975
|
+
return { layout: "pixel-interleaved", data: c };
|
|
976
|
+
if (d === 3) {
|
|
977
|
+
const h = a * s, g = new Uint8ClampedArray(h * 3);
|
|
978
|
+
for (let f = 0, S = 0; f < g.length; f += 3, S += 4)
|
|
979
|
+
g[f] = c[S], g[f + 1] = c[S + 1], g[f + 2] = c[S + 2];
|
|
980
|
+
return { layout: "pixel-interleaved", data: g };
|
|
981
|
+
}
|
|
982
|
+
if (d === 1) {
|
|
983
|
+
const h = a * s, g = new Uint8ClampedArray(h);
|
|
984
|
+
for (let f = 0, S = 0; f < h; f++, S += 4)
|
|
985
|
+
g[f] = c[S];
|
|
986
|
+
return { layout: "pixel-interleaved", data: g };
|
|
987
|
+
}
|
|
988
|
+
throw new Error(`Unsupported SamplesPerPixel for JPEG: ${d}`);
|
|
989
|
+
}
|
|
990
|
+
function vt(e, t = "") {
|
|
991
|
+
if (!e)
|
|
992
|
+
throw new Error(t);
|
|
993
|
+
}
|
|
994
|
+
async function Ut(e, { format: t, signal: n }) {
|
|
995
|
+
const r = e instanceof Response ? e : new Response(e);
|
|
996
|
+
vt(r.body, "Response does not contain body.");
|
|
997
|
+
try {
|
|
998
|
+
return await new Response(r.body.pipeThrough(new DecompressionStream(t), { signal: n })).arrayBuffer();
|
|
999
|
+
} catch {
|
|
1000
|
+
throw n?.throwIfAborted(), new Error(`Failed to decode ${t}`);
|
|
1001
|
+
}
|
|
1002
|
+
}
|
|
1003
|
+
async function xe(e) {
|
|
1004
|
+
return Ut(e, { format: "deflate" });
|
|
1005
|
+
}
|
|
1006
|
+
function Ot(e, t) {
|
|
1007
|
+
const n = e;
|
|
1008
|
+
let r = 0, o = e.length - t;
|
|
1009
|
+
do {
|
|
1010
|
+
for (let i = t; i > 0; i--)
|
|
1011
|
+
n[r + t] = (n[r + t] ?? 0) + (n[r] ?? 0), r++;
|
|
1012
|
+
o -= t;
|
|
1013
|
+
} while (o > 0);
|
|
1014
|
+
}
|
|
1015
|
+
function Mt(e, t, n) {
|
|
1016
|
+
let r = 0, o = e.length;
|
|
1017
|
+
const i = o / n;
|
|
1018
|
+
for (; o > t; ) {
|
|
1019
|
+
for (let s = t; s > 0; s--)
|
|
1020
|
+
e[r + t] += e[r], r++;
|
|
1021
|
+
o -= t;
|
|
1022
|
+
}
|
|
1023
|
+
const a = e.slice();
|
|
1024
|
+
for (let s = 0; s < i; s++)
|
|
1025
|
+
for (let l = 0; l < n; l++)
|
|
1026
|
+
e[n * s + l] = a[(n - l - 1) * i + s];
|
|
1027
|
+
}
|
|
1028
|
+
function Kt(e, t, n, r, o, i, a) {
|
|
1029
|
+
if (t === _.None)
|
|
1030
|
+
return e;
|
|
1031
|
+
const s = o / 8, l = a === U.Separate ? 1 : i;
|
|
1032
|
+
for (let c = 0; c < r; c++) {
|
|
1033
|
+
const d = c * l * n * s;
|
|
1034
|
+
if (d >= e.byteLength)
|
|
1035
|
+
break;
|
|
1036
|
+
if (t === _.Horizontal) {
|
|
1037
|
+
let h;
|
|
1038
|
+
const g = l * n;
|
|
1039
|
+
switch (o) {
|
|
1040
|
+
case 8:
|
|
1041
|
+
h = new Uint8Array(e, d, g);
|
|
1042
|
+
break;
|
|
1043
|
+
case 16:
|
|
1044
|
+
h = new Uint16Array(e, d, g);
|
|
1045
|
+
break;
|
|
1046
|
+
case 32:
|
|
1047
|
+
h = new Uint32Array(e, d, g);
|
|
1048
|
+
break;
|
|
1049
|
+
default:
|
|
1050
|
+
throw new Error(`Predictor 2 not supported for ${o} bits per sample.`);
|
|
1051
|
+
}
|
|
1052
|
+
Ot(h, l);
|
|
1053
|
+
} else if (t === _.FloatingPoint) {
|
|
1054
|
+
const h = new Uint8Array(e, d, l * n * s);
|
|
1055
|
+
Mt(h, l, s);
|
|
1056
|
+
}
|
|
1057
|
+
}
|
|
1058
|
+
return e;
|
|
1059
|
+
}
|
|
1060
|
+
async function Dt(e) {
|
|
1061
|
+
return e;
|
|
1062
|
+
}
|
|
1063
|
+
const A = /* @__PURE__ */ new Map();
|
|
1064
|
+
A.set(m.None, () => Promise.resolve(Dt));
|
|
1065
|
+
A.set(m.Deflate, () => Promise.resolve(xe));
|
|
1066
|
+
A.set(m.DeflateOther, () => Promise.resolve(xe));
|
|
1067
|
+
A.set(m.Lzw, () => import("./lzw-BY5a_5nb.js").then((e) => e.decode));
|
|
1068
|
+
A.set(m.Zstd, () => import("./zstd-jXobGRcq.js").then((e) => e.decode));
|
|
1069
|
+
A.set(m.Jpeg, () => Promise.resolve(oe));
|
|
1070
|
+
A.set(m.Jpeg6, () => Promise.resolve(oe));
|
|
1071
|
+
A.set(m.Webp, () => Promise.resolve(oe));
|
|
1072
|
+
A.set(m.Lerc, () => import("./lerc-Bl4IMkfo.js").then((e) => e.l).then((e) => e.decode));
|
|
1073
|
+
async function ie(e, t, n) {
|
|
1074
|
+
const r = A.get(t);
|
|
1075
|
+
if (!r)
|
|
1076
|
+
throw new Error(`Unsupported compression: ${t}`);
|
|
1077
|
+
const i = await (await r())(e, n);
|
|
1078
|
+
if (i instanceof ArrayBuffer) {
|
|
1079
|
+
const { predictor: a, width: s, height: l, bitsPerSample: c, samplesPerPixel: d, planarConfiguration: h } = n, g = Kt(i, a, s, l, c, d, h);
|
|
1080
|
+
return {
|
|
1081
|
+
layout: "pixel-interleaved",
|
|
1082
|
+
data: Nt(g, n)
|
|
1083
|
+
};
|
|
1084
|
+
}
|
|
1085
|
+
return i;
|
|
1086
|
+
}
|
|
1087
|
+
function xt(e, t) {
|
|
1088
|
+
const n = new Uint8Array(e), r = new Uint8Array(t);
|
|
1089
|
+
for (let o = 0; o < t; o++)
|
|
1090
|
+
r[o] = n[o >> 3] >> 7 - (o & 7) & 1 ? 255 : 0;
|
|
1091
|
+
return r;
|
|
1092
|
+
}
|
|
1093
|
+
function Nt(e, t) {
|
|
1094
|
+
const { sampleFormat: n, bitsPerSample: r } = t;
|
|
1095
|
+
switch (n) {
|
|
1096
|
+
case F.Uint:
|
|
1097
|
+
switch (r) {
|
|
1098
|
+
case 1:
|
|
1099
|
+
return xt(e, t.width * t.height * t.samplesPerPixel);
|
|
1100
|
+
case 8:
|
|
1101
|
+
return new Uint8Array(e);
|
|
1102
|
+
case 16:
|
|
1103
|
+
return new Uint16Array(e);
|
|
1104
|
+
case 32:
|
|
1105
|
+
return new Uint32Array(e);
|
|
1106
|
+
}
|
|
1107
|
+
break;
|
|
1108
|
+
case F.Int:
|
|
1109
|
+
switch (r) {
|
|
1110
|
+
case 8:
|
|
1111
|
+
return new Int8Array(e);
|
|
1112
|
+
case 16:
|
|
1113
|
+
return new Int16Array(e);
|
|
1114
|
+
case 32:
|
|
1115
|
+
return new Int32Array(e);
|
|
1116
|
+
}
|
|
1117
|
+
break;
|
|
1118
|
+
case F.Float:
|
|
1119
|
+
switch (r) {
|
|
1120
|
+
case 32:
|
|
1121
|
+
return new Float32Array(e);
|
|
1122
|
+
case 64:
|
|
1123
|
+
return new Float64Array(e);
|
|
1124
|
+
}
|
|
1125
|
+
break;
|
|
1126
|
+
}
|
|
1127
|
+
throw new Error(`Unsupported sample format/depth: SampleFormat=${n}, BitsPerSample=${r}`);
|
|
1128
|
+
}
|
|
1129
|
+
class zt {
|
|
1130
|
+
name = "source:cache";
|
|
1131
|
+
maxSize;
|
|
1132
|
+
/** Number of bytes cached in cacheA, when this overflows maxSize cacheA is moved to cacheB and cacheB is dropped */
|
|
1133
|
+
size = 0;
|
|
1134
|
+
/** Number of times `this.cacheB` has been cleared */
|
|
1135
|
+
resets = 0;
|
|
1136
|
+
/** Primary cache of objects */
|
|
1137
|
+
cacheA = /* @__PURE__ */ new Map();
|
|
1138
|
+
cacheB = /* @__PURE__ */ new Map();
|
|
1139
|
+
/** List of protocols to cache */
|
|
1140
|
+
protocols;
|
|
1141
|
+
constructor(t) {
|
|
1142
|
+
this.maxSize = t.size, this.protocols = new Set(t.protocols ?? []);
|
|
1143
|
+
}
|
|
1144
|
+
fetch(t, n) {
|
|
1145
|
+
if (this.protocols.size > 0 && !this.protocols.has(t.source.url.protocol) || t.length == null)
|
|
1146
|
+
return n(t);
|
|
1147
|
+
const r = `${t.source.url.toString()}@${t.offset}+${t.length}`;
|
|
1148
|
+
let o = this.cacheA.get(r);
|
|
1149
|
+
return o ? (o.hits++, o.promise) : (o = this.cacheB.get(r), o ? (o.hits++, o.saves++, this.size += o.size, this.cacheA.set(r, o), o.promise) : (o = { promise: n(t), hits: 0, saves: 0, size: t.length }, this.size += o.size, this.size > this.maxSize && (this.size = o.size, this.cacheB = this.cacheA, this.cacheA = /* @__PURE__ */ new Map(), this.resets++), this.cacheA.set(r, o), o.promise));
|
|
1150
|
+
}
|
|
1151
|
+
}
|
|
1152
|
+
class O extends Error {
|
|
1153
|
+
/** Status code for the error eg 403 - Forbidden vs 404 Not found */
|
|
1154
|
+
code;
|
|
1155
|
+
/** URL that the status code came from */
|
|
1156
|
+
url;
|
|
1157
|
+
/** File system that triggered the error */
|
|
1158
|
+
source;
|
|
1159
|
+
constructor(t, n, r, o) {
|
|
1160
|
+
super(t, { cause: o }), this.code = n, this.url = r.url, this.source = r, Object.defineProperty(this, "_sourceError", {
|
|
1161
|
+
enumerable: !1,
|
|
1162
|
+
// hide it from for..in
|
|
1163
|
+
value: "SourceError"
|
|
1164
|
+
});
|
|
1165
|
+
}
|
|
1166
|
+
/** Check that a unknown is a FsError */
|
|
1167
|
+
static is(t) {
|
|
1168
|
+
return t instanceof O ? !0 : typeof t != "object" || t == null ? !1 : "_sourceError" in t && t._sourceError === "SourceError";
|
|
1169
|
+
}
|
|
1170
|
+
}
|
|
1171
|
+
const X = {
|
|
1172
|
+
/** Convert a offset/length to a range request
|
|
1173
|
+
*
|
|
1174
|
+
* @example
|
|
1175
|
+
* ```typescript
|
|
1176
|
+
* ContentRange.toRange(10) // "bytes=10"
|
|
1177
|
+
* ContentRange.toRange(0, 1024) // "bytes=0-1023"
|
|
1178
|
+
* ```
|
|
1179
|
+
*/
|
|
1180
|
+
toRange(e, t) {
|
|
1181
|
+
if (t == null)
|
|
1182
|
+
return `bytes=${e}`;
|
|
1183
|
+
if (e < 0)
|
|
1184
|
+
throw new Error("Cannot read from remote source with negative offset and length");
|
|
1185
|
+
return `bytes=${e}-${e + t - 1}`;
|
|
1186
|
+
},
|
|
1187
|
+
/**
|
|
1188
|
+
* Parse a Content-Range header to extract the size of the source
|
|
1189
|
+
*
|
|
1190
|
+
* @example
|
|
1191
|
+
* ```typescript
|
|
1192
|
+
* ContentRange.parseRange("bytes 200-1000/67589"); // 67589
|
|
1193
|
+
* ```
|
|
1194
|
+
* @throws if range is not a Content-Range with size
|
|
1195
|
+
*/
|
|
1196
|
+
parseSize(e) {
|
|
1197
|
+
const [t, n] = e.split(" ");
|
|
1198
|
+
if (t !== "bytes")
|
|
1199
|
+
throw new Error("Failed to parse content-range: " + e);
|
|
1200
|
+
if (n == null)
|
|
1201
|
+
throw new Error("Failed to parse content-range: " + e);
|
|
1202
|
+
const [, r] = n.split("/"), o = Number(r);
|
|
1203
|
+
if (isNaN(o))
|
|
1204
|
+
throw new Error("Failed to parse content-range: " + e);
|
|
1205
|
+
return o;
|
|
1206
|
+
}
|
|
1207
|
+
};
|
|
1208
|
+
class Bt {
|
|
1209
|
+
source;
|
|
1210
|
+
middleware;
|
|
1211
|
+
static is(t) {
|
|
1212
|
+
return "middleware" in t;
|
|
1213
|
+
}
|
|
1214
|
+
constructor(t, n = []) {
|
|
1215
|
+
this.source = t, this.middleware = n;
|
|
1216
|
+
}
|
|
1217
|
+
get type() {
|
|
1218
|
+
return this.source.type;
|
|
1219
|
+
}
|
|
1220
|
+
get url() {
|
|
1221
|
+
return this.source.url;
|
|
1222
|
+
}
|
|
1223
|
+
get metadata() {
|
|
1224
|
+
return this.source.metadata;
|
|
1225
|
+
}
|
|
1226
|
+
head(t) {
|
|
1227
|
+
return this.source.head(t);
|
|
1228
|
+
}
|
|
1229
|
+
async fetch(t, n, r) {
|
|
1230
|
+
const o = this.middleware;
|
|
1231
|
+
if (o == null || o.length === 0)
|
|
1232
|
+
return this.source.fetch(t, n, r);
|
|
1233
|
+
const i = (a) => this.source.fetch(a.offset, a.length, r);
|
|
1234
|
+
return this.run(i, t, n, r);
|
|
1235
|
+
}
|
|
1236
|
+
/** Run a request using all the middleware */
|
|
1237
|
+
async run(t, n, r, o) {
|
|
1238
|
+
const i = this.middleware;
|
|
1239
|
+
if (i == null)
|
|
1240
|
+
return t({ source: this, offset: n, length: r, signal: o?.signal });
|
|
1241
|
+
function a(s, l) {
|
|
1242
|
+
return (c) => s.fetch(c, l);
|
|
1243
|
+
}
|
|
1244
|
+
for (let s = i.length - 1; s >= 0; s--)
|
|
1245
|
+
t = a(i[s], t);
|
|
1246
|
+
return t({ source: this, offset: n, length: r, signal: o?.signal });
|
|
1247
|
+
}
|
|
1248
|
+
}
|
|
1249
|
+
function _t(e) {
|
|
1250
|
+
try {
|
|
1251
|
+
return new URL(e);
|
|
1252
|
+
} catch {
|
|
1253
|
+
return null;
|
|
1254
|
+
}
|
|
1255
|
+
}
|
|
1256
|
+
class kt {
|
|
1257
|
+
name = "source:chunk";
|
|
1258
|
+
/** Number of bytes to chunk requests into */
|
|
1259
|
+
chunkSize;
|
|
1260
|
+
constructor(t) {
|
|
1261
|
+
this.chunkSize = t.size ?? 32 * 1024;
|
|
1262
|
+
}
|
|
1263
|
+
async fetch(t, n) {
|
|
1264
|
+
if (t.offset < 0 || t.length == null)
|
|
1265
|
+
return n(t);
|
|
1266
|
+
const r = Math.floor(t.offset / this.chunkSize), o = Math.ceil((t.offset + t.length) / this.chunkSize), i = t.source.metadata?.size;
|
|
1267
|
+
if (i != null && t.offset + t.length > i)
|
|
1268
|
+
throw new O(`Request outside of bounds ${X.toRange(t.offset, t.length)}`, 416, t.source);
|
|
1269
|
+
const a = r * this.chunkSize, l = (i != null ? Math.min(o * this.chunkSize, i) : o * this.chunkSize) - a, c = t.offset - a;
|
|
1270
|
+
return o - r > 1 ? (await this.fetchChunks(t, r, o)).slice(c, c + t.length) : t.offset === a && t.length === l ? n(t) : (await n({ ...t, offset: a, length: l })).slice(c, c + t.length);
|
|
1271
|
+
}
|
|
1272
|
+
async fetchChunks(t, n, r) {
|
|
1273
|
+
const o = [], i = t.source.metadata?.size ?? r * this.chunkSize;
|
|
1274
|
+
for (let l = n; l < r; l++) {
|
|
1275
|
+
const c = l * this.chunkSize, h = Math.min(c + this.chunkSize, i) - c;
|
|
1276
|
+
o.push(t.source.fetch(l * this.chunkSize, h, t.signal ? { signal: t.signal } : void 0));
|
|
1277
|
+
}
|
|
1278
|
+
const a = await Promise.all(o), s = new Uint8Array(o.length * this.chunkSize);
|
|
1279
|
+
for (let l = 0; l < a.length; l++)
|
|
1280
|
+
s.set(new Uint8Array(a[l]), l * this.chunkSize);
|
|
1281
|
+
return s.buffer;
|
|
1282
|
+
}
|
|
1283
|
+
}
|
|
1284
|
+
function Ge(e) {
|
|
1285
|
+
const t = {}, n = e.headers.get("content-length");
|
|
1286
|
+
n && (t.size = parseInt(n));
|
|
1287
|
+
const r = e.headers.get("content-range");
|
|
1288
|
+
return r != null && (t.size = X.parseSize(r)), t.eTag = e.headers.get("etag") ?? void 0, t.contentType = e.headers.get("content-type") ?? void 0, t.contentDisposition = e.headers.get("content-disposition") ?? void 0, t.cacheControl = e.headers.get("cache-control") ?? void 0, t.contentEncoding = e.headers.get("content-encoding") ?? void 0, t;
|
|
1289
|
+
}
|
|
1290
|
+
class k {
|
|
1291
|
+
constructor(t, n) {
|
|
1292
|
+
this.type = "http", this.url = typeof t == "string" ? k.tryUrl(t) : t, this.headers = n;
|
|
1293
|
+
}
|
|
1294
|
+
/** Attempt to parse a relative string into a URL */
|
|
1295
|
+
static tryUrl(t) {
|
|
1296
|
+
try {
|
|
1297
|
+
return new URL(t);
|
|
1298
|
+
} catch {
|
|
1299
|
+
return typeof document < "u" ? new URL(t, document.baseURI) : new URL(t, import.meta.url);
|
|
1300
|
+
}
|
|
1301
|
+
}
|
|
1302
|
+
head() {
|
|
1303
|
+
return this._head ? this._head : (this._head = k.fetch(this.url, { method: "HEAD", headers: this.headers }).then((t) => {
|
|
1304
|
+
if (!t.ok)
|
|
1305
|
+
throw delete this._head, new Error(`Failed to HEAD ${this.url.href}`, { cause: { statusCode: t.status, msg: t.statusText } });
|
|
1306
|
+
return this.metadata = Ge(t), this.metadata;
|
|
1307
|
+
}), this._head);
|
|
1308
|
+
}
|
|
1309
|
+
async fetch(t, n, r) {
|
|
1310
|
+
try {
|
|
1311
|
+
const o = { range: X.toRange(t, n), ...this.headers }, i = await k.fetch(this.url, { headers: o, signal: r?.signal });
|
|
1312
|
+
if (!i.ok)
|
|
1313
|
+
throw new O(`Failed to fetch ${this.url.href} ${o.range}`, i.status, this, new Error(i.statusText));
|
|
1314
|
+
const a = Ge(i);
|
|
1315
|
+
if (this.metadata == null)
|
|
1316
|
+
this.metadata = a;
|
|
1317
|
+
else if (this.metadata.eTag && this.metadata.eTag !== a.eTag)
|
|
1318
|
+
throw new O(`ETag conflict ${this.url.href} ${o.range} expected: ${this.metadata.eTag} got: ${a.eTag}`, 409, this);
|
|
1319
|
+
return i.arrayBuffer();
|
|
1320
|
+
} catch (o) {
|
|
1321
|
+
throw O.is(o) && o.source === this ? o : new O(`Failed to fetch: ${this.url.href}`, 500, this, o);
|
|
1322
|
+
}
|
|
1323
|
+
}
|
|
1324
|
+
}
|
|
1325
|
+
k.fetch = (e, t) => fetch(e, t);
|
|
1326
|
+
function $t(e) {
|
|
1327
|
+
if (typeof e != "string")
|
|
1328
|
+
return e;
|
|
1329
|
+
const t = _t(e);
|
|
1330
|
+
return t || new URL("memory://" + e);
|
|
1331
|
+
}
|
|
1332
|
+
class ae {
|
|
1333
|
+
url;
|
|
1334
|
+
type = "memory";
|
|
1335
|
+
data;
|
|
1336
|
+
metadata;
|
|
1337
|
+
static toArrayBuffer(t) {
|
|
1338
|
+
return t instanceof ArrayBuffer ? t : t.byteLength === t.buffer.byteLength ? t.buffer : t.buffer.slice(t.byteOffset, t.byteOffset + t.byteLength);
|
|
1339
|
+
}
|
|
1340
|
+
constructor(t, n) {
|
|
1341
|
+
const r = ae.toArrayBuffer(n ?? new Uint8Array());
|
|
1342
|
+
this.url = $t(t), this.data = r, this.metadata = { size: r.byteLength };
|
|
1343
|
+
}
|
|
1344
|
+
head() {
|
|
1345
|
+
return Promise.resolve({ size: this.data.byteLength });
|
|
1346
|
+
}
|
|
1347
|
+
fetch(t, n) {
|
|
1348
|
+
if (t < 0 && (t = this.data.byteLength + t), t > this.data.byteLength)
|
|
1349
|
+
throw new O(`Read offset outside of file bounds range:${X.toRange(t, n)} fileSize:${this.data.byteLength}`, 416, this);
|
|
1350
|
+
return Promise.resolve(this.data.slice(t, n == null ? void 0 : t + n));
|
|
1351
|
+
}
|
|
1352
|
+
}
|
|
1353
|
+
const Ne = "https://proj.org/schemas/v0.7/projjson.schema.json", Wt = 1, Jt = 2, V = 32767, je = 1, Vt = 2, Ht = 3, Yt = 4, Xt = 5, Zt = 6, Qt = 7, qt = 8, Tt = 9, en = 10, tn = 11, nn = 12, rn = 14, on = 15, an = 16, sn = 17, ln = 18, cn = 21, un = 22, dn = 24, hn = 26, pn = 27, ze = 9102, gn = 9101, mn = 9105, fn = {
|
|
1354
|
+
[ze]: "degree",
|
|
1355
|
+
[gn]: "radian",
|
|
1356
|
+
[mn]: "grad"
|
|
1357
|
+
}, Be = 9001, yn = 9002, wn = 9003, Sn = {
|
|
1358
|
+
type: "LinearUnit",
|
|
1359
|
+
name: "US survey foot",
|
|
1360
|
+
conversion_factor: 0.30480060960121924
|
|
1361
|
+
}, Pn = {
|
|
1362
|
+
[Be]: "metre",
|
|
1363
|
+
[yn]: "foot",
|
|
1364
|
+
[wn]: Sn
|
|
1365
|
+
};
|
|
1366
|
+
function Cn(e) {
|
|
1367
|
+
const t = e.modelType;
|
|
1368
|
+
if (t === Wt)
|
|
1369
|
+
return bn(e);
|
|
1370
|
+
if (t === Jt)
|
|
1371
|
+
return Ln(e);
|
|
1372
|
+
throw new Error(`Unsupported GeoTIFF model type: ${t}`);
|
|
1373
|
+
}
|
|
1374
|
+
function Ln(e) {
|
|
1375
|
+
const t = e.geodeticCRS;
|
|
1376
|
+
return t !== null && t !== V ? t : _e(e, Ne);
|
|
1377
|
+
}
|
|
1378
|
+
function bn(e) {
|
|
1379
|
+
const t = e.projectedCRS;
|
|
1380
|
+
return t !== null && t !== V ? t : In(e);
|
|
1381
|
+
}
|
|
1382
|
+
function _e(e, t) {
|
|
1383
|
+
const n = Gn(e);
|
|
1384
|
+
let r = "Greenwich", o = 0;
|
|
1385
|
+
e.primeMeridian !== null && e.primeMeridian !== V ? r = `EPSG:${e.primeMeridian}` : e.primeMeridianLongitude !== null && (o = e.primeMeridianLongitude, r = "User-defined");
|
|
1386
|
+
let i;
|
|
1387
|
+
e.geodeticDatum !== null && e.geodeticDatum !== V ? i = {
|
|
1388
|
+
type: "GeodeticReferenceFrame",
|
|
1389
|
+
name: `Unknown datum based upon EPSG ${e.geodeticDatum} ellipsoid`
|
|
1390
|
+
} : i = {
|
|
1391
|
+
type: "GeodeticReferenceFrame",
|
|
1392
|
+
name: e.geodeticCitation ?? "User-defined",
|
|
1393
|
+
ellipsoid: n,
|
|
1394
|
+
prime_meridian: { name: r, longitude: o }
|
|
1395
|
+
};
|
|
1396
|
+
const a = {
|
|
1397
|
+
type: "GeographicCRS",
|
|
1398
|
+
name: e.geodeticCitation ?? "User-defined",
|
|
1399
|
+
datum: i,
|
|
1400
|
+
coordinate_system: En(e)
|
|
1401
|
+
};
|
|
1402
|
+
return t !== void 0 && (a.$schema = t), a;
|
|
1403
|
+
}
|
|
1404
|
+
function In(e) {
|
|
1405
|
+
const t = _e(e), n = jn(e), r = Fn(e);
|
|
1406
|
+
return {
|
|
1407
|
+
type: "ProjectedCRS",
|
|
1408
|
+
$schema: Ne,
|
|
1409
|
+
name: e.projectedCitation ?? e.citation ?? "User-defined",
|
|
1410
|
+
base_crs: t,
|
|
1411
|
+
conversion: n,
|
|
1412
|
+
coordinate_system: r
|
|
1413
|
+
};
|
|
1414
|
+
}
|
|
1415
|
+
function Gn(e) {
|
|
1416
|
+
if (e.ellipsoid !== null && e.ellipsoid !== V) {
|
|
1417
|
+
const n = {
|
|
1418
|
+
name: `EPSG ellipsoid ${e.ellipsoid}`
|
|
1419
|
+
};
|
|
1420
|
+
return e.ellipsoidSemiMajorAxis !== null && (n.semi_major_axis = e.ellipsoidSemiMajorAxis), e.ellipsoidInvFlattening !== null ? n.inverse_flattening = e.ellipsoidInvFlattening : e.ellipsoidSemiMinorAxis !== null && (n.semi_minor_axis = e.ellipsoidSemiMinorAxis), n;
|
|
1421
|
+
}
|
|
1422
|
+
if (e.ellipsoidSemiMajorAxis === null)
|
|
1423
|
+
throw new Error("User-defined ellipsoid requires ellipsoidSemiMajorAxis");
|
|
1424
|
+
const t = {
|
|
1425
|
+
name: e.geodeticCitation ?? "User-defined",
|
|
1426
|
+
semi_major_axis: e.ellipsoidSemiMajorAxis
|
|
1427
|
+
};
|
|
1428
|
+
if (e.ellipsoidInvFlattening !== null)
|
|
1429
|
+
t.inverse_flattening = e.ellipsoidInvFlattening;
|
|
1430
|
+
else if (e.ellipsoidSemiMinorAxis !== null)
|
|
1431
|
+
t.semi_minor_axis = e.ellipsoidSemiMinorAxis;
|
|
1432
|
+
else
|
|
1433
|
+
throw new Error("User-defined ellipsoid requires ellipsoidInvFlattening or ellipsoidSemiMinorAxis");
|
|
1434
|
+
return t;
|
|
1435
|
+
}
|
|
1436
|
+
function jn(e) {
|
|
1437
|
+
const t = e.projMethod;
|
|
1438
|
+
if (t === null)
|
|
1439
|
+
throw new Error("User-defined projected CRS requires projMethod");
|
|
1440
|
+
const n = (i, a, s = 0) => ({
|
|
1441
|
+
name: i,
|
|
1442
|
+
value: a ?? s,
|
|
1443
|
+
unit: "degree"
|
|
1444
|
+
}), r = (i, a, s = 0) => ({
|
|
1445
|
+
name: i,
|
|
1446
|
+
value: a ?? s,
|
|
1447
|
+
unit: "metre"
|
|
1448
|
+
}), o = (i, a, s = 1) => ({
|
|
1449
|
+
name: i,
|
|
1450
|
+
value: a ?? s,
|
|
1451
|
+
unit: "unity"
|
|
1452
|
+
});
|
|
1453
|
+
switch (t) {
|
|
1454
|
+
case je:
|
|
1455
|
+
case Vt:
|
|
1456
|
+
case pn: {
|
|
1457
|
+
const i = t === je ? "Transverse Mercator" : "Transverse Mercator (South Orientated)";
|
|
1458
|
+
return {
|
|
1459
|
+
name: i,
|
|
1460
|
+
method: { name: i },
|
|
1461
|
+
parameters: [
|
|
1462
|
+
n("Latitude of natural origin", e.projNatOriginLat),
|
|
1463
|
+
n("Longitude of natural origin", e.projNatOriginLong),
|
|
1464
|
+
o("Scale factor at natural origin", e.projScaleAtNatOrigin),
|
|
1465
|
+
r("False easting", e.projFalseEasting),
|
|
1466
|
+
r("False northing", e.projFalseNorthing)
|
|
1467
|
+
]
|
|
1468
|
+
};
|
|
1469
|
+
}
|
|
1470
|
+
case Ht:
|
|
1471
|
+
case Yt:
|
|
1472
|
+
case Xt:
|
|
1473
|
+
case Zt: {
|
|
1474
|
+
const i = "Hotine Oblique Mercator (variant B)";
|
|
1475
|
+
return {
|
|
1476
|
+
name: i,
|
|
1477
|
+
method: { name: i },
|
|
1478
|
+
parameters: [
|
|
1479
|
+
n("Latitude of projection centre", e.projCenterLat),
|
|
1480
|
+
n("Longitude of projection centre", e.projCenterLong),
|
|
1481
|
+
n("Azimuth of initial line", e.projAzimuthAngle),
|
|
1482
|
+
n("Angle from Rectified to Skew Grid", e.projAzimuthAngle),
|
|
1483
|
+
o("Scale factor on initial line", e.projScaleAtCenter),
|
|
1484
|
+
r("Easting at projection centre", e.projCenterEasting),
|
|
1485
|
+
r("Northing at projection centre", e.projCenterNorthing)
|
|
1486
|
+
]
|
|
1487
|
+
};
|
|
1488
|
+
}
|
|
1489
|
+
case Qt: {
|
|
1490
|
+
const i = "Mercator (variant A)";
|
|
1491
|
+
return {
|
|
1492
|
+
name: i,
|
|
1493
|
+
method: { name: i },
|
|
1494
|
+
parameters: [
|
|
1495
|
+
n("Latitude of natural origin", e.projNatOriginLat),
|
|
1496
|
+
n("Longitude of natural origin", e.projNatOriginLong),
|
|
1497
|
+
o("Scale factor at natural origin", e.projScaleAtNatOrigin),
|
|
1498
|
+
r("False easting", e.projFalseEasting),
|
|
1499
|
+
r("False northing", e.projFalseNorthing)
|
|
1500
|
+
]
|
|
1501
|
+
};
|
|
1502
|
+
}
|
|
1503
|
+
case qt: {
|
|
1504
|
+
const i = "Lambert Conic Conformal (2SP)";
|
|
1505
|
+
return {
|
|
1506
|
+
name: i,
|
|
1507
|
+
method: { name: i },
|
|
1508
|
+
parameters: [
|
|
1509
|
+
n("Latitude of false origin", e.projFalseOriginLat ?? e.projNatOriginLat),
|
|
1510
|
+
n("Longitude of false origin", e.projFalseOriginLong ?? e.projNatOriginLong),
|
|
1511
|
+
n("Latitude of 1st standard parallel", e.projStdParallel1),
|
|
1512
|
+
n("Latitude of 2nd standard parallel", e.projStdParallel2),
|
|
1513
|
+
r("Easting at false origin", e.projFalseOriginEasting ?? e.projFalseEasting),
|
|
1514
|
+
r("Northing at false origin", e.projFalseOriginNorthing ?? e.projFalseNorthing)
|
|
1515
|
+
]
|
|
1516
|
+
};
|
|
1517
|
+
}
|
|
1518
|
+
case Tt: {
|
|
1519
|
+
const i = "Lambert Conic Conformal (1SP)";
|
|
1520
|
+
return {
|
|
1521
|
+
name: i,
|
|
1522
|
+
method: { name: i },
|
|
1523
|
+
parameters: [
|
|
1524
|
+
n("Latitude of natural origin", e.projNatOriginLat),
|
|
1525
|
+
n("Longitude of natural origin", e.projNatOriginLong),
|
|
1526
|
+
o("Scale factor at natural origin", e.projScaleAtNatOrigin),
|
|
1527
|
+
r("False easting", e.projFalseEasting),
|
|
1528
|
+
r("False northing", e.projFalseNorthing)
|
|
1529
|
+
]
|
|
1530
|
+
};
|
|
1531
|
+
}
|
|
1532
|
+
case en: {
|
|
1533
|
+
const i = "Lambert Azimuthal Equal Area";
|
|
1534
|
+
return {
|
|
1535
|
+
name: i,
|
|
1536
|
+
method: { name: i },
|
|
1537
|
+
parameters: [
|
|
1538
|
+
n("Latitude of natural origin", e.projCenterLat),
|
|
1539
|
+
n("Longitude of natural origin", e.projCenterLong),
|
|
1540
|
+
r("False easting", e.projFalseEasting),
|
|
1541
|
+
r("False northing", e.projFalseNorthing)
|
|
1542
|
+
]
|
|
1543
|
+
};
|
|
1544
|
+
}
|
|
1545
|
+
case tn: {
|
|
1546
|
+
const i = "Albers Equal Area";
|
|
1547
|
+
return {
|
|
1548
|
+
name: i,
|
|
1549
|
+
method: { name: i },
|
|
1550
|
+
parameters: [
|
|
1551
|
+
n("Latitude of false origin", e.projFalseOriginLat ?? e.projNatOriginLat),
|
|
1552
|
+
n("Longitude of false origin", e.projFalseOriginLong ?? e.projNatOriginLong),
|
|
1553
|
+
n("Latitude of 1st standard parallel", e.projStdParallel1),
|
|
1554
|
+
n("Latitude of 2nd standard parallel", e.projStdParallel2),
|
|
1555
|
+
r("Easting at false origin", e.projFalseOriginEasting ?? e.projFalseEasting),
|
|
1556
|
+
r("Northing at false origin", e.projFalseOriginNorthing ?? e.projFalseNorthing)
|
|
1557
|
+
]
|
|
1558
|
+
};
|
|
1559
|
+
}
|
|
1560
|
+
case nn: {
|
|
1561
|
+
const i = "Modified Azimuthal Equidistant";
|
|
1562
|
+
return {
|
|
1563
|
+
name: i,
|
|
1564
|
+
method: { name: i },
|
|
1565
|
+
parameters: [
|
|
1566
|
+
n("Latitude of natural origin", e.projCenterLat),
|
|
1567
|
+
n("Longitude of natural origin", e.projCenterLong),
|
|
1568
|
+
r("False easting", e.projFalseEasting),
|
|
1569
|
+
r("False northing", e.projFalseNorthing)
|
|
1570
|
+
]
|
|
1571
|
+
};
|
|
1572
|
+
}
|
|
1573
|
+
case rn: {
|
|
1574
|
+
const i = "Stereographic";
|
|
1575
|
+
return {
|
|
1576
|
+
name: i,
|
|
1577
|
+
method: { name: i },
|
|
1578
|
+
parameters: [
|
|
1579
|
+
n("Latitude of natural origin", e.projCenterLat),
|
|
1580
|
+
n("Longitude of natural origin", e.projCenterLong),
|
|
1581
|
+
o("Scale factor at natural origin", e.projScaleAtCenter),
|
|
1582
|
+
r("False easting", e.projFalseEasting),
|
|
1583
|
+
r("False northing", e.projFalseNorthing)
|
|
1584
|
+
]
|
|
1585
|
+
};
|
|
1586
|
+
}
|
|
1587
|
+
case on: {
|
|
1588
|
+
const i = "Polar Stereographic (variant B)";
|
|
1589
|
+
return {
|
|
1590
|
+
name: i,
|
|
1591
|
+
method: { name: i },
|
|
1592
|
+
parameters: [
|
|
1593
|
+
n("Latitude of standard parallel", e.projNatOriginLat ?? e.projStdParallel1),
|
|
1594
|
+
n("Longitude of origin", e.projStraightVertPoleLong ?? e.projNatOriginLong),
|
|
1595
|
+
r("False easting", e.projFalseEasting),
|
|
1596
|
+
r("False northing", e.projFalseNorthing)
|
|
1597
|
+
]
|
|
1598
|
+
};
|
|
1599
|
+
}
|
|
1600
|
+
case an: {
|
|
1601
|
+
const i = "Oblique Stereographic";
|
|
1602
|
+
return {
|
|
1603
|
+
name: i,
|
|
1604
|
+
method: { name: i },
|
|
1605
|
+
parameters: [
|
|
1606
|
+
n("Latitude of natural origin", e.projCenterLat),
|
|
1607
|
+
n("Longitude of natural origin", e.projCenterLong),
|
|
1608
|
+
o("Scale factor at natural origin", e.projScaleAtCenter),
|
|
1609
|
+
r("False easting", e.projFalseEasting),
|
|
1610
|
+
r("False northing", e.projFalseNorthing)
|
|
1611
|
+
]
|
|
1612
|
+
};
|
|
1613
|
+
}
|
|
1614
|
+
case sn: {
|
|
1615
|
+
const i = "Equidistant Cylindrical";
|
|
1616
|
+
return {
|
|
1617
|
+
name: i,
|
|
1618
|
+
method: { name: i },
|
|
1619
|
+
parameters: [
|
|
1620
|
+
n("Latitude of 1st standard parallel", e.projStdParallel1 ?? e.projCenterLat),
|
|
1621
|
+
n("Longitude of natural origin", e.projCenterLong),
|
|
1622
|
+
r("False easting", e.projFalseEasting),
|
|
1623
|
+
r("False northing", e.projFalseNorthing)
|
|
1624
|
+
]
|
|
1625
|
+
};
|
|
1626
|
+
}
|
|
1627
|
+
case ln: {
|
|
1628
|
+
const i = "Cassini-Soldner";
|
|
1629
|
+
return {
|
|
1630
|
+
name: i,
|
|
1631
|
+
method: { name: i },
|
|
1632
|
+
parameters: [
|
|
1633
|
+
n("Latitude of natural origin", e.projNatOriginLat),
|
|
1634
|
+
n("Longitude of natural origin", e.projNatOriginLong),
|
|
1635
|
+
r("False easting", e.projFalseEasting),
|
|
1636
|
+
r("False northing", e.projFalseNorthing)
|
|
1637
|
+
]
|
|
1638
|
+
};
|
|
1639
|
+
}
|
|
1640
|
+
case un: {
|
|
1641
|
+
const i = "American Polyconic";
|
|
1642
|
+
return {
|
|
1643
|
+
name: i,
|
|
1644
|
+
method: { name: i },
|
|
1645
|
+
parameters: [
|
|
1646
|
+
n("Latitude of natural origin", e.projNatOriginLat),
|
|
1647
|
+
n("Longitude of natural origin", e.projNatOriginLong),
|
|
1648
|
+
r("False easting", e.projFalseEasting),
|
|
1649
|
+
r("False northing", e.projFalseNorthing)
|
|
1650
|
+
]
|
|
1651
|
+
};
|
|
1652
|
+
}
|
|
1653
|
+
case dn: {
|
|
1654
|
+
const i = "Sinusoidal";
|
|
1655
|
+
return {
|
|
1656
|
+
name: i,
|
|
1657
|
+
method: { name: i },
|
|
1658
|
+
parameters: [
|
|
1659
|
+
n("Longitude of natural origin", e.projCenterLong),
|
|
1660
|
+
r("False easting", e.projFalseEasting),
|
|
1661
|
+
r("False northing", e.projFalseNorthing)
|
|
1662
|
+
]
|
|
1663
|
+
};
|
|
1664
|
+
}
|
|
1665
|
+
case cn: {
|
|
1666
|
+
const i = "Orthographic";
|
|
1667
|
+
return {
|
|
1668
|
+
name: i,
|
|
1669
|
+
method: { name: i },
|
|
1670
|
+
parameters: [
|
|
1671
|
+
n("Latitude of natural origin", e.projCenterLat),
|
|
1672
|
+
n("Longitude of natural origin", e.projCenterLong),
|
|
1673
|
+
r("False easting", e.projFalseEasting),
|
|
1674
|
+
r("False northing", e.projFalseNorthing)
|
|
1675
|
+
]
|
|
1676
|
+
};
|
|
1677
|
+
}
|
|
1678
|
+
case hn: {
|
|
1679
|
+
const i = "New Zealand Map Grid";
|
|
1680
|
+
return {
|
|
1681
|
+
name: i,
|
|
1682
|
+
method: { name: i },
|
|
1683
|
+
parameters: [
|
|
1684
|
+
n("Latitude of natural origin", e.projNatOriginLat),
|
|
1685
|
+
n("Longitude of natural origin", e.projNatOriginLong),
|
|
1686
|
+
r("False easting", e.projFalseEasting),
|
|
1687
|
+
r("False northing", e.projFalseNorthing)
|
|
1688
|
+
]
|
|
1689
|
+
};
|
|
1690
|
+
}
|
|
1691
|
+
default:
|
|
1692
|
+
throw new Error(`Unsupported coordinate transformation type: ${t}`);
|
|
1693
|
+
}
|
|
1694
|
+
}
|
|
1695
|
+
function En(e) {
|
|
1696
|
+
const t = fn[e.angularUnits ?? ze] ?? "degree";
|
|
1697
|
+
return {
|
|
1698
|
+
subtype: "ellipsoidal",
|
|
1699
|
+
axis: [
|
|
1700
|
+
{
|
|
1701
|
+
name: "Geodetic latitude",
|
|
1702
|
+
abbreviation: "Lat",
|
|
1703
|
+
direction: "north",
|
|
1704
|
+
unit: t
|
|
1705
|
+
},
|
|
1706
|
+
{
|
|
1707
|
+
name: "Geodetic longitude",
|
|
1708
|
+
abbreviation: "Lon",
|
|
1709
|
+
direction: "east",
|
|
1710
|
+
unit: t
|
|
1711
|
+
}
|
|
1712
|
+
]
|
|
1713
|
+
};
|
|
1714
|
+
}
|
|
1715
|
+
function Fn(e) {
|
|
1716
|
+
const t = Pn[e.projLinearUnits ?? Be] ?? "metre";
|
|
1717
|
+
return {
|
|
1718
|
+
subtype: "Cartesian",
|
|
1719
|
+
axis: [
|
|
1720
|
+
{ name: "Easting", abbreviation: "E", direction: "east", unit: t },
|
|
1721
|
+
{ name: "Northing", abbreviation: "N", direction: "north", unit: t }
|
|
1722
|
+
]
|
|
1723
|
+
};
|
|
1724
|
+
}
|
|
1725
|
+
const An = 1024 * 1024, Rn = 16 * 1024 * 1024, Ee = 6;
|
|
1726
|
+
async function vn(e, t, n) {
|
|
1727
|
+
if (t.length === 0)
|
|
1728
|
+
return [];
|
|
1729
|
+
const r = n?.coalesce ?? An, o = n?.maxRangeSize ?? Rn, i = n?.signal, a = Un(t, r, o), s = await Mn(e, a, i), l = new Array(t.length);
|
|
1730
|
+
for (let c = 0; c < t.length; c++) {
|
|
1731
|
+
const d = t[c], h = On(a, d.offset), g = a[h], f = s[h], S = d.offset - g.offset, P = S + d.length;
|
|
1732
|
+
if (P > f.byteLength)
|
|
1733
|
+
throw new Error(`Failed to fetch bytes from offset:${d.offset} wanted:${d.length} got:${f.byteLength - S}`);
|
|
1734
|
+
l[c] = f.slice(S, P);
|
|
1735
|
+
}
|
|
1736
|
+
return l;
|
|
1737
|
+
}
|
|
1738
|
+
function Un(e, t, n) {
|
|
1739
|
+
const r = [...e].sort((a, s) => a.offset - s.offset), o = [];
|
|
1740
|
+
let i = null;
|
|
1741
|
+
for (const a of r) {
|
|
1742
|
+
if (i == null) {
|
|
1743
|
+
i = { offset: a.offset, length: a.length };
|
|
1744
|
+
continue;
|
|
1745
|
+
}
|
|
1746
|
+
const s = i.offset + i.length, l = a.offset + a.length, c = a.offset - s, d = Math.max(s, l), h = d - i.offset;
|
|
1747
|
+
c <= t && h <= n ? i.length = d - i.offset : (o.push(i), i = { offset: a.offset, length: a.length });
|
|
1748
|
+
}
|
|
1749
|
+
return i != null && o.push(i), o;
|
|
1750
|
+
}
|
|
1751
|
+
function On(e, t) {
|
|
1752
|
+
let n = 0, r = e.length - 1;
|
|
1753
|
+
for (; n < r; ) {
|
|
1754
|
+
const o = n + r + 1 >>> 1;
|
|
1755
|
+
e[o].offset <= t ? n = o : r = o - 1;
|
|
1756
|
+
}
|
|
1757
|
+
return n;
|
|
1758
|
+
}
|
|
1759
|
+
async function Mn(e, t, n) {
|
|
1760
|
+
const r = new Array(t.length);
|
|
1761
|
+
for (let o = 0; o < t.length; o += Ee) {
|
|
1762
|
+
const i = t.slice(o, o + Ee), a = await Promise.all(i.map((s) => e.fetch(s.offset, s.length, { signal: n })));
|
|
1763
|
+
for (let s = 0; s < a.length; s++)
|
|
1764
|
+
r[o + s] = a[s];
|
|
1765
|
+
}
|
|
1766
|
+
return r;
|
|
1767
|
+
}
|
|
1768
|
+
async function ke(e, t, n, { boundless: r = !0, pool: o, signal: i } = {}) {
|
|
1769
|
+
const a = xn(e, t, n, { signal: i }), s = e.maskImage != null ? Ve(e.maskImage, t, n, e.dataSource, {
|
|
1770
|
+
signal: i,
|
|
1771
|
+
debug: e._debug ? { label: "mask" } : void 0
|
|
1772
|
+
}) : Promise.resolve(null), [l, c] = await Promise.all([a, s]);
|
|
1773
|
+
return $e(e, t, n, l, c, { boundless: r, pool: o });
|
|
1774
|
+
}
|
|
1775
|
+
async function $e(e, t, n, r, o, { boundless: i, pool: a }) {
|
|
1776
|
+
const { bitsPerSample: s, predictor: l, planarConfiguration: c, sampleFormat: d, lercParameters: h } = e.cachedTags, { sampleFormat: g, bitsPerSample: f } = Ze(d, s), S = re(e.transform, Ae(t * e.tileWidth, n * e.tileHeight)), P = e.image.value(u.SamplesPerPixel) ?? 1, C = {
|
|
1777
|
+
sampleFormat: g,
|
|
1778
|
+
bitsPerSample: f,
|
|
1779
|
+
samplesPerPixel: P,
|
|
1780
|
+
width: e.tileWidth,
|
|
1781
|
+
height: e.tileHeight,
|
|
1782
|
+
predictor: l,
|
|
1783
|
+
planarConfiguration: c,
|
|
1784
|
+
lercParameters: h
|
|
1785
|
+
}, [j, b] = await Promise.all([
|
|
1786
|
+
Dn(r, C, a),
|
|
1787
|
+
o != null && e.maskImage != null ? Kn(o, e.maskImage, a) : Promise.resolve(null)
|
|
1788
|
+
]), G = {
|
|
1789
|
+
...j,
|
|
1790
|
+
count: P,
|
|
1791
|
+
height: e.tileHeight,
|
|
1792
|
+
width: e.tileWidth,
|
|
1793
|
+
mask: b,
|
|
1794
|
+
transform: S,
|
|
1795
|
+
crs: e.crs,
|
|
1796
|
+
nodata: e.nodata
|
|
1797
|
+
};
|
|
1798
|
+
return {
|
|
1799
|
+
x: t,
|
|
1800
|
+
y: n,
|
|
1801
|
+
array: i === !0 ? G : _n(e, t, n, G)
|
|
1802
|
+
};
|
|
1803
|
+
}
|
|
1804
|
+
async function We(e, t, { boundless: n = !0, pool: r, signal: o } = {}) {
|
|
1805
|
+
if (t.length === 0)
|
|
1806
|
+
return [];
|
|
1807
|
+
const i = zn(e, t, { signal: o }), a = e.maskImage != null ? Xe(e.maskImage, t, e.dataSource, {
|
|
1808
|
+
signal: o,
|
|
1809
|
+
debug: e._debug ? { label: "mask" } : void 0
|
|
1810
|
+
}) : Promise.resolve(t.map(() => null)), [s, l] = await Promise.all([
|
|
1811
|
+
i,
|
|
1812
|
+
a
|
|
1813
|
+
]);
|
|
1814
|
+
return Promise.all(t.map(([c, d], h) => $e(e, c, d, s[h], l[h] ?? null, {
|
|
1815
|
+
boundless: n,
|
|
1816
|
+
pool: r
|
|
1817
|
+
})));
|
|
1818
|
+
}
|
|
1819
|
+
async function Kn(e, t, n) {
|
|
1820
|
+
const r = t.value(u.SampleFormat) ?? [1], o = t.value(u.BitsPerSample) ?? [8], { sampleFormat: i, bitsPerSample: a } = Ze(r, new Uint16Array(o)), { width: s, height: l } = t.tileSize, c = {
|
|
1821
|
+
sampleFormat: i,
|
|
1822
|
+
bitsPerSample: a,
|
|
1823
|
+
samplesPerPixel: t.value(u.SamplesPerPixel) ?? 1,
|
|
1824
|
+
width: s,
|
|
1825
|
+
height: l,
|
|
1826
|
+
predictor: t.value(u.Predictor) ?? 1,
|
|
1827
|
+
planarConfiguration: t.value(u.PlanarConfiguration) ?? U.Contig
|
|
1828
|
+
}, d = (P, C, j) => n ? n.decode(P, C, j) : ie(P, C, j), { bytes: h, compression: g } = e, f = await d(h, g, c), S = f.layout === "pixel-interleaved" ? f.data : f.bands[0];
|
|
1829
|
+
if (S instanceof Uint8Array)
|
|
1830
|
+
return S;
|
|
1831
|
+
throw new Error("Expected mask data to decode to Uint8Array");
|
|
1832
|
+
}
|
|
1833
|
+
async function Dn(e, t, n) {
|
|
1834
|
+
const r = (o, i, a) => n ? n.decode(o, i, a) : ie(o, i, a);
|
|
1835
|
+
if (Array.isArray(e)) {
|
|
1836
|
+
const o = { ...t, samplesPerPixel: 1 };
|
|
1837
|
+
return { layout: "band-separate", bands: (await Promise.all(e.map(({ bytes: s, compression: l }) => r(s, l, o)))).map((s) => s.layout === "band-separate" ? s.bands[0] : s.data) };
|
|
1838
|
+
} else {
|
|
1839
|
+
const { bytes: o, compression: i } = e;
|
|
1840
|
+
return r(o, i, t);
|
|
1841
|
+
}
|
|
1842
|
+
}
|
|
1843
|
+
async function xn(e, t, n, { signal: r } = {}) {
|
|
1844
|
+
const o = e._debug ? { label: "data" } : void 0;
|
|
1845
|
+
switch (e.cachedTags.planarConfiguration) {
|
|
1846
|
+
case U.Contig: {
|
|
1847
|
+
const i = await Ve(e.image, t, n, e.dataSource, {
|
|
1848
|
+
signal: r,
|
|
1849
|
+
debug: o
|
|
1850
|
+
});
|
|
1851
|
+
if (i === null)
|
|
1852
|
+
throw new Error(`Tile at (${t}, ${n}) not found`);
|
|
1853
|
+
return i;
|
|
1854
|
+
}
|
|
1855
|
+
case U.Separate:
|
|
1856
|
+
return await Nn(e, t, n, { signal: r });
|
|
1857
|
+
default:
|
|
1858
|
+
throw new Error(`Unsupported PlanarConfiguration: ${e.cachedTags.planarConfiguration}`);
|
|
1859
|
+
}
|
|
1860
|
+
}
|
|
1861
|
+
async function Je(e, t, n) {
|
|
1862
|
+
const { x: r, y: o } = e.image.tileCount, i = r * o, a = e.cachedTags.samplesPerPixel, s = [...Array(a).keys()].map((l) => {
|
|
1863
|
+
const c = l * i + n * r + t;
|
|
1864
|
+
return e.image.getTileSize(c);
|
|
1865
|
+
});
|
|
1866
|
+
return Promise.all(s);
|
|
1867
|
+
}
|
|
1868
|
+
async function Nn(e, t, n, { signal: r } = {}) {
|
|
1869
|
+
const o = e._debug ? { label: "data" } : void 0, a = (await Je(e, t, n)).map(async ({ offset: s, imageSize: l }) => {
|
|
1870
|
+
const c = await He(e.image, s, l, e.dataSource, { signal: r, debug: o });
|
|
1871
|
+
if (c === null)
|
|
1872
|
+
throw new Error(`Tile at (${t}, ${n}) not found`);
|
|
1873
|
+
return c;
|
|
1874
|
+
});
|
|
1875
|
+
return Promise.all(a);
|
|
1876
|
+
}
|
|
1877
|
+
async function zn(e, t, { signal: n } = {}) {
|
|
1878
|
+
const r = e._debug ? { label: "data" } : void 0;
|
|
1879
|
+
switch (e.cachedTags.planarConfiguration) {
|
|
1880
|
+
case U.Contig:
|
|
1881
|
+
return (await Xe(e.image, t, e.dataSource, {
|
|
1882
|
+
signal: n,
|
|
1883
|
+
debug: r
|
|
1884
|
+
})).map((i, a) => {
|
|
1885
|
+
if (i === null) {
|
|
1886
|
+
const [s, l] = t[a];
|
|
1887
|
+
throw new Error(`Tile at (${s}, ${l}) not found`);
|
|
1888
|
+
}
|
|
1889
|
+
return i;
|
|
1890
|
+
});
|
|
1891
|
+
case U.Separate:
|
|
1892
|
+
return Bn(e, t, { signal: n });
|
|
1893
|
+
default:
|
|
1894
|
+
throw new Error(`Unsupported PlanarConfiguration: ${e.cachedTags.planarConfiguration}`);
|
|
1895
|
+
}
|
|
1896
|
+
}
|
|
1897
|
+
async function Bn(e, t, { signal: n } = {}) {
|
|
1898
|
+
const r = e._debug ? { label: "data" } : void 0, o = e.cachedTags.samplesPerPixel, a = (await Promise.all(t.map(([l, c]) => Je(e, l, c)))).flatMap((l) => l.map(({ offset: c, imageSize: d }) => ({
|
|
1899
|
+
offset: c,
|
|
1900
|
+
byteCount: d
|
|
1901
|
+
}))), s = await Ye(e.image, a, e.dataSource, { signal: n, debug: r });
|
|
1902
|
+
return t.map(([l, c], d) => s.slice(d * o, d * o + o).map((h) => {
|
|
1903
|
+
if (h === null)
|
|
1904
|
+
throw new Error(`Tile at (${l}, ${c}) not found`);
|
|
1905
|
+
return h;
|
|
1906
|
+
}));
|
|
1907
|
+
}
|
|
1908
|
+
async function Ve(e, t, n, r, o) {
|
|
1909
|
+
const { size: i, tileSize: a } = e;
|
|
1910
|
+
if (a == null)
|
|
1911
|
+
throw new Error("Tiff is not tiled");
|
|
1912
|
+
const s = Math.ceil(i.height / a.height), l = Math.ceil(i.width / a.width);
|
|
1913
|
+
if (t >= l || n >= s)
|
|
1914
|
+
throw new Error(`Tile index is outside of range x:${t} >= ${l} or y:${n} >= ${s}`);
|
|
1915
|
+
const c = n * l + t, d = l * s;
|
|
1916
|
+
if (c >= d)
|
|
1917
|
+
throw new Error(`Tile index is outside of tile range: ${c} >= ${d}`);
|
|
1918
|
+
const { offset: h, imageSize: g } = await e.getTileSize(c);
|
|
1919
|
+
return He(e, h, g, r, o);
|
|
1920
|
+
}
|
|
1921
|
+
async function He(e, t, n, r, o) {
|
|
1922
|
+
if (n === 0)
|
|
1923
|
+
return null;
|
|
1924
|
+
o?.debug !== void 0 && console.log(`[geotiff dataSource] ${o.debug.label}: offset=${t} length=${n}`);
|
|
1925
|
+
const i = await r.fetch(t, n, o);
|
|
1926
|
+
if (i.byteLength < n)
|
|
1927
|
+
throw new Error(`Failed to fetch bytes from offset:${t} wanted:${n} got:${i.byteLength}`);
|
|
1928
|
+
const a = e.value(u.Compression) ?? m.None;
|
|
1929
|
+
return a === m.Jpeg ? {
|
|
1930
|
+
bytes: e.getJpegHeader(i),
|
|
1931
|
+
compression: a
|
|
1932
|
+
} : { bytes: i, compression: a };
|
|
1933
|
+
}
|
|
1934
|
+
async function Ye(e, t, n, r) {
|
|
1935
|
+
if (t.length === 0)
|
|
1936
|
+
return [];
|
|
1937
|
+
const o = new Array(t.length), i = [], a = [];
|
|
1938
|
+
for (let c = 0; c < t.length; c++) {
|
|
1939
|
+
const d = t[c];
|
|
1940
|
+
d.offset === 0 || d.byteCount === 0 ? o[c] = null : (a.push(c), i.push({ offset: d.offset, length: d.byteCount }));
|
|
1941
|
+
}
|
|
1942
|
+
if (i.length === 0)
|
|
1943
|
+
return o;
|
|
1944
|
+
if (r?.debug !== void 0)
|
|
1945
|
+
for (const c of i)
|
|
1946
|
+
console.log(`[geotiff dataSource] ${r.debug.label}: offset=${c.offset} length=${c.length}`);
|
|
1947
|
+
const s = await vn(n, i, {
|
|
1948
|
+
coalesce: r?.coalesce,
|
|
1949
|
+
maxRangeSize: r?.maxRangeSize,
|
|
1950
|
+
signal: r?.signal
|
|
1951
|
+
}), l = e.value(u.Compression) ?? m.None;
|
|
1952
|
+
for (let c = 0; c < s.length; c++) {
|
|
1953
|
+
const d = a[c], h = s[c], g = l === m.Jpeg ? e.getJpegHeader(h) : h;
|
|
1954
|
+
o[d] = { bytes: g, compression: l };
|
|
1955
|
+
}
|
|
1956
|
+
return o;
|
|
1957
|
+
}
|
|
1958
|
+
async function Xe(e, t, n, r) {
|
|
1959
|
+
if (t.length === 0)
|
|
1960
|
+
return [];
|
|
1961
|
+
const { size: o, tileSize: i } = e;
|
|
1962
|
+
if (i == null)
|
|
1963
|
+
throw new Error("Tiff is not tiled");
|
|
1964
|
+
const a = Math.ceil(o.height / i.height), s = Math.ceil(o.width / i.width), l = s * a, c = t.map(([h, g]) => {
|
|
1965
|
+
if (h >= s || g >= a)
|
|
1966
|
+
throw new Error(`Tile index is outside of range x:${h} >= ${s} or y:${g} >= ${a}`);
|
|
1967
|
+
const f = g * s + h;
|
|
1968
|
+
if (f >= l)
|
|
1969
|
+
throw new Error(`Tile index is outside of tile range: ${f} >= ${l}`);
|
|
1970
|
+
return f;
|
|
1971
|
+
}), d = await Promise.all(c.map((h) => e.getTileSize(h)));
|
|
1972
|
+
return Ye(e, d.map((h) => ({ offset: h.offset, byteCount: h.imageSize })), n, r);
|
|
1973
|
+
}
|
|
1974
|
+
function _n(e, t, n, r) {
|
|
1975
|
+
const { width: o, height: i } = e.image.getTileBounds(t, n);
|
|
1976
|
+
if (o === e.tileWidth && i === e.tileHeight)
|
|
1977
|
+
return r;
|
|
1978
|
+
const a = r.mask ? Q(r.mask, e.tileWidth, o, i, 1) : r.mask;
|
|
1979
|
+
if (r.layout === "pixel-interleaved") {
|
|
1980
|
+
const { count: c, data: d } = r, h = Q(d, e.tileWidth, o, i, c);
|
|
1981
|
+
return {
|
|
1982
|
+
...r,
|
|
1983
|
+
width: o,
|
|
1984
|
+
height: i,
|
|
1985
|
+
data: h,
|
|
1986
|
+
mask: a
|
|
1987
|
+
};
|
|
1988
|
+
}
|
|
1989
|
+
const { bands: s } = r, l = s.map((c) => Q(c, e.tileWidth, o, i, 1));
|
|
1990
|
+
return {
|
|
1991
|
+
...r,
|
|
1992
|
+
width: o,
|
|
1993
|
+
height: i,
|
|
1994
|
+
bands: l,
|
|
1995
|
+
mask: a
|
|
1996
|
+
};
|
|
1997
|
+
}
|
|
1998
|
+
function Q(e, t, n, r, o) {
|
|
1999
|
+
const i = t * o, a = n * o, s = new e.constructor(a * r);
|
|
2000
|
+
for (let l = 0; l < r; l++)
|
|
2001
|
+
s.set(e.subarray(l * i, l * i + a), l * a);
|
|
2002
|
+
return s;
|
|
2003
|
+
}
|
|
2004
|
+
function Ze(e, t) {
|
|
2005
|
+
const n = new Set(e), r = new Set(t);
|
|
2006
|
+
if (n.size > 1)
|
|
2007
|
+
throw new Error("Multiple sample formats are not supported.");
|
|
2008
|
+
if (r.size > 1)
|
|
2009
|
+
throw new Error("Multiple bits per sample values are not supported.");
|
|
2010
|
+
const o = e[0], i = t[0];
|
|
2011
|
+
if (o === void 0 || i === void 0)
|
|
2012
|
+
throw new Error("SampleFormat and BitsPerSample arrays cannot be empty.");
|
|
2013
|
+
return {
|
|
2014
|
+
sampleFormat: o,
|
|
2015
|
+
bitsPerSample: i
|
|
2016
|
+
};
|
|
2017
|
+
}
|
|
2018
|
+
function kn(e, { count: t }) {
|
|
2019
|
+
if (e == null)
|
|
2020
|
+
return null;
|
|
2021
|
+
const o = new DOMParser().parseFromString(e, "text/xml").documentElement;
|
|
2022
|
+
if (o.tagName !== "GDALMetadata")
|
|
2023
|
+
throw new Error("Not a GDALMetadata XML block");
|
|
2024
|
+
const i = /* @__PURE__ */ new Map(), a = Array(t).fill(0), s = Array(t).fill(1), l = (c) => {
|
|
2025
|
+
const d = parseInt(c, 10) + 1;
|
|
2026
|
+
return i.has(d) || i.set(d, {
|
|
2027
|
+
max: null,
|
|
2028
|
+
min: null,
|
|
2029
|
+
mean: null,
|
|
2030
|
+
std: null,
|
|
2031
|
+
validPercent: null
|
|
2032
|
+
}), i.get(d);
|
|
2033
|
+
};
|
|
2034
|
+
for (const c of Array.from(o.querySelectorAll("Item"))) {
|
|
2035
|
+
const d = c.getAttribute("name"), h = c.getAttribute("sample"), g = c.textContent ?? "";
|
|
2036
|
+
if (h !== null)
|
|
2037
|
+
switch (d) {
|
|
2038
|
+
case "STATISTICS_MAXIMUM":
|
|
2039
|
+
l(h).max = parseFloat(g);
|
|
2040
|
+
break;
|
|
2041
|
+
case "STATISTICS_MEAN":
|
|
2042
|
+
l(h).mean = parseFloat(g);
|
|
2043
|
+
break;
|
|
2044
|
+
case "STATISTICS_MINIMUM":
|
|
2045
|
+
l(h).min = parseFloat(g);
|
|
2046
|
+
break;
|
|
2047
|
+
case "STATISTICS_STDDEV":
|
|
2048
|
+
l(h).std = parseFloat(g);
|
|
2049
|
+
break;
|
|
2050
|
+
case "STATISTICS_VALID_PERCENT":
|
|
2051
|
+
l(h).validPercent = parseFloat(g);
|
|
2052
|
+
break;
|
|
2053
|
+
case "OFFSET":
|
|
2054
|
+
a[parseInt(h, 10)] = parseFloat(g);
|
|
2055
|
+
break;
|
|
2056
|
+
case "SCALE":
|
|
2057
|
+
s[parseInt(h, 10)] = parseFloat(g);
|
|
2058
|
+
break;
|
|
2059
|
+
}
|
|
2060
|
+
}
|
|
2061
|
+
return { bandStatistics: i, offsets: a, scales: s };
|
|
2062
|
+
}
|
|
2063
|
+
async function $n(e, t = {}) {
|
|
2064
|
+
const { signal: n } = t, r = e.value(u.Compression);
|
|
2065
|
+
if (r === null)
|
|
2066
|
+
throw new Error("Compression tag should always exist.");
|
|
2067
|
+
const [o, i, a, s, l, c, d, h, g, f, S, P, C] = await Promise.all([
|
|
2068
|
+
e.fetch(u.BitsPerSample, { signal: n }),
|
|
2069
|
+
e.fetch(u.ColorMap, { signal: n }),
|
|
2070
|
+
e.fetch(u.GdalNoData, { signal: n }),
|
|
2071
|
+
e.fetch(u.GdalMetadata, { signal: n }),
|
|
2072
|
+
e.fetch(u.LercParameters, { signal: n }),
|
|
2073
|
+
e.fetch(u.ModelPixelScale, { signal: n }),
|
|
2074
|
+
e.fetch(u.ModelTiePoint, { signal: n }),
|
|
2075
|
+
e.fetch(u.ModelTransformation, { signal: n }),
|
|
2076
|
+
e.fetch(u.Photometric, { signal: n }),
|
|
2077
|
+
e.fetch(u.PlanarConfiguration, { signal: n }),
|
|
2078
|
+
e.fetch(u.Predictor, { signal: n }),
|
|
2079
|
+
e.fetch(u.SampleFormat, { signal: n }),
|
|
2080
|
+
e.fetch(u.SamplesPerPixel, { signal: n })
|
|
2081
|
+
]), j = (b) => {
|
|
2082
|
+
throw new Error(`${b} tag should always exist.`);
|
|
2083
|
+
};
|
|
2084
|
+
return o === null && j("BitsPerSample"), C === null && j("SamplesPerPixel"), g === null && j("Photometric"), {
|
|
2085
|
+
bitsPerSample: new Uint16Array(o),
|
|
2086
|
+
colorMap: i ? new Uint16Array(i) : void 0,
|
|
2087
|
+
compression: r,
|
|
2088
|
+
gdalMetadata: s,
|
|
2089
|
+
lercParameters: l,
|
|
2090
|
+
modelTiepoint: d,
|
|
2091
|
+
modelPixelScale: c,
|
|
2092
|
+
modelTransformation: h,
|
|
2093
|
+
nodata: a !== null ? Number(a) : null,
|
|
2094
|
+
photometric: g,
|
|
2095
|
+
// PlanarConfiguration defaults to interleaved/chunky/contig
|
|
2096
|
+
// https://web.archive.org/web/20240329145253/https://www.awaresystems.be/imaging/tiff/tifftags/planarconfiguration.html
|
|
2097
|
+
planarConfiguration: f ?? U.Contig,
|
|
2098
|
+
predictor: S ?? _.None,
|
|
2099
|
+
// Uint is the default sample format according to the spec
|
|
2100
|
+
// https://web.archive.org/web/20240329145340/https://www.awaresystems.be/imaging/tiff/tifftags/sampleformat.html
|
|
2101
|
+
sampleFormat: P ?? [F.Uint],
|
|
2102
|
+
samplesPerPixel: C
|
|
2103
|
+
};
|
|
2104
|
+
}
|
|
2105
|
+
function Wn(e) {
|
|
2106
|
+
const t = (n) => e.valueGeo(n) ?? null;
|
|
2107
|
+
return {
|
|
2108
|
+
// Configuration keys
|
|
2109
|
+
modelType: t(p.GTModelTypeGeoKey),
|
|
2110
|
+
rasterType: t(p.GTRasterTypeGeoKey),
|
|
2111
|
+
citation: t(p.GTCitationGeoKey),
|
|
2112
|
+
// Geographic CRS keys
|
|
2113
|
+
geodeticCRS: t(p.GeodeticCRSGeoKey),
|
|
2114
|
+
geodeticCitation: t(p.GeodeticCitationGeoKey),
|
|
2115
|
+
geodeticDatum: t(p.GeodeticDatumGeoKey),
|
|
2116
|
+
primeMeridian: t(p.PrimeMeridianGeoKey),
|
|
2117
|
+
linearUnits: t(p.GeogLinearUnitsGeoKey),
|
|
2118
|
+
linearUnitSize: t(p.GeogLinearUnitSizeGeoKey),
|
|
2119
|
+
angularUnits: t(p.GeogAngularUnitsGeoKey),
|
|
2120
|
+
angularUnitSize: t(p.GeogAngularUnitSizeGeoKey),
|
|
2121
|
+
ellipsoid: t(p.EllipsoidGeoKey),
|
|
2122
|
+
ellipsoidSemiMajorAxis: t(p.EllipsoidSemiMajorAxisGeoKey),
|
|
2123
|
+
ellipsoidSemiMinorAxis: t(p.EllipsoidSemiMinorAxisGeoKey),
|
|
2124
|
+
ellipsoidInvFlattening: t(p.EllipsoidInvFlatteningGeoKey),
|
|
2125
|
+
azimuthUnits: t(p.GeogAzimuthUnitsGeoKey),
|
|
2126
|
+
primeMeridianLongitude: t(p.PrimeMeridianLongitudeGeoKey),
|
|
2127
|
+
toWGS84: t(p.GeogTOWGS84GeoKey),
|
|
2128
|
+
// Projected CRS keys
|
|
2129
|
+
projectedCRS: t(p.ProjectedCRSGeoKey),
|
|
2130
|
+
projectedCitation: t(p.ProjectedCitationGeoKey),
|
|
2131
|
+
projection: t(p.ProjectionGeoKey),
|
|
2132
|
+
projMethod: t(p.ProjMethodGeoKey),
|
|
2133
|
+
projLinearUnits: t(p.ProjLinearUnitsGeoKey),
|
|
2134
|
+
projLinearUnitSize: t(p.ProjLinearUnitSizeGeoKey),
|
|
2135
|
+
projStdParallel1: t(p.ProjStdParallel1GeoKey),
|
|
2136
|
+
projStdParallel2: t(p.ProjStdParallel2GeoKey),
|
|
2137
|
+
projNatOriginLong: t(p.ProjNatOriginLongGeoKey),
|
|
2138
|
+
projNatOriginLat: t(p.ProjNatOriginLatGeoKey),
|
|
2139
|
+
projFalseEasting: t(p.ProjFalseEastingGeoKey),
|
|
2140
|
+
projFalseNorthing: t(p.ProjFalseNorthingGeoKey),
|
|
2141
|
+
projFalseOriginLong: t(p.ProjFalseOriginLongGeoKey),
|
|
2142
|
+
projFalseOriginLat: t(p.ProjFalseOriginLatGeoKey),
|
|
2143
|
+
projFalseOriginEasting: t(p.ProjFalseOriginEastingGeoKey),
|
|
2144
|
+
projFalseOriginNorthing: t(p.ProjFalseOriginNorthingGeoKey),
|
|
2145
|
+
projCenterLong: t(p.ProjCenterLongGeoKey),
|
|
2146
|
+
projCenterLat: t(p.ProjCenterLatGeoKey),
|
|
2147
|
+
projCenterEasting: t(p.ProjCenterEastingGeoKey),
|
|
2148
|
+
projCenterNorthing: t(p.ProjCenterNorthingGeoKey),
|
|
2149
|
+
projScaleAtNatOrigin: t(p.ProjScaleAtNatOriginGeoKey),
|
|
2150
|
+
projScaleAtCenter: t(p.ProjScaleAtCenterGeoKey),
|
|
2151
|
+
projAzimuthAngle: t(p.ProjAzimuthAngleGeoKey),
|
|
2152
|
+
projStraightVertPoleLong: t(p.ProjStraightVertPoleLongGeoKey),
|
|
2153
|
+
projRectifiedGridAngle: t(p.ProjRectifiedGridAngleGeoKey),
|
|
2154
|
+
// Vertical CRS keys
|
|
2155
|
+
verticalCRS: t(p.VerticalGeoKey),
|
|
2156
|
+
verticalCitation: t(p.VerticalCitationGeoKey),
|
|
2157
|
+
verticalDatum: t(p.VerticalDatumGeoKey),
|
|
2158
|
+
verticalUnits: t(p.VerticalUnitsGeoKey)
|
|
2159
|
+
};
|
|
2160
|
+
}
|
|
2161
|
+
function Jn({ modelTiepoint: e, modelPixelScale: t, modelTransformation: n, rasterType: r }) {
|
|
2162
|
+
let o;
|
|
2163
|
+
if (e && t)
|
|
2164
|
+
o = Vn(e, t);
|
|
2165
|
+
else if (n)
|
|
2166
|
+
o = Hn(n);
|
|
2167
|
+
else
|
|
2168
|
+
throw new Error("The image does not have an affine transformation.");
|
|
2169
|
+
return r === T.PixelIsPoint && (o = re(o, Ae(-0.5, -0.5))), o;
|
|
2170
|
+
}
|
|
2171
|
+
function Vn(e, t) {
|
|
2172
|
+
const n = e[3], r = e[4], o = t[0], i = -t[1];
|
|
2173
|
+
return [o, 0, n, 0, i, r];
|
|
2174
|
+
}
|
|
2175
|
+
function Hn(e) {
|
|
2176
|
+
const t = e[3], n = e[7], r = e[1], o = e[4], i = e[0], a = e[5];
|
|
2177
|
+
return [i, r, t, o, a, n];
|
|
2178
|
+
}
|
|
2179
|
+
function Qe(e, t, n, r = Math.floor) {
|
|
2180
|
+
const o = nt(e.transform), [i, a] = Re(o, t, n);
|
|
2181
|
+
return [r(a), r(i)];
|
|
2182
|
+
}
|
|
2183
|
+
function qe(e, t, n, r = "center") {
|
|
2184
|
+
let o, i;
|
|
2185
|
+
switch (r) {
|
|
2186
|
+
case "center":
|
|
2187
|
+
o = n + 0.5, i = t + 0.5;
|
|
2188
|
+
break;
|
|
2189
|
+
case "ul":
|
|
2190
|
+
o = n, i = t;
|
|
2191
|
+
break;
|
|
2192
|
+
case "ur":
|
|
2193
|
+
o = n + 1, i = t;
|
|
2194
|
+
break;
|
|
2195
|
+
case "ll":
|
|
2196
|
+
o = n, i = t + 1;
|
|
2197
|
+
break;
|
|
2198
|
+
case "lr":
|
|
2199
|
+
o = n + 1, i = t + 1;
|
|
2200
|
+
break;
|
|
2201
|
+
}
|
|
2202
|
+
return Re(e.transform, o, i);
|
|
2203
|
+
}
|
|
2204
|
+
class Yn {
|
|
2205
|
+
cachedTags;
|
|
2206
|
+
/** The data source used for fetching tile data. */
|
|
2207
|
+
dataSource;
|
|
2208
|
+
/** A reference to the parent GeoTIFF object. */
|
|
2209
|
+
geotiff;
|
|
2210
|
+
/** The GeoKeyDirectory of the primary IFD. */
|
|
2211
|
+
gkd;
|
|
2212
|
+
/** The data IFD for this resolution level. */
|
|
2213
|
+
image;
|
|
2214
|
+
/** The IFD for the mask associated with this overview level, if any. */
|
|
2215
|
+
maskImage = null;
|
|
2216
|
+
constructor(t, n, r, o, i, a) {
|
|
2217
|
+
this.geotiff = t, this.gkd = n, this.image = r, this.maskImage = o, this.cachedTags = i, this.dataSource = a;
|
|
2218
|
+
}
|
|
2219
|
+
/**
|
|
2220
|
+
* The CRS parsed from the GeoKeyDirectory.
|
|
2221
|
+
*
|
|
2222
|
+
* Returns an EPSG code (number) for EPSG-coded CRSes, or a PROJJSON object
|
|
2223
|
+
* for user-defined CRSes. The result is cached after the first access.
|
|
2224
|
+
*
|
|
2225
|
+
* See also {@link GeoTIFF.epsg} for the EPSG code directly from the TIFF tags.
|
|
2226
|
+
*/
|
|
2227
|
+
get crs() {
|
|
2228
|
+
return this.geotiff.crs;
|
|
2229
|
+
}
|
|
2230
|
+
/** Image height in pixels. */
|
|
2231
|
+
get height() {
|
|
2232
|
+
return this.image.size.height;
|
|
2233
|
+
}
|
|
2234
|
+
/** The no data value, or null if not set. */
|
|
2235
|
+
get nodata() {
|
|
2236
|
+
return this.geotiff.nodata;
|
|
2237
|
+
}
|
|
2238
|
+
/** Inherits the {@link GeoTIFF._debug} flag from the parent. */
|
|
2239
|
+
get _debug() {
|
|
2240
|
+
return this.geotiff._debug;
|
|
2241
|
+
}
|
|
2242
|
+
/** The number of tiles in the x and y directions */
|
|
2243
|
+
get tileCount() {
|
|
2244
|
+
return this.image.tileCount;
|
|
2245
|
+
}
|
|
2246
|
+
/** Tile height in pixels. */
|
|
2247
|
+
get tileHeight() {
|
|
2248
|
+
return this.image.tileSize.height;
|
|
2249
|
+
}
|
|
2250
|
+
/** Tile width in pixels. */
|
|
2251
|
+
get tileWidth() {
|
|
2252
|
+
return this.image.tileSize.width;
|
|
2253
|
+
}
|
|
2254
|
+
/**
|
|
2255
|
+
* Return the dataset's georeferencing transformation matrix.
|
|
2256
|
+
*/
|
|
2257
|
+
get transform() {
|
|
2258
|
+
const t = this.geotiff.transform, n = this.geotiff.width / this.width, r = this.geotiff.height / this.height;
|
|
2259
|
+
return re(t, rt(n, r));
|
|
2260
|
+
}
|
|
2261
|
+
/** Image width in pixels. */
|
|
2262
|
+
get width() {
|
|
2263
|
+
return this.image.size.width;
|
|
2264
|
+
}
|
|
2265
|
+
/** Fetch a single tile from the full-resolution image.
|
|
2266
|
+
*
|
|
2267
|
+
* @param x The tile column index (0-based).
|
|
2268
|
+
* @param y The tile row index (0-based).
|
|
2269
|
+
* @param options Optional parameters for fetching the tile.
|
|
2270
|
+
* @param options.boundless Whether to clip tiles that are partially outside the image bounds. When `true`, no clipping is applied and edge tiles are returned at the full nominal tile size. Defaults to `true`.
|
|
2271
|
+
* @param options.pool An optional {@link DecoderPool} for decoding the tile data. If not provided, a new decoder will be created for each tile.
|
|
2272
|
+
* @param options.signal An optional {@link AbortSignal} to cancel the fetch request.
|
|
2273
|
+
*/
|
|
2274
|
+
async fetchTile(t, n, r = {}) {
|
|
2275
|
+
return await ke(this, t, n, r);
|
|
2276
|
+
}
|
|
2277
|
+
/**
|
|
2278
|
+
* Fetch multiple tiles in parallel.
|
|
2279
|
+
*
|
|
2280
|
+
* A future implementation may coalesce contiguous byte ranges to reduce
|
|
2281
|
+
* the number of HTTP requests.
|
|
2282
|
+
*
|
|
2283
|
+
* @param xy - Array of `[x, y]` tile coordinates.
|
|
2284
|
+
* @param options - Optional parameters (same as {@link fetchTile}).
|
|
2285
|
+
* @returns Array of {@link Tile} objects in the same order as `xy`.
|
|
2286
|
+
*
|
|
2287
|
+
* @see {@link fetchTile} for single-tile fetching.
|
|
2288
|
+
*/
|
|
2289
|
+
async fetchTiles(t, n = {}) {
|
|
2290
|
+
return await We(this, t, n);
|
|
2291
|
+
}
|
|
2292
|
+
// TiledMixin
|
|
2293
|
+
// Transform mixin
|
|
2294
|
+
/**
|
|
2295
|
+
* Get the (row, col) pixel index containing the geographic coordinate (x, y).
|
|
2296
|
+
*
|
|
2297
|
+
* @param x x coordinate in the CRS.
|
|
2298
|
+
* @param y y coordinate in the CRS.
|
|
2299
|
+
* @param op Rounding function applied to fractional pixel indices.
|
|
2300
|
+
* Defaults to Math.floor.
|
|
2301
|
+
* @returns [row, col] pixel indices.
|
|
2302
|
+
*/
|
|
2303
|
+
index(t, n, r = Math.floor) {
|
|
2304
|
+
return Qe(this, t, n, r);
|
|
2305
|
+
}
|
|
2306
|
+
/**
|
|
2307
|
+
* Get the geographic (x, y) coordinate of the pixel at (row, col).
|
|
2308
|
+
*
|
|
2309
|
+
* @param row Pixel row.
|
|
2310
|
+
* @param col Pixel column.
|
|
2311
|
+
* @param offset Which part of the pixel to return. Defaults to "center".
|
|
2312
|
+
* @returns [x, y] in the CRS.
|
|
2313
|
+
*/
|
|
2314
|
+
xy(t, n, r = "center") {
|
|
2315
|
+
return qe(this, t, n, r);
|
|
2316
|
+
}
|
|
2317
|
+
}
|
|
2318
|
+
class D {
|
|
2319
|
+
/**
|
|
2320
|
+
* Reduced-resolution overview levels, sorted finest-to-coarsest.
|
|
2321
|
+
*
|
|
2322
|
+
* Does not include the full-resolution image — use {@link fetchTile} on the
|
|
2323
|
+
* GeoTIFF instance itself for that.
|
|
2324
|
+
*/
|
|
2325
|
+
overviews;
|
|
2326
|
+
/** A cached CRS value. */
|
|
2327
|
+
_crs;
|
|
2328
|
+
/** Cached TIFF tags that are pre-fetched when opening the GeoTIFF. */
|
|
2329
|
+
cachedTags;
|
|
2330
|
+
/** The data source used for fetching tile data.
|
|
2331
|
+
*
|
|
2332
|
+
* This is typically the raw source (e.g. HTTP or memory) rather than a
|
|
2333
|
+
* layered source with caching and chunking, to avoid unnecessary copying of
|
|
2334
|
+
* tile data through cache layers.
|
|
2335
|
+
*/
|
|
2336
|
+
dataSource;
|
|
2337
|
+
/** The underlying Tiff instance. */
|
|
2338
|
+
tiff;
|
|
2339
|
+
/** The primary (full-resolution) TiffImage. */
|
|
2340
|
+
image;
|
|
2341
|
+
/** The mask IFD of the full-resolution GeoTIFF, if any. */
|
|
2342
|
+
maskImage;
|
|
2343
|
+
/** The GeoKeyDirectory of the primary IFD. */
|
|
2344
|
+
gkd;
|
|
2345
|
+
/** Parsed GDALMetadata tag, if present. */
|
|
2346
|
+
gdalMetadata;
|
|
2347
|
+
/**
|
|
2348
|
+
* Internal: when true, log each `dataSource` fetch (image tile data and
|
|
2349
|
+
* mask tile data) to the console with offset/length and a `data`/`mask`
|
|
2350
|
+
* label. Enable via the `debug` option on {@link GeoTIFF.open} or
|
|
2351
|
+
* {@link GeoTIFF.fromUrl}. Read by the tile-fetch path; not part of the
|
|
2352
|
+
* public API surface.
|
|
2353
|
+
*
|
|
2354
|
+
* @internal
|
|
2355
|
+
*/
|
|
2356
|
+
_debug;
|
|
2357
|
+
constructor(t, n, r, o, i, a, s, l, c) {
|
|
2358
|
+
this.tiff = t, this.image = n, this.maskImage = r, this.gkd = o, this.overviews = i, this.cachedTags = a, this.dataSource = s, this.gdalMetadata = l, this._debug = c;
|
|
2359
|
+
}
|
|
2360
|
+
/**
|
|
2361
|
+
* Open a GeoTIFF from a @cogeotiff/core Source.
|
|
2362
|
+
*
|
|
2363
|
+
* This creates and initialises the underlying Tiff, then classifies IFDs.
|
|
2364
|
+
*
|
|
2365
|
+
* @param options.dataSource A source for fetching tile data. This is separate from the source used to construct the TIFF to allow for separate caching implementations.
|
|
2366
|
+
* @param options.headerSource The source used to construct the TIFF. This is typically a layered source with caching and chunking, to optimise access to TIFF tags and IFDs. Callers who want to control the initial read size should compose a `SourceChunk` of the desired block size; cogeotiff's default `defaultReadSize` (16 KiB) gets padded up by the chunking layer anyway.
|
|
2367
|
+
* @param options.signal An optional {@link AbortSignal} to cancel the header reads.
|
|
2368
|
+
* @param options.debug When true, the returned GeoTIFF logs each tile/mask data fetch to the console. Off by default.
|
|
2369
|
+
*/
|
|
2370
|
+
static async open(t) {
|
|
2371
|
+
const { dataSource: n, headerSource: r, signal: o, debug: i } = t, a = await new B(r).init({ signal: o });
|
|
2372
|
+
return a.options = void 0, D.fromTiff(a, n, { signal: o, debug: i });
|
|
2373
|
+
}
|
|
2374
|
+
/**
|
|
2375
|
+
* Create a GeoTIFF from an already-initialised Tiff instance.
|
|
2376
|
+
*
|
|
2377
|
+
* All IFDs are walked; mask IFDs are matched to data IFDs by matching
|
|
2378
|
+
* (width, height). Overviews are sorted from finest to coarsest resolution.
|
|
2379
|
+
*
|
|
2380
|
+
* @param dataSource A source for fetching tile data. This is separate from the source used to construct the TIFF to allow for separate caching implementations.
|
|
2381
|
+
* @param options.signal An optional {@link AbortSignal} to cancel header tag reads.
|
|
2382
|
+
* @param options.debug When true, the returned GeoTIFF logs each tile/mask data fetch to the console.
|
|
2383
|
+
*/
|
|
2384
|
+
static async fromTiff(t, n, r = {}) {
|
|
2385
|
+
const { signal: o, debug: i = !1 } = r, a = t.images;
|
|
2386
|
+
if (a.length === 0)
|
|
2387
|
+
throw new Error("TIFF does not contain any IFDs");
|
|
2388
|
+
await Promise.all(a.map((b) => b.init(!0, { signal: o })));
|
|
2389
|
+
const s = a[0], l = Wn(s), c = /* @__PURE__ */ new Map(), d = /* @__PURE__ */ new Map();
|
|
2390
|
+
for (let b = 1; b < a.length; b++) {
|
|
2391
|
+
const G = a[b], R = G.size, I = `${R.width},${R.height}`;
|
|
2392
|
+
Xn(G) ? d.set(I, G) : c.set(I, G);
|
|
2393
|
+
}
|
|
2394
|
+
const h = `${s.size.width},${s.size.height}`, g = d.get(h) ?? null, f = Array.from(c.entries());
|
|
2395
|
+
f.sort((b, G) => {
|
|
2396
|
+
const R = b[1].size, I = G[1].size;
|
|
2397
|
+
return I.width * I.height - R.width * R.height;
|
|
2398
|
+
});
|
|
2399
|
+
const S = await $n(s, { signal: o }), P = kn(S.gdalMetadata, {
|
|
2400
|
+
count: S.samplesPerPixel
|
|
2401
|
+
}), C = new D(t, s, g, l, [], S, n, P, i), j = f.map(([b, G]) => {
|
|
2402
|
+
const R = d.get(b) ?? null;
|
|
2403
|
+
return new Yn(C, l, G, R, S, n);
|
|
2404
|
+
});
|
|
2405
|
+
return C.overviews = j, C;
|
|
2406
|
+
}
|
|
2407
|
+
/**
|
|
2408
|
+
* Create a GeoTIFF from an ArrayBuffer containing the entire file.
|
|
2409
|
+
*
|
|
2410
|
+
* This is a convenience method that wraps the ArrayBuffer in a memory source
|
|
2411
|
+
* and calls {@link GeoTIFF.open}. For large files, consider using
|
|
2412
|
+
* {@link GeoTIFF.fromUrl} or {@link GeoTIFF.open} with a chunked HTTP source
|
|
2413
|
+
* to avoid loading the entire file into memory at once.
|
|
2414
|
+
*
|
|
2415
|
+
* @param input The ArrayBuffer containing the GeoTIFF file data.
|
|
2416
|
+
* @returns A Promise that resolves to a GeoTIFF instance.
|
|
2417
|
+
*/
|
|
2418
|
+
static async fromArrayBuffer(t) {
|
|
2419
|
+
const n = new ae("memory://input.tif", t);
|
|
2420
|
+
return await D.open({
|
|
2421
|
+
dataSource: n,
|
|
2422
|
+
headerSource: n
|
|
2423
|
+
});
|
|
2424
|
+
}
|
|
2425
|
+
/**
|
|
2426
|
+
* Create a new GeoTIFF from a URL.
|
|
2427
|
+
*
|
|
2428
|
+
* Wraps the HTTP source with a fixed-size block-aligned LRU cache tuned for
|
|
2429
|
+
* TIFF metadata. cogeotiff's lazy per-entry reads (for tile offsets, byte
|
|
2430
|
+
* counts, and other tag values) are served by the block cache; adjacent
|
|
2431
|
+
* entries within a single block hit one underlying request. Tile data reads
|
|
2432
|
+
* bypass the cache and go straight to the raw HTTP source.
|
|
2433
|
+
*
|
|
2434
|
+
* @param url The URL of the GeoTIFF to open.
|
|
2435
|
+
* @param options Optional parameters.
|
|
2436
|
+
* @param options.chunkSize Bytes per chunk for the header cache. Defaults to 64 KiB (matches geotiff.js's BlockedSource).
|
|
2437
|
+
* @param options.cacheSize Total cache size in bytes. Defaults to 8 MiB (~128 blocks at the default chunk size).
|
|
2438
|
+
* @param options.signal An optional {@link AbortSignal} to cancel the header reads.
|
|
2439
|
+
* @param options.debug When true, the returned GeoTIFF logs each tile/mask data fetch to the console with offset/length and a `data`/`mask` label. Off by default.
|
|
2440
|
+
* @returns A Promise that resolves to a GeoTIFF instance.
|
|
2441
|
+
*/
|
|
2442
|
+
static async fromUrl(t, { chunkSize: n = 64 * 1024, cacheSize: r = 8 * 1024 * 1024, signal: o, debug: i } = {}) {
|
|
2443
|
+
const a = new k(t, {});
|
|
2444
|
+
a.metadata = { size: Number.POSITIVE_INFINITY };
|
|
2445
|
+
const s = new Bt(a, [
|
|
2446
|
+
new kt({ size: n }),
|
|
2447
|
+
new zt({ size: r })
|
|
2448
|
+
]);
|
|
2449
|
+
return await D.open({
|
|
2450
|
+
// Tile data reads bypass the header cache (raw source).
|
|
2451
|
+
dataSource: a,
|
|
2452
|
+
headerSource: s,
|
|
2453
|
+
signal: o,
|
|
2454
|
+
debug: i
|
|
2455
|
+
});
|
|
2456
|
+
}
|
|
2457
|
+
// ── Properties from the primary image ─────────────────────────────────
|
|
2458
|
+
/**
|
|
2459
|
+
* The CRS parsed from the GeoKeyDirectory.
|
|
2460
|
+
*
|
|
2461
|
+
* Returns an EPSG code (number) for EPSG-coded CRSes, or a PROJJSON object
|
|
2462
|
+
* for user-defined CRSes. The result is cached after the first access.
|
|
2463
|
+
*
|
|
2464
|
+
* See also {@link GeoTIFF.epsg} for the EPSG code directly from the TIFF tags.
|
|
2465
|
+
*/
|
|
2466
|
+
get crs() {
|
|
2467
|
+
return this._crs === void 0 && (this._crs = Cn(this.gkd)), this._crs;
|
|
2468
|
+
}
|
|
2469
|
+
/** Image width in pixels. */
|
|
2470
|
+
get width() {
|
|
2471
|
+
return this.image.size.width;
|
|
2472
|
+
}
|
|
2473
|
+
/** Image height in pixels. */
|
|
2474
|
+
get height() {
|
|
2475
|
+
return this.image.size.height;
|
|
2476
|
+
}
|
|
2477
|
+
/** The number of tiles in the x and y directions */
|
|
2478
|
+
get tileCount() {
|
|
2479
|
+
return this.image.tileCount;
|
|
2480
|
+
}
|
|
2481
|
+
/** Tile width in pixels. */
|
|
2482
|
+
get tileWidth() {
|
|
2483
|
+
return this.image.tileSize.width;
|
|
2484
|
+
}
|
|
2485
|
+
/** Tile height in pixels. */
|
|
2486
|
+
get tileHeight() {
|
|
2487
|
+
return this.image.tileSize.height;
|
|
2488
|
+
}
|
|
2489
|
+
/** The no data value, or null if not set. */
|
|
2490
|
+
get nodata() {
|
|
2491
|
+
return this.image.noData;
|
|
2492
|
+
}
|
|
2493
|
+
/** Whether the primary image is tiled. */
|
|
2494
|
+
get isTiled() {
|
|
2495
|
+
return this.image.isTiled();
|
|
2496
|
+
}
|
|
2497
|
+
/**
|
|
2498
|
+
* The pre-existing statistics for each band, if available.
|
|
2499
|
+
*
|
|
2500
|
+
* Extracted from the GDALMetadata TIFF tag; never computed on demand.
|
|
2501
|
+
* Keys are **1-based** band indices to match GDAL's convention.
|
|
2502
|
+
*
|
|
2503
|
+
* Returns `null` if no statistics are stored in the file.
|
|
2504
|
+
*/
|
|
2505
|
+
get storedStats() {
|
|
2506
|
+
const t = this.gdalMetadata?.bandStatistics;
|
|
2507
|
+
return t && t.size > 0 ? t : null;
|
|
2508
|
+
}
|
|
2509
|
+
/**
|
|
2510
|
+
* The offset for each band (0-indexed), defaulting to 0.
|
|
2511
|
+
*
|
|
2512
|
+
* Extracted from the GDALMetadata TIFF tag.
|
|
2513
|
+
*/
|
|
2514
|
+
get offsets() {
|
|
2515
|
+
return this.gdalMetadata?.offsets ?? Array(this.count).fill(0);
|
|
2516
|
+
}
|
|
2517
|
+
/**
|
|
2518
|
+
* The scale for each band (0-indexed), defaulting to 1.
|
|
2519
|
+
*
|
|
2520
|
+
* Extracted from the GDALMetadata TIFF tag.
|
|
2521
|
+
*/
|
|
2522
|
+
get scales() {
|
|
2523
|
+
return this.gdalMetadata?.scales ?? Array(this.count).fill(1);
|
|
2524
|
+
}
|
|
2525
|
+
/** Number of bands (samples per pixel). */
|
|
2526
|
+
get count() {
|
|
2527
|
+
return this.image.value(u.SamplesPerPixel) ?? 1;
|
|
2528
|
+
}
|
|
2529
|
+
/** Bounding box [minX, minY, maxX, maxY] in the CRS. */
|
|
2530
|
+
get bbox() {
|
|
2531
|
+
return this.image.bbox;
|
|
2532
|
+
}
|
|
2533
|
+
/**
|
|
2534
|
+
* Return the dataset's georeferencing transformation matrix.
|
|
2535
|
+
*/
|
|
2536
|
+
get transform() {
|
|
2537
|
+
const { modelPixelScale: t, modelTiepoint: n, modelTransformation: r } = this.cachedTags;
|
|
2538
|
+
return Jn({
|
|
2539
|
+
modelTiepoint: n,
|
|
2540
|
+
modelPixelScale: t,
|
|
2541
|
+
modelTransformation: r,
|
|
2542
|
+
rasterType: this.gkd.rasterType
|
|
2543
|
+
});
|
|
2544
|
+
}
|
|
2545
|
+
// Mixins
|
|
2546
|
+
/** Fetch a single tile from the full-resolution image.
|
|
2547
|
+
*
|
|
2548
|
+
* @param x The tile column index (0-based).
|
|
2549
|
+
* @param y The tile row index (0-based).
|
|
2550
|
+
* @param options Optional parameters for fetching the tile.
|
|
2551
|
+
* @param options.boundless Whether to clip tiles that are partially outside the image bounds. When `true`, no clipping is applied and edge tiles are returned at the full nominal tile size. Defaults to `true`.
|
|
2552
|
+
* @param options.pool An optional {@link DecoderPool} for decoding the tile data. If not provided, a new decoder will be created for each tile.
|
|
2553
|
+
* @param options.signal An optional {@link AbortSignal} to cancel the fetch request.
|
|
2554
|
+
*/
|
|
2555
|
+
async fetchTile(t, n, r = {}) {
|
|
2556
|
+
return await ke(this, t, n, r);
|
|
2557
|
+
}
|
|
2558
|
+
/**
|
|
2559
|
+
* Fetch multiple tiles in parallel.
|
|
2560
|
+
*
|
|
2561
|
+
* A future implementation may coalesce contiguous byte ranges to reduce
|
|
2562
|
+
* the number of HTTP requests.
|
|
2563
|
+
*
|
|
2564
|
+
* @param xy - Array of `[x, y]` tile coordinates.
|
|
2565
|
+
* @param options - Optional parameters (same as {@link fetchTile}).
|
|
2566
|
+
* @returns Array of {@link Tile} objects in the same order as `xy`.
|
|
2567
|
+
*
|
|
2568
|
+
* @see {@link fetchTile} for single-tile fetching.
|
|
2569
|
+
*/
|
|
2570
|
+
async fetchTiles(t, n = {}) {
|
|
2571
|
+
return await We(this, t, n);
|
|
2572
|
+
}
|
|
2573
|
+
// Transform mixin
|
|
2574
|
+
/**
|
|
2575
|
+
* Get the (row, col) pixel index containing the geographic coordinate (x, y).
|
|
2576
|
+
*
|
|
2577
|
+
* @param x x coordinate in the CRS.
|
|
2578
|
+
* @param y y coordinate in the CRS.
|
|
2579
|
+
* @param op Rounding function applied to fractional pixel indices.
|
|
2580
|
+
* Defaults to Math.floor.
|
|
2581
|
+
* @returns [row, col] pixel indices.
|
|
2582
|
+
*/
|
|
2583
|
+
index(t, n, r = Math.floor) {
|
|
2584
|
+
return Qe(this, t, n, r);
|
|
2585
|
+
}
|
|
2586
|
+
/**
|
|
2587
|
+
* Get the geographic (x, y) coordinate of the pixel at (row, col).
|
|
2588
|
+
*
|
|
2589
|
+
* @param row Pixel row.
|
|
2590
|
+
* @param col Pixel column.
|
|
2591
|
+
* @param offset Which part of the pixel to return. Defaults to "center".
|
|
2592
|
+
* @returns [x, y] in the CRS.
|
|
2593
|
+
*/
|
|
2594
|
+
xy(t, n, r = "center") {
|
|
2595
|
+
return qe(this, t, n, r);
|
|
2596
|
+
}
|
|
2597
|
+
}
|
|
2598
|
+
function Xn(e) {
|
|
2599
|
+
const t = e.value(u.SubFileType), n = e.value(u.Photometric);
|
|
2600
|
+
return t !== null && (t & J.Mask) !== 0 && n === E.Mask;
|
|
2601
|
+
}
|
|
2602
|
+
let Zn = class {
|
|
2603
|
+
worker;
|
|
2604
|
+
jobIdCounter = 0;
|
|
2605
|
+
jobs = /* @__PURE__ */ new Map();
|
|
2606
|
+
constructor(t) {
|
|
2607
|
+
this.worker = t, this.worker.addEventListener("message", (n) => this.onMessage(n));
|
|
2608
|
+
}
|
|
2609
|
+
get jobCount() {
|
|
2610
|
+
return this.jobs.size;
|
|
2611
|
+
}
|
|
2612
|
+
onMessage(t) {
|
|
2613
|
+
const { jobId: n, error: r, pixels: o } = t.data, i = this.jobs.get(n);
|
|
2614
|
+
this.jobs.delete(n), i && (r ? i.reject(new Error(r)) : i.resolve(o));
|
|
2615
|
+
}
|
|
2616
|
+
submitJob(t, n) {
|
|
2617
|
+
const r = this.jobIdCounter++;
|
|
2618
|
+
return new Promise((o, i) => {
|
|
2619
|
+
this.jobs.set(r, { resolve: o, reject: i }), this.worker.postMessage({ ...t, jobId: r }, { transfer: n });
|
|
2620
|
+
});
|
|
2621
|
+
}
|
|
2622
|
+
terminate() {
|
|
2623
|
+
this.worker.terminate();
|
|
2624
|
+
}
|
|
2625
|
+
};
|
|
2626
|
+
const Qn = typeof navigator < "u" ? navigator.hardwareConcurrency ?? 2 : 2;
|
|
2627
|
+
class ne {
|
|
2628
|
+
workerWrappers;
|
|
2629
|
+
constructor(t = {}) {
|
|
2630
|
+
const { size: n = Qn, createWorker: r } = t;
|
|
2631
|
+
if (this.workerWrappers = [], r && n > 0)
|
|
2632
|
+
for (let o = 0; o < n; o++)
|
|
2633
|
+
this.workerWrappers.push(new Zn(r()));
|
|
2634
|
+
}
|
|
2635
|
+
/** True when workers are available for off-main-thread decoding. */
|
|
2636
|
+
get hasWorkers() {
|
|
2637
|
+
return this.workerWrappers.length > 0;
|
|
2638
|
+
}
|
|
2639
|
+
/**
|
|
2640
|
+
* Decode a compressed tile buffer.
|
|
2641
|
+
*
|
|
2642
|
+
* When workers are available, the compressed `bytes` buffer is transferred
|
|
2643
|
+
* zero-copy to the least-loaded worker. The returned `DecodedPixels` typed
|
|
2644
|
+
* array buffers are transferred back to the main thread.
|
|
2645
|
+
*
|
|
2646
|
+
* When no workers are available, decoding runs on the main thread via the
|
|
2647
|
+
* normal `decode()` path.
|
|
2648
|
+
*/
|
|
2649
|
+
async decode(t, n, r) {
|
|
2650
|
+
if (!this.hasWorkers)
|
|
2651
|
+
return ie(t, n, r);
|
|
2652
|
+
const o = this.leastLoaded(), i = {
|
|
2653
|
+
compression: n,
|
|
2654
|
+
metadata: r,
|
|
2655
|
+
buffer: t
|
|
2656
|
+
};
|
|
2657
|
+
return await o.submitJob(i, [t]);
|
|
2658
|
+
}
|
|
2659
|
+
/** Terminate all workers and release resources. */
|
|
2660
|
+
destroy() {
|
|
2661
|
+
for (const t of this.workerWrappers)
|
|
2662
|
+
t.terminate();
|
|
2663
|
+
this.workerWrappers.length = 0;
|
|
2664
|
+
}
|
|
2665
|
+
leastLoaded() {
|
|
2666
|
+
let t = this.workerWrappers[0];
|
|
2667
|
+
for (let n = 1; n < this.workerWrappers.length; n++)
|
|
2668
|
+
this.workerWrappers[n].jobCount < t.jobCount && (t = this.workerWrappers[n]);
|
|
2669
|
+
return t;
|
|
2670
|
+
}
|
|
2671
|
+
}
|
|
2672
|
+
let H = null;
|
|
2673
|
+
function qn() {
|
|
2674
|
+
return H !== null || (H = new ne({
|
|
2675
|
+
createWorker: () => new Worker(new URL(
|
|
2676
|
+
/* @vite-ignore */
|
|
2677
|
+
"" + new URL("assets/worker-DtIrTJB7.js", import.meta.url).href,
|
|
2678
|
+
import.meta.url
|
|
2679
|
+
), { type: "module" })
|
|
2680
|
+
})), H;
|
|
2681
|
+
}
|
|
2682
|
+
function Tn(e) {
|
|
2683
|
+
const { height: t, width: n } = e;
|
|
2684
|
+
if (e.layout === "band-separate")
|
|
2685
|
+
throw new Error("Band-separate images not yet implemented.");
|
|
2686
|
+
if (e.data.length === t * n * 4)
|
|
2687
|
+
return e;
|
|
2688
|
+
if (e.data.length === t * n * 3) {
|
|
2689
|
+
const r = e.data.length / 3 * 4, o = e.data instanceof Uint16Array, i = o ? new Uint16Array(r) : new Uint8ClampedArray(r), a = o ? 65535 : 255;
|
|
2690
|
+
for (let s = 0; s < e.data.length / 3; ++s)
|
|
2691
|
+
i[s * 4] = e.data[s * 3], i[s * 4 + 1] = e.data[s * 3 + 1], i[s * 4 + 2] = e.data[s * 3 + 2], i[s * 4 + 3] = a;
|
|
2692
|
+
return {
|
|
2693
|
+
...e,
|
|
2694
|
+
count: 4,
|
|
2695
|
+
data: i
|
|
2696
|
+
};
|
|
2697
|
+
} else
|
|
2698
|
+
throw new Error(`Unexpected number of channels in raster data: ${e.data.length / (t * n)}`);
|
|
2699
|
+
}
|
|
2700
|
+
async function er(e) {
|
|
2701
|
+
return typeof e == "string" || e instanceof URL ? await D.fromUrl(e) : e instanceof ArrayBuffer ? await D.fromArrayBuffer(e) : e;
|
|
2702
|
+
}
|
|
2703
|
+
function tr(e, t) {
|
|
2704
|
+
const [n, r, o, i] = e.bbox, a = [
|
|
2705
|
+
t.forward([n, r]),
|
|
2706
|
+
// bottom-left
|
|
2707
|
+
t.forward([o, r]),
|
|
2708
|
+
// bottom-right
|
|
2709
|
+
t.forward([o, i]),
|
|
2710
|
+
// top-right
|
|
2711
|
+
t.forward([n, i])
|
|
2712
|
+
// top-left
|
|
2713
|
+
], s = a.map((f) => f[0]), l = a.map((f) => f[1]), c = Math.min(...s), d = Math.min(...l), h = Math.max(...s), g = Math.max(...l);
|
|
2714
|
+
return { west: c, south: d, east: h, north: g };
|
|
2715
|
+
}
|
|
2716
|
+
const nr = (
|
|
2717
|
+
/* glsl */
|
|
2718
|
+
`
|
|
2719
|
+
vec3 black_zero_to_rgb(float value) {
|
|
2720
|
+
return vec3(value, value, value);
|
|
2721
|
+
}
|
|
2722
|
+
`
|
|
2723
|
+
), rr = {
|
|
2724
|
+
name: "black-is-zero",
|
|
2725
|
+
inject: {
|
|
2726
|
+
"fs:#decl": nr,
|
|
2727
|
+
"fs:DECKGL_FILTER_COLOR": (
|
|
2728
|
+
/* glsl */
|
|
2729
|
+
`
|
|
2730
|
+
color.rgb = black_zero_to_rgb(color.r);
|
|
2731
|
+
`
|
|
2732
|
+
)
|
|
2733
|
+
}
|
|
2734
|
+
}, or = (
|
|
2735
|
+
/* glsl */
|
|
2736
|
+
`
|
|
2737
|
+
const vec3 D65 = vec3(
|
|
2738
|
+
0.95047, // Xn
|
|
2739
|
+
1.00000, // Yn
|
|
2740
|
+
1.08883 // Zn
|
|
2741
|
+
);
|
|
2742
|
+
|
|
2743
|
+
vec3 cielabToRgb(vec3 labTex) {
|
|
2744
|
+
// labTex in [0,1] from RGB8 texture
|
|
2745
|
+
float L = labTex.r * 255.0;
|
|
2746
|
+
float a = (labTex.g - 0.5) * 255.0;
|
|
2747
|
+
float b = (labTex.b - 0.5) * 255.0;
|
|
2748
|
+
|
|
2749
|
+
float y = (L + 16.0) / 116.0;
|
|
2750
|
+
float x = (a / 500.0) + y;
|
|
2751
|
+
float z = y - (b / 200.0);
|
|
2752
|
+
|
|
2753
|
+
vec3 xyz;
|
|
2754
|
+
vec3 v = vec3(x, y, z);
|
|
2755
|
+
vec3 v3 = v * v * v;
|
|
2756
|
+
|
|
2757
|
+
xyz = D65 * mix(
|
|
2758
|
+
(v - 16.0 / 116.0) / 7.787,
|
|
2759
|
+
v3,
|
|
2760
|
+
step(0.008856, v3)
|
|
2761
|
+
);
|
|
2762
|
+
|
|
2763
|
+
vec3 rgb = mat3(
|
|
2764
|
+
3.2406, -1.5372, -0.4986,
|
|
2765
|
+
-0.9689, 1.8758, 0.0415,
|
|
2766
|
+
0.0557, -0.2040, 1.0570
|
|
2767
|
+
) * xyz;
|
|
2768
|
+
|
|
2769
|
+
// sRGB gamma
|
|
2770
|
+
rgb = mix(
|
|
2771
|
+
12.92 * rgb,
|
|
2772
|
+
1.055 * pow(rgb, vec3(1.0 / 2.4)) - 0.055,
|
|
2773
|
+
step(0.0031308, rgb)
|
|
2774
|
+
);
|
|
2775
|
+
|
|
2776
|
+
return clamp(rgb, 0.0, 1.0);
|
|
2777
|
+
}
|
|
2778
|
+
`
|
|
2779
|
+
), ir = {
|
|
2780
|
+
name: "cielab-to-rgb",
|
|
2781
|
+
inject: {
|
|
2782
|
+
"fs:#decl": or,
|
|
2783
|
+
"fs:DECKGL_FILTER_COLOR": (
|
|
2784
|
+
/* glsl */
|
|
2785
|
+
`
|
|
2786
|
+
color.rgb = cielabToRgb(color);
|
|
2787
|
+
`
|
|
2788
|
+
)
|
|
2789
|
+
}
|
|
2790
|
+
}, ar = (
|
|
2791
|
+
/* glsl */
|
|
2792
|
+
`
|
|
2793
|
+
vec3 cmykToRgb(vec4 cmyk) {
|
|
2794
|
+
// cmyk in [0.0, 1.0]
|
|
2795
|
+
float invK = 1.0 - cmyk.a;
|
|
2796
|
+
|
|
2797
|
+
return vec3(
|
|
2798
|
+
(1.0 - cmyk.r) * invK,
|
|
2799
|
+
(1.0 - cmyk.g) * invK,
|
|
2800
|
+
(1.0 - cmyk.b) * invK
|
|
2801
|
+
);
|
|
2802
|
+
}
|
|
2803
|
+
`
|
|
2804
|
+
), sr = {
|
|
2805
|
+
name: "cmyk-to-rgb",
|
|
2806
|
+
inject: {
|
|
2807
|
+
"fs:#decl": ar,
|
|
2808
|
+
"fs:DECKGL_FILTER_COLOR": (
|
|
2809
|
+
/* glsl */
|
|
2810
|
+
`
|
|
2811
|
+
color.rgb = cmykToRgb(color);
|
|
2812
|
+
`
|
|
2813
|
+
)
|
|
2814
|
+
}
|
|
2815
|
+
}, lr = (
|
|
2816
|
+
/* glsl */
|
|
2817
|
+
`
|
|
2818
|
+
vec3 white_zero_to_rgb(float value) {
|
|
2819
|
+
return vec3(1.0 - value, 1.0 - value, 1.0 - value);
|
|
2820
|
+
}
|
|
2821
|
+
`
|
|
2822
|
+
), cr = {
|
|
2823
|
+
name: "white-is-zero",
|
|
2824
|
+
inject: {
|
|
2825
|
+
"fs:#decl": lr,
|
|
2826
|
+
"fs:DECKGL_FILTER_COLOR": (
|
|
2827
|
+
/* glsl */
|
|
2828
|
+
`
|
|
2829
|
+
color.rgb = white_zero_to_rgb(color.r);
|
|
2830
|
+
`
|
|
2831
|
+
)
|
|
2832
|
+
}
|
|
2833
|
+
}, ur = {
|
|
2834
|
+
name: "mask-texture",
|
|
2835
|
+
inject: {
|
|
2836
|
+
"fs:#decl": "uniform sampler2D maskTexture;",
|
|
2837
|
+
"fs:DECKGL_FILTER_COLOR": (
|
|
2838
|
+
/* glsl */
|
|
2839
|
+
`
|
|
2840
|
+
float maskValue = texture(maskTexture, geometry.uv).r;
|
|
2841
|
+
if (maskValue == 0.0) {
|
|
2842
|
+
discard;
|
|
2843
|
+
}
|
|
2844
|
+
`
|
|
2845
|
+
)
|
|
2846
|
+
},
|
|
2847
|
+
getUniforms: (e) => ({
|
|
2848
|
+
maskTexture: e.maskTexture
|
|
2849
|
+
})
|
|
2850
|
+
};
|
|
2851
|
+
function dr(e, t, n) {
|
|
2852
|
+
const r = hr(e), o = pr(t), i = gr(n), a = `${r}:${i}:${o}`, s = mr[a];
|
|
2853
|
+
if (!s)
|
|
2854
|
+
throw new Error(`Unsupported texture format for SamplesPerPixel=${e}, BitsPerSample=${t}, SampleFormat=${n}`);
|
|
2855
|
+
return s;
|
|
2856
|
+
}
|
|
2857
|
+
function hr(e) {
|
|
2858
|
+
if (e === 1 || e === 2 || e === 3 || e === 4)
|
|
2859
|
+
return e;
|
|
2860
|
+
throw new Error(`Unsupported SamplesPerPixel ${e}. Only 1, 2, 3, or 4 are supported.`);
|
|
2861
|
+
}
|
|
2862
|
+
function pr(e) {
|
|
2863
|
+
const t = e[0];
|
|
2864
|
+
for (let n = 1; n < e.length; n++)
|
|
2865
|
+
if (e[n] !== t)
|
|
2866
|
+
throw new Error(`Unsupported varying BitsPerSample ${e}. All samples must have the same bit width.`);
|
|
2867
|
+
if (t !== 8 && t !== 16 && t !== 32)
|
|
2868
|
+
throw new Error(`Unsupported BitsPerSample ${t}. Only 8, 16, or 32 are supported.`);
|
|
2869
|
+
return t;
|
|
2870
|
+
}
|
|
2871
|
+
function gr(e) {
|
|
2872
|
+
const t = e[0];
|
|
2873
|
+
for (let n = 1; n < e.length; n++)
|
|
2874
|
+
if (e[n] !== t)
|
|
2875
|
+
throw new Error(`Unsupported varying SampleFormat ${e}. All samples must have the same format.`);
|
|
2876
|
+
switch (t) {
|
|
2877
|
+
case F.Uint:
|
|
2878
|
+
return "unorm";
|
|
2879
|
+
case F.Int:
|
|
2880
|
+
return "sint";
|
|
2881
|
+
case F.Float:
|
|
2882
|
+
return "float";
|
|
2883
|
+
default:
|
|
2884
|
+
throw new Error(`Unsupported SampleFormat ${e}`);
|
|
2885
|
+
}
|
|
2886
|
+
}
|
|
2887
|
+
const mr = {
|
|
2888
|
+
// 1 byte per pixel
|
|
2889
|
+
"1:sint:8": "r8sint",
|
|
2890
|
+
"1:uint:8": "r8uint",
|
|
2891
|
+
"1:unorm:8": "r8unorm",
|
|
2892
|
+
// 2 bytes per pixel (one channel)
|
|
2893
|
+
"1:float:16": "r16float",
|
|
2894
|
+
"1:sint:16": "r16sint",
|
|
2895
|
+
"1:uint:16": "r16uint",
|
|
2896
|
+
"1:unorm:16": "r16unorm",
|
|
2897
|
+
// 2 bytes per pixel (two channels)
|
|
2898
|
+
"2:sint:8": "rg8sint",
|
|
2899
|
+
"2:uint:8": "rg8uint",
|
|
2900
|
+
"2:unorm:8": "rg8unorm",
|
|
2901
|
+
// 4 bytes per pixel (one channel)
|
|
2902
|
+
"1:float:32": "r32float",
|
|
2903
|
+
"1:sint:32": "r32sint",
|
|
2904
|
+
"1:uint:32": "r32uint",
|
|
2905
|
+
// 4 bytes per pixel (two channels)
|
|
2906
|
+
"2:float:16": "rg16float",
|
|
2907
|
+
"2:sint:16": "rg16sint",
|
|
2908
|
+
"2:uint:16": "rg16uint",
|
|
2909
|
+
"2:unorm:16": "rg16unorm",
|
|
2910
|
+
// 4 bytes per pixel (four channels)
|
|
2911
|
+
"4:sint:8": "rgba8sint",
|
|
2912
|
+
"4:uint:8": "rgba8uint",
|
|
2913
|
+
"4:unorm:8": "rgba8unorm",
|
|
2914
|
+
// 6 bytes per pixel (three channels)
|
|
2915
|
+
// Note: this is supported on WebGL2 but not supported on WebGPU
|
|
2916
|
+
// I expect actual switch to WebGPU to be quite a ways off still
|
|
2917
|
+
"3:uint:16": "rgb16unorm-webgl",
|
|
2918
|
+
// 8 bytes per pixel (two channels)
|
|
2919
|
+
"2:float:32": "rg32float",
|
|
2920
|
+
"2:sint:32": "rg32sint",
|
|
2921
|
+
"2:uint:32": "rg32uint",
|
|
2922
|
+
// 8 bytes per pixel (four channels)
|
|
2923
|
+
"4:float:16": "rgba16float",
|
|
2924
|
+
"4:sint:16": "rgba16sint",
|
|
2925
|
+
"4:uint:16": "rgba16uint",
|
|
2926
|
+
"4:unorm:16": "rgba16unorm",
|
|
2927
|
+
// 12 bytes per pixel (three channels)
|
|
2928
|
+
"3:float:32": "rgb32float-webgl",
|
|
2929
|
+
// 16 bytes per pixel (four channels)
|
|
2930
|
+
"4:float:32": "rgba32float",
|
|
2931
|
+
"4:sint:32": "rgba32sint",
|
|
2932
|
+
"4:uint:32": "rgba32uint"
|
|
2933
|
+
};
|
|
2934
|
+
function fr(e, t) {
|
|
2935
|
+
const { sampleFormat: n } = e.cachedTags;
|
|
2936
|
+
if (n === null)
|
|
2937
|
+
throw new Error("SampleFormat tag is required to infer render pipeline");
|
|
2938
|
+
switch (n[0]) {
|
|
2939
|
+
// Unsigned integers
|
|
2940
|
+
case F.Uint:
|
|
2941
|
+
return yr(e, t);
|
|
2942
|
+
}
|
|
2943
|
+
throw new Error(`Inferring render pipeline for non-unsigned integers not yet supported. Found SampleFormat: ${n}`);
|
|
2944
|
+
}
|
|
2945
|
+
function yr(e, t) {
|
|
2946
|
+
const { bitsPerSample: n, colorMap: r, photometric: o, sampleFormat: i, samplesPerPixel: a, nodata: s } = e.cachedTags, l = [
|
|
2947
|
+
{
|
|
2948
|
+
module: it,
|
|
2949
|
+
props: {
|
|
2950
|
+
textureName: (f) => f.texture
|
|
2951
|
+
}
|
|
2952
|
+
}
|
|
2953
|
+
];
|
|
2954
|
+
if (s !== null) {
|
|
2955
|
+
const f = 2 ** n[0] - 1, S = s / f;
|
|
2956
|
+
l.push({
|
|
2957
|
+
module: at,
|
|
2958
|
+
props: { value: S }
|
|
2959
|
+
});
|
|
2960
|
+
}
|
|
2961
|
+
e.maskImage !== null && l.push({
|
|
2962
|
+
module: ur,
|
|
2963
|
+
props: {
|
|
2964
|
+
// TODO: how to handle if mask failed to load and is undefined here
|
|
2965
|
+
maskTexture: (f) => f.mask
|
|
2966
|
+
}
|
|
2967
|
+
});
|
|
2968
|
+
const c = wr({
|
|
2969
|
+
count: a,
|
|
2970
|
+
photometric: o,
|
|
2971
|
+
device: t,
|
|
2972
|
+
colorMap: r
|
|
2973
|
+
});
|
|
2974
|
+
c && l.push(c);
|
|
2975
|
+
const d = o === E.Palette ? {
|
|
2976
|
+
magFilter: "nearest",
|
|
2977
|
+
minFilter: "nearest"
|
|
2978
|
+
} : {
|
|
2979
|
+
magFilter: "linear",
|
|
2980
|
+
minFilter: "linear"
|
|
2981
|
+
};
|
|
2982
|
+
return { getTileData: async (f, S) => {
|
|
2983
|
+
const { device: P, x: C, y: j, signal: b, pool: G } = S, R = await f.fetchTile(C, j, {
|
|
2984
|
+
boundless: !1,
|
|
2985
|
+
pool: G,
|
|
2986
|
+
signal: b
|
|
2987
|
+
});
|
|
2988
|
+
let { array: I } = R;
|
|
2989
|
+
const { width: se, height: le, mask: Z } = I;
|
|
2990
|
+
let ce = a;
|
|
2991
|
+
if (a === 3 && (I = Tn(I), ce = 4), I.layout === "band-separate")
|
|
2992
|
+
throw new Error("Band-separate images not yet implemented.");
|
|
2993
|
+
const et = dr(
|
|
2994
|
+
// Add one sample for added alpha channel
|
|
2995
|
+
ce,
|
|
2996
|
+
n,
|
|
2997
|
+
i
|
|
2998
|
+
);
|
|
2999
|
+
let ue = I.data.byteLength;
|
|
3000
|
+
const tt = P.createTexture({
|
|
3001
|
+
data: I.data,
|
|
3002
|
+
format: et,
|
|
3003
|
+
width: se,
|
|
3004
|
+
height: le,
|
|
3005
|
+
sampler: d
|
|
3006
|
+
});
|
|
3007
|
+
let de;
|
|
3008
|
+
return Z !== null && (de = P.createTexture({
|
|
3009
|
+
data: Z,
|
|
3010
|
+
// Single-channel 8-bit texture for the mask
|
|
3011
|
+
format: "r8unorm",
|
|
3012
|
+
width: se,
|
|
3013
|
+
height: le,
|
|
3014
|
+
// Use nearest filtering for the mask to avoid interpolated edges/halos
|
|
3015
|
+
sampler: {
|
|
3016
|
+
minFilter: "nearest",
|
|
3017
|
+
magFilter: "nearest"
|
|
3018
|
+
}
|
|
3019
|
+
}), ue += Z.byteLength), {
|
|
3020
|
+
texture: tt,
|
|
3021
|
+
mask: de,
|
|
3022
|
+
byteLength: ue,
|
|
3023
|
+
height: I.height,
|
|
3024
|
+
width: I.width
|
|
3025
|
+
};
|
|
3026
|
+
}, renderTile: (f) => ({
|
|
3027
|
+
renderPipeline: l.map((S, P) => Sr(S, f))
|
|
3028
|
+
}) };
|
|
3029
|
+
}
|
|
3030
|
+
function wr({ count: e, colorMap: t, device: n, photometric: r }) {
|
|
3031
|
+
if (e === 3 || e === 4)
|
|
3032
|
+
return null;
|
|
3033
|
+
switch (r) {
|
|
3034
|
+
case E.MinIsWhite:
|
|
3035
|
+
return {
|
|
3036
|
+
module: cr
|
|
3037
|
+
};
|
|
3038
|
+
case E.MinIsBlack:
|
|
3039
|
+
return {
|
|
3040
|
+
module: rr
|
|
3041
|
+
};
|
|
3042
|
+
case E.Rgb:
|
|
3043
|
+
return null;
|
|
3044
|
+
case E.Palette: {
|
|
3045
|
+
if (!t)
|
|
3046
|
+
throw new Error("ColorMap is required for PhotometricInterpretation Palette");
|
|
3047
|
+
const { data: o, width: i, height: a } = mt(t), s = n.createTexture({
|
|
3048
|
+
dimension: "2d-array",
|
|
3049
|
+
data: o,
|
|
3050
|
+
format: "rgba8unorm",
|
|
3051
|
+
width: i,
|
|
3052
|
+
height: a,
|
|
3053
|
+
depth: 1,
|
|
3054
|
+
mipLevels: 1,
|
|
3055
|
+
sampler: {
|
|
3056
|
+
minFilter: "nearest",
|
|
3057
|
+
magFilter: "nearest",
|
|
3058
|
+
addressModeU: "clamp-to-edge",
|
|
3059
|
+
addressModeV: "clamp-to-edge",
|
|
3060
|
+
addressModeW: "clamp-to-edge"
|
|
3061
|
+
}
|
|
3062
|
+
});
|
|
3063
|
+
return {
|
|
3064
|
+
module: ot,
|
|
3065
|
+
props: {
|
|
3066
|
+
colormapTexture: s
|
|
3067
|
+
}
|
|
3068
|
+
};
|
|
3069
|
+
}
|
|
3070
|
+
// Not sure why cogeotiff calls this "Separated", but it means CMYK
|
|
3071
|
+
case E.Separated:
|
|
3072
|
+
return {
|
|
3073
|
+
module: sr
|
|
3074
|
+
};
|
|
3075
|
+
case E.Ycbcr:
|
|
3076
|
+
return null;
|
|
3077
|
+
case E.Cielab:
|
|
3078
|
+
return {
|
|
3079
|
+
module: ir
|
|
3080
|
+
};
|
|
3081
|
+
default:
|
|
3082
|
+
throw new Error(`Unsupported PhotometricInterpretation ${r}`);
|
|
3083
|
+
}
|
|
3084
|
+
}
|
|
3085
|
+
function Sr(e, t) {
|
|
3086
|
+
const { module: n, props: r } = e;
|
|
3087
|
+
if (!r)
|
|
3088
|
+
return { module: n };
|
|
3089
|
+
const o = {};
|
|
3090
|
+
for (const [i, a] of Object.entries(r)) {
|
|
3091
|
+
const s = typeof a == "function" ? a(t) : a;
|
|
3092
|
+
s !== void 0 && (o[i] = s);
|
|
3093
|
+
}
|
|
3094
|
+
return { module: n, props: o };
|
|
3095
|
+
}
|
|
3096
|
+
function Pr(e, t) {
|
|
3097
|
+
const r = [
|
|
3098
|
+
...[...e.overviews].reverse(),
|
|
3099
|
+
e
|
|
3100
|
+
].map((o) => new st({
|
|
3101
|
+
affine: o.transform,
|
|
3102
|
+
arrayWidth: o.width,
|
|
3103
|
+
arrayHeight: o.height,
|
|
3104
|
+
tileWidth: o.tileWidth,
|
|
3105
|
+
tileHeight: o.tileHeight,
|
|
3106
|
+
mpu: t.mpu
|
|
3107
|
+
}));
|
|
3108
|
+
return new lt({
|
|
3109
|
+
levels: r,
|
|
3110
|
+
projectTo3857: t.projectTo3857,
|
|
3111
|
+
projectFrom3857: t.projectFrom3857,
|
|
3112
|
+
projectTo4326: t.projectTo4326,
|
|
3113
|
+
projectFrom4326: t.projectFrom4326
|
|
3114
|
+
});
|
|
3115
|
+
}
|
|
3116
|
+
class Cr extends he {
|
|
3117
|
+
static layerName = "COGLayer";
|
|
3118
|
+
// COGLayer's getTileData signature differs from the base class's, so
|
|
3119
|
+
// `DefaultProps<COGLayerProps>` is not assignable to
|
|
3120
|
+
// `DefaultProps<RasterTileLayerProps>`. Cast to the base static-side type
|
|
3121
|
+
// to keep inheritance happy. The only COG-specific default is
|
|
3122
|
+
// `epsgResolver`; all behavior still flows from the base class.
|
|
3123
|
+
static defaultProps = {
|
|
3124
|
+
...he.defaultProps,
|
|
3125
|
+
epsgResolver: ct
|
|
3126
|
+
};
|
|
3127
|
+
initializeState() {
|
|
3128
|
+
this.setState({});
|
|
3129
|
+
}
|
|
3130
|
+
updateState(t) {
|
|
3131
|
+
super.updateState(t);
|
|
3132
|
+
const { props: n, oldProps: r, changeFlags: o } = t;
|
|
3133
|
+
(!!o.dataChanged || n.geotiff !== r.geotiff) && (this.clearState(), this._parseGeoTIFF());
|
|
3134
|
+
}
|
|
3135
|
+
clearState() {
|
|
3136
|
+
this.setState({
|
|
3137
|
+
geotiff: void 0,
|
|
3138
|
+
tilesetDescriptor: void 0,
|
|
3139
|
+
defaultGetTileData: void 0,
|
|
3140
|
+
defaultRenderTile: void 0
|
|
3141
|
+
});
|
|
3142
|
+
}
|
|
3143
|
+
async _parseGeoTIFF() {
|
|
3144
|
+
const t = await er(this.props.geotiff), n = t.crs, r = typeof n == "number" ? await this.props.epsgResolver(n) : ut(n), o = pe(r, "EPSG:4326"), i = (P, C) => o.forward([P, C], !1), a = (P, C) => o.inverse([P, C], !1), s = pe(r, "EPSG:3857"), l = ht((P, C) => s.forward([P, C], !1), i), c = (P, C) => s.inverse([P, C], !1), d = r.units;
|
|
3145
|
+
if (!d)
|
|
3146
|
+
throw new Error("Source projection is missing 'units' property, cannot compute meters per unit");
|
|
3147
|
+
const h = dt(d, {
|
|
3148
|
+
semiMajorAxis: r.datum?.a ?? r.a
|
|
3149
|
+
}), g = Pr(t, {
|
|
3150
|
+
projectTo4326: i,
|
|
3151
|
+
projectFrom4326: a,
|
|
3152
|
+
projectTo3857: l,
|
|
3153
|
+
projectFrom3857: c,
|
|
3154
|
+
mpu: h
|
|
3155
|
+
});
|
|
3156
|
+
if (this.props.onGeoTIFFLoad) {
|
|
3157
|
+
const P = tr(t, o);
|
|
3158
|
+
this.props.onGeoTIFFLoad(t, {
|
|
3159
|
+
projection: r,
|
|
3160
|
+
geographicBounds: P
|
|
3161
|
+
});
|
|
3162
|
+
}
|
|
3163
|
+
let f, S;
|
|
3164
|
+
(!this.props.getTileData || !this.props.renderTile) && ({ getTileData: f, renderTile: S } = fr(t, this.context.device)), this.setState({
|
|
3165
|
+
geotiff: t,
|
|
3166
|
+
tilesetDescriptor: g,
|
|
3167
|
+
defaultGetTileData: f,
|
|
3168
|
+
defaultRenderTile: S
|
|
3169
|
+
});
|
|
3170
|
+
}
|
|
3171
|
+
_tilesetDescriptor() {
|
|
3172
|
+
return this.state.tilesetDescriptor;
|
|
3173
|
+
}
|
|
3174
|
+
/**
|
|
3175
|
+
* Adapts the user-facing `(image, { x, y, ... }) => Promise<DataT>` signature
|
|
3176
|
+
* into RasterTileLayer's `(tile, { signal, device }) => Promise<DataT>`.
|
|
3177
|
+
*/
|
|
3178
|
+
_getTileDataCallback() {
|
|
3179
|
+
const t = this.state.geotiff;
|
|
3180
|
+
if (!t)
|
|
3181
|
+
return;
|
|
3182
|
+
const n = this.props.getTileData ?? this.state.defaultGetTileData;
|
|
3183
|
+
return n ? async (o, i) => {
|
|
3184
|
+
const { x: a, y: s, z: l } = o.index, c = l === t.overviews.length ? t : t.overviews[t.overviews.length - 1 - l];
|
|
3185
|
+
return n(c, {
|
|
3186
|
+
device: i.device,
|
|
3187
|
+
x: a,
|
|
3188
|
+
y: s,
|
|
3189
|
+
signal: i.signal,
|
|
3190
|
+
pool: this.props.pool ?? qn()
|
|
3191
|
+
});
|
|
3192
|
+
} : void 0;
|
|
3193
|
+
}
|
|
3194
|
+
_renderTileCallback() {
|
|
3195
|
+
const t = this.props.renderTile ?? this.state.defaultRenderTile;
|
|
3196
|
+
if (t)
|
|
3197
|
+
return t;
|
|
3198
|
+
}
|
|
3199
|
+
}
|
|
3200
|
+
const Te = `var j;
|
|
3201
|
+
(function(e) {
|
|
3202
|
+
e[e.Big = 19789] = "Big", e[e.Little = 18761] = "Little";
|
|
3203
|
+
})(j || (j = {}));
|
|
3204
|
+
var F;
|
|
3205
|
+
(function(e) {
|
|
3206
|
+
e[e.ReducedImage = 1] = "ReducedImage", e[e.Page = 2] = "Page", e[e.Mask = 4] = "Mask";
|
|
3207
|
+
})(F || (F = {}));
|
|
3208
|
+
var m;
|
|
3209
|
+
(function(e) {
|
|
3210
|
+
e[e.TopLeft = 1] = "TopLeft", e[e.TopRight = 2] = "TopRight", e[e.BottomRight = 3] = "BottomRight", e[e.BottomLeft = 4] = "BottomLeft", e[e.LeftTop = 5] = "LeftTop", e[e.RightTOP = 6] = "RightTOP", e[e.RightBottom = 7] = "RightBottom", e[e.LeftBottom = 8] = "LeftBottom";
|
|
3211
|
+
})(m || (m = {}));
|
|
3212
|
+
var A;
|
|
3213
|
+
(function(e) {
|
|
3214
|
+
e[e.PixelIsArea = 1] = "PixelIsArea", e[e.PixelIsPoint = 2] = "PixelIsPoint";
|
|
3215
|
+
})(A || (A = {}));
|
|
3216
|
+
var G;
|
|
3217
|
+
(function(e) {
|
|
3218
|
+
e[e.Unknown = 0] = "Unknown", e[e.Projected = 1] = "Projected", e[e.Geographic = 2] = "Geographic", e[e.Geocentric = 3] = "Geocentric", e[e.UserDefined = 32767] = "UserDefined";
|
|
3219
|
+
})(G || (G = {}));
|
|
3220
|
+
var C;
|
|
3221
|
+
(function(e) {
|
|
3222
|
+
e[e.Image = 1] = "Image", e[e.ReducedImage = 2] = "ReducedImage", e[e.Page = 3] = "Page";
|
|
3223
|
+
})(C || (C = {}));
|
|
3224
|
+
var t;
|
|
3225
|
+
(function(e) {
|
|
3226
|
+
e[e.None = 1] = "None", e[e.Ccittrle = 2] = "Ccittrle", e[e.CcittT4 = 3] = "CcittT4", e[e.CcittT6 = 4] = "CcittT6", e[e.Lzw = 5] = "Lzw", e[e.Jpeg6 = 6] = "Jpeg6", e[e.Jpeg = 7] = "Jpeg", e[e.DeflateOther = 8] = "DeflateOther", e[e.T85 = 9] = "T85", e[e.T43 = 10] = "T43", e[e.Next = 32766] = "Next", e[e.Ccittrlew = 32771] = "Ccittrlew", e[e.PackBits = 32773] = "PackBits", e[e.ThunderScan = 32809] = "ThunderScan", e[e.It8ctpad = 32895] = "It8ctpad", e[e.It8lw = 32896] = "It8lw", e[e.It8mp = 32897] = "It8mp", e[e.It8bl = 32898] = "It8bl", e[e.PixarFilm = 32908] = "PixarFilm", e[e.PixarLog = 32909] = "PixarLog", e[e.Deflate = 32946] = "Deflate", e[e.Dcs = 32947] = "Dcs", e[e.Jbig = 34661] = "Jbig", e[e.SgiLog = 34676] = "SgiLog", e[e.SgiLog24 = 34677] = "SgiLog24", e[e.Jp2000 = 34712] = "Jp2000", e[e.Lerc = 34887] = "Lerc", e[e.Lzma = 34925] = "Lzma", e[e.Zstd = 5e4] = "Zstd", e[e.Webp = 50001] = "Webp", e[e.JpegXl = 50002] = "JpegXl", e[e.JpegXlDng17 = 52546] = "JpegXlDng17";
|
|
3227
|
+
})(t || (t = {}));
|
|
3228
|
+
var x;
|
|
3229
|
+
(function(e) {
|
|
3230
|
+
e[e.Contig = 1] = "Contig", e[e.Separate = 2] = "Separate";
|
|
3231
|
+
})(x || (x = {}));
|
|
3232
|
+
var L;
|
|
3233
|
+
(function(e) {
|
|
3234
|
+
e[e.None = 1] = "None", e[e.Horizontal = 2] = "Horizontal", e[e.FloatingPoint = 3] = "FloatingPoint";
|
|
3235
|
+
})(L || (L = {}));
|
|
3236
|
+
var R;
|
|
3237
|
+
(function(e) {
|
|
3238
|
+
e[e.Uint = 1] = "Uint", e[e.Int = 2] = "Int", e[e.Float = 3] = "Float", e[e.Void = 4] = "Void", e[e.ComplexInt = 5] = "ComplexInt", e[e.ComplexFloat = 6] = "ComplexFloat";
|
|
3239
|
+
})(R || (R = {}));
|
|
3240
|
+
var N;
|
|
3241
|
+
(function(e) {
|
|
3242
|
+
e[e.MinIsWhite = 0] = "MinIsWhite", e[e.MinIsBlack = 1] = "MinIsBlack", e[e.Rgb = 2] = "Rgb", e[e.Palette = 3] = "Palette", e[e.Mask = 4] = "Mask", e[e.Separated = 5] = "Separated", e[e.Ycbcr = 6] = "Ycbcr", e[e.Cielab = 8] = "Cielab", e[e.Icclab = 9] = "Icclab", e[e.Itulab = 10] = "Itulab", e[e.Cfa = 32803] = "Cfa", e[e.Logl = 32844] = "Logl", e[e.Logluv = 32845] = "Logluv";
|
|
3243
|
+
})(N || (N = {}));
|
|
3244
|
+
var s;
|
|
3245
|
+
(function(e) {
|
|
3246
|
+
e[e.SubFileType = 254] = "SubFileType", e[e.OldSubFileType = 255] = "OldSubFileType", e[e.ImageWidth = 256] = "ImageWidth", e[e.ImageHeight = 257] = "ImageHeight", e[e.BitsPerSample = 258] = "BitsPerSample", e[e.SampleFormat = 339] = "SampleFormat", e[e.Compression = 259] = "Compression", e[e.Photometric = 262] = "Photometric", e[e.TileWidth = 322] = "TileWidth", e[e.TileHeight = 323] = "TileHeight", e[e.TileOffsets = 324] = "TileOffsets", e[e.TileByteCounts = 325] = "TileByteCounts", e[e.JpegTables = 347] = "JpegTables", e[e.StripOffsets = 273] = "StripOffsets", e[e.StripByteCounts = 279] = "StripByteCounts", e[e.GdalMetadata = 42112] = "GdalMetadata", e[e.GdalNoData = 42113] = "GdalNoData", e[e.ModelPixelScale = 33550] = "ModelPixelScale", e[e.ModelTiePoint = 33922] = "ModelTiePoint", e[e.ModelTransformation = 34264] = "ModelTransformation", e[e.GeoKeyDirectory = 34735] = "GeoKeyDirectory", e[e.GeoDoubleParams = 34736] = "GeoDoubleParams", e[e.GeoAsciiParams = 34737] = "GeoAsciiParams", e[e.LercParameters = 50674] = "LercParameters", e[e.PlanarConfiguration = 284] = "PlanarConfiguration", e[e.CellLength = 265] = "CellLength", e[e.CellWidth = 264] = "CellWidth", e[e.ColorMap = 320] = "ColorMap", e[e.Copyright = 33432] = "Copyright", e[e.DateTime = 306] = "DateTime", e[e.ExtraSamples = 338] = "ExtraSamples", e[e.FillOrder = 266] = "FillOrder", e[e.FreeByteCounts = 289] = "FreeByteCounts", e[e.FreeOffsets = 288] = "FreeOffsets", e[e.GrayResponseCurve = 291] = "GrayResponseCurve", e[e.GrayResponseUnit = 290] = "GrayResponseUnit", e[e.HostComputer = 316] = "HostComputer", e[e.ImageDescription = 270] = "ImageDescription", e[e.Make = 271] = "Make", e[e.MaxSampleValue = 281] = "MaxSampleValue", e[e.MinSampleValue = 280] = "MinSampleValue", e[e.Model = 272] = "Model", e[e.Orientation = 274] = "Orientation", e[e.ResolutionUnit = 296] = "ResolutionUnit", e[e.RowsPerStrip = 278] = "RowsPerStrip", e[e.SamplesPerPixel = 277] = "SamplesPerPixel", e[e.Software = 305] = "Software", e[e.Threshholding = 263] = "Threshholding", e[e.XResolution = 282] = "XResolution", e[e.YResolution = 283] = "YResolution", e[e.BadFaxLines = 326] = "BadFaxLines", e[e.CleanFaxData = 327] = "CleanFaxData", e[e.ClipPath = 343] = "ClipPath", e[e.ConsecutiveBadFaxLines = 328] = "ConsecutiveBadFaxLines", e[e.Decode = 433] = "Decode", e[e.DefaultImageColor = 434] = "DefaultImageColor", e[e.DocumentName = 269] = "DocumentName", e[e.DotRange = 336] = "DotRange", e[e.HalftoneHints = 321] = "HalftoneHints", e[e.Indexed = 346] = "Indexed", e[e.PageName = 285] = "PageName", e[e.PageNumber = 297] = "PageNumber", e[e.Predictor = 317] = "Predictor", e[e.PrimaryChromaticities = 319] = "PrimaryChromaticities", e[e.ReferenceBlackWhite = 532] = "ReferenceBlackWhite", e[e.SMinSampleValue = 340] = "SMinSampleValue", e[e.SMaxSampleValue = 341] = "SMaxSampleValue", e[e.StripRowCounts = 559] = "StripRowCounts", e[e.SubIFDs = 330] = "SubIFDs", e[e.T4Options = 292] = "T4Options", e[e.T6Options = 293] = "T6Options", e[e.TransferFunction = 301] = "TransferFunction", e[e.WhitePoint = 318] = "WhitePoint", e[e.XClipPathUnits = 344] = "XClipPathUnits", e[e.XPosition = 286] = "XPosition", e[e.YCbCrCoefficients = 529] = "YCbCrCoefficients", e[e.YCbCrPositioning = 531] = "YCbCrPositioning", e[e.YCbCrSubSampling = 530] = "YCbCrSubSampling", e[e.YClipPathUnits = 345] = "YClipPathUnits", e[e.YPosition = 287] = "YPosition", e[e.ApertureValue = 37378] = "ApertureValue", e[e.ColorSpace = 40961] = "ColorSpace", e[e.DateTimeDigitized = 36868] = "DateTimeDigitized", e[e.DateTimeOriginal = 36867] = "DateTimeOriginal", e[e.ExifIFD = 34665] = "ExifIFD", e[e.ExifVersion = 36864] = "ExifVersion", e[e.ExposureTime = 33434] = "ExposureTime", e[e.FileSource = 41728] = "FileSource", e[e.Flash = 37385] = "Flash", e[e.FlashpixVersion = 40960] = "FlashpixVersion", e[e.FNumber = 33437] = "FNumber", e[e.ImageUniqueID = 42016] = "ImageUniqueID", e[e.LightSource = 37384] = "LightSource", e[e.MakerNote = 37500] = "MakerNote", e[e.ShutterSpeedValue = 37377] = "ShutterSpeedValue", e[e.UserComment = 37510] = "UserComment", e[e.IPTC = 33723] = "IPTC", e[e.ICCProfile = 34675] = "ICCProfile", e[e.XMP = 700] = "XMP";
|
|
3247
|
+
})(s || (s = {}));
|
|
3248
|
+
var v;
|
|
3249
|
+
(function(e) {
|
|
3250
|
+
e[e.GTModelTypeGeoKey = 1024] = "GTModelTypeGeoKey", e[e.GTRasterTypeGeoKey = 1025] = "GTRasterTypeGeoKey", e[e.GTCitationGeoKey = 1026] = "GTCitationGeoKey", e[e.GeodeticCRSGeoKey = 2048] = "GeodeticCRSGeoKey", e[e.GeodeticCitationGeoKey = 2049] = "GeodeticCitationGeoKey", e[e.GeodeticDatumGeoKey = 2050] = "GeodeticDatumGeoKey", e[e.PrimeMeridianGeoKey = 2051] = "PrimeMeridianGeoKey", e[e.GeogLinearUnitsGeoKey = 2052] = "GeogLinearUnitsGeoKey", e[e.GeogLinearUnitSizeGeoKey = 2053] = "GeogLinearUnitSizeGeoKey", e[e.GeogAngularUnitsGeoKey = 2054] = "GeogAngularUnitsGeoKey", e[e.GeogAngularUnitSizeGeoKey = 2055] = "GeogAngularUnitSizeGeoKey", e[e.EllipsoidGeoKey = 2056] = "EllipsoidGeoKey", e[e.EllipsoidSemiMajorAxisGeoKey = 2057] = "EllipsoidSemiMajorAxisGeoKey", e[e.EllipsoidSemiMinorAxisGeoKey = 2058] = "EllipsoidSemiMinorAxisGeoKey", e[e.EllipsoidInvFlatteningGeoKey = 2059] = "EllipsoidInvFlatteningGeoKey", e[e.PrimeMeridianLongitudeGeoKey = 2061] = "PrimeMeridianLongitudeGeoKey", e[e.GeogTOWGS84GeoKey = 2062] = "GeogTOWGS84GeoKey", e[e.GeogAzimuthUnitsGeoKey = 2060] = "GeogAzimuthUnitsGeoKey", e[e.ProjectedCRSGeoKey = 3072] = "ProjectedCRSGeoKey", e[e.ProjectedCitationGeoKey = 3073] = "ProjectedCitationGeoKey", e[e.ProjectionGeoKey = 3074] = "ProjectionGeoKey", e[e.ProjMethodGeoKey = 3075] = "ProjMethodGeoKey", e[e.ProjLinearUnitsGeoKey = 3076] = "ProjLinearUnitsGeoKey", e[e.ProjLinearUnitSizeGeoKey = 3077] = "ProjLinearUnitSizeGeoKey", e[e.ProjStdParallel1GeoKey = 3078] = "ProjStdParallel1GeoKey", e[e.ProjStdParallel2GeoKey = 3079] = "ProjStdParallel2GeoKey", e[e.ProjNatOriginLongGeoKey = 3080] = "ProjNatOriginLongGeoKey", e[e.ProjNatOriginLatGeoKey = 3081] = "ProjNatOriginLatGeoKey", e[e.ProjFalseEastingGeoKey = 3082] = "ProjFalseEastingGeoKey", e[e.ProjFalseNorthingGeoKey = 3083] = "ProjFalseNorthingGeoKey", e[e.ProjFalseOriginLongGeoKey = 3084] = "ProjFalseOriginLongGeoKey", e[e.ProjFalseOriginLatGeoKey = 3085] = "ProjFalseOriginLatGeoKey", e[e.ProjFalseOriginEastingGeoKey = 3086] = "ProjFalseOriginEastingGeoKey", e[e.ProjFalseOriginNorthingGeoKey = 3087] = "ProjFalseOriginNorthingGeoKey", e[e.ProjCenterLongGeoKey = 3088] = "ProjCenterLongGeoKey", e[e.ProjCenterLatGeoKey = 3089] = "ProjCenterLatGeoKey", e[e.ProjCenterEastingGeoKey = 3090] = "ProjCenterEastingGeoKey", e[e.ProjCenterNorthingGeoKey = 3091] = "ProjCenterNorthingGeoKey", e[e.ProjScaleAtNatOriginGeoKey = 3092] = "ProjScaleAtNatOriginGeoKey", e[e.ProjScaleAtCenterGeoKey = 3093] = "ProjScaleAtCenterGeoKey", e[e.ProjAzimuthAngleGeoKey = 3094] = "ProjAzimuthAngleGeoKey", e[e.ProjStraightVertPoleLongGeoKey = 3095] = "ProjStraightVertPoleLongGeoKey", e[e.ProjRectifiedGridAngleGeoKey = 3096] = "ProjRectifiedGridAngleGeoKey", e[e.VerticalGeoKey = 4096] = "VerticalGeoKey", e[e.VerticalCitationGeoKey = 4097] = "VerticalCitationGeoKey", e[e.VerticalDatumGeoKey = 4098] = "VerticalDatumGeoKey", e[e.VerticalUnitsGeoKey = 4099] = "VerticalUnitsGeoKey";
|
|
3251
|
+
})(v || (v = {}));
|
|
3252
|
+
var B;
|
|
3253
|
+
(function(e) {
|
|
3254
|
+
e[e.Radian = 9101] = "Radian", e[e.Degree = 9102] = "Degree", e[e.ArcMinute = 9103] = "ArcMinute", e[e.ArcDegree = 9104] = "ArcDegree", e[e.Grad = 9105] = "Grad", e[e.Gon = 9106] = "Gon", e[e.Dms = 9107] = "Dms";
|
|
3255
|
+
})(B || (B = {}));
|
|
3256
|
+
var M;
|
|
3257
|
+
(function(e) {
|
|
3258
|
+
e[e.Metre = 9001] = "Metre", e[e.Foot = 9002] = "Foot", e[e.FootUsSurvey = 9003] = "FootUsSurvey", e[e.FootModifiedAmerican = 9004] = "FootModifiedAmerican", e[e.FootClarke = 9005] = "FootClarke", e[e.FootIndian = 9006] = "FootIndian", e[e.Link = 9007] = "Link", e[e.LinkBenoit = 9008] = "LinkBenoit", e[e.LinkSears = 9009] = "LinkSears", e[e.ChainBenoit = 9010] = "ChainBenoit", e[e.ChainSears = 9011] = "ChainSears", e[e.YardSears = 9012] = "YardSears", e[e.YardIndian = 9013] = "YardIndian", e[e.Fathom = 9014] = "Fathom", e[e.MileInternationalNautical = 9015] = "MileInternationalNautical";
|
|
3259
|
+
})(M || (M = {}));
|
|
3260
|
+
s.TileByteCounts + "", s.TileOffsets + "", s.StripOffsets + "", s.StripByteCounts + "", s.BitsPerSample + "", s.SampleFormat + "", s.GeoKeyDirectory + "", s.GeoDoubleParams + "";
|
|
3261
|
+
var r;
|
|
3262
|
+
(function(e) {
|
|
3263
|
+
e.None = "application/octet-stream", e.Jbig = "image/jbig", e.Dcs = "image/x-kodak-dcs", e.PackBits = "application/packbits", e.Jpeg = "image/jpeg", e.Jp2000 = "image/jp2", e.JpegXl = "image/jpegxl", e.Webp = "image/webp", e.Zstd = "application/zstd", e.Lzw = "application/lzw", e.Deflate = "application/deflate", e.Lerc = "application/lerc", e.Lzma = "application/x-lzma";
|
|
3264
|
+
})(r || (r = {}));
|
|
3265
|
+
t.None + "", r.None, t.Lzw + "", r.Lzw, t.Jpeg6 + "", r.Jpeg, t.Jpeg + "", r.Jpeg, t.DeflateOther + "", r.Deflate, t.Deflate + "", r.Deflate, t.Lerc + "", r.Lerc, t.Lzma + "", r.Lzma, t.Jp2000 + "", r.Jp2000, t.Zstd + "", r.Zstd, t.Webp + "", r.Webp, t.JpegXl + "", r.JpegXl, t.Ccittrle + "", r.None, t.CcittT4 + "", r.None, t.CcittT6 + "", r.None, t.T85 + "", r.Jbig, t.T43 + "", r.Jbig, t.Next + "", r.None, t.Ccittrlew + "", r.None, t.PackBits + "", r.PackBits, t.ThunderScan + "", r.None, t.It8ctpad + "", r.None, t.It8lw + "", r.None, t.It8mp + "", r.None, t.It8bl + "", r.None, t.PixarFilm + "", r.None, t.PixarLog + "", r.None, t.Dcs + "", r.Dcs, t.Jbig + "", r.Jbig, t.SgiLog + "", r.None, t.SgiLog24 + "", r.None, t.JpegXlDng17 + "", r.JpegXl;
|
|
3266
|
+
var U;
|
|
3267
|
+
(function(e) {
|
|
3268
|
+
e[e.Uint8 = 1] = "Uint8", e[e.Ascii = 2] = "Ascii", e[e.Uint16 = 3] = "Uint16", e[e.Uint32 = 4] = "Uint32", e[e.Rational = 5] = "Rational", e[e.Int8 = 6] = "Int8", e[e.Undefined = 7] = "Undefined", e[e.Int16 = 8] = "Int16", e[e.Int32 = 9] = "Int32", e[e.SignedRational = 10] = "SignedRational", e[e.Float32 = 11] = "Float32", e[e.Float64 = 12] = "Float64", e[e.Ifd = 13] = "Ifd", e[e.Uint64 = 16] = "Uint64", e[e.Int64 = 17] = "Int64", e[e.Ifd8 = 18] = "Ifd8";
|
|
3269
|
+
})(U || (U = {}));
|
|
3270
|
+
var w;
|
|
3271
|
+
(function(e) {
|
|
3272
|
+
e[e.BigTiff = 43] = "BigTiff", e[e.Tiff = 42] = "Tiff";
|
|
3273
|
+
})(w || (w = {}));
|
|
3274
|
+
var E;
|
|
3275
|
+
(function(e) {
|
|
3276
|
+
e[e.Double = 8] = "Double", e[e.Float32 = 4] = "Float32";
|
|
3277
|
+
})(E || (E = {}));
|
|
3278
|
+
var K;
|
|
3279
|
+
(function(e) {
|
|
3280
|
+
e[e.UInt64 = 8] = "UInt64", e[e.UInt32 = 4] = "UInt32", e[e.UInt16 = 2] = "UInt16", e[e.UInt8 = 1] = "UInt8";
|
|
3281
|
+
})(K || (K = {}));
|
|
3282
|
+
const W = new ArrayBuffer(4), Y = new Uint32Array(W), X = new Uint8Array(W);
|
|
3283
|
+
Y[0] = 1;
|
|
3284
|
+
X[0];
|
|
3285
|
+
s.Compression, s.ImageHeight, s.ImageWidth, s.ModelPixelScale, s.ModelTiePoint, s.ModelTransformation, s.TileHeight, s.TileWidth;
|
|
3286
|
+
s.GeoKeyDirectory, s.GeoAsciiParams, s.GeoDoubleParams;
|
|
3287
|
+
var k;
|
|
3288
|
+
(function(e) {
|
|
3289
|
+
e.GdalStructuralMetadataSize = "GDAL_STRUCTURAL_METADATA_SIZE", e.Layout = "LAYOUT", e.BlockOrder = "BLOCK_ORDER", e.BlockLeader = "BLOCK_LEADER", e.BlockTrailer = "BLOCK_TRAILER", e.KnownIncompatibleEdition = "KNOWN_INCOMPATIBLE_EDITION", e.MaskInterleavedWithImagery = "MASK_INTERLEAVED_WITH_IMAGERY";
|
|
3290
|
+
})(k || (k = {}));
|
|
3291
|
+
var J;
|
|
3292
|
+
(function(e) {
|
|
3293
|
+
e.RowMajor = "ROW_MAJOR";
|
|
3294
|
+
})(J || (J = {}));
|
|
3295
|
+
var O;
|
|
3296
|
+
(function(e) {
|
|
3297
|
+
e.uint32 = "SIZE_AS_UINT4";
|
|
3298
|
+
})(O || (O = {}));
|
|
3299
|
+
const H = {
|
|
3300
|
+
version: w.Tiff,
|
|
3301
|
+
pointer: K.UInt32,
|
|
3302
|
+
offset: K.UInt16,
|
|
3303
|
+
/**
|
|
3304
|
+
* Each tag entry is specified as
|
|
3305
|
+
* UInt16:TagCode
|
|
3306
|
+
* UInt16:TagType
|
|
3307
|
+
* UInt32:TagCount
|
|
3308
|
+
* UInt32:Pointer To Value or value
|
|
3309
|
+
*/
|
|
3310
|
+
ifd: K.UInt16 + K.UInt16 + 2 * K.UInt32
|
|
3311
|
+
}, _ = {
|
|
3312
|
+
version: w.BigTiff,
|
|
3313
|
+
/** Size of most pointers */
|
|
3314
|
+
pointer: K.UInt64,
|
|
3315
|
+
/** Size of offsets */
|
|
3316
|
+
offset: K.UInt64,
|
|
3317
|
+
/**
|
|
3318
|
+
* Each tag entry is specified as
|
|
3319
|
+
* UInt16:TagCode
|
|
3320
|
+
* UInt16:TagType
|
|
3321
|
+
* UInt64:TagCount
|
|
3322
|
+
* UInt64:Pointer To Value or value
|
|
3323
|
+
*/
|
|
3324
|
+
ifd: K.UInt16 + K.UInt16 + 2 * K.UInt64
|
|
3325
|
+
};
|
|
3326
|
+
w.BigTiff + "", w.Tiff + "";
|
|
3327
|
+
async function b(e, n) {
|
|
3328
|
+
const l = new Blob([e]), o = await createImageBitmap(l), c = new OffscreenCanvas(o.width, o.height), d = c.getContext("2d");
|
|
3329
|
+
d.drawImage(o, 0, 0), o.close();
|
|
3330
|
+
const { width: P, height: a } = c, h = d.getImageData(0, 0, P, a).data, y = n.samplesPerPixel;
|
|
3331
|
+
if (y === 4)
|
|
3332
|
+
return { layout: "pixel-interleaved", data: h };
|
|
3333
|
+
if (y === 3) {
|
|
3334
|
+
const I = P * a, u = new Uint8ClampedArray(I * 3);
|
|
3335
|
+
for (let p = 0, D = 0; p < u.length; p += 3, D += 4)
|
|
3336
|
+
u[p] = h[D], u[p + 1] = h[D + 1], u[p + 2] = h[D + 2];
|
|
3337
|
+
return { layout: "pixel-interleaved", data: u };
|
|
3338
|
+
}
|
|
3339
|
+
if (y === 1) {
|
|
3340
|
+
const I = P * a, u = new Uint8ClampedArray(I);
|
|
3341
|
+
for (let p = 0, D = 0; p < I; p++, D += 4)
|
|
3342
|
+
u[p] = h[D];
|
|
3343
|
+
return { layout: "pixel-interleaved", data: u };
|
|
3344
|
+
}
|
|
3345
|
+
throw new Error(\`Unsupported SamplesPerPixel for JPEG: \${y}\`);
|
|
3346
|
+
}
|
|
3347
|
+
function Z(e, n = "") {
|
|
3348
|
+
if (!e)
|
|
3349
|
+
throw new Error(n);
|
|
3350
|
+
}
|
|
3351
|
+
async function $(e, { format: n, signal: l }) {
|
|
3352
|
+
const o = e instanceof Response ? e : new Response(e);
|
|
3353
|
+
Z(o.body, "Response does not contain body.");
|
|
3354
|
+
try {
|
|
3355
|
+
return await new Response(o.body.pipeThrough(new DecompressionStream(n), { signal: l })).arrayBuffer();
|
|
3356
|
+
} catch {
|
|
3357
|
+
throw l?.throwIfAborted(), new Error(\`Failed to decode \${n}\`);
|
|
3358
|
+
}
|
|
3359
|
+
}
|
|
3360
|
+
async function z(e) {
|
|
3361
|
+
return $(e, { format: "deflate" });
|
|
3362
|
+
}
|
|
3363
|
+
function q(e, n) {
|
|
3364
|
+
const l = e;
|
|
3365
|
+
let o = 0, c = e.length - n;
|
|
3366
|
+
do {
|
|
3367
|
+
for (let d = n; d > 0; d--)
|
|
3368
|
+
l[o + n] = (l[o + n] ?? 0) + (l[o] ?? 0), o++;
|
|
3369
|
+
c -= n;
|
|
3370
|
+
} while (c > 0);
|
|
3371
|
+
}
|
|
3372
|
+
function Q(e, n, l) {
|
|
3373
|
+
let o = 0, c = e.length;
|
|
3374
|
+
const d = c / l;
|
|
3375
|
+
for (; c > n; ) {
|
|
3376
|
+
for (let a = n; a > 0; a--)
|
|
3377
|
+
e[o + n] += e[o], o++;
|
|
3378
|
+
c -= n;
|
|
3379
|
+
}
|
|
3380
|
+
const P = e.slice();
|
|
3381
|
+
for (let a = 0; a < d; a++)
|
|
3382
|
+
for (let i = 0; i < l; i++)
|
|
3383
|
+
e[l * a + i] = P[(l - i - 1) * d + a];
|
|
3384
|
+
}
|
|
3385
|
+
function V(e, n, l, o, c, d, P) {
|
|
3386
|
+
if (n === L.None)
|
|
3387
|
+
return e;
|
|
3388
|
+
const a = c / 8, i = P === x.Separate ? 1 : d;
|
|
3389
|
+
for (let h = 0; h < o; h++) {
|
|
3390
|
+
const y = h * i * l * a;
|
|
3391
|
+
if (y >= e.byteLength)
|
|
3392
|
+
break;
|
|
3393
|
+
if (n === L.Horizontal) {
|
|
3394
|
+
let I;
|
|
3395
|
+
const u = i * l;
|
|
3396
|
+
switch (c) {
|
|
3397
|
+
case 8:
|
|
3398
|
+
I = new Uint8Array(e, y, u);
|
|
3399
|
+
break;
|
|
3400
|
+
case 16:
|
|
3401
|
+
I = new Uint16Array(e, y, u);
|
|
3402
|
+
break;
|
|
3403
|
+
case 32:
|
|
3404
|
+
I = new Uint32Array(e, y, u);
|
|
3405
|
+
break;
|
|
3406
|
+
default:
|
|
3407
|
+
throw new Error(\`Predictor 2 not supported for \${c} bits per sample.\`);
|
|
3408
|
+
}
|
|
3409
|
+
q(I, i);
|
|
3410
|
+
} else if (n === L.FloatingPoint) {
|
|
3411
|
+
const I = new Uint8Array(e, y, i * l * a);
|
|
3412
|
+
Q(I, i, a);
|
|
3413
|
+
}
|
|
3414
|
+
}
|
|
3415
|
+
return e;
|
|
3416
|
+
}
|
|
3417
|
+
async function g(e) {
|
|
3418
|
+
return e;
|
|
3419
|
+
}
|
|
3420
|
+
const S = /* @__PURE__ */ new Map();
|
|
3421
|
+
S.set(t.None, () => Promise.resolve(g));
|
|
3422
|
+
S.set(t.Deflate, () => Promise.resolve(z));
|
|
3423
|
+
S.set(t.DeflateOther, () => Promise.resolve(z));
|
|
3424
|
+
S.set(t.Lzw, () => import("./lzw-BY5a_5nb.js").then((e) => e.decode));
|
|
3425
|
+
S.set(t.Zstd, () => import("./zstd-QGAv3PMm.js").then((e) => e.decode));
|
|
3426
|
+
S.set(t.Jpeg, () => Promise.resolve(b));
|
|
3427
|
+
S.set(t.Jpeg6, () => Promise.resolve(b));
|
|
3428
|
+
S.set(t.Webp, () => Promise.resolve(b));
|
|
3429
|
+
S.set(t.Lerc, () => import("./__vite-browser-external-DDArsqdc.js").then(function(e) {
|
|
3430
|
+
return e.l;
|
|
3431
|
+
}).then((e) => e.decode));
|
|
3432
|
+
async function f(e, n, l) {
|
|
3433
|
+
const o = S.get(n);
|
|
3434
|
+
if (!o)
|
|
3435
|
+
throw new Error(\`Unsupported compression: \${n}\`);
|
|
3436
|
+
const d = await (await o())(e, l);
|
|
3437
|
+
if (d instanceof ArrayBuffer) {
|
|
3438
|
+
const { predictor: P, width: a, height: i, bitsPerSample: h, samplesPerPixel: y, planarConfiguration: I } = l, u = V(d, P, a, i, h, y, I);
|
|
3439
|
+
return {
|
|
3440
|
+
layout: "pixel-interleaved",
|
|
3441
|
+
data: ee(u, l)
|
|
3442
|
+
};
|
|
3443
|
+
}
|
|
3444
|
+
return d;
|
|
3445
|
+
}
|
|
3446
|
+
function T(e, n) {
|
|
3447
|
+
const l = new Uint8Array(e), o = new Uint8Array(n);
|
|
3448
|
+
for (let c = 0; c < n; c++)
|
|
3449
|
+
o[c] = l[c >> 3] >> 7 - (c & 7) & 1 ? 255 : 0;
|
|
3450
|
+
return o;
|
|
3451
|
+
}
|
|
3452
|
+
function ee(e, n) {
|
|
3453
|
+
const { sampleFormat: l, bitsPerSample: o } = n;
|
|
3454
|
+
switch (l) {
|
|
3455
|
+
case R.Uint:
|
|
3456
|
+
switch (o) {
|
|
3457
|
+
case 1:
|
|
3458
|
+
return T(e, n.width * n.height * n.samplesPerPixel);
|
|
3459
|
+
case 8:
|
|
3460
|
+
return new Uint8Array(e);
|
|
3461
|
+
case 16:
|
|
3462
|
+
return new Uint16Array(e);
|
|
3463
|
+
case 32:
|
|
3464
|
+
return new Uint32Array(e);
|
|
3465
|
+
}
|
|
3466
|
+
break;
|
|
3467
|
+
case R.Int:
|
|
3468
|
+
switch (o) {
|
|
3469
|
+
case 8:
|
|
3470
|
+
return new Int8Array(e);
|
|
3471
|
+
case 16:
|
|
3472
|
+
return new Int16Array(e);
|
|
3473
|
+
case 32:
|
|
3474
|
+
return new Int32Array(e);
|
|
3475
|
+
}
|
|
3476
|
+
break;
|
|
3477
|
+
case R.Float:
|
|
3478
|
+
switch (o) {
|
|
3479
|
+
case 32:
|
|
3480
|
+
return new Float32Array(e);
|
|
3481
|
+
case 64:
|
|
3482
|
+
return new Float64Array(e);
|
|
3483
|
+
}
|
|
3484
|
+
break;
|
|
3485
|
+
}
|
|
3486
|
+
throw new Error(\`Unsupported sample format/depth: SampleFormat=\${l}, BitsPerSample=\${o}\`);
|
|
3487
|
+
}
|
|
3488
|
+
function te(e) {
|
|
3489
|
+
return e.layout === "pixel-interleaved" ? [e.data.buffer] : e.bands.map((n) => n.buffer);
|
|
3490
|
+
}
|
|
3491
|
+
self.addEventListener("message", async (e) => {
|
|
3492
|
+
const { jobId: n, compression: l, metadata: o, buffer: c } = e.data;
|
|
3493
|
+
try {
|
|
3494
|
+
const d = await f(c, l, o), P = te(d), a = { jobId: n, pixels: d };
|
|
3495
|
+
self.postMessage(a, { transfer: P });
|
|
3496
|
+
} catch (d) {
|
|
3497
|
+
const P = { jobId: n, error: String(d) };
|
|
3498
|
+
self.postMessage(P);
|
|
3499
|
+
}
|
|
3500
|
+
});
|
|
3501
|
+
export {
|
|
3502
|
+
t as C,
|
|
3503
|
+
S as D
|
|
3504
|
+
};
|
|
3505
|
+
`, Fe = typeof self < "u" && self.Blob && new Blob(["URL.revokeObjectURL(import.meta.url);", Te], { type: "text/javascript;charset=utf-8" });
|
|
3506
|
+
function Lr(e) {
|
|
3507
|
+
let t;
|
|
3508
|
+
try {
|
|
3509
|
+
if (t = Fe && (self.URL || self.webkitURL).createObjectURL(Fe), !t) throw "";
|
|
3510
|
+
const n = new Worker(t, {
|
|
3511
|
+
type: "module",
|
|
3512
|
+
name: e?.name
|
|
3513
|
+
});
|
|
3514
|
+
return n.addEventListener("error", () => {
|
|
3515
|
+
(self.URL || self.webkitURL).revokeObjectURL(t);
|
|
3516
|
+
}), n;
|
|
3517
|
+
} catch {
|
|
3518
|
+
return new Worker(
|
|
3519
|
+
"data:text/javascript;charset=utf-8," + encodeURIComponent(Te),
|
|
3520
|
+
{
|
|
3521
|
+
type: "module",
|
|
3522
|
+
name: e?.name
|
|
3523
|
+
}
|
|
3524
|
+
);
|
|
3525
|
+
}
|
|
3526
|
+
}
|
|
3527
|
+
function br(e) {
|
|
3528
|
+
const t = e.layout === "band-separate" ? e.bands[0] : e.data;
|
|
3529
|
+
return t instanceof Float32Array ? t : new Float32Array(t);
|
|
3530
|
+
}
|
|
3531
|
+
function Ir(e) {
|
|
3532
|
+
const t = e.width * e.height, n = new Float32Array(t * 4);
|
|
3533
|
+
if (e.layout === "band-separate") {
|
|
3534
|
+
const [r, o, i] = [e.bands[0], e.bands[1], e.bands[2]];
|
|
3535
|
+
for (let a = 0; a < t; a++)
|
|
3536
|
+
n[a * 4] = r[a], n[a * 4 + 1] = o[a], n[a * 4 + 2] = i[a], n[a * 4 + 3] = 1;
|
|
3537
|
+
} else {
|
|
3538
|
+
const { data: r, count: o } = e;
|
|
3539
|
+
for (let i = 0; i < t; i++)
|
|
3540
|
+
n[i * 4] = r[i * o], n[i * 4 + 1] = r[i * o + 1], n[i * 4 + 2] = r[i * o + 2], n[i * 4 + 3] = 1;
|
|
3541
|
+
}
|
|
3542
|
+
return n;
|
|
3543
|
+
}
|
|
3544
|
+
const Gr = async (e, { device: t, x: n, y: r, signal: o, pool: i }) => {
|
|
3545
|
+
const a = () => {
|
|
3546
|
+
throw o?.reason ?? new DOMException("aborted", "AbortError");
|
|
3547
|
+
};
|
|
3548
|
+
o?.aborted && a();
|
|
3549
|
+
const s = await e.fetchTile(n, r, { boundless: !1, pool: i, signal: o });
|
|
3550
|
+
o?.aborted && a();
|
|
3551
|
+
const l = s.array, c = e.cachedTags.samplesPerPixel, d = { minFilter: "nearest", magFilter: "nearest" }, h = c === 1, g = h ? br(l) : Ir(l), f = t.createTexture({
|
|
3552
|
+
data: g,
|
|
3553
|
+
format: h ? "r32float" : "rgba32float",
|
|
3554
|
+
width: l.width,
|
|
3555
|
+
height: l.height,
|
|
3556
|
+
sampler: d
|
|
3557
|
+
});
|
|
3558
|
+
return {
|
|
3559
|
+
width: l.width,
|
|
3560
|
+
height: l.height,
|
|
3561
|
+
byteLength: g.byteLength,
|
|
3562
|
+
texture: f,
|
|
3563
|
+
colormapTexture: await gt(t),
|
|
3564
|
+
bandCount: c,
|
|
3565
|
+
nodata: l.nodata
|
|
3566
|
+
};
|
|
3567
|
+
};
|
|
3568
|
+
let W;
|
|
3569
|
+
function jr() {
|
|
3570
|
+
if (W) return W;
|
|
3571
|
+
try {
|
|
3572
|
+
W = new ne({ createWorker: () => new Lr() });
|
|
3573
|
+
} catch (e) {
|
|
3574
|
+
console.warn("[onlymapjs] COGLayer: worker decode unavailable — falling back to main-thread decode.", e), W = new ne({});
|
|
3575
|
+
}
|
|
3576
|
+
return W;
|
|
3577
|
+
}
|
|
3578
|
+
class Er extends Cr {
|
|
3579
|
+
static layerName = "OmCOGLayer";
|
|
3580
|
+
// Plain nulls (not `{type:"number", value:null}` specs): deck's typed
|
|
3581
|
+
// number props reject null defaults with a console warning per instance.
|
|
3582
|
+
static defaultProps = {
|
|
3583
|
+
rescaleMin: null,
|
|
3584
|
+
rescaleMax: null,
|
|
3585
|
+
colormap: null,
|
|
3586
|
+
nodataOverride: null
|
|
3587
|
+
};
|
|
3588
|
+
constructor(t) {
|
|
3589
|
+
const n = t, r = { ...t, pool: t.pool ?? jr() };
|
|
3590
|
+
if (!(n.rescaleMin != null || n.rescaleMax != null || n.colormap != null && n.colormap !== "" || n.nodataOverride != null)) {
|
|
3591
|
+
super(r);
|
|
3592
|
+
return;
|
|
3593
|
+
}
|
|
3594
|
+
super(r, {
|
|
3595
|
+
getTileData: Gr,
|
|
3596
|
+
renderTile: (i) => i ? pt(i, n) : null,
|
|
3597
|
+
// Free the per-tile texture on cache eviction; the sprite texture is
|
|
3598
|
+
// device-scoped (WeakMap above) and must NOT be destroyed here.
|
|
3599
|
+
onTileUnload: (i) => {
|
|
3600
|
+
const a = i.data;
|
|
3601
|
+
a && typeof a == "object" && "texture" in a && a.texture.destroy();
|
|
3602
|
+
}
|
|
3603
|
+
});
|
|
3604
|
+
}
|
|
3605
|
+
}
|
|
3606
|
+
const vr = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
3607
|
+
__proto__: null,
|
|
3608
|
+
OmCOGLayer: Er
|
|
3609
|
+
}, Symbol.toStringTag, { value: "Module" }));
|
|
3610
|
+
export {
|
|
3611
|
+
m as C,
|
|
3612
|
+
A as D,
|
|
3613
|
+
vr as r
|
|
3614
|
+
};
|