@gisfun/maplibre-gl-components 0.15.0-alpha.0
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/LICENSE +21 -0
- package/README.md +1960 -0
- package/dist/ControlGrid-DN5md8hp.cjs +19636 -0
- package/dist/ControlGrid-rVNG7B9O.js +170422 -0
- package/dist/DuckDBConverter-B98M0DFs.cjs +23 -0
- package/dist/DuckDBConverter-RPq48-t0.js +434 -0
- package/dist/ShapefileConverter-AjbEjEyq.cjs +1 -0
- package/dist/ShapefileConverter-trvt8J3z.js +125 -0
- package/dist/decoder-CLokFc0V.js +8 -0
- package/dist/decoder-D9LU4bUo.cjs +1 -0
- package/dist/deflate-BA1jZeSX.js +10 -0
- package/dist/deflate-DEdCz12a.cjs +1 -0
- package/dist/geojson-BQSVgKFt.cjs +1 -0
- package/dist/geojson-BSUuDj5k.js +2551 -0
- package/dist/geotiff-De1w1lBy.cjs +8 -0
- package/dist/geotiff-o_Fq1Na4.js +3108 -0
- package/dist/index-8ZZtuDTp.js +705 -0
- package/dist/index-B-Nr9y7J.cjs +84 -0
- package/dist/index-B5NoFrpY.js +8892 -0
- package/dist/index-Bi1MMPUx.js +4163 -0
- package/dist/index-C9fk_HKR.js +167 -0
- package/dist/index-CBBRBJvR.cjs +274 -0
- package/dist/index-CZxPF1qt.js +4 -0
- package/dist/index-CiDPSJ9T.cjs +1 -0
- package/dist/index-CjM_nbxd.cjs +107 -0
- package/dist/index-DQXdX5y1.js +4666 -0
- package/dist/index-Dh1kpCb6.cjs +1 -0
- package/dist/index-IrsIiQNM.cjs +4 -0
- package/dist/index.cjs +3819 -0
- package/dist/index.mjs +19580 -0
- package/dist/jpeg-CF9OGQg_.js +533 -0
- package/dist/jpeg-JSQOxGHy.cjs +1 -0
- package/dist/lerc-7LlQoT6u.js +1032 -0
- package/dist/lerc-BIsodce9.cjs +1 -0
- package/dist/lzw-BZniWIYG.js +84 -0
- package/dist/lzw-BhML-BvT.cjs +1 -0
- package/dist/main-dist-Bymiy5aM.cjs +2 -0
- package/dist/main-dist-Cv8AKwrY.js +629 -0
- package/dist/maplibre-geoman.es-Bxdg-2EU.cjs +129 -0
- package/dist/maplibre-geoman.es-CFgM2ajb.js +22827 -0
- package/dist/maplibre-gl-components.css +1 -0
- package/dist/packbits-B9b7gX2c.cjs +1 -0
- package/dist/packbits-DWY5O-FG.js +24 -0
- package/dist/pako.esm-Bx5X36Wo.js +1074 -0
- package/dist/pako.esm-DZC2QrbJ.cjs +1 -0
- package/dist/raw-C3ARbSFo.cjs +1 -0
- package/dist/raw-DUslI1gr.js +9 -0
- package/dist/react.cjs +1 -0
- package/dist/react.mjs +1306 -0
- package/dist/types/index.d.ts +44 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/lib/adapters/AddVectorAdapter.d.ts +66 -0
- package/dist/types/lib/adapters/AddVectorAdapter.d.ts.map +1 -0
- package/dist/types/lib/adapters/CogLayerAdapter.d.ts +126 -0
- package/dist/types/lib/adapters/CogLayerAdapter.d.ts.map +1 -0
- package/dist/types/lib/adapters/PMTilesLayerAdapter.d.ts +78 -0
- package/dist/types/lib/adapters/PMTilesLayerAdapter.d.ts.map +1 -0
- package/dist/types/lib/adapters/StacLayerAdapter.d.ts +71 -0
- package/dist/types/lib/adapters/StacLayerAdapter.d.ts.map +1 -0
- package/dist/types/lib/adapters/ZarrLayerAdapter.d.ts +72 -0
- package/dist/types/lib/adapters/ZarrLayerAdapter.d.ts.map +1 -0
- package/dist/types/lib/adapters/index.d.ts +7 -0
- package/dist/types/lib/adapters/index.d.ts.map +1 -0
- package/dist/types/lib/addControlGrid.d.ts +80 -0
- package/dist/types/lib/addControlGrid.d.ts.map +1 -0
- package/dist/types/lib/colormaps/diverging.d.ts +30 -0
- package/dist/types/lib/colormaps/diverging.d.ts.map +1 -0
- package/dist/types/lib/colormaps/index.d.ts +32 -0
- package/dist/types/lib/colormaps/index.d.ts.map +1 -0
- package/dist/types/lib/colormaps/misc.d.ts +38 -0
- package/dist/types/lib/colormaps/misc.d.ts.map +1 -0
- package/dist/types/lib/colormaps/sequential.d.ts +22 -0
- package/dist/types/lib/colormaps/sequential.d.ts.map +1 -0
- package/dist/types/lib/converters/DuckDBConverter.d.ts +112 -0
- package/dist/types/lib/converters/DuckDBConverter.d.ts.map +1 -0
- package/dist/types/lib/converters/ShapefileConverter.d.ts +56 -0
- package/dist/types/lib/converters/ShapefileConverter.d.ts.map +1 -0
- package/dist/types/lib/converters/index.d.ts +8 -0
- package/dist/types/lib/converters/index.d.ts.map +1 -0
- package/dist/types/lib/converters/types.d.ts +75 -0
- package/dist/types/lib/converters/types.d.ts.map +1 -0
- package/dist/types/lib/core/AddVector.d.ts +116 -0
- package/dist/types/lib/core/AddVector.d.ts.map +1 -0
- package/dist/types/lib/core/Basemap.d.ts +206 -0
- package/dist/types/lib/core/Basemap.d.ts.map +1 -0
- package/dist/types/lib/core/BasemapReact.d.ts +32 -0
- package/dist/types/lib/core/BasemapReact.d.ts.map +1 -0
- package/dist/types/lib/core/BookmarkControl.d.ts +180 -0
- package/dist/types/lib/core/BookmarkControl.d.ts.map +1 -0
- package/dist/types/lib/core/ChoroplethControl.d.ts +105 -0
- package/dist/types/lib/core/ChoroplethControl.d.ts.map +1 -0
- package/dist/types/lib/core/CogLayer.d.ts +139 -0
- package/dist/types/lib/core/CogLayer.d.ts.map +1 -0
- package/dist/types/lib/core/CogLayerReact.d.ts +32 -0
- package/dist/types/lib/core/CogLayerReact.d.ts.map +1 -0
- package/dist/types/lib/core/Colorbar.d.ts +133 -0
- package/dist/types/lib/core/Colorbar.d.ts.map +1 -0
- package/dist/types/lib/core/ColorbarGuiControl.d.ts +79 -0
- package/dist/types/lib/core/ColorbarGuiControl.d.ts.map +1 -0
- package/dist/types/lib/core/ColorbarReact.d.ts +34 -0
- package/dist/types/lib/core/ColorbarReact.d.ts.map +1 -0
- package/dist/types/lib/core/ControlGrid.d.ts +125 -0
- package/dist/types/lib/core/ControlGrid.d.ts.map +1 -0
- package/dist/types/lib/core/ControlGridReact.d.ts +32 -0
- package/dist/types/lib/core/ControlGridReact.d.ts.map +1 -0
- package/dist/types/lib/core/HtmlControl.d.ts +140 -0
- package/dist/types/lib/core/HtmlControl.d.ts.map +1 -0
- package/dist/types/lib/core/HtmlControlReact.d.ts +32 -0
- package/dist/types/lib/core/HtmlControlReact.d.ts.map +1 -0
- package/dist/types/lib/core/HtmlGuiControl.d.ts +68 -0
- package/dist/types/lib/core/HtmlGuiControl.d.ts.map +1 -0
- package/dist/types/lib/core/InspectControl.d.ts +202 -0
- package/dist/types/lib/core/InspectControl.d.ts.map +1 -0
- package/dist/types/lib/core/InspectControlReact.d.ts +32 -0
- package/dist/types/lib/core/InspectControlReact.d.ts.map +1 -0
- package/dist/types/lib/core/Legend.d.ts +142 -0
- package/dist/types/lib/core/Legend.d.ts.map +1 -0
- package/dist/types/lib/core/LegendGuiControl.d.ts +69 -0
- package/dist/types/lib/core/LegendGuiControl.d.ts.map +1 -0
- package/dist/types/lib/core/LegendReact.d.ts +34 -0
- package/dist/types/lib/core/LegendReact.d.ts.map +1 -0
- package/dist/types/lib/core/MeasureControl.d.ts +211 -0
- package/dist/types/lib/core/MeasureControl.d.ts.map +1 -0
- package/dist/types/lib/core/MinimapControl.d.ts +77 -0
- package/dist/types/lib/core/MinimapControl.d.ts.map +1 -0
- package/dist/types/lib/core/MinimapControlReact.d.ts +32 -0
- package/dist/types/lib/core/MinimapControlReact.d.ts.map +1 -0
- package/dist/types/lib/core/PMTilesLayer.d.ts +119 -0
- package/dist/types/lib/core/PMTilesLayer.d.ts.map +1 -0
- package/dist/types/lib/core/PrintControl.d.ts +226 -0
- package/dist/types/lib/core/PrintControl.d.ts.map +1 -0
- package/dist/types/lib/core/SearchControl.d.ts +172 -0
- package/dist/types/lib/core/SearchControl.d.ts.map +1 -0
- package/dist/types/lib/core/SearchControlReact.d.ts +32 -0
- package/dist/types/lib/core/SearchControlReact.d.ts.map +1 -0
- package/dist/types/lib/core/StacLayer.d.ts +107 -0
- package/dist/types/lib/core/StacLayer.d.ts.map +1 -0
- package/dist/types/lib/core/StacSearch.d.ts +109 -0
- package/dist/types/lib/core/StacSearch.d.ts.map +1 -0
- package/dist/types/lib/core/Terrain.d.ts +165 -0
- package/dist/types/lib/core/Terrain.d.ts.map +1 -0
- package/dist/types/lib/core/TerrainReact.d.ts +32 -0
- package/dist/types/lib/core/TerrainReact.d.ts.map +1 -0
- package/dist/types/lib/core/VectorDataset.d.ts +228 -0
- package/dist/types/lib/core/VectorDataset.d.ts.map +1 -0
- package/dist/types/lib/core/VectorDatasetReact.d.ts +31 -0
- package/dist/types/lib/core/VectorDatasetReact.d.ts.map +1 -0
- package/dist/types/lib/core/ViewStateControl.d.ts +205 -0
- package/dist/types/lib/core/ViewStateControl.d.ts.map +1 -0
- package/dist/types/lib/core/ViewStateControlReact.d.ts +32 -0
- package/dist/types/lib/core/ViewStateControlReact.d.ts.map +1 -0
- package/dist/types/lib/core/ZarrLayer.d.ts +110 -0
- package/dist/types/lib/core/ZarrLayer.d.ts.map +1 -0
- package/dist/types/lib/core/types.d.ts +2793 -0
- package/dist/types/lib/core/types.d.ts.map +1 -0
- package/dist/types/lib/hooks/index.d.ts +13 -0
- package/dist/types/lib/hooks/index.d.ts.map +1 -0
- package/dist/types/lib/hooks/useBasemap.d.ts +43 -0
- package/dist/types/lib/hooks/useBasemap.d.ts.map +1 -0
- package/dist/types/lib/hooks/useCogLayer.d.ts +44 -0
- package/dist/types/lib/hooks/useCogLayer.d.ts.map +1 -0
- package/dist/types/lib/hooks/useColorbar.d.ts +36 -0
- package/dist/types/lib/hooks/useColorbar.d.ts.map +1 -0
- package/dist/types/lib/hooks/useControlGrid.d.ts +41 -0
- package/dist/types/lib/hooks/useControlGrid.d.ts.map +1 -0
- package/dist/types/lib/hooks/useHtmlControl.d.ts +39 -0
- package/dist/types/lib/hooks/useHtmlControl.d.ts.map +1 -0
- package/dist/types/lib/hooks/useInspectControl.d.ts +49 -0
- package/dist/types/lib/hooks/useInspectControl.d.ts.map +1 -0
- package/dist/types/lib/hooks/useLegend.d.ts +41 -0
- package/dist/types/lib/hooks/useLegend.d.ts.map +1 -0
- package/dist/types/lib/hooks/useMinimapControl.d.ts +35 -0
- package/dist/types/lib/hooks/useMinimapControl.d.ts.map +1 -0
- package/dist/types/lib/hooks/useSearchControl.d.ts +43 -0
- package/dist/types/lib/hooks/useSearchControl.d.ts.map +1 -0
- package/dist/types/lib/hooks/useTerrain.d.ts +43 -0
- package/dist/types/lib/hooks/useTerrain.d.ts.map +1 -0
- package/dist/types/lib/hooks/useVectorDataset.d.ts +35 -0
- package/dist/types/lib/hooks/useVectorDataset.d.ts.map +1 -0
- package/dist/types/lib/hooks/useViewState.d.ts +43 -0
- package/dist/types/lib/hooks/useViewState.d.ts.map +1 -0
- package/dist/types/lib/utils/color.d.ts +47 -0
- package/dist/types/lib/utils/color.d.ts.map +1 -0
- package/dist/types/lib/utils/fileHelpers.d.ts +207 -0
- package/dist/types/lib/utils/fileHelpers.d.ts.map +1 -0
- package/dist/types/lib/utils/helpers.d.ts +48 -0
- package/dist/types/lib/utils/helpers.d.ts.map +1 -0
- package/dist/types/lib/utils/index.d.ts +4 -0
- package/dist/types/lib/utils/index.d.ts.map +1 -0
- package/dist/types/lib/utils/providers.d.ts +46 -0
- package/dist/types/lib/utils/providers.d.ts.map +1 -0
- package/dist/types/react.d.ts +15 -0
- package/dist/types/react.d.ts.map +1 -0
- package/dist/webimage-CBRffWZD.cjs +1 -0
- package/dist/webimage-ibSPOLHJ.js +19 -0
- package/package.json +137 -0
|
@@ -0,0 +1,4163 @@
|
|
|
1
|
+
import q from "./index-DQXdX5y1.js";
|
|
2
|
+
import { f as $e, b as Xe, c as Ze, d as He, e as Ke, P as Qe } from "./geotiff-o_Fq1Na4.js";
|
|
3
|
+
import { CreateTexture as xe, cieLabToRGB as Je, YCbCrToRGB as ts, CMYKToRGB as es, Colormap as ss, FilterNoDataVal as ns } from "./index-C9fk_HKR.js";
|
|
4
|
+
import { aX as is, aY as os, aZ as rs, a_ as Wt, a$ as R, b0 as as, b1 as Me, b2 as cs, b3 as ls, b4 as it, b5 as hs, b6 as us, b7 as ds, b8 as we, b9 as fs, ba as ms, bb as ps, bc as gs, bd as Vt, be as ys, bf as ut, bg as _s, bh as xs, bi as Ms, bj as ws, bk as Ts, bl as bs, bm as Ss, bn as Cs, bo as Ls, bp as Es, bq as Ps, br as Rs, bs as Is, bt as V, bu as Te, bv as As, bw as be, bx as vs, by as Os, bz as Se, bA as M, bB as zs, bC as xt, bD as st, bE as Ce, bF as kt, bG as ot, bH as G, bI as Ns, bJ as Fs, bK as dt, bL as qs, bM as Bs, bN as Gs, bO as Ds, bP as Us, bQ as ft, bR as Ws, bS as Vs } from "./ControlGrid-rVNG7B9O.js";
|
|
5
|
+
const ks = "Queued Requests", js = "Active Requests", Ys = "Cancelled Requests", $s = "Queued Requests Ever", Xs = "Active Requests Ever", Zs = {
|
|
6
|
+
id: "request-scheduler",
|
|
7
|
+
/** Specifies if the request scheduler should throttle incoming requests, mainly for comparative testing. */
|
|
8
|
+
throttleRequests: !0,
|
|
9
|
+
/** The maximum number of simultaneous active requests. Un-throttled requests do not observe this limit. */
|
|
10
|
+
maxRequests: 6,
|
|
11
|
+
/**
|
|
12
|
+
* Specifies a debounce time, in milliseconds. All requests are queued, until no new requests have
|
|
13
|
+
* been added to the queue for this amount of time.
|
|
14
|
+
*/
|
|
15
|
+
debounceTime: 0
|
|
16
|
+
};
|
|
17
|
+
class Hs {
|
|
18
|
+
props;
|
|
19
|
+
stats;
|
|
20
|
+
activeRequestCount = 0;
|
|
21
|
+
/** Tracks the number of active requests and prioritizes/cancels queued requests. */
|
|
22
|
+
requestQueue = [];
|
|
23
|
+
requestMap = /* @__PURE__ */ new Map();
|
|
24
|
+
updateTimer = null;
|
|
25
|
+
constructor(t = {}) {
|
|
26
|
+
this.props = { ...Zs, ...t }, this.stats = new is({ id: this.props.id }), this.stats.get(ks), this.stats.get(js), this.stats.get(Ys), this.stats.get($s), this.stats.get(Xs);
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Called by an application that wants to issue a request, without having it deeply queued by the browser
|
|
30
|
+
*
|
|
31
|
+
* When the returned promise resolved, it is OK for the application to issue a request.
|
|
32
|
+
* The promise resolves to an object that contains a `done` method.
|
|
33
|
+
* When the application's request has completed (or failed), the application must call the `done` function
|
|
34
|
+
*
|
|
35
|
+
* @param handle
|
|
36
|
+
* @param getPriority will be called when request "slots" open up,
|
|
37
|
+
* allowing the caller to update priority or cancel the request
|
|
38
|
+
* Highest priority executes first, priority < 0 cancels the request
|
|
39
|
+
* @returns a promise
|
|
40
|
+
* - resolves to a object (with a `done` field) when the request can be issued without queueing,
|
|
41
|
+
* - resolves to `null` if the request has been cancelled (by the callback return < 0).
|
|
42
|
+
* In this case the application should not issue the request
|
|
43
|
+
*/
|
|
44
|
+
scheduleRequest(t, e = () => 0) {
|
|
45
|
+
if (!this.props.throttleRequests)
|
|
46
|
+
return Promise.resolve({ done: () => {
|
|
47
|
+
} });
|
|
48
|
+
if (this.requestMap.has(t))
|
|
49
|
+
return this.requestMap.get(t);
|
|
50
|
+
const s = { handle: t, priority: 0, getPriority: e }, i = new Promise((o) => (s.resolve = o, s));
|
|
51
|
+
return this.requestQueue.push(s), this.requestMap.set(t, i), this._issueNewRequests(), i;
|
|
52
|
+
}
|
|
53
|
+
// PRIVATE
|
|
54
|
+
_issueRequest(t) {
|
|
55
|
+
const { handle: e, resolve: s } = t;
|
|
56
|
+
let i = !1;
|
|
57
|
+
const o = () => {
|
|
58
|
+
i || (i = !0, this.requestMap.delete(e), this.activeRequestCount--, this._issueNewRequests());
|
|
59
|
+
};
|
|
60
|
+
return this.activeRequestCount++, s ? s({ done: o }) : Promise.resolve({ done: o });
|
|
61
|
+
}
|
|
62
|
+
/** We check requests asynchronously, to prevent multiple updates */
|
|
63
|
+
_issueNewRequests() {
|
|
64
|
+
this.updateTimer !== null && clearTimeout(this.updateTimer), this.updateTimer = setTimeout(() => this._issueNewRequestsAsync(), this.props.debounceTime);
|
|
65
|
+
}
|
|
66
|
+
/** Refresh all requests */
|
|
67
|
+
_issueNewRequestsAsync() {
|
|
68
|
+
this.updateTimer !== null && clearTimeout(this.updateTimer), this.updateTimer = null;
|
|
69
|
+
const t = Math.max(this.props.maxRequests - this.activeRequestCount, 0);
|
|
70
|
+
if (t !== 0) {
|
|
71
|
+
this._updateAllRequests();
|
|
72
|
+
for (let e = 0; e < t; ++e) {
|
|
73
|
+
const s = this.requestQueue.shift();
|
|
74
|
+
s && this._issueRequest(s);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
/** Ensure all requests have updated priorities, and that no longer valid requests are cancelled */
|
|
79
|
+
_updateAllRequests() {
|
|
80
|
+
const t = this.requestQueue;
|
|
81
|
+
for (let e = 0; e < t.length; ++e) {
|
|
82
|
+
const s = t[e];
|
|
83
|
+
this._updateRequest(s) || (t.splice(e, 1), this.requestMap.delete(s.handle), e--);
|
|
84
|
+
}
|
|
85
|
+
t.sort((e, s) => e.priority - s.priority);
|
|
86
|
+
}
|
|
87
|
+
/** Update a single request by calling the callback */
|
|
88
|
+
_updateRequest(t) {
|
|
89
|
+
return t.priority = t.getPriority(t.handle), t.priority < 0 ? (t.resolve(null), !1) : !0;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
function Ks(n) {
|
|
93
|
+
let t = 1 / 0, e = 1 / 0, s = 1 / 0, i = -1 / 0, o = -1 / 0, r = -1 / 0;
|
|
94
|
+
const a = n.POSITION ? n.POSITION.value : [], c = a && a.length;
|
|
95
|
+
for (let h = 0; h < c; h += 3) {
|
|
96
|
+
const u = a[h], l = a[h + 1], d = a[h + 2];
|
|
97
|
+
t = u < t ? u : t, e = l < e ? l : e, s = d < s ? d : s, i = u > i ? u : i, o = l > o ? l : o, r = d > r ? d : r;
|
|
98
|
+
}
|
|
99
|
+
return [
|
|
100
|
+
[t, e, s],
|
|
101
|
+
[i, o, r]
|
|
102
|
+
];
|
|
103
|
+
}
|
|
104
|
+
let $;
|
|
105
|
+
class Et extends os {
|
|
106
|
+
static get ZERO() {
|
|
107
|
+
return $ || ($ = new Et(0, 0, 0, 0), Object.freeze($)), $;
|
|
108
|
+
}
|
|
109
|
+
constructor(t = 0, e = 0, s = 0, i = 0) {
|
|
110
|
+
super(-0, -0, -0, -0), rs(t) && arguments.length === 1 ? this.copy(t) : (Wt.debug && (R(t), R(e), R(s), R(i)), this[0] = t, this[1] = e, this[2] = s, this[3] = i);
|
|
111
|
+
}
|
|
112
|
+
set(t, e, s, i) {
|
|
113
|
+
return this[0] = t, this[1] = e, this[2] = s, this[3] = i, this.check();
|
|
114
|
+
}
|
|
115
|
+
copy(t) {
|
|
116
|
+
return this[0] = t[0], this[1] = t[1], this[2] = t[2], this[3] = t[3], this.check();
|
|
117
|
+
}
|
|
118
|
+
fromObject(t) {
|
|
119
|
+
return Wt.debug && (R(t.x), R(t.y), R(t.z), R(t.w)), this[0] = t.x, this[1] = t.y, this[2] = t.z, this[3] = t.w, this;
|
|
120
|
+
}
|
|
121
|
+
toObject(t) {
|
|
122
|
+
return t.x = this[0], t.y = this[1], t.z = this[2], t.w = this[3], t;
|
|
123
|
+
}
|
|
124
|
+
// Getters/setters
|
|
125
|
+
/* eslint-disable no-multi-spaces, brace-style, no-return-assign */
|
|
126
|
+
get ELEMENTS() {
|
|
127
|
+
return 4;
|
|
128
|
+
}
|
|
129
|
+
get z() {
|
|
130
|
+
return this[2];
|
|
131
|
+
}
|
|
132
|
+
set z(t) {
|
|
133
|
+
this[2] = R(t);
|
|
134
|
+
}
|
|
135
|
+
get w() {
|
|
136
|
+
return this[3];
|
|
137
|
+
}
|
|
138
|
+
set w(t) {
|
|
139
|
+
this[3] = R(t);
|
|
140
|
+
}
|
|
141
|
+
transform(t) {
|
|
142
|
+
return as(this, this, t), this.check();
|
|
143
|
+
}
|
|
144
|
+
transformByMatrix3(t) {
|
|
145
|
+
return Me(this, this, t), this.check();
|
|
146
|
+
}
|
|
147
|
+
transformByMatrix2(t) {
|
|
148
|
+
return cs(this, this, t), this.check();
|
|
149
|
+
}
|
|
150
|
+
transformByQuaternion(t) {
|
|
151
|
+
return ls(this, this, t), this.check();
|
|
152
|
+
}
|
|
153
|
+
// three.js compatibility
|
|
154
|
+
applyMatrix4(t) {
|
|
155
|
+
return t.transform(this, this), this;
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
function Qs() {
|
|
159
|
+
const n = new it(9);
|
|
160
|
+
return it != Float32Array && (n[1] = 0, n[2] = 0, n[3] = 0, n[5] = 0, n[6] = 0, n[7] = 0), n[0] = 1, n[4] = 1, n[8] = 1, n;
|
|
161
|
+
}
|
|
162
|
+
function Js(n, t) {
|
|
163
|
+
if (n === t) {
|
|
164
|
+
const e = t[1], s = t[2], i = t[5];
|
|
165
|
+
n[1] = t[3], n[2] = t[6], n[3] = e, n[5] = t[7], n[6] = s, n[7] = i;
|
|
166
|
+
} else
|
|
167
|
+
n[0] = t[0], n[1] = t[3], n[2] = t[6], n[3] = t[1], n[4] = t[4], n[5] = t[7], n[6] = t[2], n[7] = t[5], n[8] = t[8];
|
|
168
|
+
return n;
|
|
169
|
+
}
|
|
170
|
+
function tn(n, t) {
|
|
171
|
+
const e = t[0], s = t[1], i = t[2], o = t[3], r = t[4], a = t[5], c = t[6], h = t[7], u = t[8], l = u * r - a * h, d = -u * o + a * c, f = h * o - r * c;
|
|
172
|
+
let m = e * l + s * d + i * f;
|
|
173
|
+
return m ? (m = 1 / m, n[0] = l * m, n[1] = (-u * s + i * h) * m, n[2] = (a * s - i * r) * m, n[3] = d * m, n[4] = (u * e - i * c) * m, n[5] = (-a * e + i * o) * m, n[6] = f * m, n[7] = (-h * e + s * c) * m, n[8] = (r * e - s * o) * m, n) : null;
|
|
174
|
+
}
|
|
175
|
+
function en(n) {
|
|
176
|
+
const t = n[0], e = n[1], s = n[2], i = n[3], o = n[4], r = n[5], a = n[6], c = n[7], h = n[8];
|
|
177
|
+
return t * (h * o - r * c) + e * (-h * i + r * a) + s * (c * i - o * a);
|
|
178
|
+
}
|
|
179
|
+
function jt(n, t, e) {
|
|
180
|
+
const s = t[0], i = t[1], o = t[2], r = t[3], a = t[4], c = t[5], h = t[6], u = t[7], l = t[8], d = e[0], f = e[1], m = e[2], p = e[3], g = e[4], y = e[5], _ = e[6], x = e[7], w = e[8];
|
|
181
|
+
return n[0] = d * s + f * r + m * h, n[1] = d * i + f * a + m * u, n[2] = d * o + f * c + m * l, n[3] = p * s + g * r + y * h, n[4] = p * i + g * a + y * u, n[5] = p * o + g * c + y * l, n[6] = _ * s + x * r + w * h, n[7] = _ * i + x * a + w * u, n[8] = _ * o + x * c + w * l, n;
|
|
182
|
+
}
|
|
183
|
+
function sn(n, t, e) {
|
|
184
|
+
const s = t[0], i = t[1], o = t[2], r = t[3], a = t[4], c = t[5], h = t[6], u = t[7], l = t[8], d = e[0], f = e[1];
|
|
185
|
+
return n[0] = s, n[1] = i, n[2] = o, n[3] = r, n[4] = a, n[5] = c, n[6] = d * s + f * r + h, n[7] = d * i + f * a + u, n[8] = d * o + f * c + l, n;
|
|
186
|
+
}
|
|
187
|
+
function nn(n, t, e) {
|
|
188
|
+
const s = t[0], i = t[1], o = t[2], r = t[3], a = t[4], c = t[5], h = t[6], u = t[7], l = t[8], d = Math.sin(e), f = Math.cos(e);
|
|
189
|
+
return n[0] = f * s + d * r, n[1] = f * i + d * a, n[2] = f * o + d * c, n[3] = f * r - d * s, n[4] = f * a - d * i, n[5] = f * c - d * o, n[6] = h, n[7] = u, n[8] = l, n;
|
|
190
|
+
}
|
|
191
|
+
function Yt(n, t, e) {
|
|
192
|
+
const s = e[0], i = e[1];
|
|
193
|
+
return n[0] = s * t[0], n[1] = s * t[1], n[2] = s * t[2], n[3] = i * t[3], n[4] = i * t[4], n[5] = i * t[5], n[6] = t[6], n[7] = t[7], n[8] = t[8], n;
|
|
194
|
+
}
|
|
195
|
+
function on(n, t) {
|
|
196
|
+
const e = t[0], s = t[1], i = t[2], o = t[3], r = e + e, a = s + s, c = i + i, h = e * r, u = s * r, l = s * a, d = i * r, f = i * a, m = i * c, p = o * r, g = o * a, y = o * c;
|
|
197
|
+
return n[0] = 1 - l - m, n[3] = u - y, n[6] = d + g, n[1] = u + y, n[4] = 1 - h - m, n[7] = f - p, n[2] = d - g, n[5] = f + p, n[8] = 1 - h - l, n;
|
|
198
|
+
}
|
|
199
|
+
var Mt;
|
|
200
|
+
(function(n) {
|
|
201
|
+
n[n.COL0ROW0 = 0] = "COL0ROW0", n[n.COL0ROW1 = 1] = "COL0ROW1", n[n.COL0ROW2 = 2] = "COL0ROW2", n[n.COL1ROW0 = 3] = "COL1ROW0", n[n.COL1ROW1 = 4] = "COL1ROW1", n[n.COL1ROW2 = 5] = "COL1ROW2", n[n.COL2ROW0 = 6] = "COL2ROW0", n[n.COL2ROW1 = 7] = "COL2ROW1", n[n.COL2ROW2 = 8] = "COL2ROW2";
|
|
202
|
+
})(Mt || (Mt = {}));
|
|
203
|
+
const rn = Object.freeze([1, 0, 0, 0, 1, 0, 0, 0, 1]);
|
|
204
|
+
class E extends hs {
|
|
205
|
+
static get IDENTITY() {
|
|
206
|
+
return cn();
|
|
207
|
+
}
|
|
208
|
+
static get ZERO() {
|
|
209
|
+
return an();
|
|
210
|
+
}
|
|
211
|
+
get ELEMENTS() {
|
|
212
|
+
return 9;
|
|
213
|
+
}
|
|
214
|
+
get RANK() {
|
|
215
|
+
return 3;
|
|
216
|
+
}
|
|
217
|
+
get INDICES() {
|
|
218
|
+
return Mt;
|
|
219
|
+
}
|
|
220
|
+
constructor(t, ...e) {
|
|
221
|
+
super(-0, -0, -0, -0, -0, -0, -0, -0, -0), arguments.length === 1 && Array.isArray(t) ? this.copy(t) : e.length > 0 ? this.copy([t, ...e]) : this.identity();
|
|
222
|
+
}
|
|
223
|
+
copy(t) {
|
|
224
|
+
return this[0] = t[0], this[1] = t[1], this[2] = t[2], this[3] = t[3], this[4] = t[4], this[5] = t[5], this[6] = t[6], this[7] = t[7], this[8] = t[8], this.check();
|
|
225
|
+
}
|
|
226
|
+
// Constructors
|
|
227
|
+
identity() {
|
|
228
|
+
return this.copy(rn);
|
|
229
|
+
}
|
|
230
|
+
/**
|
|
231
|
+
*
|
|
232
|
+
* @param object
|
|
233
|
+
* @returns self
|
|
234
|
+
*/
|
|
235
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
236
|
+
fromObject(t) {
|
|
237
|
+
return this.check();
|
|
238
|
+
}
|
|
239
|
+
/** Calculates a 3x3 matrix from the given quaternion
|
|
240
|
+
* q quat Quaternion to create matrix from
|
|
241
|
+
*/
|
|
242
|
+
fromQuaternion(t) {
|
|
243
|
+
return on(this, t), this.check();
|
|
244
|
+
}
|
|
245
|
+
/**
|
|
246
|
+
* accepts column major order, stores in column major order
|
|
247
|
+
*/
|
|
248
|
+
// eslint-disable-next-line max-params
|
|
249
|
+
set(t, e, s, i, o, r, a, c, h) {
|
|
250
|
+
return this[0] = t, this[1] = e, this[2] = s, this[3] = i, this[4] = o, this[5] = r, this[6] = a, this[7] = c, this[8] = h, this.check();
|
|
251
|
+
}
|
|
252
|
+
/**
|
|
253
|
+
* accepts row major order, stores as column major
|
|
254
|
+
*/
|
|
255
|
+
// eslint-disable-next-line max-params
|
|
256
|
+
setRowMajor(t, e, s, i, o, r, a, c, h) {
|
|
257
|
+
return this[0] = t, this[1] = i, this[2] = a, this[3] = e, this[4] = o, this[5] = c, this[6] = s, this[7] = r, this[8] = h, this.check();
|
|
258
|
+
}
|
|
259
|
+
// Accessors
|
|
260
|
+
determinant() {
|
|
261
|
+
return en(this);
|
|
262
|
+
}
|
|
263
|
+
// Modifiers
|
|
264
|
+
transpose() {
|
|
265
|
+
return Js(this, this), this.check();
|
|
266
|
+
}
|
|
267
|
+
/** Invert a matrix. Note that this can fail if the matrix is not invertible */
|
|
268
|
+
invert() {
|
|
269
|
+
return tn(this, this), this.check();
|
|
270
|
+
}
|
|
271
|
+
// Operations
|
|
272
|
+
multiplyLeft(t) {
|
|
273
|
+
return jt(this, t, this), this.check();
|
|
274
|
+
}
|
|
275
|
+
multiplyRight(t) {
|
|
276
|
+
return jt(this, this, t), this.check();
|
|
277
|
+
}
|
|
278
|
+
rotate(t) {
|
|
279
|
+
return nn(this, this, t), this.check();
|
|
280
|
+
}
|
|
281
|
+
scale(t) {
|
|
282
|
+
return Array.isArray(t) ? Yt(this, this, t) : Yt(this, this, [t, t]), this.check();
|
|
283
|
+
}
|
|
284
|
+
translate(t) {
|
|
285
|
+
return sn(this, this, t), this.check();
|
|
286
|
+
}
|
|
287
|
+
// Transforms
|
|
288
|
+
transform(t, e) {
|
|
289
|
+
let s;
|
|
290
|
+
switch (t.length) {
|
|
291
|
+
case 2:
|
|
292
|
+
s = ds(e || [-0, -0], t, this);
|
|
293
|
+
break;
|
|
294
|
+
case 3:
|
|
295
|
+
s = us(e || [-0, -0, -0], t, this);
|
|
296
|
+
break;
|
|
297
|
+
case 4:
|
|
298
|
+
s = Me(e || [-0, -0, -0, -0], t, this);
|
|
299
|
+
break;
|
|
300
|
+
default:
|
|
301
|
+
throw new Error("Illegal vector");
|
|
302
|
+
}
|
|
303
|
+
return we(s, t.length), s;
|
|
304
|
+
}
|
|
305
|
+
/** @deprecated */
|
|
306
|
+
transformVector(t, e) {
|
|
307
|
+
return this.transform(t, e);
|
|
308
|
+
}
|
|
309
|
+
/** @deprecated */
|
|
310
|
+
transformVector2(t, e) {
|
|
311
|
+
return this.transform(t, e);
|
|
312
|
+
}
|
|
313
|
+
/** @deprecated */
|
|
314
|
+
transformVector3(t, e) {
|
|
315
|
+
return this.transform(t, e);
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
let X, Z = null;
|
|
319
|
+
function an() {
|
|
320
|
+
return X || (X = new E([0, 0, 0, 0, 0, 0, 0, 0, 0]), Object.freeze(X)), X;
|
|
321
|
+
}
|
|
322
|
+
function cn() {
|
|
323
|
+
return Z || (Z = new E(), Object.freeze(Z)), Z;
|
|
324
|
+
}
|
|
325
|
+
function $t() {
|
|
326
|
+
const n = new it(4);
|
|
327
|
+
return it != Float32Array && (n[0] = 0, n[1] = 0, n[2] = 0), n[3] = 1, n;
|
|
328
|
+
}
|
|
329
|
+
function ln(n) {
|
|
330
|
+
return n[0] = 0, n[1] = 0, n[2] = 0, n[3] = 1, n;
|
|
331
|
+
}
|
|
332
|
+
function Le(n, t, e) {
|
|
333
|
+
e = e * 0.5;
|
|
334
|
+
const s = Math.sin(e);
|
|
335
|
+
return n[0] = s * t[0], n[1] = s * t[1], n[2] = s * t[2], n[3] = Math.cos(e), n;
|
|
336
|
+
}
|
|
337
|
+
function Xt(n, t, e) {
|
|
338
|
+
const s = t[0], i = t[1], o = t[2], r = t[3], a = e[0], c = e[1], h = e[2], u = e[3];
|
|
339
|
+
return n[0] = s * u + r * a + i * h - o * c, n[1] = i * u + r * c + o * a - s * h, n[2] = o * u + r * h + s * c - i * a, n[3] = r * u - s * a - i * c - o * h, n;
|
|
340
|
+
}
|
|
341
|
+
function hn(n, t, e) {
|
|
342
|
+
e *= 0.5;
|
|
343
|
+
const s = t[0], i = t[1], o = t[2], r = t[3], a = Math.sin(e), c = Math.cos(e);
|
|
344
|
+
return n[0] = s * c + r * a, n[1] = i * c + o * a, n[2] = o * c - i * a, n[3] = r * c - s * a, n;
|
|
345
|
+
}
|
|
346
|
+
function un(n, t, e) {
|
|
347
|
+
e *= 0.5;
|
|
348
|
+
const s = t[0], i = t[1], o = t[2], r = t[3], a = Math.sin(e), c = Math.cos(e);
|
|
349
|
+
return n[0] = s * c - o * a, n[1] = i * c + r * a, n[2] = o * c + s * a, n[3] = r * c - i * a, n;
|
|
350
|
+
}
|
|
351
|
+
function dn(n, t, e) {
|
|
352
|
+
e *= 0.5;
|
|
353
|
+
const s = t[0], i = t[1], o = t[2], r = t[3], a = Math.sin(e), c = Math.cos(e);
|
|
354
|
+
return n[0] = s * c + i * a, n[1] = i * c - s * a, n[2] = o * c + r * a, n[3] = r * c - o * a, n;
|
|
355
|
+
}
|
|
356
|
+
function fn(n, t) {
|
|
357
|
+
const e = t[0], s = t[1], i = t[2];
|
|
358
|
+
return n[0] = e, n[1] = s, n[2] = i, n[3] = Math.sqrt(Math.abs(1 - e * e - s * s - i * i)), n;
|
|
359
|
+
}
|
|
360
|
+
function nt(n, t, e, s) {
|
|
361
|
+
const i = t[0], o = t[1], r = t[2], a = t[3];
|
|
362
|
+
let c = e[0], h = e[1], u = e[2], l = e[3], d, f, m, p, g;
|
|
363
|
+
return d = i * c + o * h + r * u + a * l, d < 0 && (d = -d, c = -c, h = -h, u = -u, l = -l), 1 - d > Ss ? (f = Math.acos(d), g = Math.sin(f), m = Math.sin((1 - s) * f) / g, p = Math.sin(s * f) / g) : (m = 1 - s, p = s), n[0] = m * i + p * c, n[1] = m * o + p * h, n[2] = m * r + p * u, n[3] = m * a + p * l, n;
|
|
364
|
+
}
|
|
365
|
+
function mn(n, t) {
|
|
366
|
+
const e = t[0], s = t[1], i = t[2], o = t[3], r = e * e + s * s + i * i + o * o, a = r ? 1 / r : 0;
|
|
367
|
+
return n[0] = -e * a, n[1] = -s * a, n[2] = -i * a, n[3] = o * a, n;
|
|
368
|
+
}
|
|
369
|
+
function pn(n, t) {
|
|
370
|
+
return n[0] = -t[0], n[1] = -t[1], n[2] = -t[2], n[3] = t[3], n;
|
|
371
|
+
}
|
|
372
|
+
function Ee(n, t) {
|
|
373
|
+
const e = t[0] + t[4] + t[8];
|
|
374
|
+
let s;
|
|
375
|
+
if (e > 0)
|
|
376
|
+
s = Math.sqrt(e + 1), n[3] = 0.5 * s, s = 0.5 / s, n[0] = (t[5] - t[7]) * s, n[1] = (t[6] - t[2]) * s, n[2] = (t[1] - t[3]) * s;
|
|
377
|
+
else {
|
|
378
|
+
let i = 0;
|
|
379
|
+
t[4] > t[0] && (i = 1), t[8] > t[i * 3 + i] && (i = 2);
|
|
380
|
+
const o = (i + 1) % 3, r = (i + 2) % 3;
|
|
381
|
+
s = Math.sqrt(t[i * 3 + i] - t[o * 3 + o] - t[r * 3 + r] + 1), n[i] = 0.5 * s, s = 0.5 / s, n[3] = (t[o * 3 + r] - t[r * 3 + o]) * s, n[o] = (t[o * 3 + i] + t[i * 3 + o]) * s, n[r] = (t[r * 3 + i] + t[i * 3 + r]) * s;
|
|
382
|
+
}
|
|
383
|
+
return n;
|
|
384
|
+
}
|
|
385
|
+
const gn = Ms, yn = Ts, _n = ps, xn = ws, Mn = fs, wn = ms, Pe = bs, Tn = (function() {
|
|
386
|
+
const n = gs(), t = Vt(1, 0, 0), e = Vt(0, 1, 0);
|
|
387
|
+
return function(s, i, o) {
|
|
388
|
+
const r = ys(i, o);
|
|
389
|
+
return r < -0.999999 ? (ut(n, t, i), _s(n) < 1e-6 && ut(n, e, i), xs(n, n), Le(s, n, Math.PI), s) : r > 0.999999 ? (s[0] = 0, s[1] = 0, s[2] = 0, s[3] = 1, s) : (ut(n, i, o), s[0] = n[0], s[1] = n[1], s[2] = n[2], s[3] = 1 + r, Pe(s, s));
|
|
390
|
+
};
|
|
391
|
+
})();
|
|
392
|
+
(function() {
|
|
393
|
+
const n = $t(), t = $t();
|
|
394
|
+
return function(e, s, i, o, r, a) {
|
|
395
|
+
return nt(n, s, r, a), nt(t, i, o, a), nt(e, n, t, 2 * a * (1 - a)), e;
|
|
396
|
+
};
|
|
397
|
+
})();
|
|
398
|
+
(function() {
|
|
399
|
+
const n = Qs();
|
|
400
|
+
return function(t, e, s, i) {
|
|
401
|
+
return n[0] = s[0], n[3] = s[1], n[6] = s[2], n[1] = i[0], n[4] = i[1], n[7] = i[2], n[2] = -e[0], n[5] = -e[1], n[8] = -e[2], Pe(t, Ee(t, n));
|
|
402
|
+
};
|
|
403
|
+
})();
|
|
404
|
+
const bn = [0, 0, 0, 1];
|
|
405
|
+
class Zt extends Cs {
|
|
406
|
+
constructor(t = 0, e = 0, s = 0, i = 1) {
|
|
407
|
+
super(-0, -0, -0, -0), Array.isArray(t) && arguments.length === 1 ? this.copy(t) : this.set(t, e, s, i);
|
|
408
|
+
}
|
|
409
|
+
copy(t) {
|
|
410
|
+
return this[0] = t[0], this[1] = t[1], this[2] = t[2], this[3] = t[3], this.check();
|
|
411
|
+
}
|
|
412
|
+
set(t, e, s, i) {
|
|
413
|
+
return this[0] = t, this[1] = e, this[2] = s, this[3] = i, this.check();
|
|
414
|
+
}
|
|
415
|
+
fromObject(t) {
|
|
416
|
+
return this[0] = t.x, this[1] = t.y, this[2] = t.z, this[3] = t.w, this.check();
|
|
417
|
+
}
|
|
418
|
+
/**
|
|
419
|
+
* Creates a quaternion from the given 3x3 rotation matrix.
|
|
420
|
+
* NOTE: The resultant quaternion is not normalized, so you should
|
|
421
|
+
* be sure to renormalize the quaternion yourself where necessary.
|
|
422
|
+
* @param m
|
|
423
|
+
* @returns
|
|
424
|
+
*/
|
|
425
|
+
fromMatrix3(t) {
|
|
426
|
+
return Ee(this, t), this.check();
|
|
427
|
+
}
|
|
428
|
+
fromAxisRotation(t, e) {
|
|
429
|
+
return Le(this, t, e), this.check();
|
|
430
|
+
}
|
|
431
|
+
/** Set a quat to the identity quaternion */
|
|
432
|
+
identity() {
|
|
433
|
+
return ln(this), this.check();
|
|
434
|
+
}
|
|
435
|
+
// Set the components of a quat to the given values
|
|
436
|
+
// set(i, j, k, l) {
|
|
437
|
+
// quat_set(this, i, j, k, l);
|
|
438
|
+
// return this.check();
|
|
439
|
+
// }
|
|
440
|
+
// Sets a quat from the given angle and rotation axis, then returns it.
|
|
441
|
+
setAxisAngle(t, e) {
|
|
442
|
+
return this.fromAxisRotation(t, e);
|
|
443
|
+
}
|
|
444
|
+
// Getters/setters
|
|
445
|
+
get ELEMENTS() {
|
|
446
|
+
return 4;
|
|
447
|
+
}
|
|
448
|
+
get x() {
|
|
449
|
+
return this[0];
|
|
450
|
+
}
|
|
451
|
+
set x(t) {
|
|
452
|
+
this[0] = R(t);
|
|
453
|
+
}
|
|
454
|
+
get y() {
|
|
455
|
+
return this[1];
|
|
456
|
+
}
|
|
457
|
+
set y(t) {
|
|
458
|
+
this[1] = R(t);
|
|
459
|
+
}
|
|
460
|
+
get z() {
|
|
461
|
+
return this[2];
|
|
462
|
+
}
|
|
463
|
+
set z(t) {
|
|
464
|
+
this[2] = R(t);
|
|
465
|
+
}
|
|
466
|
+
get w() {
|
|
467
|
+
return this[3];
|
|
468
|
+
}
|
|
469
|
+
set w(t) {
|
|
470
|
+
this[3] = R(t);
|
|
471
|
+
}
|
|
472
|
+
// Calculates the length of a quat
|
|
473
|
+
len() {
|
|
474
|
+
return Mn(this);
|
|
475
|
+
}
|
|
476
|
+
// Calculates the squared length of a quat
|
|
477
|
+
lengthSquared() {
|
|
478
|
+
return wn(this);
|
|
479
|
+
}
|
|
480
|
+
// Calculates the dot product of two quat's
|
|
481
|
+
// @return {Number}
|
|
482
|
+
dot(t) {
|
|
483
|
+
return _n(this, t);
|
|
484
|
+
}
|
|
485
|
+
// Gets the rotation axis and angle for a given quaternion.
|
|
486
|
+
// If a quaternion is created with setAxisAngle, this method will
|
|
487
|
+
// return the same values as providied in the original parameter
|
|
488
|
+
// list OR functionally equivalent values.
|
|
489
|
+
// Example: The quaternion formed by axis [0, 0, 1] and angle -90
|
|
490
|
+
// is the same as the quaternion formed by [0, 0, 1] and 270.
|
|
491
|
+
// This method favors the latter.
|
|
492
|
+
// @return {{[x,y,z], Number}}
|
|
493
|
+
// getAxisAngle() {
|
|
494
|
+
// const axis = [];
|
|
495
|
+
// // const angle = quat_getAxisAngle(axis, this);
|
|
496
|
+
// return {axis, angle};
|
|
497
|
+
// }
|
|
498
|
+
// MODIFIERS
|
|
499
|
+
// Sets a quaternion to represent the shortest rotation from one vector
|
|
500
|
+
// to another. Both vectors are assumed to be unit length.
|
|
501
|
+
rotationTo(t, e) {
|
|
502
|
+
return Tn(this, t, e), this.check();
|
|
503
|
+
}
|
|
504
|
+
// Sets the specified quaternion with values corresponding to the given axes.
|
|
505
|
+
// Each axis is a vec3 and is expected to be unit length and perpendicular
|
|
506
|
+
// to all other specified axes.
|
|
507
|
+
// setAxes() {
|
|
508
|
+
// Number
|
|
509
|
+
// }
|
|
510
|
+
// Performs a spherical linear interpolation with two control points
|
|
511
|
+
// sqlerp() {
|
|
512
|
+
// Number;
|
|
513
|
+
// }
|
|
514
|
+
// Adds two quat's
|
|
515
|
+
add(t) {
|
|
516
|
+
return gn(this, this, t), this.check();
|
|
517
|
+
}
|
|
518
|
+
// Calculates the W component of a quat from the X, Y, and Z components.
|
|
519
|
+
// Any existing W component will be ignored.
|
|
520
|
+
calculateW() {
|
|
521
|
+
return fn(this, this), this.check();
|
|
522
|
+
}
|
|
523
|
+
// Calculates the conjugate of a quat If the quaternion is normalized,
|
|
524
|
+
// this function is faster than quat_invert and produces the same result.
|
|
525
|
+
conjugate() {
|
|
526
|
+
return pn(this, this), this.check();
|
|
527
|
+
}
|
|
528
|
+
// Calculates the inverse of a quat
|
|
529
|
+
invert() {
|
|
530
|
+
return mn(this, this), this.check();
|
|
531
|
+
}
|
|
532
|
+
// Performs a linear interpolation between two quat's
|
|
533
|
+
lerp(t, e, s) {
|
|
534
|
+
return s === void 0 ? this.lerp(this, t, e) : (xn(this, t, e, s), this.check());
|
|
535
|
+
}
|
|
536
|
+
// Multiplies two quat's
|
|
537
|
+
multiplyRight(t) {
|
|
538
|
+
return Xt(this, this, t), this.check();
|
|
539
|
+
}
|
|
540
|
+
multiplyLeft(t) {
|
|
541
|
+
return Xt(this, t, this), this.check();
|
|
542
|
+
}
|
|
543
|
+
// Normalize a quat
|
|
544
|
+
normalize() {
|
|
545
|
+
const t = this.len(), e = t > 0 ? 1 / t : 0;
|
|
546
|
+
return this[0] = this[0] * e, this[1] = this[1] * e, this[2] = this[2] * e, this[3] = this[3] * e, t === 0 && (this[3] = 1), this.check();
|
|
547
|
+
}
|
|
548
|
+
// Rotates a quaternion by the given angle about the X axis
|
|
549
|
+
rotateX(t) {
|
|
550
|
+
return hn(this, this, t), this.check();
|
|
551
|
+
}
|
|
552
|
+
// Rotates a quaternion by the given angle about the Y axis
|
|
553
|
+
rotateY(t) {
|
|
554
|
+
return un(this, this, t), this.check();
|
|
555
|
+
}
|
|
556
|
+
// Rotates a quaternion by the given angle about the Z axis
|
|
557
|
+
rotateZ(t) {
|
|
558
|
+
return dn(this, this, t), this.check();
|
|
559
|
+
}
|
|
560
|
+
// Scales a quat by a scalar number
|
|
561
|
+
scale(t) {
|
|
562
|
+
return yn(this, this, t), this.check();
|
|
563
|
+
}
|
|
564
|
+
// Performs a spherical linear interpolation between two quat
|
|
565
|
+
slerp(t, e, s) {
|
|
566
|
+
let i, o, r;
|
|
567
|
+
switch (arguments.length) {
|
|
568
|
+
case 1:
|
|
569
|
+
({
|
|
570
|
+
start: i = bn,
|
|
571
|
+
target: o,
|
|
572
|
+
ratio: r
|
|
573
|
+
} = t);
|
|
574
|
+
break;
|
|
575
|
+
case 2:
|
|
576
|
+
i = this, o = t, r = e;
|
|
577
|
+
break;
|
|
578
|
+
default:
|
|
579
|
+
i = t, o = e, r = s;
|
|
580
|
+
}
|
|
581
|
+
return nt(this, i, o, r), this.check();
|
|
582
|
+
}
|
|
583
|
+
transformVector4(t, e = new Et()) {
|
|
584
|
+
return Ls(e, t, this), we(e, 4);
|
|
585
|
+
}
|
|
586
|
+
// THREE.js Math API compatibility
|
|
587
|
+
lengthSq() {
|
|
588
|
+
return this.lengthSquared();
|
|
589
|
+
}
|
|
590
|
+
setFromAxisAngle(t, e) {
|
|
591
|
+
return this.setAxisAngle(t, e);
|
|
592
|
+
}
|
|
593
|
+
premultiply(t) {
|
|
594
|
+
return this.multiplyLeft(t);
|
|
595
|
+
}
|
|
596
|
+
multiply(t) {
|
|
597
|
+
return this.multiplyRight(t);
|
|
598
|
+
}
|
|
599
|
+
}
|
|
600
|
+
const Sn = 1e-15, Cn = 1e-20, Re = {
|
|
601
|
+
name: "phongMaterial",
|
|
602
|
+
dependencies: [Is],
|
|
603
|
+
// Note these are switched between phong and gouraud
|
|
604
|
+
source: Rs,
|
|
605
|
+
vs: Ps,
|
|
606
|
+
fs: Es,
|
|
607
|
+
defines: {
|
|
608
|
+
LIGHTING_FRAGMENT: !0
|
|
609
|
+
},
|
|
610
|
+
uniformTypes: {
|
|
611
|
+
ambient: "f32",
|
|
612
|
+
diffuse: "f32",
|
|
613
|
+
shininess: "f32",
|
|
614
|
+
specularColor: "vec3<f32>"
|
|
615
|
+
},
|
|
616
|
+
defaultUniforms: {
|
|
617
|
+
ambient: 0.35,
|
|
618
|
+
diffuse: 0.6,
|
|
619
|
+
shininess: 32,
|
|
620
|
+
specularColor: [0.15, 0.15, 0.15]
|
|
621
|
+
},
|
|
622
|
+
getUniforms(n) {
|
|
623
|
+
const t = { ...n };
|
|
624
|
+
return t.specularColor && (t.specularColor = t.specularColor.map((e) => e / 255)), { ...Re.defaultUniforms, ...t };
|
|
625
|
+
}
|
|
626
|
+
}, Ie = [0, 0, 0, 255], Ln = [0, 0, 0, 255], En = {
|
|
627
|
+
stroked: !0,
|
|
628
|
+
filled: !0,
|
|
629
|
+
extruded: !1,
|
|
630
|
+
elevationScale: 1,
|
|
631
|
+
wireframe: !1,
|
|
632
|
+
_normalize: !0,
|
|
633
|
+
_windingOrder: "CW",
|
|
634
|
+
lineWidthUnits: "meters",
|
|
635
|
+
lineWidthScale: 1,
|
|
636
|
+
lineWidthMinPixels: 0,
|
|
637
|
+
lineWidthMaxPixels: Number.MAX_SAFE_INTEGER,
|
|
638
|
+
lineJointRounded: !1,
|
|
639
|
+
lineMiterLimit: 4,
|
|
640
|
+
getPolygon: { type: "accessor", value: (n) => n.polygon },
|
|
641
|
+
// Polygon fill color
|
|
642
|
+
getFillColor: { type: "accessor", value: Ln },
|
|
643
|
+
// Point, line and polygon outline color
|
|
644
|
+
getLineColor: { type: "accessor", value: Ie },
|
|
645
|
+
// Line and polygon outline accessors
|
|
646
|
+
getLineWidth: { type: "accessor", value: 1 },
|
|
647
|
+
// Polygon extrusion accessor
|
|
648
|
+
getElevation: { type: "accessor", value: 1e3 },
|
|
649
|
+
// Optional material for 'lighting' shader module
|
|
650
|
+
material: !0
|
|
651
|
+
};
|
|
652
|
+
class Pt extends V {
|
|
653
|
+
initializeState() {
|
|
654
|
+
this.state = {
|
|
655
|
+
paths: [],
|
|
656
|
+
pathsDiff: null
|
|
657
|
+
}, this.props.getLineDashArray && Te.removed("getLineDashArray", "PathStyleExtension")();
|
|
658
|
+
}
|
|
659
|
+
updateState({ changeFlags: t }) {
|
|
660
|
+
const e = t.dataChanged || t.updateTriggersChanged && (t.updateTriggersChanged.all || t.updateTriggersChanged.getPolygon);
|
|
661
|
+
if (e && Array.isArray(t.dataChanged)) {
|
|
662
|
+
const s = this.state.paths.slice(), i = t.dataChanged.map((o) => As({
|
|
663
|
+
data: s,
|
|
664
|
+
getIndex: (r) => r.__source.index,
|
|
665
|
+
dataRange: o,
|
|
666
|
+
replace: this._getPaths(o)
|
|
667
|
+
}));
|
|
668
|
+
this.setState({ paths: s, pathsDiff: i });
|
|
669
|
+
} else e && this.setState({
|
|
670
|
+
paths: this._getPaths(),
|
|
671
|
+
pathsDiff: null
|
|
672
|
+
});
|
|
673
|
+
}
|
|
674
|
+
_getPaths(t = {}) {
|
|
675
|
+
const { data: e, getPolygon: s, positionFormat: i, _normalize: o } = this.props, r = [], a = i === "XY" ? 2 : 3, { startRow: c, endRow: h } = t, { iterable: u, objectInfo: l } = be(e, c, h);
|
|
676
|
+
for (const d of u) {
|
|
677
|
+
l.index++;
|
|
678
|
+
let f = s(d, l);
|
|
679
|
+
o && (f = vs(f, a));
|
|
680
|
+
const { holeIndices: m } = f, p = f.positions || f;
|
|
681
|
+
if (m)
|
|
682
|
+
for (let g = 0; g <= m.length; g++) {
|
|
683
|
+
const y = p.slice(m[g - 1] || 0, m[g] || p.length);
|
|
684
|
+
r.push(this.getSubLayerRow({ path: y }, d, l.index));
|
|
685
|
+
}
|
|
686
|
+
else
|
|
687
|
+
r.push(this.getSubLayerRow({ path: p }, d, l.index));
|
|
688
|
+
}
|
|
689
|
+
return r;
|
|
690
|
+
}
|
|
691
|
+
/* eslint-disable complexity */
|
|
692
|
+
renderLayers() {
|
|
693
|
+
const { data: t, _dataDiff: e, stroked: s, filled: i, extruded: o, wireframe: r, _normalize: a, _windingOrder: c, elevationScale: h, transitions: u, positionFormat: l } = this.props, { lineWidthUnits: d, lineWidthScale: f, lineWidthMinPixels: m, lineWidthMaxPixels: p, lineJointRounded: g, lineMiterLimit: y, lineDashJustified: _ } = this.props, { getFillColor: x, getLineColor: w, getLineWidth: T, getLineDashArray: S, getElevation: L, getPolygon: I, updateTriggers: b, material: C } = this.props, { paths: B, pathsDiff: k } = this.state, lt = this.getSubLayerClass("fill", Os), ht = this.getSubLayerClass("stroke", Se), j = this.shouldRenderSubLayer("fill", B) && new lt({
|
|
694
|
+
_dataDiff: e,
|
|
695
|
+
extruded: o,
|
|
696
|
+
elevationScale: h,
|
|
697
|
+
filled: i,
|
|
698
|
+
wireframe: r,
|
|
699
|
+
_normalize: a,
|
|
700
|
+
_windingOrder: c,
|
|
701
|
+
getElevation: L,
|
|
702
|
+
getFillColor: x,
|
|
703
|
+
getLineColor: o && r ? w : Ie,
|
|
704
|
+
material: C,
|
|
705
|
+
transitions: u
|
|
706
|
+
}, this.getSubLayerProps({
|
|
707
|
+
id: "fill",
|
|
708
|
+
updateTriggers: b && {
|
|
709
|
+
getPolygon: b.getPolygon,
|
|
710
|
+
getElevation: b.getElevation,
|
|
711
|
+
getFillColor: b.getFillColor,
|
|
712
|
+
// using a legacy API to invalid lineColor attributes
|
|
713
|
+
// if (extruded && wireframe) has changed
|
|
714
|
+
lineColors: o && r,
|
|
715
|
+
getLineColor: b.getLineColor
|
|
716
|
+
}
|
|
717
|
+
}), {
|
|
718
|
+
data: t,
|
|
719
|
+
positionFormat: l,
|
|
720
|
+
getPolygon: I
|
|
721
|
+
}), je = !o && s && this.shouldRenderSubLayer("stroke", B) && new ht({
|
|
722
|
+
_dataDiff: k && (() => k),
|
|
723
|
+
widthUnits: d,
|
|
724
|
+
widthScale: f,
|
|
725
|
+
widthMinPixels: m,
|
|
726
|
+
widthMaxPixels: p,
|
|
727
|
+
jointRounded: g,
|
|
728
|
+
miterLimit: y,
|
|
729
|
+
dashJustified: _,
|
|
730
|
+
// Already normalized
|
|
731
|
+
_pathType: "loop",
|
|
732
|
+
transitions: u && {
|
|
733
|
+
getWidth: u.getLineWidth,
|
|
734
|
+
getColor: u.getLineColor,
|
|
735
|
+
getPath: u.getPolygon
|
|
736
|
+
},
|
|
737
|
+
getColor: this.getSubLayerAccessor(w),
|
|
738
|
+
getWidth: this.getSubLayerAccessor(T),
|
|
739
|
+
getDashArray: this.getSubLayerAccessor(S)
|
|
740
|
+
}, this.getSubLayerProps({
|
|
741
|
+
id: "stroke",
|
|
742
|
+
updateTriggers: b && {
|
|
743
|
+
getWidth: b.getLineWidth,
|
|
744
|
+
getColor: b.getLineColor,
|
|
745
|
+
getDashArray: b.getLineDashArray
|
|
746
|
+
}
|
|
747
|
+
}), {
|
|
748
|
+
data: B,
|
|
749
|
+
positionFormat: l,
|
|
750
|
+
getPath: (Ye) => Ye.path
|
|
751
|
+
});
|
|
752
|
+
return [
|
|
753
|
+
// If not extruded: flat fill layer is drawn below outlines
|
|
754
|
+
!o && j,
|
|
755
|
+
je,
|
|
756
|
+
// If extruded: draw fill layer last for correct blending behavior
|
|
757
|
+
o && j
|
|
758
|
+
];
|
|
759
|
+
}
|
|
760
|
+
}
|
|
761
|
+
Pt.layerName = "PolygonLayer";
|
|
762
|
+
Pt.defaultProps = En;
|
|
763
|
+
class Pn {
|
|
764
|
+
constructor(t) {
|
|
765
|
+
this.index = t, this.isVisible = !1, this.isSelected = !1, this.parent = null, this.children = [], this.content = null, this._loader = void 0, this._abortController = null, this._loaderId = 0, this._isLoaded = !1, this._isCancelled = !1, this._needsReload = !1;
|
|
766
|
+
}
|
|
767
|
+
/** @deprecated use `boundingBox` instead */
|
|
768
|
+
get bbox() {
|
|
769
|
+
return this._bbox;
|
|
770
|
+
}
|
|
771
|
+
// TODO - remove in v9
|
|
772
|
+
set bbox(t) {
|
|
773
|
+
this._bbox || (this._bbox = t, "west" in t ? this.boundingBox = [
|
|
774
|
+
[t.west, t.south],
|
|
775
|
+
[t.east, t.north]
|
|
776
|
+
] : this.boundingBox = [
|
|
777
|
+
[t.left, t.top],
|
|
778
|
+
[t.right, t.bottom]
|
|
779
|
+
]);
|
|
780
|
+
}
|
|
781
|
+
get data() {
|
|
782
|
+
return this.isLoading && this._loader ? this._loader.then(() => this.data) : this.content;
|
|
783
|
+
}
|
|
784
|
+
get isLoaded() {
|
|
785
|
+
return this._isLoaded && !this._needsReload;
|
|
786
|
+
}
|
|
787
|
+
get isLoading() {
|
|
788
|
+
return !!this._loader && !this._isCancelled;
|
|
789
|
+
}
|
|
790
|
+
get needsReload() {
|
|
791
|
+
return this._needsReload || this._isCancelled;
|
|
792
|
+
}
|
|
793
|
+
get byteLength() {
|
|
794
|
+
const t = this.content ? this.content.byteLength : 0;
|
|
795
|
+
return Number.isFinite(t) || console.error("byteLength not defined in tile data"), t;
|
|
796
|
+
}
|
|
797
|
+
/* eslint-disable max-statements */
|
|
798
|
+
async _loadData({ getData: t, requestScheduler: e, onLoad: s, onError: i }) {
|
|
799
|
+
const { index: o, id: r, bbox: a, userData: c, zoom: h } = this, u = this._loaderId;
|
|
800
|
+
this._abortController = new AbortController();
|
|
801
|
+
const { signal: l } = this._abortController, d = await e.scheduleRequest(this, (p) => p.isSelected ? 1 : -1);
|
|
802
|
+
if (!d) {
|
|
803
|
+
this._isCancelled = !0;
|
|
804
|
+
return;
|
|
805
|
+
}
|
|
806
|
+
if (this._isCancelled) {
|
|
807
|
+
d.done();
|
|
808
|
+
return;
|
|
809
|
+
}
|
|
810
|
+
let f = null, m;
|
|
811
|
+
try {
|
|
812
|
+
f = await t({ index: o, id: r, bbox: a, userData: c, zoom: h, signal: l });
|
|
813
|
+
} catch (p) {
|
|
814
|
+
m = p || !0;
|
|
815
|
+
} finally {
|
|
816
|
+
d.done();
|
|
817
|
+
}
|
|
818
|
+
if (u === this._loaderId) {
|
|
819
|
+
if (this._loader = void 0, this.content = f, this._isCancelled && !f) {
|
|
820
|
+
this._isLoaded = !1;
|
|
821
|
+
return;
|
|
822
|
+
}
|
|
823
|
+
this._isLoaded = !0, this._isCancelled = !1, m ? i(m, this) : s(this);
|
|
824
|
+
}
|
|
825
|
+
}
|
|
826
|
+
loadData(t) {
|
|
827
|
+
return this._isLoaded = !1, this._isCancelled = !1, this._needsReload = !1, this._loaderId++, this._loader = this._loadData(t), this._loader;
|
|
828
|
+
}
|
|
829
|
+
setNeedsReload() {
|
|
830
|
+
this.isLoading && (this.abort(), this._loader = void 0), this._needsReload = !0;
|
|
831
|
+
}
|
|
832
|
+
abort() {
|
|
833
|
+
this.isLoaded || (this._isCancelled = !0, this._abortController?.abort());
|
|
834
|
+
}
|
|
835
|
+
}
|
|
836
|
+
const P = {
|
|
837
|
+
OUTSIDE: -1,
|
|
838
|
+
// Represents that an object is not contained within the frustum.
|
|
839
|
+
INTERSECTING: 0,
|
|
840
|
+
// Represents that an object intersects one of the frustum's planes.
|
|
841
|
+
INSIDE: 1
|
|
842
|
+
// Represents that an object is fully within the frustum.
|
|
843
|
+
}, Ht = new M(), Rn = new M();
|
|
844
|
+
class Rt {
|
|
845
|
+
/**
|
|
846
|
+
* Creates an instance of an AxisAlignedBoundingBox from the minimum and maximum points along the x, y, and z axes.
|
|
847
|
+
* @param minimum=[0, 0, 0] The minimum point along the x, y, and z axes.
|
|
848
|
+
* @param maximum=[0, 0, 0] The maximum point along the x, y, and z axes.
|
|
849
|
+
* @param center The center of the box; automatically computed if not supplied.
|
|
850
|
+
*/
|
|
851
|
+
constructor(t = [0, 0, 0], e = [0, 0, 0], s) {
|
|
852
|
+
s = s || Ht.copy(t).add(e).scale(0.5), this.center = new M(s), this.halfDiagonal = new M(e).subtract(this.center), this.minimum = new M(t), this.maximum = new M(e);
|
|
853
|
+
}
|
|
854
|
+
/**
|
|
855
|
+
* Duplicates a AxisAlignedBoundingBox instance.
|
|
856
|
+
*
|
|
857
|
+
* @returns {AxisAlignedBoundingBox} A new AxisAlignedBoundingBox instance.
|
|
858
|
+
*/
|
|
859
|
+
clone() {
|
|
860
|
+
return new Rt(this.minimum, this.maximum, this.center);
|
|
861
|
+
}
|
|
862
|
+
/**
|
|
863
|
+
* Compares the provided AxisAlignedBoundingBox componentwise and returns
|
|
864
|
+
* <code>true</code> if they are equal, <code>false</code> otherwise.
|
|
865
|
+
*
|
|
866
|
+
* @param {AxisAlignedBoundingBox} [right] The second AxisAlignedBoundingBox to compare with.
|
|
867
|
+
* @returns {Boolean} <code>true</code> if left and right are equal, <code>false</code> otherwise.
|
|
868
|
+
*/
|
|
869
|
+
equals(t) {
|
|
870
|
+
return this === t || !!t && this.minimum.equals(t.minimum) && this.maximum.equals(t.maximum);
|
|
871
|
+
}
|
|
872
|
+
/**
|
|
873
|
+
* Applies a 4x4 affine transformation matrix to a bounding sphere.
|
|
874
|
+
* @param transform The transformation matrix to apply to the bounding sphere.
|
|
875
|
+
* @returns itself, i.e. the modified BoundingVolume.
|
|
876
|
+
*/
|
|
877
|
+
transform(t) {
|
|
878
|
+
return this.center.transformAsPoint(t), this.halfDiagonal.transform(t), this.minimum.transform(t), this.maximum.transform(t), this;
|
|
879
|
+
}
|
|
880
|
+
/**
|
|
881
|
+
* Determines which side of a plane a box is located.
|
|
882
|
+
*/
|
|
883
|
+
intersectPlane(t) {
|
|
884
|
+
const { halfDiagonal: e } = this, s = Rn.from(t.normal), i = e.x * Math.abs(s.x) + e.y * Math.abs(s.y) + e.z * Math.abs(s.z), o = this.center.dot(s) + t.distance;
|
|
885
|
+
return o - i > 0 ? P.INSIDE : o + i < 0 ? P.OUTSIDE : P.INTERSECTING;
|
|
886
|
+
}
|
|
887
|
+
/** Computes the estimated distance from the closest point on a bounding box to a point. */
|
|
888
|
+
distanceTo(t) {
|
|
889
|
+
return Math.sqrt(this.distanceSquaredTo(t));
|
|
890
|
+
}
|
|
891
|
+
/** Computes the estimated distance squared from the closest point on a bounding box to a point. */
|
|
892
|
+
distanceSquaredTo(t) {
|
|
893
|
+
const e = Ht.from(t).subtract(this.center), { halfDiagonal: s } = this;
|
|
894
|
+
let i = 0, o;
|
|
895
|
+
return o = Math.abs(e.x) - s.x, o > 0 && (i += o * o), o = Math.abs(e.y) - s.y, o > 0 && (i += o * o), o = Math.abs(e.z) - s.z, o > 0 && (i += o * o), i;
|
|
896
|
+
}
|
|
897
|
+
}
|
|
898
|
+
const Y = new M(), Kt = new M();
|
|
899
|
+
class It {
|
|
900
|
+
/** Creates a bounding sphere */
|
|
901
|
+
constructor(t = [0, 0, 0], e = 0) {
|
|
902
|
+
this.radius = -0, this.center = new M(), this.fromCenterRadius(t, e);
|
|
903
|
+
}
|
|
904
|
+
/** Sets the bounding sphere from `center` and `radius`. */
|
|
905
|
+
fromCenterRadius(t, e) {
|
|
906
|
+
return this.center.from(t), this.radius = e, this;
|
|
907
|
+
}
|
|
908
|
+
/**
|
|
909
|
+
* Computes a bounding sphere from the corner points of an axis-aligned bounding box. The sphere
|
|
910
|
+
* tightly and fully encompasses the box.
|
|
911
|
+
*/
|
|
912
|
+
fromCornerPoints(t, e) {
|
|
913
|
+
return e = Y.from(e), this.center = new M().from(t).add(e).scale(0.5), this.radius = this.center.distance(e), this;
|
|
914
|
+
}
|
|
915
|
+
/** Compares the provided BoundingSphere component wise */
|
|
916
|
+
equals(t) {
|
|
917
|
+
return this === t || !!t && this.center.equals(t.center) && this.radius === t.radius;
|
|
918
|
+
}
|
|
919
|
+
/** Duplicates a BoundingSphere instance. */
|
|
920
|
+
clone() {
|
|
921
|
+
return new It(this.center, this.radius);
|
|
922
|
+
}
|
|
923
|
+
/** Computes a bounding sphere that contains both the left and right bounding spheres. */
|
|
924
|
+
union(t) {
|
|
925
|
+
const e = this.center, s = this.radius, i = t.center, o = t.radius, r = Y.copy(i).subtract(e), a = r.magnitude();
|
|
926
|
+
if (s >= a + o)
|
|
927
|
+
return this.clone();
|
|
928
|
+
if (o >= a + s)
|
|
929
|
+
return t.clone();
|
|
930
|
+
const c = (s + a + o) * 0.5;
|
|
931
|
+
return Kt.copy(r).scale((-s + c) / a).add(e), this.center.copy(Kt), this.radius = c, this;
|
|
932
|
+
}
|
|
933
|
+
/** Computes a bounding sphere by enlarging the provided sphere to contain the provided point. */
|
|
934
|
+
expand(t) {
|
|
935
|
+
const s = Y.from(t).subtract(this.center).magnitude();
|
|
936
|
+
return s > this.radius && (this.radius = s), this;
|
|
937
|
+
}
|
|
938
|
+
// BoundingVolume interface
|
|
939
|
+
/**
|
|
940
|
+
* Applies a 4x4 affine transformation matrix to a bounding sphere.
|
|
941
|
+
* @param sphere The bounding sphere to apply the transformation to.
|
|
942
|
+
* @param transform The transformation matrix to apply to the bounding sphere.
|
|
943
|
+
* @returns self.
|
|
944
|
+
*/
|
|
945
|
+
transform(t) {
|
|
946
|
+
this.center.transform(t);
|
|
947
|
+
const e = zs(Y, t);
|
|
948
|
+
return this.radius = Math.max(e[0], Math.max(e[1], e[2])) * this.radius, this;
|
|
949
|
+
}
|
|
950
|
+
/** Computes the estimated distance squared from the closest point on a bounding sphere to a point. */
|
|
951
|
+
distanceSquaredTo(t) {
|
|
952
|
+
const e = this.distanceTo(t);
|
|
953
|
+
return e * e;
|
|
954
|
+
}
|
|
955
|
+
/** Computes the estimated distance from the closest point on a bounding sphere to a point. */
|
|
956
|
+
distanceTo(t) {
|
|
957
|
+
const s = Y.from(t).subtract(this.center);
|
|
958
|
+
return Math.max(0, s.len() - this.radius);
|
|
959
|
+
}
|
|
960
|
+
/** Determines which side of a plane a sphere is located. */
|
|
961
|
+
intersectPlane(t) {
|
|
962
|
+
const e = this.center, s = this.radius, o = t.normal.dot(e) + t.distance;
|
|
963
|
+
return o < -s ? P.OUTSIDE : o < s ? P.INTERSECTING : P.INSIDE;
|
|
964
|
+
}
|
|
965
|
+
}
|
|
966
|
+
const In = new M(), An = new M(), H = new M(), K = new M(), Q = new M(), vn = new M(), On = new M(), O = {
|
|
967
|
+
COLUMN0ROW0: 0,
|
|
968
|
+
COLUMN0ROW1: 1,
|
|
969
|
+
COLUMN0ROW2: 2,
|
|
970
|
+
COLUMN1ROW0: 3,
|
|
971
|
+
COLUMN1ROW1: 4,
|
|
972
|
+
COLUMN1ROW2: 5,
|
|
973
|
+
COLUMN2ROW0: 6,
|
|
974
|
+
COLUMN2ROW1: 7,
|
|
975
|
+
COLUMN2ROW2: 8
|
|
976
|
+
};
|
|
977
|
+
class At {
|
|
978
|
+
constructor(t = [0, 0, 0], e = [0, 0, 0, 0, 0, 0, 0, 0, 0]) {
|
|
979
|
+
this.center = new M().from(t), this.halfAxes = new E(e);
|
|
980
|
+
}
|
|
981
|
+
/** Returns an array with three halfSizes for the bounding box */
|
|
982
|
+
get halfSize() {
|
|
983
|
+
const t = this.halfAxes.getColumn(0), e = this.halfAxes.getColumn(1), s = this.halfAxes.getColumn(2);
|
|
984
|
+
return [new M(t).len(), new M(e).len(), new M(s).len()];
|
|
985
|
+
}
|
|
986
|
+
/** Returns a quaternion describing the orientation of the bounding box */
|
|
987
|
+
get quaternion() {
|
|
988
|
+
const t = this.halfAxes.getColumn(0), e = this.halfAxes.getColumn(1), s = this.halfAxes.getColumn(2), i = new M(t).normalize(), o = new M(e).normalize(), r = new M(s).normalize();
|
|
989
|
+
return new Zt().fromMatrix3(new E([...i, ...o, ...r]));
|
|
990
|
+
}
|
|
991
|
+
/**
|
|
992
|
+
* Create OrientedBoundingBox from quaternion based OBB,
|
|
993
|
+
*/
|
|
994
|
+
fromCenterHalfSizeQuaternion(t, e, s) {
|
|
995
|
+
const i = new Zt(s), o = new E().fromQuaternion(i);
|
|
996
|
+
return o[0] = o[0] * e[0], o[1] = o[1] * e[0], o[2] = o[2] * e[0], o[3] = o[3] * e[1], o[4] = o[4] * e[1], o[5] = o[5] * e[1], o[6] = o[6] * e[2], o[7] = o[7] * e[2], o[8] = o[8] * e[2], this.center = new M().from(t), this.halfAxes = o, this;
|
|
997
|
+
}
|
|
998
|
+
/** Duplicates a OrientedBoundingBox instance. */
|
|
999
|
+
clone() {
|
|
1000
|
+
return new At(this.center, this.halfAxes);
|
|
1001
|
+
}
|
|
1002
|
+
/** Compares the provided OrientedBoundingBox component wise and returns */
|
|
1003
|
+
equals(t) {
|
|
1004
|
+
return this === t || !!t && this.center.equals(t.center) && this.halfAxes.equals(t.halfAxes);
|
|
1005
|
+
}
|
|
1006
|
+
/** Computes a tight-fitting bounding sphere enclosing the provided oriented bounding box. */
|
|
1007
|
+
getBoundingSphere(t = new It()) {
|
|
1008
|
+
const e = this.halfAxes, s = e.getColumn(0, H), i = e.getColumn(1, K), o = e.getColumn(2, Q), r = In.copy(s).add(i).add(o);
|
|
1009
|
+
return t.center.copy(this.center), t.radius = r.magnitude(), t;
|
|
1010
|
+
}
|
|
1011
|
+
/** Determines which side of a plane the oriented bounding box is located. */
|
|
1012
|
+
intersectPlane(t) {
|
|
1013
|
+
const e = this.center, s = t.normal, i = this.halfAxes, o = s.x, r = s.y, a = s.z, c = Math.abs(o * i[O.COLUMN0ROW0] + r * i[O.COLUMN0ROW1] + a * i[O.COLUMN0ROW2]) + Math.abs(o * i[O.COLUMN1ROW0] + r * i[O.COLUMN1ROW1] + a * i[O.COLUMN1ROW2]) + Math.abs(o * i[O.COLUMN2ROW0] + r * i[O.COLUMN2ROW1] + a * i[O.COLUMN2ROW2]), h = s.dot(e) + t.distance;
|
|
1014
|
+
return h <= -c ? P.OUTSIDE : h >= c ? P.INSIDE : P.INTERSECTING;
|
|
1015
|
+
}
|
|
1016
|
+
/** Computes the estimated distance from the closest point on a bounding box to a point. */
|
|
1017
|
+
distanceTo(t) {
|
|
1018
|
+
return Math.sqrt(this.distanceSquaredTo(t));
|
|
1019
|
+
}
|
|
1020
|
+
/**
|
|
1021
|
+
* Computes the estimated distance squared from the closest point
|
|
1022
|
+
* on a bounding box to a point.
|
|
1023
|
+
* See Geometric Tools for Computer Graphics 10.4.2
|
|
1024
|
+
*/
|
|
1025
|
+
distanceSquaredTo(t) {
|
|
1026
|
+
const e = An.from(t).subtract(this.center), s = this.halfAxes, i = s.getColumn(0, H), o = s.getColumn(1, K), r = s.getColumn(2, Q), a = i.magnitude(), c = o.magnitude(), h = r.magnitude();
|
|
1027
|
+
i.normalize(), o.normalize(), r.normalize();
|
|
1028
|
+
let u = 0, l;
|
|
1029
|
+
return l = Math.abs(e.dot(i)) - a, l > 0 && (u += l * l), l = Math.abs(e.dot(o)) - c, l > 0 && (u += l * l), l = Math.abs(e.dot(r)) - h, l > 0 && (u += l * l), u;
|
|
1030
|
+
}
|
|
1031
|
+
/**
|
|
1032
|
+
* The distances calculated by the vector from the center of the bounding box
|
|
1033
|
+
* to position projected onto direction.
|
|
1034
|
+
*
|
|
1035
|
+
* - If you imagine the infinite number of planes with normal direction,
|
|
1036
|
+
* this computes the smallest distance to the closest and farthest planes
|
|
1037
|
+
* from `position` that intersect the bounding box.
|
|
1038
|
+
*
|
|
1039
|
+
* @param position The position to calculate the distance from.
|
|
1040
|
+
* @param direction The direction from position.
|
|
1041
|
+
* @param result An Interval (array of length 2) to store the nearest and farthest distances.
|
|
1042
|
+
* @returns Interval (array of length 2) with nearest and farthest distances
|
|
1043
|
+
* on the bounding box from position in direction.
|
|
1044
|
+
*/
|
|
1045
|
+
// eslint-disable-next-line max-statements
|
|
1046
|
+
computePlaneDistances(t, e, s = [-0, -0]) {
|
|
1047
|
+
let i = Number.POSITIVE_INFINITY, o = Number.NEGATIVE_INFINITY;
|
|
1048
|
+
const r = this.center, a = this.halfAxes, c = a.getColumn(0, H), h = a.getColumn(1, K), u = a.getColumn(2, Q), l = vn.copy(c).add(h).add(u).add(r), d = On.copy(l).subtract(t);
|
|
1049
|
+
let f = e.dot(d);
|
|
1050
|
+
return i = Math.min(f, i), o = Math.max(f, o), l.copy(r).add(c).add(h).subtract(u), d.copy(l).subtract(t), f = e.dot(d), i = Math.min(f, i), o = Math.max(f, o), l.copy(r).add(c).subtract(h).add(u), d.copy(l).subtract(t), f = e.dot(d), i = Math.min(f, i), o = Math.max(f, o), l.copy(r).add(c).subtract(h).subtract(u), d.copy(l).subtract(t), f = e.dot(d), i = Math.min(f, i), o = Math.max(f, o), r.copy(l).subtract(c).add(h).add(u), d.copy(l).subtract(t), f = e.dot(d), i = Math.min(f, i), o = Math.max(f, o), r.copy(l).subtract(c).add(h).subtract(u), d.copy(l).subtract(t), f = e.dot(d), i = Math.min(f, i), o = Math.max(f, o), r.copy(l).subtract(c).subtract(h).add(u), d.copy(l).subtract(t), f = e.dot(d), i = Math.min(f, i), o = Math.max(f, o), r.copy(l).subtract(c).subtract(h).subtract(u), d.copy(l).subtract(t), f = e.dot(d), i = Math.min(f, i), o = Math.max(f, o), s[0] = i, s[1] = o, s;
|
|
1051
|
+
}
|
|
1052
|
+
/**
|
|
1053
|
+
* Applies a 4x4 affine transformation matrix to a bounding sphere.
|
|
1054
|
+
* @param transform The transformation matrix to apply to the bounding sphere.
|
|
1055
|
+
* @returns itself, i.e. the modified BoundingVolume.
|
|
1056
|
+
*/
|
|
1057
|
+
transform(t) {
|
|
1058
|
+
this.center.transformAsPoint(t);
|
|
1059
|
+
const e = this.halfAxes.getColumn(0, H);
|
|
1060
|
+
e.transformAsPoint(t);
|
|
1061
|
+
const s = this.halfAxes.getColumn(1, K);
|
|
1062
|
+
s.transformAsPoint(t);
|
|
1063
|
+
const i = this.halfAxes.getColumn(2, Q);
|
|
1064
|
+
return i.transformAsPoint(t), this.halfAxes = new E([...e, ...s, ...i]), this;
|
|
1065
|
+
}
|
|
1066
|
+
getTransform() {
|
|
1067
|
+
throw new Error("not implemented");
|
|
1068
|
+
}
|
|
1069
|
+
}
|
|
1070
|
+
const Qt = new M(), Jt = new M();
|
|
1071
|
+
class W {
|
|
1072
|
+
constructor(t = [0, 0, 1], e = 0) {
|
|
1073
|
+
this.normal = new M(), this.distance = -0, this.fromNormalDistance(t, e);
|
|
1074
|
+
}
|
|
1075
|
+
/** Creates a plane from a normal and a distance from the origin. */
|
|
1076
|
+
fromNormalDistance(t, e) {
|
|
1077
|
+
return xt(Number.isFinite(e)), this.normal.from(t).normalize(), this.distance = e, this;
|
|
1078
|
+
}
|
|
1079
|
+
/** Creates a plane from a normal and a point on the plane. */
|
|
1080
|
+
fromPointNormal(t, e) {
|
|
1081
|
+
t = Qt.from(t), this.normal.from(e).normalize();
|
|
1082
|
+
const s = -this.normal.dot(t);
|
|
1083
|
+
return this.distance = s, this;
|
|
1084
|
+
}
|
|
1085
|
+
/** Creates a plane from the general equation */
|
|
1086
|
+
fromCoefficients(t, e, s, i) {
|
|
1087
|
+
return this.normal.set(t, e, s), xt(st(this.normal.len(), 1)), this.distance = i, this;
|
|
1088
|
+
}
|
|
1089
|
+
/** Duplicates a Plane instance. */
|
|
1090
|
+
clone() {
|
|
1091
|
+
return new W(this.normal, this.distance);
|
|
1092
|
+
}
|
|
1093
|
+
/** Compares the provided Planes by normal and distance */
|
|
1094
|
+
equals(t) {
|
|
1095
|
+
return st(this.distance, t.distance) && st(this.normal, t.normal);
|
|
1096
|
+
}
|
|
1097
|
+
/** Computes the signed shortest distance of a point to a plane.
|
|
1098
|
+
* The sign of the distance determines which side of the plane the point is on.
|
|
1099
|
+
*/
|
|
1100
|
+
getPointDistance(t) {
|
|
1101
|
+
return this.normal.dot(t) + this.distance;
|
|
1102
|
+
}
|
|
1103
|
+
/** Transforms the plane by the given transformation matrix. */
|
|
1104
|
+
transform(t) {
|
|
1105
|
+
const e = Jt.copy(this.normal).transformAsVector(t).normalize(), s = this.normal.scale(-this.distance).transform(t);
|
|
1106
|
+
return this.fromPointNormal(s, e);
|
|
1107
|
+
}
|
|
1108
|
+
projectPointOntoPlane(t, e = [0, 0, 0]) {
|
|
1109
|
+
const s = Qt.from(t), i = this.getPointDistance(s), o = Jt.copy(this.normal).scale(i);
|
|
1110
|
+
return s.subtract(o).to(e);
|
|
1111
|
+
}
|
|
1112
|
+
}
|
|
1113
|
+
const te = [new M([1, 0, 0]), new M([0, 1, 0]), new M([0, 0, 1])], ee = new M(), zn = new M();
|
|
1114
|
+
class v {
|
|
1115
|
+
/**
|
|
1116
|
+
* Create a new `CullingVolume` bounded by an array of clipping planed
|
|
1117
|
+
* @param planes Array of clipping planes.
|
|
1118
|
+
* */
|
|
1119
|
+
constructor(t = []) {
|
|
1120
|
+
this.planes = t;
|
|
1121
|
+
}
|
|
1122
|
+
/**
|
|
1123
|
+
* Constructs a culling volume from a bounding sphere. Creates six planes that create a box containing the sphere.
|
|
1124
|
+
* The planes are aligned to the x, y, and z axes in world coordinates.
|
|
1125
|
+
*/
|
|
1126
|
+
fromBoundingSphere(t) {
|
|
1127
|
+
this.planes.length = 2 * te.length;
|
|
1128
|
+
const e = t.center, s = t.radius;
|
|
1129
|
+
let i = 0;
|
|
1130
|
+
for (const o of te) {
|
|
1131
|
+
let r = this.planes[i], a = this.planes[i + 1];
|
|
1132
|
+
r || (r = this.planes[i] = new W()), a || (a = this.planes[i + 1] = new W());
|
|
1133
|
+
const c = ee.copy(o).scale(-s).add(e);
|
|
1134
|
+
r.fromPointNormal(c, o);
|
|
1135
|
+
const h = ee.copy(o).scale(s).add(e), u = zn.copy(o).negate();
|
|
1136
|
+
a.fromPointNormal(h, u), i += 2;
|
|
1137
|
+
}
|
|
1138
|
+
return this;
|
|
1139
|
+
}
|
|
1140
|
+
/** Determines whether a bounding volume intersects the culling volume. */
|
|
1141
|
+
computeVisibility(t) {
|
|
1142
|
+
let e = P.INSIDE;
|
|
1143
|
+
for (const s of this.planes)
|
|
1144
|
+
switch (t.intersectPlane(s)) {
|
|
1145
|
+
case P.OUTSIDE:
|
|
1146
|
+
return P.OUTSIDE;
|
|
1147
|
+
case P.INTERSECTING:
|
|
1148
|
+
e = P.INTERSECTING;
|
|
1149
|
+
break;
|
|
1150
|
+
}
|
|
1151
|
+
return e;
|
|
1152
|
+
}
|
|
1153
|
+
/**
|
|
1154
|
+
* Determines whether a bounding volume intersects the culling volume.
|
|
1155
|
+
*
|
|
1156
|
+
* @param parentPlaneMask A bit mask from the boundingVolume's parent's check against the same culling
|
|
1157
|
+
* volume, such that if (planeMask & (1 << planeIndex) === 0), for k < 31, then
|
|
1158
|
+
* the parent (and therefore this) volume is completely inside plane[planeIndex]
|
|
1159
|
+
* and that plane check can be skipped.
|
|
1160
|
+
*/
|
|
1161
|
+
computeVisibilityWithPlaneMask(t, e) {
|
|
1162
|
+
if (xt(Number.isFinite(e), "parentPlaneMask is required."), e === v.MASK_OUTSIDE || e === v.MASK_INSIDE)
|
|
1163
|
+
return e;
|
|
1164
|
+
let s = v.MASK_INSIDE;
|
|
1165
|
+
const i = this.planes;
|
|
1166
|
+
for (let o = 0; o < this.planes.length; ++o) {
|
|
1167
|
+
const r = o < 31 ? 1 << o : 0;
|
|
1168
|
+
if (o < 31 && (e & r) === 0)
|
|
1169
|
+
continue;
|
|
1170
|
+
const a = i[o], c = t.intersectPlane(a);
|
|
1171
|
+
if (c === P.OUTSIDE)
|
|
1172
|
+
return v.MASK_OUTSIDE;
|
|
1173
|
+
c === P.INTERSECTING && (s |= r);
|
|
1174
|
+
}
|
|
1175
|
+
return s;
|
|
1176
|
+
}
|
|
1177
|
+
}
|
|
1178
|
+
v.MASK_OUTSIDE = 4294967295;
|
|
1179
|
+
v.MASK_INSIDE = 0;
|
|
1180
|
+
v.MASK_INDETERMINATE = 2147483647;
|
|
1181
|
+
new M();
|
|
1182
|
+
new M();
|
|
1183
|
+
new M();
|
|
1184
|
+
new M();
|
|
1185
|
+
new M();
|
|
1186
|
+
new M();
|
|
1187
|
+
new M();
|
|
1188
|
+
new M();
|
|
1189
|
+
new M();
|
|
1190
|
+
new M();
|
|
1191
|
+
new M();
|
|
1192
|
+
new M();
|
|
1193
|
+
new M();
|
|
1194
|
+
new M();
|
|
1195
|
+
new M();
|
|
1196
|
+
new M();
|
|
1197
|
+
new M();
|
|
1198
|
+
const A = new E(), Nn = new E(), Fn = new E(), J = new E(), se = new E();
|
|
1199
|
+
function qn(n, t = {}) {
|
|
1200
|
+
const e = Cn, s = 10;
|
|
1201
|
+
let i = 0, o = 0;
|
|
1202
|
+
const r = Nn, a = Fn;
|
|
1203
|
+
r.identity(), a.copy(n);
|
|
1204
|
+
const c = e * Bn(a);
|
|
1205
|
+
for (; o < s && Gn(a) > c; )
|
|
1206
|
+
Dn(a, J), se.copy(J).transpose(), a.multiplyRight(J), a.multiplyLeft(se), r.multiplyRight(J), ++i > 2 && (++o, i = 0);
|
|
1207
|
+
return t.unitary = r.toTarget(t.unitary), t.diagonal = a.toTarget(t.diagonal), t;
|
|
1208
|
+
}
|
|
1209
|
+
function Bn(n) {
|
|
1210
|
+
let t = 0;
|
|
1211
|
+
for (let e = 0; e < 9; ++e) {
|
|
1212
|
+
const s = n[e];
|
|
1213
|
+
t += s * s;
|
|
1214
|
+
}
|
|
1215
|
+
return Math.sqrt(t);
|
|
1216
|
+
}
|
|
1217
|
+
const wt = [1, 0, 0], Tt = [2, 2, 1];
|
|
1218
|
+
function Gn(n) {
|
|
1219
|
+
let t = 0;
|
|
1220
|
+
for (let e = 0; e < 3; ++e) {
|
|
1221
|
+
const s = n[A.getElementIndex(Tt[e], wt[e])];
|
|
1222
|
+
t += 2 * s * s;
|
|
1223
|
+
}
|
|
1224
|
+
return Math.sqrt(t);
|
|
1225
|
+
}
|
|
1226
|
+
function Dn(n, t) {
|
|
1227
|
+
const e = Sn;
|
|
1228
|
+
let s = 0, i = 1;
|
|
1229
|
+
for (let h = 0; h < 3; ++h) {
|
|
1230
|
+
const u = Math.abs(n[A.getElementIndex(Tt[h], wt[h])]);
|
|
1231
|
+
u > s && (i = h, s = u);
|
|
1232
|
+
}
|
|
1233
|
+
const o = wt[i], r = Tt[i];
|
|
1234
|
+
let a = 1, c = 0;
|
|
1235
|
+
if (Math.abs(n[A.getElementIndex(r, o)]) > e) {
|
|
1236
|
+
const h = n[A.getElementIndex(r, r)], u = n[A.getElementIndex(o, o)], l = n[A.getElementIndex(r, o)], d = (h - u) / 2 / l;
|
|
1237
|
+
let f;
|
|
1238
|
+
d < 0 ? f = -1 / (-d + Math.sqrt(1 + d * d)) : f = 1 / (d + Math.sqrt(1 + d * d)), a = 1 / Math.sqrt(1 + f * f), c = f * a;
|
|
1239
|
+
}
|
|
1240
|
+
return E.IDENTITY.to(t), t[A.getElementIndex(o, o)] = t[A.getElementIndex(r, r)] = a, t[A.getElementIndex(r, o)] = c, t[A.getElementIndex(o, r)] = -c, t;
|
|
1241
|
+
}
|
|
1242
|
+
const N = new M(), Un = new M(), Wn = new M(), Vn = new M(), kn = new M(), jn = new E(), Yn = {
|
|
1243
|
+
diagonal: new E(),
|
|
1244
|
+
unitary: new E()
|
|
1245
|
+
};
|
|
1246
|
+
function Ae(n, t = new At()) {
|
|
1247
|
+
if (!n || n.length === 0)
|
|
1248
|
+
return t.halfAxes = new E([0, 0, 0, 0, 0, 0, 0, 0, 0]), t.center = new M(), t;
|
|
1249
|
+
const e = n.length, s = new M(0, 0, 0);
|
|
1250
|
+
for (const b of n)
|
|
1251
|
+
s.add(b);
|
|
1252
|
+
const i = 1 / e;
|
|
1253
|
+
s.multiplyByScalar(i);
|
|
1254
|
+
let o = 0, r = 0, a = 0, c = 0, h = 0, u = 0;
|
|
1255
|
+
for (const b of n) {
|
|
1256
|
+
const C = N.copy(b).subtract(s);
|
|
1257
|
+
o += C.x * C.x, r += C.x * C.y, a += C.x * C.z, c += C.y * C.y, h += C.y * C.z, u += C.z * C.z;
|
|
1258
|
+
}
|
|
1259
|
+
o *= i, r *= i, a *= i, c *= i, h *= i, u *= i;
|
|
1260
|
+
const l = jn;
|
|
1261
|
+
l[0] = o, l[1] = r, l[2] = a, l[3] = r, l[4] = c, l[5] = h, l[6] = a, l[7] = h, l[8] = u;
|
|
1262
|
+
const { unitary: d } = qn(l, Yn), f = t.halfAxes.copy(d);
|
|
1263
|
+
let m = f.getColumn(0, Wn), p = f.getColumn(1, Vn), g = f.getColumn(2, kn), y = -Number.MAX_VALUE, _ = -Number.MAX_VALUE, x = -Number.MAX_VALUE, w = Number.MAX_VALUE, T = Number.MAX_VALUE, S = Number.MAX_VALUE;
|
|
1264
|
+
for (const b of n)
|
|
1265
|
+
N.copy(b), y = Math.max(N.dot(m), y), _ = Math.max(N.dot(p), _), x = Math.max(N.dot(g), x), w = Math.min(N.dot(m), w), T = Math.min(N.dot(p), T), S = Math.min(N.dot(g), S);
|
|
1266
|
+
m = m.multiplyByScalar(0.5 * (w + y)), p = p.multiplyByScalar(0.5 * (T + _)), g = g.multiplyByScalar(0.5 * (S + x)), t.center.copy(m).add(p).add(g);
|
|
1267
|
+
const L = Un.set(y - w, _ - T, x - S).multiplyByScalar(0.5), I = new E([L[0], 0, 0, 0, L[1], 0, 0, 0, L[2]]);
|
|
1268
|
+
return t.halfAxes.multiplyRight(I), t;
|
|
1269
|
+
}
|
|
1270
|
+
const D = 512, ne = 3, ve = [
|
|
1271
|
+
[0.5, 0.5],
|
|
1272
|
+
[0, 0],
|
|
1273
|
+
[0, 1],
|
|
1274
|
+
[1, 0],
|
|
1275
|
+
[1, 1]
|
|
1276
|
+
], Oe = ve.concat([
|
|
1277
|
+
[0, 0.5],
|
|
1278
|
+
[0.5, 0],
|
|
1279
|
+
[1, 0.5],
|
|
1280
|
+
[0.5, 1]
|
|
1281
|
+
]), $n = Oe.concat([
|
|
1282
|
+
[0.25, 0.5],
|
|
1283
|
+
[0.75, 0.5]
|
|
1284
|
+
]);
|
|
1285
|
+
class U {
|
|
1286
|
+
constructor(t, e, s) {
|
|
1287
|
+
this.x = t, this.y = e, this.z = s;
|
|
1288
|
+
}
|
|
1289
|
+
get children() {
|
|
1290
|
+
if (!this._children) {
|
|
1291
|
+
const t = this.x * 2, e = this.y * 2, s = this.z + 1;
|
|
1292
|
+
this._children = [
|
|
1293
|
+
new U(t, e, s),
|
|
1294
|
+
new U(t, e + 1, s),
|
|
1295
|
+
new U(t + 1, e, s),
|
|
1296
|
+
new U(t + 1, e + 1, s)
|
|
1297
|
+
];
|
|
1298
|
+
}
|
|
1299
|
+
return this._children;
|
|
1300
|
+
}
|
|
1301
|
+
// eslint-disable-next-line complexity
|
|
1302
|
+
update(t) {
|
|
1303
|
+
const { viewport: e, cullingVolume: s, elevationBounds: i, minZ: o, maxZ: r, bounds: a, offset: c, project: h } = t, u = this.getBoundingVolume(i, c, h);
|
|
1304
|
+
if (a && !this.insideBounds(a) || s.computeVisibility(u) < 0)
|
|
1305
|
+
return !1;
|
|
1306
|
+
if (!this.childVisible) {
|
|
1307
|
+
let { z: d } = this;
|
|
1308
|
+
if (d < r && d >= o) {
|
|
1309
|
+
const f = u.distanceTo(e.cameraPosition) * e.scale / e.height;
|
|
1310
|
+
d += Math.floor(Math.log2(f));
|
|
1311
|
+
}
|
|
1312
|
+
if (d >= r)
|
|
1313
|
+
return this.selected = !0, !0;
|
|
1314
|
+
}
|
|
1315
|
+
this.selected = !1, this.childVisible = !0;
|
|
1316
|
+
for (const d of this.children)
|
|
1317
|
+
d.update(t);
|
|
1318
|
+
return !0;
|
|
1319
|
+
}
|
|
1320
|
+
getSelected(t = []) {
|
|
1321
|
+
if (this.selected && t.push(this), this._children)
|
|
1322
|
+
for (const e of this._children)
|
|
1323
|
+
e.getSelected(t);
|
|
1324
|
+
return t;
|
|
1325
|
+
}
|
|
1326
|
+
insideBounds([t, e, s, i]) {
|
|
1327
|
+
const o = Math.pow(2, this.z), r = D / o;
|
|
1328
|
+
return this.x * r < s && this.y * r < i && (this.x + 1) * r > t && (this.y + 1) * r > e;
|
|
1329
|
+
}
|
|
1330
|
+
getBoundingVolume(t, e, s) {
|
|
1331
|
+
if (s) {
|
|
1332
|
+
const c = this.z < 1 ? $n : this.z < 2 ? Oe : ve, h = [];
|
|
1333
|
+
for (const u of c) {
|
|
1334
|
+
const l = St(this.x + u[0], this.y + u[1], this.z);
|
|
1335
|
+
l[2] = t[0], h.push(s(l)), t[0] !== t[1] && (l[2] = t[1], h.push(s(l)));
|
|
1336
|
+
}
|
|
1337
|
+
return Ae(h);
|
|
1338
|
+
}
|
|
1339
|
+
const i = Math.pow(2, this.z), o = D / i, r = this.x * o + e * D, a = D - (this.y + 1) * o;
|
|
1340
|
+
return new Rt([r, a, t[0]], [r + o, a + o, t[1]]);
|
|
1341
|
+
}
|
|
1342
|
+
}
|
|
1343
|
+
function Xn(n, t, e, s) {
|
|
1344
|
+
const i = n instanceof Ce && n.resolution ? (
|
|
1345
|
+
// eslint-disable-next-line @typescript-eslint/unbound-method
|
|
1346
|
+
n.projectPosition
|
|
1347
|
+
) : null, o = Object.values(n.getFrustumPlanes()).map(({ normal: f, distance: m }) => new W(f.clone().negate(), m)), r = new v(o), a = n.distanceScales.unitsPerMeter[2], c = e && e[0] * a || 0, h = e && e[1] * a || 0, u = n instanceof kt && n.pitch <= 60 ? t : 0;
|
|
1348
|
+
if (s) {
|
|
1349
|
+
const [f, m, p, g] = s, y = ot([f, g]), _ = ot([p, m]);
|
|
1350
|
+
s = [y[0], D - y[1], _[0], D - _[1]];
|
|
1351
|
+
}
|
|
1352
|
+
const l = new U(0, 0, 0), d = {
|
|
1353
|
+
viewport: n,
|
|
1354
|
+
project: i,
|
|
1355
|
+
cullingVolume: r,
|
|
1356
|
+
elevationBounds: [c, h],
|
|
1357
|
+
minZ: u,
|
|
1358
|
+
maxZ: t,
|
|
1359
|
+
bounds: s,
|
|
1360
|
+
// num. of worlds from the center. For repeated maps
|
|
1361
|
+
offset: 0
|
|
1362
|
+
};
|
|
1363
|
+
if (l.update(d), n instanceof kt && n.subViewports && n.subViewports.length > 1) {
|
|
1364
|
+
for (d.offset = -1; l.update(d) && !(--d.offset < -ne); )
|
|
1365
|
+
;
|
|
1366
|
+
for (d.offset = 1; l.update(d) && !(++d.offset > ne); )
|
|
1367
|
+
;
|
|
1368
|
+
}
|
|
1369
|
+
return l.getSelected();
|
|
1370
|
+
}
|
|
1371
|
+
const z = 512, Zn = [-1 / 0, -1 / 0, 1 / 0, 1 / 0], Hn = {
|
|
1372
|
+
equal: (n, t) => {
|
|
1373
|
+
if (n === t)
|
|
1374
|
+
return !0;
|
|
1375
|
+
if (!Array.isArray(n) || !Array.isArray(t))
|
|
1376
|
+
return !1;
|
|
1377
|
+
const e = n.length;
|
|
1378
|
+
if (e !== t.length)
|
|
1379
|
+
return !1;
|
|
1380
|
+
for (let s = 0; s < e; s++)
|
|
1381
|
+
if (n[s] !== t[s])
|
|
1382
|
+
return !1;
|
|
1383
|
+
return !0;
|
|
1384
|
+
}
|
|
1385
|
+
};
|
|
1386
|
+
function vt(n, t) {
|
|
1387
|
+
const e = [
|
|
1388
|
+
// top-left
|
|
1389
|
+
t.transformAsPoint([n[0], n[1]]),
|
|
1390
|
+
// top-right
|
|
1391
|
+
t.transformAsPoint([n[2], n[1]]),
|
|
1392
|
+
// bottom-left
|
|
1393
|
+
t.transformAsPoint([n[0], n[3]]),
|
|
1394
|
+
// bottom-right
|
|
1395
|
+
t.transformAsPoint([n[2], n[3]])
|
|
1396
|
+
];
|
|
1397
|
+
return [
|
|
1398
|
+
// Minimum x coord
|
|
1399
|
+
Math.min(...e.map((i) => i[0])),
|
|
1400
|
+
// Minimum y coord
|
|
1401
|
+
Math.min(...e.map((i) => i[1])),
|
|
1402
|
+
// Max x coord
|
|
1403
|
+
Math.max(...e.map((i) => i[0])),
|
|
1404
|
+
// Max y coord
|
|
1405
|
+
Math.max(...e.map((i) => i[1]))
|
|
1406
|
+
];
|
|
1407
|
+
}
|
|
1408
|
+
function Kn(n) {
|
|
1409
|
+
return Math.abs(n.split("").reduce((t, e) => (t << 5) - t + e.charCodeAt(0) | 0, 0));
|
|
1410
|
+
}
|
|
1411
|
+
function Qn(n, t) {
|
|
1412
|
+
if (!n || !n.length)
|
|
1413
|
+
return null;
|
|
1414
|
+
const { index: e, id: s } = t;
|
|
1415
|
+
if (Array.isArray(n)) {
|
|
1416
|
+
const o = Kn(s) % n.length;
|
|
1417
|
+
n = n[o];
|
|
1418
|
+
}
|
|
1419
|
+
let i = n;
|
|
1420
|
+
for (const o of Object.keys(e)) {
|
|
1421
|
+
const r = new RegExp(`{${o}}`, "g");
|
|
1422
|
+
i = i.replace(r, String(e[o]));
|
|
1423
|
+
}
|
|
1424
|
+
return Number.isInteger(e.y) && Number.isInteger(e.z) && (i = i.replace(/\{-y\}/g, String(Math.pow(2, e.z) - e.y - 1))), i;
|
|
1425
|
+
}
|
|
1426
|
+
function Jn(n, t, e) {
|
|
1427
|
+
let s;
|
|
1428
|
+
return s = n.getBounds(), n.isGeospatial ? [
|
|
1429
|
+
Math.max(s[0], e[0]),
|
|
1430
|
+
Math.max(s[1], e[1]),
|
|
1431
|
+
Math.min(s[2], e[2]),
|
|
1432
|
+
Math.min(s[3], e[3])
|
|
1433
|
+
] : [
|
|
1434
|
+
// Top corner should not be more then bottom corner in either direction
|
|
1435
|
+
Math.max(Math.min(s[0], e[2]), e[0]),
|
|
1436
|
+
Math.max(Math.min(s[1], e[3]), e[1]),
|
|
1437
|
+
// Bottom corner should not be less then top corner in either direction
|
|
1438
|
+
Math.min(Math.max(s[2], e[0]), e[2]),
|
|
1439
|
+
Math.min(Math.max(s[3], e[1]), e[3])
|
|
1440
|
+
];
|
|
1441
|
+
}
|
|
1442
|
+
function ti({ viewport: n, z: t, cullRect: e }) {
|
|
1443
|
+
return (n.subViewports || [n]).map((i) => bt(i, t || 0, e));
|
|
1444
|
+
}
|
|
1445
|
+
function bt(n, t, e) {
|
|
1446
|
+
if (!Array.isArray(t)) {
|
|
1447
|
+
const o = e.x - n.x, r = e.y - n.y, { width: a, height: c } = e, h = { targetZ: t }, u = n.unproject([o, r], h), l = n.unproject([o + a, r], h), d = n.unproject([o, r + c], h), f = n.unproject([o + a, r + c], h);
|
|
1448
|
+
return [
|
|
1449
|
+
Math.min(u[0], l[0], d[0], f[0]),
|
|
1450
|
+
Math.min(u[1], l[1], d[1], f[1]),
|
|
1451
|
+
Math.max(u[0], l[0], d[0], f[0]),
|
|
1452
|
+
Math.max(u[1], l[1], d[1], f[1])
|
|
1453
|
+
];
|
|
1454
|
+
}
|
|
1455
|
+
const s = bt(n, t[0], e), i = bt(n, t[1], e);
|
|
1456
|
+
return [
|
|
1457
|
+
Math.min(s[0], i[0]),
|
|
1458
|
+
Math.min(s[1], i[1]),
|
|
1459
|
+
Math.max(s[2], i[2]),
|
|
1460
|
+
Math.max(s[3], i[3])
|
|
1461
|
+
];
|
|
1462
|
+
}
|
|
1463
|
+
function ei(n, t, e) {
|
|
1464
|
+
return e ? vt(n, e).map((i) => i * t / z) : n.map((s) => s * t / z);
|
|
1465
|
+
}
|
|
1466
|
+
function Ot(n, t) {
|
|
1467
|
+
return Math.pow(2, n) * z / t;
|
|
1468
|
+
}
|
|
1469
|
+
function St(n, t, e) {
|
|
1470
|
+
const s = Ot(e, z), i = n / s * 360 - 180, o = Math.PI - 2 * Math.PI * t / s, r = 180 / Math.PI * Math.atan(0.5 * (Math.exp(o) - Math.exp(-o)));
|
|
1471
|
+
return [i, r];
|
|
1472
|
+
}
|
|
1473
|
+
function ie(n, t, e, s) {
|
|
1474
|
+
const i = Ot(e, s);
|
|
1475
|
+
return [n / i * z, t / i * z];
|
|
1476
|
+
}
|
|
1477
|
+
function si(n, t, e, s, i = z) {
|
|
1478
|
+
if (n.isGeospatial) {
|
|
1479
|
+
const [h, u] = St(t, e, s), [l, d] = St(t + 1, e + 1, s);
|
|
1480
|
+
return { west: h, north: u, east: l, south: d };
|
|
1481
|
+
}
|
|
1482
|
+
const [o, r] = ie(t, e, s, i), [a, c] = ie(t + 1, e + 1, s, i);
|
|
1483
|
+
return { left: o, top: r, right: a, bottom: c };
|
|
1484
|
+
}
|
|
1485
|
+
function ni(n, t, e, s, i) {
|
|
1486
|
+
const o = Jn(n, null, s), r = Ot(t, e), [a, c, h, u] = ei(o, r, i), l = [];
|
|
1487
|
+
for (let d = Math.floor(a); d < h; d++)
|
|
1488
|
+
for (let f = Math.floor(c); f < u; f++)
|
|
1489
|
+
l.push({ x: d, y: f, z: t });
|
|
1490
|
+
return l;
|
|
1491
|
+
}
|
|
1492
|
+
function ii({ viewport: n, maxZoom: t, minZoom: e, zRange: s, extent: i, tileSize: o = z, modelMatrix: r, modelMatrixInverse: a, zoomOffset: c = 0 }) {
|
|
1493
|
+
let h = n.isGeospatial ? Math.round(n.zoom + Math.log2(z / o)) + c : Math.ceil(n.zoom) + c;
|
|
1494
|
+
if (typeof e == "number" && Number.isFinite(e) && h < e) {
|
|
1495
|
+
if (!i)
|
|
1496
|
+
return [];
|
|
1497
|
+
h = e;
|
|
1498
|
+
}
|
|
1499
|
+
typeof t == "number" && Number.isFinite(t) && h > t && (h = t);
|
|
1500
|
+
let u = i;
|
|
1501
|
+
return r && a && i && !n.isGeospatial && (u = vt(i, r)), n.isGeospatial ? Xn(n, h, s, i) : ni(n, h, o, u || Zn, a);
|
|
1502
|
+
}
|
|
1503
|
+
function oi(n) {
|
|
1504
|
+
let t = {}, e;
|
|
1505
|
+
return (s) => {
|
|
1506
|
+
for (const i in s)
|
|
1507
|
+
if (!ri(s[i], t[i])) {
|
|
1508
|
+
e = n(s), t = s;
|
|
1509
|
+
break;
|
|
1510
|
+
}
|
|
1511
|
+
return e;
|
|
1512
|
+
};
|
|
1513
|
+
}
|
|
1514
|
+
function ri(n, t) {
|
|
1515
|
+
if (n === t)
|
|
1516
|
+
return !0;
|
|
1517
|
+
if (Array.isArray(n)) {
|
|
1518
|
+
const e = n.length;
|
|
1519
|
+
if (!t || t.length !== e)
|
|
1520
|
+
return !1;
|
|
1521
|
+
for (let s = 0; s < e; s++)
|
|
1522
|
+
if (n[s] !== t[s])
|
|
1523
|
+
return !1;
|
|
1524
|
+
return !0;
|
|
1525
|
+
}
|
|
1526
|
+
return !1;
|
|
1527
|
+
}
|
|
1528
|
+
const oe = 1, at = 2, ai = "never", ci = "no-overlap", zt = "best-available", li = 5, hi = {
|
|
1529
|
+
[zt]: di,
|
|
1530
|
+
[ci]: fi,
|
|
1531
|
+
[ai]: () => {
|
|
1532
|
+
}
|
|
1533
|
+
}, ui = {
|
|
1534
|
+
extent: null,
|
|
1535
|
+
tileSize: 512,
|
|
1536
|
+
maxZoom: null,
|
|
1537
|
+
minZoom: null,
|
|
1538
|
+
maxCacheSize: null,
|
|
1539
|
+
maxCacheByteSize: null,
|
|
1540
|
+
refinementStrategy: "best-available",
|
|
1541
|
+
zRange: null,
|
|
1542
|
+
maxRequests: 6,
|
|
1543
|
+
debounceTime: 0,
|
|
1544
|
+
zoomOffset: 0,
|
|
1545
|
+
// onTileLoad: (tile: Tile2DHeader) => void, // onTileUnload: (tile: Tile2DHeader) => void, // onTileError: (error: any, tile: Tile2DHeader) => void, /** Called when all tiles in the current viewport are loaded. */
|
|
1546
|
+
// onViewportLoad: ((tiles: Tile2DHeader<DataT>[]) => void) | null,
|
|
1547
|
+
onTileLoad: () => {
|
|
1548
|
+
},
|
|
1549
|
+
onTileUnload: () => {
|
|
1550
|
+
},
|
|
1551
|
+
onTileError: () => {
|
|
1552
|
+
}
|
|
1553
|
+
};
|
|
1554
|
+
class Nt {
|
|
1555
|
+
/**
|
|
1556
|
+
* Takes in a function that returns tile data, a cache size, and a max and a min zoom level.
|
|
1557
|
+
* Cache size defaults to 5 * number of tiles in the current viewport
|
|
1558
|
+
*/
|
|
1559
|
+
constructor(t) {
|
|
1560
|
+
this._getCullBounds = oi(ti), this.opts = { ...ui, ...t }, this.setOptions(this.opts), this.onTileLoad = (e) => {
|
|
1561
|
+
this.opts.onTileLoad?.(e), this.opts.maxCacheByteSize !== null && (this._cacheByteSize += e.byteLength, this._resizeCache());
|
|
1562
|
+
}, this._requestScheduler = new Hs({
|
|
1563
|
+
throttleRequests: this.opts.maxRequests > 0 || this.opts.debounceTime > 0,
|
|
1564
|
+
maxRequests: this.opts.maxRequests,
|
|
1565
|
+
debounceTime: this.opts.debounceTime
|
|
1566
|
+
}), this._cache = /* @__PURE__ */ new Map(), this._tiles = [], this._dirty = !1, this._cacheByteSize = 0, this._viewport = null, this._zRange = null, this._selectedTiles = null, this._frameNumber = 0, this._modelMatrix = new G(), this._modelMatrixInverse = new G();
|
|
1567
|
+
}
|
|
1568
|
+
/* Public API */
|
|
1569
|
+
get tiles() {
|
|
1570
|
+
return this._tiles;
|
|
1571
|
+
}
|
|
1572
|
+
get selectedTiles() {
|
|
1573
|
+
return this._selectedTiles;
|
|
1574
|
+
}
|
|
1575
|
+
get isLoaded() {
|
|
1576
|
+
return this._selectedTiles !== null && this._selectedTiles.every((t) => t.isLoaded);
|
|
1577
|
+
}
|
|
1578
|
+
get needsReload() {
|
|
1579
|
+
return this._selectedTiles !== null && this._selectedTiles.some((t) => t.needsReload);
|
|
1580
|
+
}
|
|
1581
|
+
setOptions(t) {
|
|
1582
|
+
Object.assign(this.opts, t), Number.isFinite(t.maxZoom) && (this._maxZoom = Math.floor(t.maxZoom)), Number.isFinite(t.minZoom) && (this._minZoom = Math.ceil(t.minZoom));
|
|
1583
|
+
}
|
|
1584
|
+
// Clean up any outstanding tile requests.
|
|
1585
|
+
finalize() {
|
|
1586
|
+
for (const t of this._cache.values())
|
|
1587
|
+
t.isLoading && t.abort();
|
|
1588
|
+
this._cache.clear(), this._tiles = [], this._selectedTiles = null;
|
|
1589
|
+
}
|
|
1590
|
+
reloadAll() {
|
|
1591
|
+
for (const t of this._cache.keys()) {
|
|
1592
|
+
const e = this._cache.get(t);
|
|
1593
|
+
!this._selectedTiles || !this._selectedTiles.includes(e) ? this._cache.delete(t) : e.setNeedsReload();
|
|
1594
|
+
}
|
|
1595
|
+
}
|
|
1596
|
+
/**
|
|
1597
|
+
* Update the cache with the given viewport and model matrix and triggers callback onUpdate.
|
|
1598
|
+
*/
|
|
1599
|
+
update(t, { zRange: e, modelMatrix: s } = {
|
|
1600
|
+
zRange: null,
|
|
1601
|
+
modelMatrix: null
|
|
1602
|
+
}) {
|
|
1603
|
+
const i = s ? new G(s) : new G(), o = !i.equals(this._modelMatrix);
|
|
1604
|
+
if (!this._viewport || !t.equals(this._viewport) || !st(this._zRange, e) || o) {
|
|
1605
|
+
o && (this._modelMatrixInverse = i.clone().invert(), this._modelMatrix = i), this._viewport = t, this._zRange = e;
|
|
1606
|
+
const a = this.getTileIndices({
|
|
1607
|
+
viewport: t,
|
|
1608
|
+
maxZoom: this._maxZoom,
|
|
1609
|
+
minZoom: this._minZoom,
|
|
1610
|
+
zRange: e,
|
|
1611
|
+
modelMatrix: this._modelMatrix,
|
|
1612
|
+
modelMatrixInverse: this._modelMatrixInverse
|
|
1613
|
+
});
|
|
1614
|
+
this._selectedTiles = a.map((c) => this._getTile(c, !0)), this._dirty && this._rebuildTree();
|
|
1615
|
+
} else this.needsReload && (this._selectedTiles = this._selectedTiles.map((a) => this._getTile(a.index, !0)));
|
|
1616
|
+
const r = this.updateTileStates();
|
|
1617
|
+
return this._pruneRequests(), this._dirty && this._resizeCache(), r && this._frameNumber++, this._frameNumber;
|
|
1618
|
+
}
|
|
1619
|
+
// eslint-disable-next-line complexity
|
|
1620
|
+
isTileVisible(t, e, s) {
|
|
1621
|
+
if (!t.isVisible)
|
|
1622
|
+
return !1;
|
|
1623
|
+
if (e && this._viewport) {
|
|
1624
|
+
const i = this._getCullBounds({
|
|
1625
|
+
viewport: this._viewport,
|
|
1626
|
+
z: this._zRange,
|
|
1627
|
+
cullRect: e
|
|
1628
|
+
});
|
|
1629
|
+
let { bbox: o } = t;
|
|
1630
|
+
for (const [r, a, c, h] of i) {
|
|
1631
|
+
let u;
|
|
1632
|
+
if ("west" in o)
|
|
1633
|
+
u = o.west < c && o.east > r && o.south < h && o.north > a;
|
|
1634
|
+
else {
|
|
1635
|
+
if (s && !G.IDENTITY.equals(s)) {
|
|
1636
|
+
const [f, m, p, g] = vt([o.left, o.top, o.right, o.bottom], s);
|
|
1637
|
+
o = { left: f, top: m, right: p, bottom: g };
|
|
1638
|
+
}
|
|
1639
|
+
const l = Math.min(o.top, o.bottom), d = Math.max(o.top, o.bottom);
|
|
1640
|
+
u = o.left < c && o.right > r && l < h && d > a;
|
|
1641
|
+
}
|
|
1642
|
+
if (u)
|
|
1643
|
+
return !0;
|
|
1644
|
+
}
|
|
1645
|
+
return !1;
|
|
1646
|
+
}
|
|
1647
|
+
return !0;
|
|
1648
|
+
}
|
|
1649
|
+
/* Public interface for subclassing */
|
|
1650
|
+
/** Returns array of tile indices in the current viewport */
|
|
1651
|
+
getTileIndices({ viewport: t, maxZoom: e, minZoom: s, zRange: i, modelMatrix: o, modelMatrixInverse: r }) {
|
|
1652
|
+
const { tileSize: a, extent: c, zoomOffset: h } = this.opts;
|
|
1653
|
+
return ii({
|
|
1654
|
+
viewport: t,
|
|
1655
|
+
maxZoom: e,
|
|
1656
|
+
minZoom: s,
|
|
1657
|
+
zRange: i,
|
|
1658
|
+
tileSize: a,
|
|
1659
|
+
extent: c,
|
|
1660
|
+
modelMatrix: o,
|
|
1661
|
+
modelMatrixInverse: r,
|
|
1662
|
+
zoomOffset: h
|
|
1663
|
+
});
|
|
1664
|
+
}
|
|
1665
|
+
/** Returns unique string key for a tile index */
|
|
1666
|
+
getTileId(t) {
|
|
1667
|
+
return `${t.x}-${t.y}-${t.z}`;
|
|
1668
|
+
}
|
|
1669
|
+
/** Returns a zoom level for a tile index */
|
|
1670
|
+
getTileZoom(t) {
|
|
1671
|
+
return t.z;
|
|
1672
|
+
}
|
|
1673
|
+
/** Returns additional metadata to add to tile, bbox by default */
|
|
1674
|
+
getTileMetadata(t) {
|
|
1675
|
+
const { tileSize: e } = this.opts;
|
|
1676
|
+
return { bbox: si(this._viewport, t.x, t.y, t.z, e) };
|
|
1677
|
+
}
|
|
1678
|
+
/** Returns index of the parent tile */
|
|
1679
|
+
getParentIndex(t) {
|
|
1680
|
+
const e = Math.floor(t.x / 2), s = Math.floor(t.y / 2), i = t.z - 1;
|
|
1681
|
+
return { x: e, y: s, z: i };
|
|
1682
|
+
}
|
|
1683
|
+
// Returns true if any tile's visibility changed
|
|
1684
|
+
updateTileStates() {
|
|
1685
|
+
const t = this.opts.refinementStrategy || zt, e = new Array(this._cache.size);
|
|
1686
|
+
let s = 0;
|
|
1687
|
+
for (const i of this._cache.values())
|
|
1688
|
+
e[s++] = i.isVisible, i.isSelected = !1, i.isVisible = !1;
|
|
1689
|
+
for (const i of this._selectedTiles)
|
|
1690
|
+
i.isSelected = !0, i.isVisible = !0;
|
|
1691
|
+
(typeof t == "function" ? t : hi[t])(Array.from(this._cache.values())), s = 0;
|
|
1692
|
+
for (const i of this._cache.values())
|
|
1693
|
+
if (e[s++] !== i.isVisible)
|
|
1694
|
+
return !0;
|
|
1695
|
+
return !1;
|
|
1696
|
+
}
|
|
1697
|
+
_pruneRequests() {
|
|
1698
|
+
const { maxRequests: t = 0 } = this.opts, e = [];
|
|
1699
|
+
let s = 0;
|
|
1700
|
+
for (const i of this._cache.values())
|
|
1701
|
+
i.isLoading && (s++, !i.isSelected && !i.isVisible && e.push(i));
|
|
1702
|
+
for (; t > 0 && s > t && e.length > 0; )
|
|
1703
|
+
e.shift().abort(), s--;
|
|
1704
|
+
}
|
|
1705
|
+
// This needs to be called every time some tiles have been added/removed from cache
|
|
1706
|
+
_rebuildTree() {
|
|
1707
|
+
const { _cache: t } = this;
|
|
1708
|
+
for (const e of t.values())
|
|
1709
|
+
e.parent = null, e.children && (e.children.length = 0);
|
|
1710
|
+
for (const e of t.values()) {
|
|
1711
|
+
const s = this._getNearestAncestor(e);
|
|
1712
|
+
e.parent = s, s?.children && s.children.push(e);
|
|
1713
|
+
}
|
|
1714
|
+
}
|
|
1715
|
+
/**
|
|
1716
|
+
* Clear tiles that are not visible when the cache is full
|
|
1717
|
+
*/
|
|
1718
|
+
/* eslint-disable complexity */
|
|
1719
|
+
_resizeCache() {
|
|
1720
|
+
const { _cache: t, opts: e } = this, s = e.maxCacheSize ?? // @ts-expect-error called only when selectedTiles is initialized
|
|
1721
|
+
(e.maxCacheByteSize !== null ? 1 / 0 : li * this.selectedTiles.length), i = e.maxCacheByteSize ?? 1 / 0;
|
|
1722
|
+
if (t.size > s || this._cacheByteSize > i) {
|
|
1723
|
+
for (const [r, a] of t)
|
|
1724
|
+
if (!a.isVisible && !a.isSelected && (this._cacheByteSize -= e.maxCacheByteSize !== null ? a.byteLength : 0, t.delete(r), this.opts.onTileUnload?.(a)), t.size <= s && this._cacheByteSize <= i)
|
|
1725
|
+
break;
|
|
1726
|
+
this._rebuildTree(), this._dirty = !0;
|
|
1727
|
+
}
|
|
1728
|
+
this._dirty && (this._tiles = Array.from(this._cache.values()).sort((r, a) => r.zoom - a.zoom), this._dirty = !1);
|
|
1729
|
+
}
|
|
1730
|
+
_getTile(t, e) {
|
|
1731
|
+
const s = this.getTileId(t);
|
|
1732
|
+
let i = this._cache.get(s), o = !1;
|
|
1733
|
+
return !i && e ? (i = new Pn(t), Object.assign(i, this.getTileMetadata(i.index)), Object.assign(i, { id: s, zoom: this.getTileZoom(i.index) }), o = !0, this._cache.set(s, i), this._dirty = !0) : i && i.needsReload && (o = !0), i && o && i.loadData({
|
|
1734
|
+
getData: this.opts.getTileData,
|
|
1735
|
+
requestScheduler: this._requestScheduler,
|
|
1736
|
+
onLoad: this.onTileLoad,
|
|
1737
|
+
onError: this.opts.onTileError
|
|
1738
|
+
}), i;
|
|
1739
|
+
}
|
|
1740
|
+
_getNearestAncestor(t) {
|
|
1741
|
+
const { _minZoom: e = 0 } = this;
|
|
1742
|
+
let s = t.index;
|
|
1743
|
+
for (; this.getTileZoom(s) > e; ) {
|
|
1744
|
+
s = this.getParentIndex(s);
|
|
1745
|
+
const i = this._getTile(s);
|
|
1746
|
+
if (i)
|
|
1747
|
+
return i;
|
|
1748
|
+
}
|
|
1749
|
+
return null;
|
|
1750
|
+
}
|
|
1751
|
+
}
|
|
1752
|
+
function di(n) {
|
|
1753
|
+
for (const t of n)
|
|
1754
|
+
t.state = 0;
|
|
1755
|
+
for (const t of n)
|
|
1756
|
+
t.isSelected && !ze(t) && Ft(t);
|
|
1757
|
+
for (const t of n)
|
|
1758
|
+
t.isVisible = !!(t.state & at);
|
|
1759
|
+
}
|
|
1760
|
+
function fi(n) {
|
|
1761
|
+
for (const e of n)
|
|
1762
|
+
e.state = 0;
|
|
1763
|
+
for (const e of n)
|
|
1764
|
+
e.isSelected && ze(e);
|
|
1765
|
+
const t = Array.from(n).sort((e, s) => e.zoom - s.zoom);
|
|
1766
|
+
for (const e of t)
|
|
1767
|
+
if (e.isVisible = !!(e.state & at), e.children && (e.isVisible || e.state & oe))
|
|
1768
|
+
for (const s of e.children)
|
|
1769
|
+
s.state = oe;
|
|
1770
|
+
else e.isSelected && Ft(e);
|
|
1771
|
+
}
|
|
1772
|
+
function ze(n) {
|
|
1773
|
+
let t = n;
|
|
1774
|
+
for (; t; ) {
|
|
1775
|
+
if (t.isLoaded || t.content)
|
|
1776
|
+
return t.state |= at, !0;
|
|
1777
|
+
t = t.parent;
|
|
1778
|
+
}
|
|
1779
|
+
return !1;
|
|
1780
|
+
}
|
|
1781
|
+
function Ft(n) {
|
|
1782
|
+
for (const t of n.children)
|
|
1783
|
+
t.isLoaded || t.content ? t.state |= at : Ft(t);
|
|
1784
|
+
}
|
|
1785
|
+
const mi = {
|
|
1786
|
+
TilesetClass: Nt,
|
|
1787
|
+
data: { type: "data", value: [] },
|
|
1788
|
+
dataComparator: Hn.equal,
|
|
1789
|
+
renderSubLayers: { type: "function", value: (n) => new Fs(n) },
|
|
1790
|
+
getTileData: { type: "function", optional: !0, value: null },
|
|
1791
|
+
// TODO - change to onViewportLoad to align with Tile3DLayer
|
|
1792
|
+
onViewportLoad: { type: "function", optional: !0, value: null },
|
|
1793
|
+
onTileLoad: { type: "function", value: (n) => {
|
|
1794
|
+
} },
|
|
1795
|
+
onTileUnload: { type: "function", value: (n) => {
|
|
1796
|
+
} },
|
|
1797
|
+
// eslint-disable-next-line
|
|
1798
|
+
onTileError: { type: "function", value: (n) => console.error(n) },
|
|
1799
|
+
extent: { type: "array", optional: !0, value: null, compare: !0 },
|
|
1800
|
+
tileSize: 512,
|
|
1801
|
+
maxZoom: null,
|
|
1802
|
+
minZoom: 0,
|
|
1803
|
+
maxCacheSize: null,
|
|
1804
|
+
maxCacheByteSize: null,
|
|
1805
|
+
refinementStrategy: zt,
|
|
1806
|
+
zRange: null,
|
|
1807
|
+
maxRequests: 6,
|
|
1808
|
+
debounceTime: 0,
|
|
1809
|
+
zoomOffset: 0
|
|
1810
|
+
};
|
|
1811
|
+
class ct extends V {
|
|
1812
|
+
initializeState() {
|
|
1813
|
+
this.state = {
|
|
1814
|
+
tileset: null,
|
|
1815
|
+
isLoaded: !1
|
|
1816
|
+
};
|
|
1817
|
+
}
|
|
1818
|
+
finalizeState() {
|
|
1819
|
+
this.state?.tileset?.finalize();
|
|
1820
|
+
}
|
|
1821
|
+
get isLoaded() {
|
|
1822
|
+
return !!this.state?.tileset?.selectedTiles?.every((t) => t.isLoaded && t.layers && t.layers.every((e) => e.isLoaded));
|
|
1823
|
+
}
|
|
1824
|
+
shouldUpdateState({ changeFlags: t }) {
|
|
1825
|
+
return t.somethingChanged;
|
|
1826
|
+
}
|
|
1827
|
+
updateState({ changeFlags: t }) {
|
|
1828
|
+
let { tileset: e } = this.state;
|
|
1829
|
+
const s = t.propsOrDataChanged || t.updateTriggersChanged, i = t.dataChanged || t.updateTriggersChanged && (t.updateTriggersChanged.all || t.updateTriggersChanged.getTileData);
|
|
1830
|
+
e ? s && (e.setOptions(this._getTilesetOptions()), i ? e.reloadAll() : e.tiles.forEach((o) => {
|
|
1831
|
+
o.layers = null;
|
|
1832
|
+
})) : (e = new this.props.TilesetClass(this._getTilesetOptions()), this.setState({ tileset: e })), this._updateTileset();
|
|
1833
|
+
}
|
|
1834
|
+
_getTilesetOptions() {
|
|
1835
|
+
const { tileSize: t, maxCacheSize: e, maxCacheByteSize: s, refinementStrategy: i, extent: o, maxZoom: r, minZoom: a, maxRequests: c, debounceTime: h, zoomOffset: u } = this.props;
|
|
1836
|
+
return {
|
|
1837
|
+
maxCacheSize: e,
|
|
1838
|
+
maxCacheByteSize: s,
|
|
1839
|
+
maxZoom: r,
|
|
1840
|
+
minZoom: a,
|
|
1841
|
+
tileSize: t,
|
|
1842
|
+
refinementStrategy: i,
|
|
1843
|
+
extent: o,
|
|
1844
|
+
maxRequests: c,
|
|
1845
|
+
debounceTime: h,
|
|
1846
|
+
zoomOffset: u,
|
|
1847
|
+
getTileData: this.getTileData.bind(this),
|
|
1848
|
+
onTileLoad: this._onTileLoad.bind(this),
|
|
1849
|
+
onTileError: this._onTileError.bind(this),
|
|
1850
|
+
onTileUnload: this._onTileUnload.bind(this)
|
|
1851
|
+
};
|
|
1852
|
+
}
|
|
1853
|
+
_updateTileset() {
|
|
1854
|
+
const t = this.state.tileset, { zRange: e, modelMatrix: s } = this.props, i = t.update(this.context.viewport, { zRange: e, modelMatrix: s }), { isLoaded: o } = t, r = this.state.isLoaded !== o, a = this.state.frameNumber !== i;
|
|
1855
|
+
o && (r || a) && this._onViewportLoad(), a && this.setState({ frameNumber: i }), this.state.isLoaded = o;
|
|
1856
|
+
}
|
|
1857
|
+
_onViewportLoad() {
|
|
1858
|
+
const { tileset: t } = this.state, { onViewportLoad: e } = this.props;
|
|
1859
|
+
e && e(t.selectedTiles);
|
|
1860
|
+
}
|
|
1861
|
+
_onTileLoad(t) {
|
|
1862
|
+
this.props.onTileLoad(t), t.layers = null, this.setNeedsUpdate();
|
|
1863
|
+
}
|
|
1864
|
+
_onTileError(t, e) {
|
|
1865
|
+
this.props.onTileError(t), e.layers = null, this.setNeedsUpdate();
|
|
1866
|
+
}
|
|
1867
|
+
_onTileUnload(t) {
|
|
1868
|
+
this.props.onTileUnload(t);
|
|
1869
|
+
}
|
|
1870
|
+
// Methods for subclass to override
|
|
1871
|
+
getTileData(t) {
|
|
1872
|
+
const { data: e, getTileData: s, fetch: i } = this.props, { signal: o } = t;
|
|
1873
|
+
return t.url = typeof e == "string" || Array.isArray(e) ? Qn(e, t) : null, s ? s(t) : i && t.url ? i(t.url, { propName: "data", layer: this, signal: o }) : null;
|
|
1874
|
+
}
|
|
1875
|
+
renderSubLayers(t) {
|
|
1876
|
+
return this.props.renderSubLayers(t);
|
|
1877
|
+
}
|
|
1878
|
+
getSubLayerPropsByTile(t) {
|
|
1879
|
+
return null;
|
|
1880
|
+
}
|
|
1881
|
+
getPickingInfo(t) {
|
|
1882
|
+
const e = t.sourceLayer, s = e.props.tile, i = t.info;
|
|
1883
|
+
return i.picked && (i.tile = s), i.sourceTile = s, i.sourceTileSubLayer = e, i;
|
|
1884
|
+
}
|
|
1885
|
+
_updateAutoHighlight(t) {
|
|
1886
|
+
t.sourceTileSubLayer.updateAutoHighlight(t);
|
|
1887
|
+
}
|
|
1888
|
+
renderLayers() {
|
|
1889
|
+
return this.state.tileset.tiles.map((t) => {
|
|
1890
|
+
const e = this.getSubLayerPropsByTile(t);
|
|
1891
|
+
if (!(!t.isLoaded && !t.content)) if (t.layers)
|
|
1892
|
+
e && t.layers[0] && Object.keys(e).some((s) => t.layers[0].props[s] !== e[s]) && (t.layers = t.layers.map((s) => s.clone(e)));
|
|
1893
|
+
else {
|
|
1894
|
+
const s = this.renderSubLayers({
|
|
1895
|
+
...this.props,
|
|
1896
|
+
...this.getSubLayerProps({
|
|
1897
|
+
id: t.id,
|
|
1898
|
+
updateTriggers: this.props.updateTriggers
|
|
1899
|
+
}),
|
|
1900
|
+
data: t.content,
|
|
1901
|
+
_offset: 0,
|
|
1902
|
+
tile: t
|
|
1903
|
+
});
|
|
1904
|
+
t.layers = Ns(s, Boolean).map((i) => i.clone({
|
|
1905
|
+
tile: t,
|
|
1906
|
+
...e
|
|
1907
|
+
}));
|
|
1908
|
+
}
|
|
1909
|
+
return t.layers;
|
|
1910
|
+
});
|
|
1911
|
+
}
|
|
1912
|
+
filterSubLayer({ layer: t, cullRect: e }) {
|
|
1913
|
+
const { tile: s } = t.props, { modelMatrix: i } = this.props;
|
|
1914
|
+
return this.state.tileset.isTileVisible(s, e, i ? new G(i) : null);
|
|
1915
|
+
}
|
|
1916
|
+
}
|
|
1917
|
+
ct.defaultProps = mi;
|
|
1918
|
+
ct.layerName = "TileLayer";
|
|
1919
|
+
const mt = Math.PI / 180, tt = new Float32Array(16), re = new Float32Array(12);
|
|
1920
|
+
function ae(n, t, e) {
|
|
1921
|
+
const s = t[0] * mt, i = t[1] * mt, o = t[2] * mt, r = Math.sin(o), a = Math.sin(s), c = Math.sin(i), h = Math.cos(o), u = Math.cos(s), l = Math.cos(i), d = e[0], f = e[1], m = e[2];
|
|
1922
|
+
n[0] = d * l * u, n[1] = d * c * u, n[2] = d * -a, n[3] = f * (-c * h + l * a * r), n[4] = f * (l * h + c * a * r), n[5] = f * u * r, n[6] = m * (c * r + l * a * h), n[7] = m * (-l * r + c * a * h), n[8] = m * u * h;
|
|
1923
|
+
}
|
|
1924
|
+
function ce(n) {
|
|
1925
|
+
return n[0] = n[0], n[1] = n[1], n[2] = n[2], n[3] = n[4], n[4] = n[5], n[5] = n[6], n[6] = n[8], n[7] = n[9], n[8] = n[10], n[9] = n[12], n[10] = n[13], n[11] = n[14], n.subarray(0, 12);
|
|
1926
|
+
}
|
|
1927
|
+
const pi = {
|
|
1928
|
+
size: 12,
|
|
1929
|
+
accessor: ["getOrientation", "getScale", "getTranslation", "getTransformMatrix"],
|
|
1930
|
+
shaderAttributes: {
|
|
1931
|
+
instanceModelMatrixCol0: {
|
|
1932
|
+
size: 3,
|
|
1933
|
+
elementOffset: 0
|
|
1934
|
+
},
|
|
1935
|
+
instanceModelMatrixCol1: {
|
|
1936
|
+
size: 3,
|
|
1937
|
+
elementOffset: 3
|
|
1938
|
+
},
|
|
1939
|
+
instanceModelMatrixCol2: {
|
|
1940
|
+
size: 3,
|
|
1941
|
+
elementOffset: 6
|
|
1942
|
+
},
|
|
1943
|
+
instanceTranslation: {
|
|
1944
|
+
size: 3,
|
|
1945
|
+
elementOffset: 9
|
|
1946
|
+
}
|
|
1947
|
+
},
|
|
1948
|
+
update(n, { startRow: t, endRow: e }) {
|
|
1949
|
+
const { data: s, getOrientation: i, getScale: o, getTranslation: r, getTransformMatrix: a } = this.props, c = Array.isArray(a), h = c && a.length === 16, u = Array.isArray(o), l = Array.isArray(i), d = Array.isArray(r), f = h || !c && !!a(s[0]);
|
|
1950
|
+
f ? n.constant = h : n.constant = l && u && d;
|
|
1951
|
+
const m = n.value;
|
|
1952
|
+
if (n.constant) {
|
|
1953
|
+
let p;
|
|
1954
|
+
f ? (tt.set(a), p = ce(tt)) : (p = re, ae(p, i, o), p.set(r, 9)), n.value = new Float32Array(p);
|
|
1955
|
+
} else {
|
|
1956
|
+
let p = t * n.size;
|
|
1957
|
+
const { iterable: g, objectInfo: y } = be(s, t, e);
|
|
1958
|
+
for (const _ of g) {
|
|
1959
|
+
y.index++;
|
|
1960
|
+
let x;
|
|
1961
|
+
if (f)
|
|
1962
|
+
tt.set(h ? a : a(_, y)), x = ce(tt);
|
|
1963
|
+
else {
|
|
1964
|
+
x = re;
|
|
1965
|
+
const w = l ? i : i(_, y), T = u ? o : o(_, y);
|
|
1966
|
+
ae(x, w, T), x.set(d ? r : r(_, y), 9);
|
|
1967
|
+
}
|
|
1968
|
+
m[p++] = x[0], m[p++] = x[1], m[p++] = x[2], m[p++] = x[3], m[p++] = x[4], m[p++] = x[5], m[p++] = x[6], m[p++] = x[7], m[p++] = x[8], m[p++] = x[9], m[p++] = x[10], m[p++] = x[11];
|
|
1969
|
+
}
|
|
1970
|
+
}
|
|
1971
|
+
}
|
|
1972
|
+
};
|
|
1973
|
+
function gi(n, t) {
|
|
1974
|
+
return t === dt.CARTESIAN || t === dt.METER_OFFSETS || t === dt.DEFAULT && !n.isGeospatial;
|
|
1975
|
+
}
|
|
1976
|
+
const le = `uniform simpleMeshUniforms {
|
|
1977
|
+
float sizeScale;
|
|
1978
|
+
bool composeModelMatrix;
|
|
1979
|
+
bool hasTexture;
|
|
1980
|
+
bool flatShading;
|
|
1981
|
+
} simpleMesh;
|
|
1982
|
+
`, yi = {
|
|
1983
|
+
name: "simpleMesh",
|
|
1984
|
+
vs: le,
|
|
1985
|
+
fs: le,
|
|
1986
|
+
uniformTypes: {
|
|
1987
|
+
sizeScale: "f32",
|
|
1988
|
+
composeModelMatrix: "f32",
|
|
1989
|
+
hasTexture: "f32",
|
|
1990
|
+
flatShading: "f32"
|
|
1991
|
+
}
|
|
1992
|
+
}, _i = `#version 300 es
|
|
1993
|
+
#define SHADER_NAME simple-mesh-layer-vs
|
|
1994
|
+
in vec3 positions;
|
|
1995
|
+
in vec3 normals;
|
|
1996
|
+
in vec3 colors;
|
|
1997
|
+
in vec2 texCoords;
|
|
1998
|
+
in vec3 instancePositions;
|
|
1999
|
+
in vec3 instancePositions64Low;
|
|
2000
|
+
in vec4 instanceColors;
|
|
2001
|
+
in vec3 instancePickingColors;
|
|
2002
|
+
in vec3 instanceModelMatrixCol0;
|
|
2003
|
+
in vec3 instanceModelMatrixCol1;
|
|
2004
|
+
in vec3 instanceModelMatrixCol2;
|
|
2005
|
+
in vec3 instanceTranslation;
|
|
2006
|
+
out vec2 vTexCoord;
|
|
2007
|
+
out vec3 cameraPosition;
|
|
2008
|
+
out vec3 normals_commonspace;
|
|
2009
|
+
out vec4 position_commonspace;
|
|
2010
|
+
out vec4 vColor;
|
|
2011
|
+
void main(void) {
|
|
2012
|
+
geometry.worldPosition = instancePositions;
|
|
2013
|
+
geometry.uv = texCoords;
|
|
2014
|
+
geometry.pickingColor = instancePickingColors;
|
|
2015
|
+
vTexCoord = texCoords;
|
|
2016
|
+
cameraPosition = project.cameraPosition;
|
|
2017
|
+
vColor = vec4(colors * instanceColors.rgb, instanceColors.a);
|
|
2018
|
+
mat3 instanceModelMatrix = mat3(instanceModelMatrixCol0, instanceModelMatrixCol1, instanceModelMatrixCol2);
|
|
2019
|
+
vec3 pos = (instanceModelMatrix * positions) * simpleMesh.sizeScale + instanceTranslation;
|
|
2020
|
+
if (simpleMesh.composeModelMatrix) {
|
|
2021
|
+
DECKGL_FILTER_SIZE(pos, geometry);
|
|
2022
|
+
normals_commonspace = project_normal(instanceModelMatrix * normals);
|
|
2023
|
+
geometry.worldPosition += pos;
|
|
2024
|
+
gl_Position = project_position_to_clipspace(pos + instancePositions, instancePositions64Low, vec3(0.0), position_commonspace);
|
|
2025
|
+
geometry.position = position_commonspace;
|
|
2026
|
+
}
|
|
2027
|
+
else {
|
|
2028
|
+
pos = project_size(pos);
|
|
2029
|
+
DECKGL_FILTER_SIZE(pos, geometry);
|
|
2030
|
+
gl_Position = project_position_to_clipspace(instancePositions, instancePositions64Low, pos, position_commonspace);
|
|
2031
|
+
geometry.position = position_commonspace;
|
|
2032
|
+
normals_commonspace = project_normal(instanceModelMatrix * normals);
|
|
2033
|
+
}
|
|
2034
|
+
geometry.normal = normals_commonspace;
|
|
2035
|
+
DECKGL_FILTER_GL_POSITION(gl_Position, geometry);
|
|
2036
|
+
DECKGL_FILTER_COLOR(vColor, geometry);
|
|
2037
|
+
}
|
|
2038
|
+
`, xi = `#version 300 es
|
|
2039
|
+
#define SHADER_NAME simple-mesh-layer-fs
|
|
2040
|
+
precision highp float;
|
|
2041
|
+
uniform sampler2D sampler;
|
|
2042
|
+
in vec2 vTexCoord;
|
|
2043
|
+
in vec3 cameraPosition;
|
|
2044
|
+
in vec3 normals_commonspace;
|
|
2045
|
+
in vec4 position_commonspace;
|
|
2046
|
+
in vec4 vColor;
|
|
2047
|
+
out vec4 fragColor;
|
|
2048
|
+
void main(void) {
|
|
2049
|
+
geometry.uv = vTexCoord;
|
|
2050
|
+
vec3 normal;
|
|
2051
|
+
if (simpleMesh.flatShading) {
|
|
2052
|
+
normal = normalize(cross(dFdx(position_commonspace.xyz), dFdy(position_commonspace.xyz)));
|
|
2053
|
+
} else {
|
|
2054
|
+
normal = normals_commonspace;
|
|
2055
|
+
}
|
|
2056
|
+
vec4 color = simpleMesh.hasTexture ? texture(sampler, vTexCoord) : vColor;
|
|
2057
|
+
DECKGL_FILTER_COLOR(color, geometry);
|
|
2058
|
+
vec3 lightColor = lighting_getLightColor(color.rgb, cameraPosition, position_commonspace.xyz, normal);
|
|
2059
|
+
fragColor = vec4(lightColor, color.a * layer.opacity);
|
|
2060
|
+
}
|
|
2061
|
+
`;
|
|
2062
|
+
function pt(n) {
|
|
2063
|
+
const t = n.positions || n.POSITION;
|
|
2064
|
+
Te.assert(t, 'no "postions" or "POSITION" attribute in mesh');
|
|
2065
|
+
const e = t.value.length / t.size;
|
|
2066
|
+
let s = n.COLOR_0 || n.colors;
|
|
2067
|
+
s || (s = { size: 3, value: new Float32Array(e * 3).fill(1) });
|
|
2068
|
+
let i = n.NORMAL || n.normals;
|
|
2069
|
+
i || (i = { size: 3, value: new Float32Array(e * 3).fill(0) });
|
|
2070
|
+
let o = n.TEXCOORD_0 || n.texCoords;
|
|
2071
|
+
return o || (o = { size: 2, value: new Float32Array(e * 2).fill(0) }), {
|
|
2072
|
+
positions: t,
|
|
2073
|
+
colors: s,
|
|
2074
|
+
normals: i,
|
|
2075
|
+
texCoords: o
|
|
2076
|
+
};
|
|
2077
|
+
}
|
|
2078
|
+
function he(n) {
|
|
2079
|
+
return n instanceof ft ? (n.attributes = pt(n.attributes), n) : n.attributes ? new ft({
|
|
2080
|
+
...n,
|
|
2081
|
+
topology: "triangle-list",
|
|
2082
|
+
attributes: pt(n.attributes)
|
|
2083
|
+
}) : new ft({
|
|
2084
|
+
topology: "triangle-list",
|
|
2085
|
+
attributes: pt(n)
|
|
2086
|
+
});
|
|
2087
|
+
}
|
|
2088
|
+
const Mi = [0, 0, 0, 255], wi = {
|
|
2089
|
+
mesh: { type: "object", value: null, async: !0 },
|
|
2090
|
+
texture: { type: "image", value: null, async: !0 },
|
|
2091
|
+
sizeScale: { type: "number", value: 1, min: 0 },
|
|
2092
|
+
// _instanced is a hack to use world position instead of meter offsets in mesh
|
|
2093
|
+
// TODO - formalize API
|
|
2094
|
+
_instanced: !0,
|
|
2095
|
+
// NOTE(Tarek): Quick and dirty wireframe. Just draws
|
|
2096
|
+
// the same mesh with LINE_STRIPS. Won't follow edges
|
|
2097
|
+
// of the original mesh.
|
|
2098
|
+
wireframe: !1,
|
|
2099
|
+
// Optional material for 'lighting' shader module
|
|
2100
|
+
material: !0,
|
|
2101
|
+
getPosition: { type: "accessor", value: (n) => n.position },
|
|
2102
|
+
getColor: { type: "accessor", value: Mi },
|
|
2103
|
+
// yaw, pitch and roll are in degrees
|
|
2104
|
+
// https://en.wikipedia.org/wiki/Euler_angles
|
|
2105
|
+
// [pitch, yaw, roll]
|
|
2106
|
+
getOrientation: { type: "accessor", value: [0, 0, 0] },
|
|
2107
|
+
getScale: { type: "accessor", value: [1, 1, 1] },
|
|
2108
|
+
getTranslation: { type: "accessor", value: [0, 0, 0] },
|
|
2109
|
+
// 4x4 matrix
|
|
2110
|
+
getTransformMatrix: { type: "accessor", value: [] },
|
|
2111
|
+
textureParameters: { type: "object", ignore: !0, value: null }
|
|
2112
|
+
};
|
|
2113
|
+
class rt extends qs {
|
|
2114
|
+
getShaders() {
|
|
2115
|
+
return super.getShaders({
|
|
2116
|
+
vs: _i,
|
|
2117
|
+
fs: xi,
|
|
2118
|
+
modules: [Bs, Re, Gs, yi]
|
|
2119
|
+
});
|
|
2120
|
+
}
|
|
2121
|
+
getBounds() {
|
|
2122
|
+
if (this.props._instanced)
|
|
2123
|
+
return super.getBounds();
|
|
2124
|
+
let t = this.state.positionBounds;
|
|
2125
|
+
if (t)
|
|
2126
|
+
return t;
|
|
2127
|
+
const { mesh: e } = this.props;
|
|
2128
|
+
if (!e)
|
|
2129
|
+
return null;
|
|
2130
|
+
if (t = e.header?.boundingBox, !t) {
|
|
2131
|
+
const { attributes: s } = he(e);
|
|
2132
|
+
s.POSITION = s.POSITION || s.positions, t = Ks(s);
|
|
2133
|
+
}
|
|
2134
|
+
return this.state.positionBounds = t, t;
|
|
2135
|
+
}
|
|
2136
|
+
initializeState() {
|
|
2137
|
+
this.getAttributeManager().addInstanced({
|
|
2138
|
+
instancePositions: {
|
|
2139
|
+
transition: !0,
|
|
2140
|
+
type: "float64",
|
|
2141
|
+
fp64: this.use64bitPositions(),
|
|
2142
|
+
size: 3,
|
|
2143
|
+
accessor: "getPosition"
|
|
2144
|
+
},
|
|
2145
|
+
instanceColors: {
|
|
2146
|
+
type: "unorm8",
|
|
2147
|
+
transition: !0,
|
|
2148
|
+
size: this.props.colorFormat.length,
|
|
2149
|
+
accessor: "getColor",
|
|
2150
|
+
defaultValue: [0, 0, 0, 255]
|
|
2151
|
+
},
|
|
2152
|
+
instanceModelMatrix: pi
|
|
2153
|
+
}), this.setState({
|
|
2154
|
+
// Avoid luma.gl's missing uniform warning
|
|
2155
|
+
// TODO - add feature to luma.gl to specify ignored uniforms?
|
|
2156
|
+
emptyTexture: this.context.device.createTexture({
|
|
2157
|
+
data: new Uint8Array(4),
|
|
2158
|
+
width: 1,
|
|
2159
|
+
height: 1
|
|
2160
|
+
})
|
|
2161
|
+
});
|
|
2162
|
+
}
|
|
2163
|
+
updateState(t) {
|
|
2164
|
+
super.updateState(t);
|
|
2165
|
+
const { props: e, oldProps: s, changeFlags: i } = t;
|
|
2166
|
+
if (e.mesh !== s.mesh || i.extensionsChanged) {
|
|
2167
|
+
if (this.state.positionBounds = null, this.state.model?.destroy(), e.mesh) {
|
|
2168
|
+
this.state.model = this.getModel(e.mesh);
|
|
2169
|
+
const o = e.mesh.attributes || e.mesh;
|
|
2170
|
+
this.setState({
|
|
2171
|
+
hasNormals: !!(o.NORMAL || o.normals)
|
|
2172
|
+
});
|
|
2173
|
+
}
|
|
2174
|
+
this.getAttributeManager().invalidateAll();
|
|
2175
|
+
}
|
|
2176
|
+
e.texture !== s.texture && e.texture instanceof Ds && this.setTexture(e.texture), this.state.model && this.state.model.setTopology(this.props.wireframe ? "line-strip" : "triangle-list");
|
|
2177
|
+
}
|
|
2178
|
+
finalizeState(t) {
|
|
2179
|
+
super.finalizeState(t), this.state.emptyTexture.delete();
|
|
2180
|
+
}
|
|
2181
|
+
draw({ uniforms: t }) {
|
|
2182
|
+
const { model: e } = this.state;
|
|
2183
|
+
if (!e)
|
|
2184
|
+
return;
|
|
2185
|
+
const { viewport: s, renderPass: i } = this.context, { sizeScale: o, coordinateSystem: r, _instanced: a } = this.props, c = {
|
|
2186
|
+
sizeScale: o,
|
|
2187
|
+
composeModelMatrix: !a || gi(s, r),
|
|
2188
|
+
flatShading: !this.state.hasNormals
|
|
2189
|
+
};
|
|
2190
|
+
e.shaderInputs.setProps({ simpleMesh: c }), e.draw(i);
|
|
2191
|
+
}
|
|
2192
|
+
get isLoaded() {
|
|
2193
|
+
return !!(this.state?.model && super.isLoaded);
|
|
2194
|
+
}
|
|
2195
|
+
getModel(t) {
|
|
2196
|
+
const e = new Us(this.context.device, {
|
|
2197
|
+
...this.getShaders(),
|
|
2198
|
+
id: this.props.id,
|
|
2199
|
+
bufferLayout: this.getAttributeManager().getBufferLayouts(),
|
|
2200
|
+
geometry: he(t),
|
|
2201
|
+
isInstanced: !0
|
|
2202
|
+
}), { texture: s } = this.props, { emptyTexture: i } = this.state, o = {
|
|
2203
|
+
sampler: s || i,
|
|
2204
|
+
hasTexture: !!s
|
|
2205
|
+
};
|
|
2206
|
+
return e.shaderInputs.setProps({ simpleMesh: o }), e;
|
|
2207
|
+
}
|
|
2208
|
+
setTexture(t) {
|
|
2209
|
+
const { emptyTexture: e, model: s } = this.state;
|
|
2210
|
+
if (s) {
|
|
2211
|
+
const i = {
|
|
2212
|
+
sampler: t || e,
|
|
2213
|
+
hasTexture: !!t
|
|
2214
|
+
};
|
|
2215
|
+
s.shaderInputs.setProps({ simpleMesh: i });
|
|
2216
|
+
}
|
|
2217
|
+
}
|
|
2218
|
+
}
|
|
2219
|
+
rt.defaultProps = wi;
|
|
2220
|
+
rt.layerName = "SimpleMeshLayer";
|
|
2221
|
+
const Ti = [
|
|
2222
|
+
[1 / 3, 1 / 3, 1 / 3],
|
|
2223
|
+
// centroid
|
|
2224
|
+
[0.5, 0.5, 0],
|
|
2225
|
+
// edge 0–1
|
|
2226
|
+
[0.5, 0, 0.5],
|
|
2227
|
+
// edge 0–2
|
|
2228
|
+
[0, 0.5, 0.5]
|
|
2229
|
+
// edge 1–2
|
|
2230
|
+
], bi = 0.125;
|
|
2231
|
+
class Si {
|
|
2232
|
+
reprojectors;
|
|
2233
|
+
width;
|
|
2234
|
+
height;
|
|
2235
|
+
/**
|
|
2236
|
+
* UV vertex coordinates (x, y), i.e.
|
|
2237
|
+
* [x0, y0, x1, y1, ...]
|
|
2238
|
+
*
|
|
2239
|
+
* These coordinates are floats that range from [0, 1] in both X and Y.
|
|
2240
|
+
*/
|
|
2241
|
+
uvs;
|
|
2242
|
+
/**
|
|
2243
|
+
* XY Positions in output CRS, computed via exact forward reprojection.
|
|
2244
|
+
*/
|
|
2245
|
+
exactOutputPositions;
|
|
2246
|
+
/**
|
|
2247
|
+
* triangle vertex indices
|
|
2248
|
+
*/
|
|
2249
|
+
triangles;
|
|
2250
|
+
_halfedges;
|
|
2251
|
+
/**
|
|
2252
|
+
* The UV texture coordinates of candidates found from
|
|
2253
|
+
* `findReprojectionCandidate`.
|
|
2254
|
+
*
|
|
2255
|
+
* Maybe in the future we'll want to store the barycentric coordinates instead
|
|
2256
|
+
* of just the uv coordinates?
|
|
2257
|
+
*/
|
|
2258
|
+
_candidatesUV;
|
|
2259
|
+
_queueIndices;
|
|
2260
|
+
_queue;
|
|
2261
|
+
_errors;
|
|
2262
|
+
_pending;
|
|
2263
|
+
_pendingLen;
|
|
2264
|
+
constructor(t, e, s = e) {
|
|
2265
|
+
this.reprojectors = t, this.width = e, this.height = s, this.uvs = [], this.exactOutputPositions = [], this.triangles = [], this._halfedges = [], this._candidatesUV = [], this._queueIndices = [], this._queue = [], this._errors = [], this._pending = [], this._pendingLen = 0;
|
|
2266
|
+
const i = 1, o = 1, r = this._addPoint(0, 0), a = this._addPoint(i, 0), c = this._addPoint(0, o), h = this._addPoint(i, o), u = this._addTriangle(h, r, c, -1, -1, -1);
|
|
2267
|
+
this._addTriangle(r, h, a, u, -1, -1), this._flush();
|
|
2268
|
+
}
|
|
2269
|
+
// refine the mesh until its maximum error gets below the given one
|
|
2270
|
+
run(t = bi) {
|
|
2271
|
+
if (t <= 0)
|
|
2272
|
+
throw new Error("maxError must be positive");
|
|
2273
|
+
for (; this.getMaxError() > t; )
|
|
2274
|
+
this.refine();
|
|
2275
|
+
}
|
|
2276
|
+
// refine the mesh with a single point
|
|
2277
|
+
refine() {
|
|
2278
|
+
this._step(), this._flush();
|
|
2279
|
+
}
|
|
2280
|
+
// max error of the current mesh
|
|
2281
|
+
getMaxError() {
|
|
2282
|
+
return this._errors[0];
|
|
2283
|
+
}
|
|
2284
|
+
// rasterize and queue all triangles that got added or updated in _step
|
|
2285
|
+
_flush() {
|
|
2286
|
+
for (let t = 0; t < this._pendingLen; t++) {
|
|
2287
|
+
const e = this._pending[t];
|
|
2288
|
+
this._findReprojectionCandidate(e);
|
|
2289
|
+
}
|
|
2290
|
+
this._pendingLen = 0;
|
|
2291
|
+
}
|
|
2292
|
+
/**
|
|
2293
|
+
* Conversion of upstream's `_findCandidate` for reprojection error handling.
|
|
2294
|
+
*
|
|
2295
|
+
* @param {number} t The index (into `this.triangles`) of the pending triangle to process.
|
|
2296
|
+
*
|
|
2297
|
+
* @return {void} Doesn't return; instead modifies internal state.
|
|
2298
|
+
*/
|
|
2299
|
+
_findReprojectionCandidate(t) {
|
|
2300
|
+
const e = 2 * this.triangles[t * 3 + 0], s = 2 * this.triangles[t * 3 + 1], i = 2 * this.triangles[t * 3 + 2], o = this.uvs[e], r = this.uvs[e + 1], a = this.uvs[s], c = this.uvs[s + 1], h = this.uvs[i], u = this.uvs[i + 1], l = this.exactOutputPositions[e], d = this.exactOutputPositions[e + 1], f = this.exactOutputPositions[s], m = this.exactOutputPositions[s + 1], p = this.exactOutputPositions[i], g = this.exactOutputPositions[i + 1];
|
|
2301
|
+
let y = 0, _ = 0, x = 0;
|
|
2302
|
+
for (const w of Ti) {
|
|
2303
|
+
const T = et(o, a, h, w[0], w[1], w[2]), S = et(r, c, u, w[0], w[1], w[2]), L = et(l, f, p, w[0], w[1], w[2]), I = et(d, m, g, w[0], w[1], w[2]), b = T * (this.width - 1), C = S * (this.height - 1), B = this.reprojectors.inverseReproject(L, I), k = this.reprojectors.inverseTransform(B[0], B[1]), lt = b - k[0], ht = C - k[1], j = Math.hypot(lt, ht);
|
|
2304
|
+
j > y && (y = j, _ = T, x = S);
|
|
2305
|
+
}
|
|
2306
|
+
(_ === o && x === r || _ === a && x === c || _ === h && x === u) && (y = 0), this._candidatesUV[2 * t] = _, this._candidatesUV[2 * t + 1] = x, this._queuePush(t, y);
|
|
2307
|
+
}
|
|
2308
|
+
// process the next triangle in the queue, splitting it with a new point
|
|
2309
|
+
_step() {
|
|
2310
|
+
const t = this._queuePop(), e = t * 3 + 0, s = t * 3 + 1, i = t * 3 + 2, o = this.triangles[e], r = this.triangles[s], a = this.triangles[i], c = this.uvs[2 * o], h = this.uvs[2 * o + 1], u = this.uvs[2 * r], l = this.uvs[2 * r + 1], d = this.uvs[2 * a], f = this.uvs[2 * a + 1], m = this._candidatesUV[2 * t], p = this._candidatesUV[2 * t + 1], g = this._addPoint(m, p);
|
|
2311
|
+
if (gt(c, h, u, l, m, p) === 0)
|
|
2312
|
+
this._handleCollinear(g, e);
|
|
2313
|
+
else if (gt(u, l, d, f, m, p) === 0)
|
|
2314
|
+
this._handleCollinear(g, s);
|
|
2315
|
+
else if (gt(d, f, c, h, m, p) === 0)
|
|
2316
|
+
this._handleCollinear(g, i);
|
|
2317
|
+
else {
|
|
2318
|
+
const y = this._halfedges[e], _ = this._halfedges[s], x = this._halfedges[i], w = this._addTriangle(o, r, g, y, -1, -1, e), T = this._addTriangle(r, a, g, _, -1, w + 1), S = this._addTriangle(a, o, g, x, w + 2, T + 1);
|
|
2319
|
+
this._legalize(w), this._legalize(T), this._legalize(S);
|
|
2320
|
+
}
|
|
2321
|
+
}
|
|
2322
|
+
// add coordinates for a new vertex
|
|
2323
|
+
_addPoint(t, e) {
|
|
2324
|
+
const s = this.uvs.length >> 1;
|
|
2325
|
+
this.uvs.push(t, e);
|
|
2326
|
+
const i = t * (this.width - 1), o = e * (this.height - 1), r = this.reprojectors.forwardTransform(i, o), a = this.reprojectors.forwardReproject(r[0], r[1]);
|
|
2327
|
+
return this.exactOutputPositions.push(a[0], a[1]), s;
|
|
2328
|
+
}
|
|
2329
|
+
// add or update a triangle in the mesh
|
|
2330
|
+
_addTriangle(t, e, s, i, o, r, a = this.triangles.length) {
|
|
2331
|
+
const c = a / 3;
|
|
2332
|
+
return this.triangles[a + 0] = t, this.triangles[a + 1] = e, this.triangles[a + 2] = s, this._halfedges[a + 0] = i, this._halfedges[a + 1] = o, this._halfedges[a + 2] = r, i >= 0 && (this._halfedges[i] = a + 0), o >= 0 && (this._halfedges[o] = a + 1), r >= 0 && (this._halfedges[r] = a + 2), this._candidatesUV[2 * c + 0] = 0, this._candidatesUV[2 * c + 1] = 0, this._queueIndices[c] = -1, this._pending[this._pendingLen++] = c, a;
|
|
2333
|
+
}
|
|
2334
|
+
_legalize(t) {
|
|
2335
|
+
const e = this._halfedges[t];
|
|
2336
|
+
if (e < 0)
|
|
2337
|
+
return;
|
|
2338
|
+
const s = t - t % 3, i = e - e % 3, o = s + (t + 1) % 3, r = s + (t + 2) % 3, a = i + (e + 2) % 3, c = i + (e + 1) % 3, h = this.triangles[r], u = this.triangles[t], l = this.triangles[o], d = this.triangles[a], f = this.uvs;
|
|
2339
|
+
if (!Ci(f[2 * h], f[2 * h + 1], f[2 * u], f[2 * u + 1], f[2 * l], f[2 * l + 1], f[2 * d], f[2 * d + 1]))
|
|
2340
|
+
return;
|
|
2341
|
+
const m = this._halfedges[o], p = this._halfedges[r], g = this._halfedges[a], y = this._halfedges[c];
|
|
2342
|
+
this._queueRemove(s / 3), this._queueRemove(i / 3);
|
|
2343
|
+
const _ = this._addTriangle(h, d, l, -1, g, m, s), x = this._addTriangle(d, h, u, _, p, y, i);
|
|
2344
|
+
this._legalize(_ + 1), this._legalize(x + 2);
|
|
2345
|
+
}
|
|
2346
|
+
// handle a case where new vertex is on the edge of a triangle
|
|
2347
|
+
_handleCollinear(t, e) {
|
|
2348
|
+
const s = e - e % 3, i = s + (e + 1) % 3, o = s + (e + 2) % 3, r = this.triangles[o], a = this.triangles[e], c = this.triangles[i], h = this._halfedges[i], u = this._halfedges[o], l = this._halfedges[e];
|
|
2349
|
+
if (l < 0) {
|
|
2350
|
+
const S = this._addTriangle(t, r, a, -1, u, -1, s), L = this._addTriangle(r, t, c, S, -1, h);
|
|
2351
|
+
this._legalize(S + 1), this._legalize(L + 2);
|
|
2352
|
+
return;
|
|
2353
|
+
}
|
|
2354
|
+
const d = l - l % 3, f = d + (l + 2) % 3, m = d + (l + 1) % 3, p = this.triangles[f], g = this._halfedges[f], y = this._halfedges[m];
|
|
2355
|
+
this._queueRemove(d / 3);
|
|
2356
|
+
const _ = this._addTriangle(r, a, t, u, -1, -1, s), x = this._addTriangle(a, p, t, y, -1, _ + 1, d), w = this._addTriangle(p, c, t, g, -1, x + 1), T = this._addTriangle(c, r, t, h, _ + 2, w + 1);
|
|
2357
|
+
this._legalize(_), this._legalize(x), this._legalize(w), this._legalize(T);
|
|
2358
|
+
}
|
|
2359
|
+
// priority queue methods
|
|
2360
|
+
_queuePush(t, e) {
|
|
2361
|
+
const s = this._queue.length;
|
|
2362
|
+
this._queueIndices[t] = s, this._queue.push(t), this._errors.push(e), this._queueUp(s);
|
|
2363
|
+
}
|
|
2364
|
+
_queuePop() {
|
|
2365
|
+
const t = this._queue.length - 1;
|
|
2366
|
+
return this._queueSwap(0, t), this._queueDown(0, t), this._queuePopBack();
|
|
2367
|
+
}
|
|
2368
|
+
_queuePopBack() {
|
|
2369
|
+
const t = this._queue.pop();
|
|
2370
|
+
return this._errors.pop(), this._queueIndices[t] = -1, t;
|
|
2371
|
+
}
|
|
2372
|
+
_queueRemove(t) {
|
|
2373
|
+
const e = this._queueIndices[t];
|
|
2374
|
+
if (e < 0) {
|
|
2375
|
+
const i = this._pending.indexOf(t);
|
|
2376
|
+
if (i !== -1)
|
|
2377
|
+
this._pending[i] = this._pending[--this._pendingLen];
|
|
2378
|
+
else
|
|
2379
|
+
throw new Error("Broken triangulation (something went wrong).");
|
|
2380
|
+
return;
|
|
2381
|
+
}
|
|
2382
|
+
const s = this._queue.length - 1;
|
|
2383
|
+
s !== e && (this._queueSwap(e, s), this._queueDown(e, s) || this._queueUp(e)), this._queuePopBack();
|
|
2384
|
+
}
|
|
2385
|
+
_queueLess(t, e) {
|
|
2386
|
+
return this._errors[t] > this._errors[e];
|
|
2387
|
+
}
|
|
2388
|
+
_queueSwap(t, e) {
|
|
2389
|
+
const s = this._queue[t], i = this._queue[e];
|
|
2390
|
+
this._queue[t] = i, this._queue[e] = s, this._queueIndices[s] = e, this._queueIndices[i] = t;
|
|
2391
|
+
const o = this._errors[t];
|
|
2392
|
+
this._errors[t] = this._errors[e], this._errors[e] = o;
|
|
2393
|
+
}
|
|
2394
|
+
_queueUp(t) {
|
|
2395
|
+
let e = t;
|
|
2396
|
+
for (; ; ) {
|
|
2397
|
+
const s = e - 1 >> 1;
|
|
2398
|
+
if (s === e || !this._queueLess(e, s))
|
|
2399
|
+
break;
|
|
2400
|
+
this._queueSwap(s, e), e = s;
|
|
2401
|
+
}
|
|
2402
|
+
}
|
|
2403
|
+
_queueDown(t, e) {
|
|
2404
|
+
let s = t;
|
|
2405
|
+
for (; ; ) {
|
|
2406
|
+
const i = 2 * s + 1;
|
|
2407
|
+
if (i >= e || i < 0)
|
|
2408
|
+
break;
|
|
2409
|
+
const o = i + 1;
|
|
2410
|
+
let r = i;
|
|
2411
|
+
if (o < e && this._queueLess(o, i) && (r = o), !this._queueLess(r, s))
|
|
2412
|
+
break;
|
|
2413
|
+
this._queueSwap(s, r), s = r;
|
|
2414
|
+
}
|
|
2415
|
+
return s > t;
|
|
2416
|
+
}
|
|
2417
|
+
}
|
|
2418
|
+
function gt(n, t, e, s, i, o) {
|
|
2419
|
+
return (e - i) * (t - o) - (s - o) * (n - i);
|
|
2420
|
+
}
|
|
2421
|
+
function Ci(n, t, e, s, i, o, r, a) {
|
|
2422
|
+
const c = n - r, h = t - a, u = e - r, l = s - a, d = i - r, f = o - a, m = c * c + h * h, p = u * u + l * l, g = d * d + f * f;
|
|
2423
|
+
return c * (l * g - p * f) - h * (u * g - p * d) + m * (u * f - l * d) < 0;
|
|
2424
|
+
}
|
|
2425
|
+
function et(n, t, e, s, i, o) {
|
|
2426
|
+
return s * n + i * t + o * e;
|
|
2427
|
+
}
|
|
2428
|
+
const Li = (
|
|
2429
|
+
/* glsl */
|
|
2430
|
+
`#version 300 es
|
|
2431
|
+
#define SHADER_NAME simple-mesh-layer-fs
|
|
2432
|
+
|
|
2433
|
+
precision highp float;
|
|
2434
|
+
|
|
2435
|
+
in vec2 vTexCoord;
|
|
2436
|
+
in vec3 cameraPosition;
|
|
2437
|
+
in vec3 normals_commonspace;
|
|
2438
|
+
in vec4 position_commonspace;
|
|
2439
|
+
in vec4 vColor;
|
|
2440
|
+
|
|
2441
|
+
out vec4 fragColor;
|
|
2442
|
+
|
|
2443
|
+
void main(void) {
|
|
2444
|
+
geometry.uv = vTexCoord;
|
|
2445
|
+
|
|
2446
|
+
vec3 normal;
|
|
2447
|
+
if (simpleMesh.flatShading) {
|
|
2448
|
+
|
|
2449
|
+
normal = normalize(cross(dFdx(position_commonspace.xyz), dFdy(position_commonspace.xyz)));
|
|
2450
|
+
} else {
|
|
2451
|
+
normal = normals_commonspace;
|
|
2452
|
+
}
|
|
2453
|
+
|
|
2454
|
+
// We initialize color here before passing into DECKGL_FILTER_COLOR
|
|
2455
|
+
vec4 color;
|
|
2456
|
+
DECKGL_FILTER_COLOR(color, geometry);
|
|
2457
|
+
|
|
2458
|
+
vec3 lightColor = lighting_getLightColor(color.rgb, cameraPosition, position_commonspace.xyz, normal);
|
|
2459
|
+
fragColor = vec4(lightColor, color.a * layer.opacity);
|
|
2460
|
+
}
|
|
2461
|
+
`
|
|
2462
|
+
);
|
|
2463
|
+
class Ei extends rt {
|
|
2464
|
+
static layerName = "mesh-texture-layer";
|
|
2465
|
+
static defaultProps = rt.defaultProps;
|
|
2466
|
+
getShaders() {
|
|
2467
|
+
const t = super.getShaders(), e = t.modules;
|
|
2468
|
+
for (const s of this.props.renderPipeline)
|
|
2469
|
+
e.push(s.module);
|
|
2470
|
+
return {
|
|
2471
|
+
...t,
|
|
2472
|
+
// Override upstream's fragment shader with our copy with modified
|
|
2473
|
+
// injection points
|
|
2474
|
+
fs: Li,
|
|
2475
|
+
modules: e
|
|
2476
|
+
};
|
|
2477
|
+
}
|
|
2478
|
+
draw(t) {
|
|
2479
|
+
const e = {};
|
|
2480
|
+
for (const s of this.props.renderPipeline)
|
|
2481
|
+
e[s.module.name] = s.props || {};
|
|
2482
|
+
for (const s of super.getModels())
|
|
2483
|
+
s.shaderInputs.setProps(e);
|
|
2484
|
+
super.draw(t);
|
|
2485
|
+
}
|
|
2486
|
+
}
|
|
2487
|
+
const Pi = 0.125, ue = [
|
|
2488
|
+
[252, 73, 163],
|
|
2489
|
+
// pink
|
|
2490
|
+
[255, 51, 204],
|
|
2491
|
+
// magenta-pink
|
|
2492
|
+
[204, 102, 255],
|
|
2493
|
+
// purple-ish
|
|
2494
|
+
[153, 51, 255],
|
|
2495
|
+
// deep purple
|
|
2496
|
+
[102, 204, 255],
|
|
2497
|
+
// sky blue
|
|
2498
|
+
[51, 153, 255],
|
|
2499
|
+
// clear blue
|
|
2500
|
+
[102, 255, 204],
|
|
2501
|
+
// teal
|
|
2502
|
+
[51, 255, 170],
|
|
2503
|
+
// aqua-teal
|
|
2504
|
+
[0, 255, 0],
|
|
2505
|
+
// lime green
|
|
2506
|
+
[51, 204, 51],
|
|
2507
|
+
// stronger green
|
|
2508
|
+
[255, 204, 102],
|
|
2509
|
+
// light orange
|
|
2510
|
+
[255, 179, 71],
|
|
2511
|
+
// golden-orange
|
|
2512
|
+
[255, 102, 102],
|
|
2513
|
+
// salmon
|
|
2514
|
+
[255, 80, 80],
|
|
2515
|
+
// red-salmon
|
|
2516
|
+
[255, 0, 0],
|
|
2517
|
+
// red
|
|
2518
|
+
[204, 0, 0],
|
|
2519
|
+
// crimson
|
|
2520
|
+
[255, 128, 0],
|
|
2521
|
+
// orange
|
|
2522
|
+
[255, 153, 51],
|
|
2523
|
+
// bright orange
|
|
2524
|
+
[255, 255, 102],
|
|
2525
|
+
// yellow
|
|
2526
|
+
[255, 255, 51],
|
|
2527
|
+
// lemon
|
|
2528
|
+
[0, 255, 255],
|
|
2529
|
+
// turquoise
|
|
2530
|
+
[0, 204, 255]
|
|
2531
|
+
// cyan
|
|
2532
|
+
], Ri = {
|
|
2533
|
+
debug: !1,
|
|
2534
|
+
debugOpacity: 0.5
|
|
2535
|
+
};
|
|
2536
|
+
class Ne extends V {
|
|
2537
|
+
static layerName = "RasterLayer";
|
|
2538
|
+
static defaultProps = Ri;
|
|
2539
|
+
initializeState() {
|
|
2540
|
+
this.setState({});
|
|
2541
|
+
}
|
|
2542
|
+
updateState(t) {
|
|
2543
|
+
super.updateState(t);
|
|
2544
|
+
const { props: e, oldProps: s, changeFlags: i } = t;
|
|
2545
|
+
(i.dataChanged || e.width !== s.width || e.height !== s.height || e.reprojectionFns !== s.reprojectionFns || e.maxError !== s.maxError) && this._generateMesh();
|
|
2546
|
+
}
|
|
2547
|
+
_generateMesh() {
|
|
2548
|
+
const { width: t, height: e, reprojectionFns: s, maxError: i = Pi } = this.props, o = new Si(s, t + 1, e + 1);
|
|
2549
|
+
o.run(i);
|
|
2550
|
+
const { indices: r, positions: a, texCoords: c } = Ii(o);
|
|
2551
|
+
this.setState({
|
|
2552
|
+
reprojector: o,
|
|
2553
|
+
mesh: {
|
|
2554
|
+
positions: a,
|
|
2555
|
+
indices: r,
|
|
2556
|
+
texCoords: c
|
|
2557
|
+
}
|
|
2558
|
+
});
|
|
2559
|
+
}
|
|
2560
|
+
renderDebugLayer() {
|
|
2561
|
+
const { reprojector: t } = this.state, { debugOpacity: e } = this.props;
|
|
2562
|
+
return t ? new Pt(this.getSubLayerProps({
|
|
2563
|
+
id: "polygon",
|
|
2564
|
+
// https://deck.gl/docs/developer-guide/performance#supply-binary-blobs-to-the-data-prop
|
|
2565
|
+
// This `data` gets passed into `getPolygon` with the row index.
|
|
2566
|
+
data: { reprojector: t, length: t.triangles.length / 3 },
|
|
2567
|
+
getPolygon: (s, { index: i, data: o }) => {
|
|
2568
|
+
const r = o.reprojector.triangles, a = t.exactOutputPositions, c = r[i * 3], h = r[i * 3 + 1], u = r[i * 3 + 2];
|
|
2569
|
+
return [
|
|
2570
|
+
[a[c * 2], a[c * 2 + 1]],
|
|
2571
|
+
[a[h * 2], a[h * 2 + 1]],
|
|
2572
|
+
[a[u * 2], a[u * 2 + 1]],
|
|
2573
|
+
[a[c * 2], a[c * 2 + 1]]
|
|
2574
|
+
];
|
|
2575
|
+
},
|
|
2576
|
+
getFillColor: (s, { index: i, target: o }) => {
|
|
2577
|
+
const r = ue[i % ue.length];
|
|
2578
|
+
return o[0] = r[0], o[1] = r[1], o[2] = r[2], o[3] = 255, o;
|
|
2579
|
+
},
|
|
2580
|
+
getLineColor: [0, 0, 0],
|
|
2581
|
+
getLineWidth: 1,
|
|
2582
|
+
lineWidthUnits: "pixels",
|
|
2583
|
+
opacity: e !== void 0 && Number.isFinite(e) ? Math.max(0, Math.min(1, e)) : 1,
|
|
2584
|
+
pickable: !1
|
|
2585
|
+
})) : null;
|
|
2586
|
+
}
|
|
2587
|
+
/** Create assembled render pipeline from the renderPipeline prop input. */
|
|
2588
|
+
_createRenderPipeline() {
|
|
2589
|
+
if (this.props.renderPipeline instanceof ImageData) {
|
|
2590
|
+
const t = this.props.renderPipeline, e = this.context.device.createTexture({
|
|
2591
|
+
format: "rgba8unorm",
|
|
2592
|
+
width: t.width,
|
|
2593
|
+
height: t.height,
|
|
2594
|
+
data: t.data
|
|
2595
|
+
});
|
|
2596
|
+
return [{
|
|
2597
|
+
module: xe,
|
|
2598
|
+
props: {
|
|
2599
|
+
textureName: e
|
|
2600
|
+
}
|
|
2601
|
+
}];
|
|
2602
|
+
} else
|
|
2603
|
+
return this.props.renderPipeline;
|
|
2604
|
+
}
|
|
2605
|
+
renderLayers() {
|
|
2606
|
+
const { mesh: t } = this.state, { debug: e } = this.props;
|
|
2607
|
+
if (!t)
|
|
2608
|
+
return null;
|
|
2609
|
+
const { indices: s, positions: i, texCoords: o } = t, a = [new Ei(this.getSubLayerProps({
|
|
2610
|
+
id: "raster",
|
|
2611
|
+
renderPipeline: this._createRenderPipeline(),
|
|
2612
|
+
// Dummy data because we're only rendering _one_ instance of this mesh
|
|
2613
|
+
// https://github.com/visgl/deck.gl/blob/93111b667b919148da06ff1918410cf66381904f/modules/geo-layers/src/terrain-layer/terrain-layer.ts#L241
|
|
2614
|
+
data: [1],
|
|
2615
|
+
mesh: {
|
|
2616
|
+
indices: { value: s, size: 1 },
|
|
2617
|
+
attributes: {
|
|
2618
|
+
POSITION: {
|
|
2619
|
+
value: i,
|
|
2620
|
+
size: 3
|
|
2621
|
+
},
|
|
2622
|
+
TEXCOORD_0: {
|
|
2623
|
+
value: o,
|
|
2624
|
+
size: 2
|
|
2625
|
+
}
|
|
2626
|
+
}
|
|
2627
|
+
},
|
|
2628
|
+
// We're only rendering a single mesh, without instancing
|
|
2629
|
+
// https://github.com/visgl/deck.gl/blob/93111b667b919148da06ff1918410cf66381904f/modules/geo-layers/src/terrain-layer/terrain-layer.ts#L244
|
|
2630
|
+
_instanced: !1,
|
|
2631
|
+
// Dummy accessors for the dummy data
|
|
2632
|
+
// We place our mesh at the coordinate origin
|
|
2633
|
+
getPosition: [0, 0, 0],
|
|
2634
|
+
// We give a white color to turn off color mixing with the texture
|
|
2635
|
+
getColor: [255, 255, 255]
|
|
2636
|
+
}))];
|
|
2637
|
+
if (e) {
|
|
2638
|
+
const c = this.renderDebugLayer();
|
|
2639
|
+
c && a.push(c);
|
|
2640
|
+
}
|
|
2641
|
+
return a;
|
|
2642
|
+
}
|
|
2643
|
+
}
|
|
2644
|
+
function Ii(n) {
|
|
2645
|
+
const t = n.uvs.length / 2, e = new Float32Array(t * 3), s = new Float32Array(n.uvs);
|
|
2646
|
+
for (let o = 0; o < t; o++)
|
|
2647
|
+
e[o * 3] = n.exactOutputPositions[o * 2], e[o * 3 + 1] = n.exactOutputPositions[o * 2 + 1], e[o * 3 + 2] = 0;
|
|
2648
|
+
return {
|
|
2649
|
+
indices: new Uint32Array(n.triangles),
|
|
2650
|
+
positions: e,
|
|
2651
|
+
texCoords: s
|
|
2652
|
+
};
|
|
2653
|
+
}
|
|
2654
|
+
const de = 512, Ai = [
|
|
2655
|
+
[0.5, 0.5],
|
|
2656
|
+
// center
|
|
2657
|
+
[0, 0],
|
|
2658
|
+
// top-left
|
|
2659
|
+
[0, 1],
|
|
2660
|
+
// bottom-left
|
|
2661
|
+
[1, 0],
|
|
2662
|
+
// top-right
|
|
2663
|
+
[1, 1]
|
|
2664
|
+
// bottom-right
|
|
2665
|
+
], vi = Ai.concat([
|
|
2666
|
+
[0, 0.5],
|
|
2667
|
+
// left edge
|
|
2668
|
+
[0.5, 0],
|
|
2669
|
+
// top edge
|
|
2670
|
+
[1, 0.5],
|
|
2671
|
+
// right edge
|
|
2672
|
+
[0.5, 1]
|
|
2673
|
+
// bottom edge
|
|
2674
|
+
]), Oi = 6378137, Ct = 2 * Math.PI * Oi, fe = Ct / 2, zi = 28e-5;
|
|
2675
|
+
class qt {
|
|
2676
|
+
/** Index across a row */
|
|
2677
|
+
x;
|
|
2678
|
+
/** Index down a column */
|
|
2679
|
+
y;
|
|
2680
|
+
/** Zoom index assumed to be (higher = finer detail) */
|
|
2681
|
+
z;
|
|
2682
|
+
metadata;
|
|
2683
|
+
/**
|
|
2684
|
+
* Flag indicating whether any descendant of this tile is visible.
|
|
2685
|
+
*
|
|
2686
|
+
* Used to prevent loading parent tiles when children are visible (avoids
|
|
2687
|
+
* overdraw).
|
|
2688
|
+
*/
|
|
2689
|
+
childVisible;
|
|
2690
|
+
/**
|
|
2691
|
+
* Flag indicating this tile should be rendered
|
|
2692
|
+
*
|
|
2693
|
+
* Set to `true` when this is the appropriate LOD for its distance from camera.
|
|
2694
|
+
*/
|
|
2695
|
+
selected;
|
|
2696
|
+
/** A cache of the children of this node. */
|
|
2697
|
+
_children;
|
|
2698
|
+
constructor(t, e, s, i) {
|
|
2699
|
+
this.x = t, this.y = e, this.z = s, this.metadata = i;
|
|
2700
|
+
}
|
|
2701
|
+
/** Get overview info for this tile's z level */
|
|
2702
|
+
get tileMatrix() {
|
|
2703
|
+
return this.metadata.tileMatrices[this.z];
|
|
2704
|
+
}
|
|
2705
|
+
/** Get the children of this node.
|
|
2706
|
+
*
|
|
2707
|
+
* Find all tiles at level this.z + 1 whose spatial extent overlaps this tile.
|
|
2708
|
+
*
|
|
2709
|
+
* A TileMatrixSet is not a quadtree, but rather a stack of independent grids. We can't cleanly find child tiles by decimation directly.
|
|
2710
|
+
*
|
|
2711
|
+
*/
|
|
2712
|
+
get children() {
|
|
2713
|
+
if (!this._children) {
|
|
2714
|
+
const t = this.metadata.tileMatrices.length - 1;
|
|
2715
|
+
if (this.z >= t)
|
|
2716
|
+
return this._children = null, null;
|
|
2717
|
+
const e = this.tileMatrix, s = this.z + 1, i = this.metadata.tileMatrices[s], o = me({
|
|
2718
|
+
x: this.x,
|
|
2719
|
+
y: this.y,
|
|
2720
|
+
transform: e.geotransform,
|
|
2721
|
+
tileWidth: e.tileWidth,
|
|
2722
|
+
tileHeight: e.tileHeight
|
|
2723
|
+
}), { minCol: r, maxCol: a, minRow: c, maxRow: h } = qi(o, i), u = [];
|
|
2724
|
+
for (let l = c; l <= h; l++)
|
|
2725
|
+
for (let d = r; d <= a; d++)
|
|
2726
|
+
u.push(new qt(d, l, s, this.metadata));
|
|
2727
|
+
this._children = u.length > 0 ? u : null;
|
|
2728
|
+
}
|
|
2729
|
+
return this._children;
|
|
2730
|
+
}
|
|
2731
|
+
/**
|
|
2732
|
+
* Recursively traverse the tile pyramid to determine if this tile (or its
|
|
2733
|
+
* descendants) should be rendered.
|
|
2734
|
+
*
|
|
2735
|
+
* I.e. “Given this tile node, should I render this tile, or should I recurse
|
|
2736
|
+
* into its children?”
|
|
2737
|
+
*
|
|
2738
|
+
* The algorithm performs:
|
|
2739
|
+
* 1. Visibility culling - reject tiles outside the view frustum
|
|
2740
|
+
* 2. Bounds checking - reject tiles outside the specified geographic bounds
|
|
2741
|
+
* 3. LOD selection - choose appropriate zoom level based on distance from camera
|
|
2742
|
+
* 4. Recursive subdivision - if LOD is insufficient, test child tiles
|
|
2743
|
+
*
|
|
2744
|
+
* Additionally, there should never be overdraw, i.e. a tile should never be
|
|
2745
|
+
* rendered if any of its descendants are rendered.
|
|
2746
|
+
*
|
|
2747
|
+
* @returns true if this tile or any descendant is visible, false otherwise
|
|
2748
|
+
*/
|
|
2749
|
+
update(t) {
|
|
2750
|
+
this.childVisible = !1, this.selected = !1;
|
|
2751
|
+
const { viewport: e, cullingVolume: s, elevationBounds: i, minZ: o, maxZ: r = this.metadata.tileMatrices.length - 1, project: a, bounds: c } = t, { boundingVolume: h, commonSpaceBounds: u } = this.getBoundingVolume(i, a);
|
|
2752
|
+
if (c && !this.insideBounds(c, u) || s.computeVisibility(h) < 0)
|
|
2753
|
+
return !1;
|
|
2754
|
+
const d = this.children;
|
|
2755
|
+
if (!this.childVisible && this.z >= o) {
|
|
2756
|
+
const f = Di(h, e.zoom);
|
|
2757
|
+
if (this.tileMatrix.scaleDenominator * zi <= f || this.z >= r || d === null && this.z >= o)
|
|
2758
|
+
return this.selected = !0, !0;
|
|
2759
|
+
}
|
|
2760
|
+
if (d && d.length > 0) {
|
|
2761
|
+
this.selected = !1;
|
|
2762
|
+
let f = !1;
|
|
2763
|
+
for (const m of d)
|
|
2764
|
+
m.update(t) && (f = !0);
|
|
2765
|
+
return this.childVisible = f, f;
|
|
2766
|
+
}
|
|
2767
|
+
return !0;
|
|
2768
|
+
}
|
|
2769
|
+
/**
|
|
2770
|
+
* Collect all tiles marked as selected in the tree.
|
|
2771
|
+
* Recursively traverses the entire tree and gathers tiles where selected=true.
|
|
2772
|
+
*
|
|
2773
|
+
* @param result - Accumulator array for selected tiles
|
|
2774
|
+
* @returns Array of selected OSMNode tiles
|
|
2775
|
+
*/
|
|
2776
|
+
getSelected(t = []) {
|
|
2777
|
+
if (this.selected && t.push(this), this._children)
|
|
2778
|
+
for (const e of this._children)
|
|
2779
|
+
e.getSelected(t);
|
|
2780
|
+
return t;
|
|
2781
|
+
}
|
|
2782
|
+
/**
|
|
2783
|
+
* Test if this tile intersects the specified bounds in Web Mercator space.
|
|
2784
|
+
* Used to filter tiles when only a specific geographic region is needed.
|
|
2785
|
+
*
|
|
2786
|
+
* @param bounds - [minX, minY, maxX, maxY] in Web Mercator units (0-512)
|
|
2787
|
+
* @returns true if tile overlaps the bounds
|
|
2788
|
+
*/
|
|
2789
|
+
insideBounds(t, e) {
|
|
2790
|
+
const [s, i, o, r] = t, [a, c, h, u] = e;
|
|
2791
|
+
return a < o && h > s && c < r && u > i;
|
|
2792
|
+
}
|
|
2793
|
+
/**
|
|
2794
|
+
* Calculate the 3D bounding volume for this tile in deck.gl's common
|
|
2795
|
+
* coordinate space for frustum culling.
|
|
2796
|
+
*
|
|
2797
|
+
* TODO: In the future, we can add a fast path in the case that the source
|
|
2798
|
+
* tiling is already in EPSG:3857.
|
|
2799
|
+
*/
|
|
2800
|
+
getBoundingVolume(t, e) {
|
|
2801
|
+
return e && Ws(!1, "TODO: implement getBoundingVolume in Globe view"), this._getGenericBoundingVolume(t);
|
|
2802
|
+
}
|
|
2803
|
+
/**
|
|
2804
|
+
* Generic case - sample reference points and reproject to Web Mercator, then
|
|
2805
|
+
* convert to deck.gl common space
|
|
2806
|
+
*
|
|
2807
|
+
*/
|
|
2808
|
+
_getGenericBoundingVolume(t) {
|
|
2809
|
+
const e = this.tileMatrix, { tileWidth: s, tileHeight: i, geotransform: o } = e, [r, a] = t, c = me({
|
|
2810
|
+
x: this.x,
|
|
2811
|
+
y: this.y,
|
|
2812
|
+
transform: o,
|
|
2813
|
+
tileWidth: s,
|
|
2814
|
+
tileHeight: i
|
|
2815
|
+
}), u = Ni(vi, c, this.metadata.projectTo3857).map((y) => Fi(y)), l = [];
|
|
2816
|
+
for (const y of u)
|
|
2817
|
+
l.push([y[0], y[1], r]), r !== a && l.push([y[0], y[1], a]);
|
|
2818
|
+
let d = Number.POSITIVE_INFINITY, f = Number.POSITIVE_INFINITY, m = Number.NEGATIVE_INFINITY, p = Number.NEGATIVE_INFINITY;
|
|
2819
|
+
for (const [y, _] of u)
|
|
2820
|
+
y < d && (d = y), _ < f && (f = _), y > m && (m = y), _ > p && (p = _);
|
|
2821
|
+
const g = [d, f, m, p];
|
|
2822
|
+
return {
|
|
2823
|
+
boundingVolume: Ae(l),
|
|
2824
|
+
commonSpaceBounds: g
|
|
2825
|
+
};
|
|
2826
|
+
}
|
|
2827
|
+
}
|
|
2828
|
+
function me({ x: n, y: t, transform: e, tileWidth: s, tileHeight: i }) {
|
|
2829
|
+
const [o, r, a, c, h, u] = e;
|
|
2830
|
+
if (r !== 0 || c !== 0)
|
|
2831
|
+
throw new Error(`Rotated/skewed geotransforms not yet supported (b=${r}, d=${c}). Only north-up, non-rotated rasters are currently supported.`);
|
|
2832
|
+
const l = n * s, d = t * i, f = (n + 1) * s, m = (t + 1) * i, p = o * l + r * d + a, g = c * l + h * d + u, y = o * f + r * m + a, _ = c * f + h * m + u;
|
|
2833
|
+
return [
|
|
2834
|
+
Math.min(p, y),
|
|
2835
|
+
Math.min(g, _),
|
|
2836
|
+
Math.max(p, y),
|
|
2837
|
+
Math.max(g, _)
|
|
2838
|
+
];
|
|
2839
|
+
}
|
|
2840
|
+
function Ni(n, t, e) {
|
|
2841
|
+
const [s, i, o, r] = t, a = [];
|
|
2842
|
+
for (const [c, h] of n) {
|
|
2843
|
+
const u = s + c * (o - s), l = i + h * (r - i), d = e([u, l]);
|
|
2844
|
+
a.push(d);
|
|
2845
|
+
}
|
|
2846
|
+
return a;
|
|
2847
|
+
}
|
|
2848
|
+
function Fi([n, t]) {
|
|
2849
|
+
const e = Math.max(-fe, Math.min(fe, t));
|
|
2850
|
+
return [
|
|
2851
|
+
(n / Ct + 0.5) * de,
|
|
2852
|
+
(e / Ct + 0.5) * de
|
|
2853
|
+
];
|
|
2854
|
+
}
|
|
2855
|
+
function qi(n, t) {
|
|
2856
|
+
const [e, s, i, o] = n, { tileWidth: r, tileHeight: a, cellSize: c, matrixWidth: h, matrixHeight: u, pointOfOrigin: l } = t, d = r * c, f = a * c, m = l[0], p = l[1];
|
|
2857
|
+
let g = Math.floor((e - m) / d), y = Math.floor((i - m) / d), _ = Math.floor((p - o) / f), x = Math.floor((p - s) / f);
|
|
2858
|
+
return g = Math.max(0, Math.min(h - 1, g)), y = Math.max(0, Math.min(h - 1, y)), _ = Math.max(0, Math.min(u - 1, _)), x = Math.max(0, Math.min(u - 1, x)), { minCol: g, maxCol: y, minRow: _, maxRow: x };
|
|
2859
|
+
}
|
|
2860
|
+
function Bi(n, t) {
|
|
2861
|
+
const { viewport: e, maxZ: s, zRange: i } = t, o = e instanceof Ce && e.resolution ? e.projectPosition : null, r = Object.values(e.getFrustumPlanes()).map(({ normal: b, distance: C }) => new W(b.clone().negate(), C)), a = new v(r), c = e.distanceScales.unitsPerMeter[2], h = i && i[0] * c || 0, u = i && i[1] * c || 0, l = 0, { lowerLeft: d, upperRight: f } = n.wgsBounds, [m, p] = d, [g, y] = f, _ = ot([m, p]), x = ot([g, y]), w = [
|
|
2862
|
+
_[0],
|
|
2863
|
+
_[1],
|
|
2864
|
+
x[0],
|
|
2865
|
+
x[1]
|
|
2866
|
+
], T = n.tileMatrices[0], S = [];
|
|
2867
|
+
for (let b = 0; b < T.matrixHeight; b++)
|
|
2868
|
+
for (let C = 0; C < T.matrixWidth; C++)
|
|
2869
|
+
S.push(new qt(C, b, 0, n));
|
|
2870
|
+
const L = {
|
|
2871
|
+
viewport: e,
|
|
2872
|
+
project: o,
|
|
2873
|
+
cullingVolume: a,
|
|
2874
|
+
elevationBounds: [h, u],
|
|
2875
|
+
minZ: l,
|
|
2876
|
+
maxZ: s,
|
|
2877
|
+
bounds: w
|
|
2878
|
+
};
|
|
2879
|
+
for (const b of S)
|
|
2880
|
+
b.update(L);
|
|
2881
|
+
const I = [];
|
|
2882
|
+
for (const b of S)
|
|
2883
|
+
b.getSelected(I);
|
|
2884
|
+
return I;
|
|
2885
|
+
}
|
|
2886
|
+
function Gi(n, t) {
|
|
2887
|
+
return 40075016686e-3 * Math.cos(n * Math.PI / 180) / 2 ** (t + 8);
|
|
2888
|
+
}
|
|
2889
|
+
function Di(n, t) {
|
|
2890
|
+
const [e, s] = Vs(n.center);
|
|
2891
|
+
return Gi(s, t);
|
|
2892
|
+
}
|
|
2893
|
+
class Ui extends Nt {
|
|
2894
|
+
metadata;
|
|
2895
|
+
constructor(t, e) {
|
|
2896
|
+
super(e), this.metadata = t;
|
|
2897
|
+
}
|
|
2898
|
+
/**
|
|
2899
|
+
* Get tile indices visible in viewport
|
|
2900
|
+
* Uses frustum culling similar to OSM implementation
|
|
2901
|
+
*
|
|
2902
|
+
* Overviews follow TileMatrixSet ordering: index 0 = coarsest, higher = finer
|
|
2903
|
+
*/
|
|
2904
|
+
getTileIndices(t) {
|
|
2905
|
+
const e = this.metadata.tileMatrices.length - 1, s = typeof t.maxZoom == "number" ? Math.min(t.maxZoom, e) : e;
|
|
2906
|
+
return Bi(this.metadata, {
|
|
2907
|
+
viewport: t.viewport,
|
|
2908
|
+
maxZ: s,
|
|
2909
|
+
zRange: t.zRange ?? null
|
|
2910
|
+
});
|
|
2911
|
+
}
|
|
2912
|
+
getTileId(t) {
|
|
2913
|
+
return `${t.x}-${t.y}-${t.z}`;
|
|
2914
|
+
}
|
|
2915
|
+
getParentIndex(t) {
|
|
2916
|
+
if (t.z === 0)
|
|
2917
|
+
return t;
|
|
2918
|
+
const e = this.metadata.tileMatrices[t.z], s = this.metadata.tileMatrices[t.z - 1], i = e.cellSize / s.cellSize;
|
|
2919
|
+
return {
|
|
2920
|
+
x: Math.floor(t.x / i),
|
|
2921
|
+
y: Math.floor(t.y / i),
|
|
2922
|
+
z: t.z - 1
|
|
2923
|
+
};
|
|
2924
|
+
}
|
|
2925
|
+
getTileZoom(t) {
|
|
2926
|
+
return t.z;
|
|
2927
|
+
}
|
|
2928
|
+
getTileMetadata(t) {
|
|
2929
|
+
const { x: e, y: s, z: i } = t, { tileMatrices: o } = this.metadata, r = o[i], { geotransform: a, tileHeight: c, tileWidth: h } = r, [u, l, d, f, m, p] = a, g = e * h, y = s * c, _ = (e + 1) * h, x = (s + 1) * c, w = [
|
|
2930
|
+
u * g + l * y + d,
|
|
2931
|
+
f * g + m * y + p
|
|
2932
|
+
], T = [
|
|
2933
|
+
u * _ + l * y + d,
|
|
2934
|
+
f * _ + m * y + p
|
|
2935
|
+
], S = [
|
|
2936
|
+
u * g + l * x + d,
|
|
2937
|
+
f * g + m * x + p
|
|
2938
|
+
], L = [
|
|
2939
|
+
u * _ + l * x + d,
|
|
2940
|
+
f * _ + m * x + p
|
|
2941
|
+
], I = {
|
|
2942
|
+
topLeft: w,
|
|
2943
|
+
topRight: T,
|
|
2944
|
+
bottomLeft: S,
|
|
2945
|
+
bottomRight: L
|
|
2946
|
+
};
|
|
2947
|
+
return {
|
|
2948
|
+
bounds: [
|
|
2949
|
+
Math.min(w[0], T[0], S[0], L[0]),
|
|
2950
|
+
Math.min(w[1], T[1], S[1], L[1]),
|
|
2951
|
+
Math.max(w[0], T[0], S[0], L[0]),
|
|
2952
|
+
Math.max(w[1], T[1], S[1], L[1])
|
|
2953
|
+
],
|
|
2954
|
+
projectedBounds: I,
|
|
2955
|
+
tileWidth: h,
|
|
2956
|
+
tileHeight: c,
|
|
2957
|
+
tileMatrix: r
|
|
2958
|
+
};
|
|
2959
|
+
}
|
|
2960
|
+
}
|
|
2961
|
+
const Wi = {
|
|
2962
|
+
MERIT: {
|
|
2963
|
+
a: 6378137
|
|
2964
|
+
},
|
|
2965
|
+
SGS85: {
|
|
2966
|
+
a: 6378136
|
|
2967
|
+
},
|
|
2968
|
+
GRS80: {
|
|
2969
|
+
a: 6378137
|
|
2970
|
+
},
|
|
2971
|
+
IAU76: {
|
|
2972
|
+
a: 6378140
|
|
2973
|
+
},
|
|
2974
|
+
airy: {
|
|
2975
|
+
a: 6377563396e-3,
|
|
2976
|
+
b: 635625691e-2
|
|
2977
|
+
},
|
|
2978
|
+
APL4: {
|
|
2979
|
+
a: 6378137
|
|
2980
|
+
},
|
|
2981
|
+
NWL9D: {
|
|
2982
|
+
a: 6378145
|
|
2983
|
+
},
|
|
2984
|
+
mod_airy: {
|
|
2985
|
+
a: 6377340189e-3,
|
|
2986
|
+
b: 6356034446e-3
|
|
2987
|
+
},
|
|
2988
|
+
andrae: {
|
|
2989
|
+
a: 637710443e-2
|
|
2990
|
+
},
|
|
2991
|
+
aust_SA: {
|
|
2992
|
+
a: 6378160
|
|
2993
|
+
},
|
|
2994
|
+
GRS67: {
|
|
2995
|
+
a: 6378160
|
|
2996
|
+
},
|
|
2997
|
+
bessel: {
|
|
2998
|
+
a: 6377397155e-3
|
|
2999
|
+
},
|
|
3000
|
+
bess_nam: {
|
|
3001
|
+
a: 6377483865e-3
|
|
3002
|
+
},
|
|
3003
|
+
clrk66: {
|
|
3004
|
+
a: 63782064e-1,
|
|
3005
|
+
b: 63565838e-1
|
|
3006
|
+
},
|
|
3007
|
+
clrk80: {
|
|
3008
|
+
a: 6378249145e-3
|
|
3009
|
+
},
|
|
3010
|
+
clrk80ign: {
|
|
3011
|
+
a: 63782492e-1,
|
|
3012
|
+
b: 6356515
|
|
3013
|
+
},
|
|
3014
|
+
clrk58: {
|
|
3015
|
+
a: 6378293645208759e-9
|
|
3016
|
+
},
|
|
3017
|
+
CPM: {
|
|
3018
|
+
a: 63757387e-1
|
|
3019
|
+
},
|
|
3020
|
+
delmbr: {
|
|
3021
|
+
a: 6376428
|
|
3022
|
+
},
|
|
3023
|
+
engelis: {
|
|
3024
|
+
a: 637813605e-2
|
|
3025
|
+
},
|
|
3026
|
+
evrst30: {
|
|
3027
|
+
a: 6377276345e-3
|
|
3028
|
+
},
|
|
3029
|
+
evrst48: {
|
|
3030
|
+
a: 6377304063e-3
|
|
3031
|
+
},
|
|
3032
|
+
evrst56: {
|
|
3033
|
+
a: 6377301243e-3
|
|
3034
|
+
},
|
|
3035
|
+
evrst69: {
|
|
3036
|
+
a: 6377295664e-3
|
|
3037
|
+
},
|
|
3038
|
+
evrstSS: {
|
|
3039
|
+
a: 6377298556e-3
|
|
3040
|
+
},
|
|
3041
|
+
fschr60: {
|
|
3042
|
+
a: 6378166
|
|
3043
|
+
},
|
|
3044
|
+
fschr60m: {
|
|
3045
|
+
a: 6378155
|
|
3046
|
+
},
|
|
3047
|
+
fschr68: {
|
|
3048
|
+
a: 6378150
|
|
3049
|
+
},
|
|
3050
|
+
helmert: {
|
|
3051
|
+
a: 6378200
|
|
3052
|
+
},
|
|
3053
|
+
hough: {
|
|
3054
|
+
a: 6378270
|
|
3055
|
+
},
|
|
3056
|
+
intl: {
|
|
3057
|
+
a: 6378388
|
|
3058
|
+
},
|
|
3059
|
+
kaula: {
|
|
3060
|
+
a: 6378163
|
|
3061
|
+
},
|
|
3062
|
+
lerch: {
|
|
3063
|
+
a: 6378139
|
|
3064
|
+
},
|
|
3065
|
+
mprts: {
|
|
3066
|
+
a: 6397300
|
|
3067
|
+
},
|
|
3068
|
+
new_intl: {
|
|
3069
|
+
a: 63781575e-1,
|
|
3070
|
+
b: 63567722e-1
|
|
3071
|
+
},
|
|
3072
|
+
plessis: {
|
|
3073
|
+
a: 6376523
|
|
3074
|
+
},
|
|
3075
|
+
krass: {
|
|
3076
|
+
a: 6378245
|
|
3077
|
+
},
|
|
3078
|
+
SEasia: {
|
|
3079
|
+
a: 6378155,
|
|
3080
|
+
b: 63567733205e-4
|
|
3081
|
+
},
|
|
3082
|
+
walbeck: {
|
|
3083
|
+
a: 6376896,
|
|
3084
|
+
b: 63558348467e-4
|
|
3085
|
+
},
|
|
3086
|
+
WGS60: {
|
|
3087
|
+
a: 6378165
|
|
3088
|
+
},
|
|
3089
|
+
WGS66: {
|
|
3090
|
+
a: 6378145
|
|
3091
|
+
},
|
|
3092
|
+
WGS7: {
|
|
3093
|
+
a: 6378135
|
|
3094
|
+
},
|
|
3095
|
+
WGS84: {
|
|
3096
|
+
a: 6378137
|
|
3097
|
+
},
|
|
3098
|
+
sphere: {
|
|
3099
|
+
a: 6370997,
|
|
3100
|
+
b: 6370997
|
|
3101
|
+
}
|
|
3102
|
+
};
|
|
3103
|
+
function Vi(n) {
|
|
3104
|
+
if (ki(n))
|
|
3105
|
+
throw new Error("Cannot invert degenerate transform");
|
|
3106
|
+
const t = 1 / Fe(n), [e, s, i, o, r, a] = n, c = r * t, h = -s * t, u = -o * t, l = e * t;
|
|
3107
|
+
return [
|
|
3108
|
+
c,
|
|
3109
|
+
h,
|
|
3110
|
+
-i * c - a * h,
|
|
3111
|
+
u,
|
|
3112
|
+
l,
|
|
3113
|
+
-i * u - a * l
|
|
3114
|
+
];
|
|
3115
|
+
}
|
|
3116
|
+
function ki(n) {
|
|
3117
|
+
return Fe(n) === 0;
|
|
3118
|
+
}
|
|
3119
|
+
function Fe(n) {
|
|
3120
|
+
const [t, e, s, i, o, r] = n;
|
|
3121
|
+
return t * o - e * i;
|
|
3122
|
+
}
|
|
3123
|
+
function pe(n, t, e) {
|
|
3124
|
+
const [s, i, o, r, a, c] = e;
|
|
3125
|
+
return [s * n + i * t + o, r * n + a * t + c];
|
|
3126
|
+
}
|
|
3127
|
+
const ji = {
|
|
3128
|
+
$schema: "https://proj.org/schemas/v0.7/projjson.schema.json",
|
|
3129
|
+
type: "GeographicCRS",
|
|
3130
|
+
name: "WGS 84 (CRS84)",
|
|
3131
|
+
datum_ensemble: {
|
|
3132
|
+
name: "World Geodetic System 1984 ensemble",
|
|
3133
|
+
members: [
|
|
3134
|
+
{
|
|
3135
|
+
name: "World Geodetic System 1984 (Transit)",
|
|
3136
|
+
id: { authority: "EPSG", code: 1166 }
|
|
3137
|
+
},
|
|
3138
|
+
{
|
|
3139
|
+
name: "World Geodetic System 1984 (G730)",
|
|
3140
|
+
id: { authority: "EPSG", code: 1152 }
|
|
3141
|
+
},
|
|
3142
|
+
{
|
|
3143
|
+
name: "World Geodetic System 1984 (G873)",
|
|
3144
|
+
id: { authority: "EPSG", code: 1153 }
|
|
3145
|
+
},
|
|
3146
|
+
{
|
|
3147
|
+
name: "World Geodetic System 1984 (G1150)",
|
|
3148
|
+
id: { authority: "EPSG", code: 1154 }
|
|
3149
|
+
},
|
|
3150
|
+
{
|
|
3151
|
+
name: "World Geodetic System 1984 (G1674)",
|
|
3152
|
+
id: { authority: "EPSG", code: 1155 }
|
|
3153
|
+
},
|
|
3154
|
+
{
|
|
3155
|
+
name: "World Geodetic System 1984 (G1762)",
|
|
3156
|
+
id: { authority: "EPSG", code: 1156 }
|
|
3157
|
+
},
|
|
3158
|
+
{
|
|
3159
|
+
name: "World Geodetic System 1984 (G2139)",
|
|
3160
|
+
id: { authority: "EPSG", code: 1309 }
|
|
3161
|
+
}
|
|
3162
|
+
],
|
|
3163
|
+
ellipsoid: {
|
|
3164
|
+
name: "WGS 84",
|
|
3165
|
+
semi_major_axis: 6378137,
|
|
3166
|
+
inverse_flattening: 298.257223563
|
|
3167
|
+
},
|
|
3168
|
+
accuracy: "2.0",
|
|
3169
|
+
id: { authority: "EPSG", code: 6326 }
|
|
3170
|
+
},
|
|
3171
|
+
coordinate_system: {
|
|
3172
|
+
subtype: "ellipsoidal",
|
|
3173
|
+
axis: [
|
|
3174
|
+
{
|
|
3175
|
+
name: "Geodetic longitude",
|
|
3176
|
+
abbreviation: "Lon",
|
|
3177
|
+
direction: "east",
|
|
3178
|
+
unit: "degree"
|
|
3179
|
+
},
|
|
3180
|
+
{
|
|
3181
|
+
name: "Geodetic latitude",
|
|
3182
|
+
abbreviation: "Lat",
|
|
3183
|
+
direction: "north",
|
|
3184
|
+
unit: "degree"
|
|
3185
|
+
}
|
|
3186
|
+
]
|
|
3187
|
+
},
|
|
3188
|
+
scope: "Not known.",
|
|
3189
|
+
area: "World.",
|
|
3190
|
+
bbox: {
|
|
3191
|
+
south_latitude: -90,
|
|
3192
|
+
west_longitude: -180,
|
|
3193
|
+
north_latitude: 90,
|
|
3194
|
+
east_longitude: 180
|
|
3195
|
+
},
|
|
3196
|
+
// @ts-expect-error - proj4 types are incomplete
|
|
3197
|
+
id: { authority: "OGC", code: "CRS84" }
|
|
3198
|
+
};
|
|
3199
|
+
async function Yi(n, t, e = ji) {
|
|
3200
|
+
const s = await n.getImage(), i = Be(s), o = q(t, e), { forwardTransform: r, inverseTransform: a } = qe(i);
|
|
3201
|
+
return {
|
|
3202
|
+
forwardTransform: r,
|
|
3203
|
+
inverseTransform: a,
|
|
3204
|
+
forwardReproject: (c, h) => o.forward([c, h], !1),
|
|
3205
|
+
inverseReproject: (c, h) => o.inverse([c, h], !1)
|
|
3206
|
+
};
|
|
3207
|
+
}
|
|
3208
|
+
function qe(n) {
|
|
3209
|
+
const t = Vi(n);
|
|
3210
|
+
return {
|
|
3211
|
+
forwardTransform: (e, s) => pe(e, s, n),
|
|
3212
|
+
inverseTransform: (e, s) => pe(e, s, t)
|
|
3213
|
+
};
|
|
3214
|
+
}
|
|
3215
|
+
function Be(n) {
|
|
3216
|
+
const t = n.getOrigin(), e = n.getResolution(), i = n.getFileDirectory().ModelTransformation;
|
|
3217
|
+
let o = 0, r = 0;
|
|
3218
|
+
return i && i.length >= 16 && (o = i[1], r = i[4]), [
|
|
3219
|
+
e[0],
|
|
3220
|
+
// a: pixel width
|
|
3221
|
+
o,
|
|
3222
|
+
// b: row rotation
|
|
3223
|
+
t[0],
|
|
3224
|
+
// c: x origin
|
|
3225
|
+
r,
|
|
3226
|
+
// d: column rotation
|
|
3227
|
+
e[1],
|
|
3228
|
+
// e: pixel height (often negative)
|
|
3229
|
+
t[1]
|
|
3230
|
+
];
|
|
3231
|
+
}
|
|
3232
|
+
const Ge = 28e-5;
|
|
3233
|
+
async function $i(n, t) {
|
|
3234
|
+
const e = await n.getImage();
|
|
3235
|
+
if (!e.isTiled)
|
|
3236
|
+
throw new Error("COG TileMatrixSet requires a tiled GeoTIFF");
|
|
3237
|
+
const s = await n.getImageCount(), i = e.getBoundingBox(), o = e.getWidth(), r = e.getHeight(), a = await t(e.getGeoKeys());
|
|
3238
|
+
if (a === null)
|
|
3239
|
+
throw new Error("Could not determine coordinate reference system from GeoTIFF geo keys");
|
|
3240
|
+
const c = q(a.def, "EPSG:4326").forward, h = q(a.def, "EPSG:3857").forward, u = {
|
|
3241
|
+
lowerLeft: [i[0], i[1]],
|
|
3242
|
+
upperRight: [i[2], i[3]]
|
|
3243
|
+
}, l = Be(e);
|
|
3244
|
+
if (l[1] !== 0 || l[3] !== 0)
|
|
3245
|
+
throw new Error("COG TileMatrixSet with rotation/skewed geotransform is not supported");
|
|
3246
|
+
const d = Math.abs(l[0]), f = e.getTileWidth(), m = e.getTileHeight(), p = [
|
|
3247
|
+
{
|
|
3248
|
+
// Set as highest resolution / finest level
|
|
3249
|
+
id: String(s - 1),
|
|
3250
|
+
scaleDenominator: d * Bt(a.parsed, a.coordinatesUnits) / Ge,
|
|
3251
|
+
cellSize: d,
|
|
3252
|
+
pointOfOrigin: [l[2], l[5]],
|
|
3253
|
+
tileWidth: e.getTileWidth(),
|
|
3254
|
+
tileHeight: e.getTileHeight(),
|
|
3255
|
+
matrixWidth: Math.ceil(o / f),
|
|
3256
|
+
matrixHeight: Math.ceil(r / m),
|
|
3257
|
+
geotransform: l
|
|
3258
|
+
}
|
|
3259
|
+
];
|
|
3260
|
+
for (let g = 1; g < s; g++) {
|
|
3261
|
+
const y = await n.getImage(g);
|
|
3262
|
+
if (!y.isTiled)
|
|
3263
|
+
throw new Error("COG TileMatrixSet requires a tiled GeoTIFF");
|
|
3264
|
+
const _ = Xi({
|
|
3265
|
+
id: String(s - 1 - g),
|
|
3266
|
+
image: y,
|
|
3267
|
+
fullWidth: o,
|
|
3268
|
+
baseTransform: l,
|
|
3269
|
+
crs: a
|
|
3270
|
+
});
|
|
3271
|
+
p.push(_);
|
|
3272
|
+
}
|
|
3273
|
+
return p.reverse(), {
|
|
3274
|
+
crs: a,
|
|
3275
|
+
boundingBox: u,
|
|
3276
|
+
wgsBounds: Zi(u, c),
|
|
3277
|
+
tileMatrices: p,
|
|
3278
|
+
projectToWgs84: c,
|
|
3279
|
+
projectTo3857: h
|
|
3280
|
+
};
|
|
3281
|
+
}
|
|
3282
|
+
function Bt(n, t) {
|
|
3283
|
+
const e = (t || n.units)?.toLowerCase();
|
|
3284
|
+
switch (e) {
|
|
3285
|
+
case "m":
|
|
3286
|
+
case "metre":
|
|
3287
|
+
case "meter":
|
|
3288
|
+
case "meters":
|
|
3289
|
+
return 1;
|
|
3290
|
+
case "foot":
|
|
3291
|
+
return 0.3048;
|
|
3292
|
+
case "us survey foot":
|
|
3293
|
+
return 1200 / 3937;
|
|
3294
|
+
}
|
|
3295
|
+
if (e === "degree") {
|
|
3296
|
+
const { a: s } = Wi[n.ellps];
|
|
3297
|
+
return 2 * Math.PI * s / 360;
|
|
3298
|
+
}
|
|
3299
|
+
throw new Error(`Unsupported CRS units: ${e}`);
|
|
3300
|
+
}
|
|
3301
|
+
function Xi({ id: n, image: t, fullWidth: e, baseTransform: s, crs: i }) {
|
|
3302
|
+
const o = t.getWidth(), r = t.getHeight(), c = e / o, h = [
|
|
3303
|
+
s[0] * c,
|
|
3304
|
+
s[1] * c,
|
|
3305
|
+
s[2],
|
|
3306
|
+
// x origin stays the same
|
|
3307
|
+
s[3] * c,
|
|
3308
|
+
s[4] * c,
|
|
3309
|
+
s[5]
|
|
3310
|
+
// y origin stays the same
|
|
3311
|
+
], u = Math.abs(h[0]), l = t.getTileWidth(), d = t.getTileHeight();
|
|
3312
|
+
return {
|
|
3313
|
+
id: n,
|
|
3314
|
+
scaleDenominator: u * Bt(i.parsed, i.coordinatesUnits) / Ge,
|
|
3315
|
+
cellSize: u,
|
|
3316
|
+
pointOfOrigin: [h[2], h[5]],
|
|
3317
|
+
tileWidth: l,
|
|
3318
|
+
tileHeight: d,
|
|
3319
|
+
matrixWidth: Math.ceil(o / l),
|
|
3320
|
+
matrixHeight: Math.ceil(r / d),
|
|
3321
|
+
geotransform: h
|
|
3322
|
+
};
|
|
3323
|
+
}
|
|
3324
|
+
function Zi(n, t) {
|
|
3325
|
+
const e = t(n.lowerLeft), s = t([
|
|
3326
|
+
n.upperRight[0],
|
|
3327
|
+
n.lowerLeft[1]
|
|
3328
|
+
]), i = t(n.upperRight), o = t([
|
|
3329
|
+
n.lowerLeft[0],
|
|
3330
|
+
n.upperRight[1]
|
|
3331
|
+
]), r = Math.min(e[0], s[0], i[0], o[0]), a = Math.max(e[0], s[0], i[0], o[0]), c = Math.min(e[1], s[1], i[1], o[1]), h = Math.max(e[1], s[1], i[1], o[1]);
|
|
3332
|
+
return {
|
|
3333
|
+
lowerLeft: [r, c],
|
|
3334
|
+
upperRight: [a, h]
|
|
3335
|
+
};
|
|
3336
|
+
}
|
|
3337
|
+
const Hi = {
|
|
3338
|
+
metersPerUnit: Bt
|
|
3339
|
+
};
|
|
3340
|
+
let yt = null;
|
|
3341
|
+
function De() {
|
|
3342
|
+
return yt === null && (yt = new Qe()), yt;
|
|
3343
|
+
}
|
|
3344
|
+
async function Ki(n, t) {
|
|
3345
|
+
const e = {
|
|
3346
|
+
...t,
|
|
3347
|
+
interleave: !0,
|
|
3348
|
+
enableAlpha: !0
|
|
3349
|
+
}, s = await n.readRGB(e);
|
|
3350
|
+
return {
|
|
3351
|
+
texture: Ue(s),
|
|
3352
|
+
height: s.height,
|
|
3353
|
+
width: s.width
|
|
3354
|
+
};
|
|
3355
|
+
}
|
|
3356
|
+
function Ue(n) {
|
|
3357
|
+
const { height: t, width: e } = n;
|
|
3358
|
+
if (n.length === t * e * 4)
|
|
3359
|
+
return new ImageData(new Uint8ClampedArray(n), e, t);
|
|
3360
|
+
if (n.length === t * e * 3) {
|
|
3361
|
+
const s = n.length / 3 * 4, i = new Uint8ClampedArray(s);
|
|
3362
|
+
for (let o = 0; o < n.length / 3; ++o)
|
|
3363
|
+
i[o * 4] = n[o * 3], i[o * 4 + 1] = n[o * 3 + 1], i[o * 4 + 2] = n[o * 3 + 2], i[o * 4 + 3] = 255;
|
|
3364
|
+
return new ImageData(i, e, t);
|
|
3365
|
+
} else
|
|
3366
|
+
throw new Error(`Unexpected number of channels in raster data: ${n.length / (t * e)}`);
|
|
3367
|
+
}
|
|
3368
|
+
function Qi(n) {
|
|
3369
|
+
const t = n.length / 3, e = new Uint8ClampedArray(t * 4), s = 0, i = t, o = t * 2;
|
|
3370
|
+
for (let r = 0; r < t; r++)
|
|
3371
|
+
e[4 * r + 0] = n[s + r] >> 8, e[4 * r + 1] = n[i + r] >> 8, e[4 * r + 2] = n[o + r] >> 8, e[4 * r + 3] = 255;
|
|
3372
|
+
return new ImageData(e, t, 1);
|
|
3373
|
+
}
|
|
3374
|
+
async function We(n) {
|
|
3375
|
+
return typeof n == "string" ? $e(n) : n instanceof ArrayBuffer ? Xe(n) : n instanceof Blob ? Ze(n) : n instanceof He ? Ke(n) : n;
|
|
3376
|
+
}
|
|
3377
|
+
function Ve(n, t) {
|
|
3378
|
+
const e = n.getBoundingBox(), [s, i, o, r] = e, a = [
|
|
3379
|
+
t.forward([s, i]),
|
|
3380
|
+
// bottom-left
|
|
3381
|
+
t.forward([o, i]),
|
|
3382
|
+
// bottom-right
|
|
3383
|
+
t.forward([o, r]),
|
|
3384
|
+
// top-right
|
|
3385
|
+
t.forward([s, r])
|
|
3386
|
+
// top-left
|
|
3387
|
+
], c = a.map((m) => m[0]), h = a.map((m) => m[1]), u = Math.min(...c), l = Math.min(...h), d = Math.max(...c), f = Math.max(...h);
|
|
3388
|
+
return { west: u, south: l, east: d, north: f };
|
|
3389
|
+
}
|
|
3390
|
+
function Ji(n) {
|
|
3391
|
+
if (!n)
|
|
3392
|
+
return null;
|
|
3393
|
+
const t = n?.[n?.length - 1] === "\0" ? n.slice(0, -1) : n;
|
|
3394
|
+
return t?.length > 0 ? parseFloat(t) : null;
|
|
3395
|
+
}
|
|
3396
|
+
function to(n, t, e) {
|
|
3397
|
+
const s = n.getFileDirectory(), i = s.SamplesPerPixel, o = Gt(i, s.BitsPerSample, s.SampleFormat);
|
|
3398
|
+
return {
|
|
3399
|
+
data: t,
|
|
3400
|
+
format: o,
|
|
3401
|
+
width: e.width,
|
|
3402
|
+
height: e.height
|
|
3403
|
+
};
|
|
3404
|
+
}
|
|
3405
|
+
function Gt(n, t, e) {
|
|
3406
|
+
const s = eo(n), i = so(t), o = no(e), r = `${s}:${o}:${i}`, a = io[r];
|
|
3407
|
+
if (!a)
|
|
3408
|
+
throw new Error(`Unsupported texture format for SamplesPerPixel=${n}, BitsPerSample=${t}, SampleFormat=${e}`);
|
|
3409
|
+
return a;
|
|
3410
|
+
}
|
|
3411
|
+
function eo(n) {
|
|
3412
|
+
if (n === 1 || n === 2 || n === 3 || n === 4)
|
|
3413
|
+
return n;
|
|
3414
|
+
throw new Error(`Unsupported SamplesPerPixel ${n}. Only 1, 2, 3, or 4 are supported.`);
|
|
3415
|
+
}
|
|
3416
|
+
function so(n) {
|
|
3417
|
+
const t = n[0];
|
|
3418
|
+
for (let e = 1; e < n.length; e++)
|
|
3419
|
+
if (n[e] !== t)
|
|
3420
|
+
throw new Error(`Unsupported varying BitsPerSample ${n}. All samples must have the same bit width.`);
|
|
3421
|
+
if (t !== 8 && t !== 16 && t !== 32)
|
|
3422
|
+
throw new Error(`Unsupported BitsPerSample ${t}. Only 8, 16, or 32 are supported.`);
|
|
3423
|
+
return t;
|
|
3424
|
+
}
|
|
3425
|
+
function no(n) {
|
|
3426
|
+
const t = n[0];
|
|
3427
|
+
for (let e = 1; e < n.length; e++)
|
|
3428
|
+
if (n[e] !== t)
|
|
3429
|
+
throw new Error(`Unsupported varying SampleFormat ${n}. All samples must have the same format.`);
|
|
3430
|
+
switch (t) {
|
|
3431
|
+
case 1:
|
|
3432
|
+
return "unorm";
|
|
3433
|
+
case 2:
|
|
3434
|
+
return "sint";
|
|
3435
|
+
case 3:
|
|
3436
|
+
return "float";
|
|
3437
|
+
default:
|
|
3438
|
+
throw new Error(`Unsupported SampleFormat ${n}`);
|
|
3439
|
+
}
|
|
3440
|
+
}
|
|
3441
|
+
const io = {
|
|
3442
|
+
// 1 byte per pixel
|
|
3443
|
+
"1:sint:8": "r8sint",
|
|
3444
|
+
"1:uint:8": "r8uint",
|
|
3445
|
+
"1:unorm:8": "r8unorm",
|
|
3446
|
+
// 2 bytes per pixel (one channel)
|
|
3447
|
+
"1:float:16": "r16float",
|
|
3448
|
+
"1:sint:16": "r16sint",
|
|
3449
|
+
"1:uint:16": "r16uint",
|
|
3450
|
+
"1:unorm:16": "r16unorm",
|
|
3451
|
+
// 2 bytes per pixel (two channels)
|
|
3452
|
+
"2:sint:8": "rg8sint",
|
|
3453
|
+
"2:uint:8": "rg8uint",
|
|
3454
|
+
"2:unorm:8": "rg8unorm",
|
|
3455
|
+
// 4 bytes per pixel (one channel)
|
|
3456
|
+
"1:float:32": "r32float",
|
|
3457
|
+
"1:sint:32": "r32sint",
|
|
3458
|
+
"1:uint:32": "r32uint",
|
|
3459
|
+
// 4 bytes per pixel (two channels)
|
|
3460
|
+
"2:float:16": "rg16float",
|
|
3461
|
+
"2:sint:16": "rg16sint",
|
|
3462
|
+
"2:uint:16": "rg16uint",
|
|
3463
|
+
"2:unorm:16": "rg16unorm",
|
|
3464
|
+
// 4 bytes per pixel (four channels)
|
|
3465
|
+
"4:sint:8": "rgba8sint",
|
|
3466
|
+
"4:uint:8": "rgba8uint",
|
|
3467
|
+
"4:unorm:8": "rgba8unorm",
|
|
3468
|
+
// 6 bytes per pixel (three channels)
|
|
3469
|
+
// Note: this is supported on WebGL2 but not supported on WebGPU
|
|
3470
|
+
// I expect actual switch to WebGPU to be quite a ways off still
|
|
3471
|
+
"3:uint:16": "rgb16unorm-webgl",
|
|
3472
|
+
// 8 bytes per pixel (two channels)
|
|
3473
|
+
"2:float:32": "rg32float",
|
|
3474
|
+
"2:sint:32": "rg32sint",
|
|
3475
|
+
"2:uint:32": "rg32uint",
|
|
3476
|
+
// 8 bytes per pixel (four channels)
|
|
3477
|
+
"4:float:16": "rgba16float",
|
|
3478
|
+
"4:sint:16": "rgba16sint",
|
|
3479
|
+
"4:uint:16": "rgba16uint",
|
|
3480
|
+
"4:unorm:16": "rgba16unorm",
|
|
3481
|
+
// 12 bytes per pixel (three channels)
|
|
3482
|
+
"3:float:32": "rgb32float-webgl",
|
|
3483
|
+
// 16 bytes per pixel (four channels)
|
|
3484
|
+
"4:float:32": "rgba32float",
|
|
3485
|
+
"4:sint:32": "rgba32sint",
|
|
3486
|
+
"4:uint:32": "rgba32uint"
|
|
3487
|
+
}, bo = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
3488
|
+
__proto__: null,
|
|
3489
|
+
createTextureProps: to,
|
|
3490
|
+
inferTextureFormat: Gt
|
|
3491
|
+
}, Symbol.toStringTag, { value: "Module" }));
|
|
3492
|
+
var F;
|
|
3493
|
+
(function(n) {
|
|
3494
|
+
n[n.WhiteIsZero = 0] = "WhiteIsZero", n[n.BlackIsZero = 1] = "BlackIsZero", n[n.RGB = 2] = "RGB", n[n.Palette = 3] = "Palette", n[n.TransparencyMask = 4] = "TransparencyMask", n[n.CMYK = 5] = "CMYK", n[n.YCbCr = 6] = "YCbCr", n[n.CIELab = 8] = "CIELab", n[n.ICCLab = 9] = "ICCLab";
|
|
3495
|
+
})(F || (F = {}));
|
|
3496
|
+
var ge;
|
|
3497
|
+
(function(n) {
|
|
3498
|
+
n[n.Chunky = 1] = "Chunky", n[n.Planar = 2] = "Planar";
|
|
3499
|
+
})(ge || (ge = {}));
|
|
3500
|
+
function oo(n, t) {
|
|
3501
|
+
const { SampleFormat: e } = n;
|
|
3502
|
+
if (e[0] === 1)
|
|
3503
|
+
return ro(n, t);
|
|
3504
|
+
throw new Error(`Inferring render pipeline for non-unsigned integers not yet supported. Found SampleFormat: ${e}`);
|
|
3505
|
+
}
|
|
3506
|
+
function ro(n, t) {
|
|
3507
|
+
const { BitsPerSample: e, ColorMap: s, GDAL_NODATA: i, PhotometricInterpretation: o, SampleFormat: r, SamplesPerPixel: a } = n, c = [
|
|
3508
|
+
{
|
|
3509
|
+
module: xe,
|
|
3510
|
+
props: {
|
|
3511
|
+
textureName: (m) => m.texture
|
|
3512
|
+
}
|
|
3513
|
+
}
|
|
3514
|
+
], h = Ji(i);
|
|
3515
|
+
if (h !== null) {
|
|
3516
|
+
const m = h / 255;
|
|
3517
|
+
c.push({
|
|
3518
|
+
module: ns,
|
|
3519
|
+
props: { value: m }
|
|
3520
|
+
});
|
|
3521
|
+
}
|
|
3522
|
+
const u = ao(o, t, s);
|
|
3523
|
+
u && c.push(u);
|
|
3524
|
+
const l = o === F.Palette ? {
|
|
3525
|
+
magFilter: "nearest",
|
|
3526
|
+
minFilter: "nearest"
|
|
3527
|
+
} : {
|
|
3528
|
+
magFilter: "linear",
|
|
3529
|
+
minFilter: "linear"
|
|
3530
|
+
};
|
|
3531
|
+
return { getTileData: async (m, p) => {
|
|
3532
|
+
const { device: g } = p, y = {
|
|
3533
|
+
...p,
|
|
3534
|
+
interleave: !0
|
|
3535
|
+
};
|
|
3536
|
+
let _ = await m.readRasters(y), x = a;
|
|
3537
|
+
a === 3 && (_ = Ue(_), x = 4);
|
|
3538
|
+
const w = Gt(
|
|
3539
|
+
// Add one sample for added alpha channel
|
|
3540
|
+
x,
|
|
3541
|
+
e,
|
|
3542
|
+
r
|
|
3543
|
+
);
|
|
3544
|
+
return {
|
|
3545
|
+
texture: g.createTexture({
|
|
3546
|
+
data: _,
|
|
3547
|
+
format: w,
|
|
3548
|
+
width: _.width,
|
|
3549
|
+
height: _.height,
|
|
3550
|
+
sampler: l
|
|
3551
|
+
}),
|
|
3552
|
+
height: _.height,
|
|
3553
|
+
width: _.width
|
|
3554
|
+
};
|
|
3555
|
+
}, renderTile: (m) => c.map((p, g) => co(p, m)) };
|
|
3556
|
+
}
|
|
3557
|
+
function ao(n, t, e) {
|
|
3558
|
+
switch (n) {
|
|
3559
|
+
case F.RGB:
|
|
3560
|
+
return null;
|
|
3561
|
+
case F.Palette: {
|
|
3562
|
+
if (!e)
|
|
3563
|
+
throw new Error("ColorMap is required for PhotometricInterpretation Palette");
|
|
3564
|
+
const { data: s, width: i, height: o } = Qi(e), r = t.createTexture({
|
|
3565
|
+
data: s,
|
|
3566
|
+
format: "rgba8unorm",
|
|
3567
|
+
width: i,
|
|
3568
|
+
height: o,
|
|
3569
|
+
sampler: {
|
|
3570
|
+
minFilter: "nearest",
|
|
3571
|
+
magFilter: "nearest",
|
|
3572
|
+
addressModeU: "clamp-to-edge",
|
|
3573
|
+
addressModeV: "clamp-to-edge"
|
|
3574
|
+
}
|
|
3575
|
+
});
|
|
3576
|
+
return {
|
|
3577
|
+
module: ss,
|
|
3578
|
+
props: {
|
|
3579
|
+
colormapTexture: r
|
|
3580
|
+
}
|
|
3581
|
+
};
|
|
3582
|
+
}
|
|
3583
|
+
case F.CMYK:
|
|
3584
|
+
return {
|
|
3585
|
+
module: es
|
|
3586
|
+
};
|
|
3587
|
+
case F.YCbCr:
|
|
3588
|
+
return {
|
|
3589
|
+
module: ts
|
|
3590
|
+
};
|
|
3591
|
+
case F.CIELab:
|
|
3592
|
+
return {
|
|
3593
|
+
module: Je
|
|
3594
|
+
};
|
|
3595
|
+
default:
|
|
3596
|
+
throw new Error(`Unsupported PhotometricInterpretation ${n}`);
|
|
3597
|
+
}
|
|
3598
|
+
}
|
|
3599
|
+
function co(n, t) {
|
|
3600
|
+
const { module: e, props: s } = n;
|
|
3601
|
+
if (!s)
|
|
3602
|
+
return { module: e };
|
|
3603
|
+
const i = {};
|
|
3604
|
+
for (const [o, r] of Object.entries(s)) {
|
|
3605
|
+
const a = typeof r == "function" ? r(t) : r;
|
|
3606
|
+
a !== void 0 && (i[o] = a);
|
|
3607
|
+
}
|
|
3608
|
+
return { module: e, props: i };
|
|
3609
|
+
}
|
|
3610
|
+
async function Dt(n) {
|
|
3611
|
+
const t = n.ProjectedCSTypeGeoKey || n.GeographicTypeGeoKey || null, e = await lo(t);
|
|
3612
|
+
if (!e)
|
|
3613
|
+
return null;
|
|
3614
|
+
const s = ke(e);
|
|
3615
|
+
return {
|
|
3616
|
+
def: e,
|
|
3617
|
+
parsed: s,
|
|
3618
|
+
coordinatesUnits: s.units
|
|
3619
|
+
};
|
|
3620
|
+
}
|
|
3621
|
+
async function lo(n) {
|
|
3622
|
+
if (n === null)
|
|
3623
|
+
return null;
|
|
3624
|
+
const t = `https://epsg.io/${n}.json`, e = await fetch(t);
|
|
3625
|
+
if (!e.ok)
|
|
3626
|
+
throw new Error(`Failed to fetch projection data from ${t}`);
|
|
3627
|
+
return await e.json();
|
|
3628
|
+
}
|
|
3629
|
+
function ke(n) {
|
|
3630
|
+
const t = "__deck.gl-geotiff-internal__";
|
|
3631
|
+
return q.defs(t, n), q.defs(t);
|
|
3632
|
+
}
|
|
3633
|
+
const So = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
3634
|
+
__proto__: null,
|
|
3635
|
+
epsgIoGeoKeyParser: Dt,
|
|
3636
|
+
parseCrs: ke
|
|
3637
|
+
}, Symbol.toStringTag, { value: "Module" })), ho = {
|
|
3638
|
+
geoKeysParser: Dt,
|
|
3639
|
+
debug: !1,
|
|
3640
|
+
debugOpacity: 0.5
|
|
3641
|
+
};
|
|
3642
|
+
class Co extends V {
|
|
3643
|
+
static layerName = "COGLayer";
|
|
3644
|
+
static defaultProps = ho;
|
|
3645
|
+
initializeState() {
|
|
3646
|
+
this.setState({});
|
|
3647
|
+
}
|
|
3648
|
+
updateState(t) {
|
|
3649
|
+
super.updateState(t);
|
|
3650
|
+
const { props: e, oldProps: s, changeFlags: i } = t;
|
|
3651
|
+
(i.dataChanged || e.geotiff !== s.geotiff) && this._parseGeoTIFF();
|
|
3652
|
+
}
|
|
3653
|
+
async _parseGeoTIFF() {
|
|
3654
|
+
const t = await We(this.props.geotiff), e = this.props.geoKeysParser, s = await $i(t, e), i = await t.getImage(), o = await t.getImageCount(), r = [];
|
|
3655
|
+
for (let f = 0; f < o; f++)
|
|
3656
|
+
r.push(await t.getImage(f));
|
|
3657
|
+
const a = await e(i.getGeoKeys());
|
|
3658
|
+
if (!a)
|
|
3659
|
+
throw new Error("Could not determine source projection from GeoTIFF geo keys");
|
|
3660
|
+
const c = q(a.def, "EPSG:4326"), h = (f, m) => c.forward([f, m], !1), u = (f, m) => c.inverse([f, m], !1);
|
|
3661
|
+
if (this.props.onGeoTIFFLoad) {
|
|
3662
|
+
const f = Ve(i, c);
|
|
3663
|
+
this.props.onGeoTIFFLoad(t, {
|
|
3664
|
+
projection: a,
|
|
3665
|
+
geographicBounds: f
|
|
3666
|
+
});
|
|
3667
|
+
}
|
|
3668
|
+
const { getTileData: l, renderTile: d } = oo(i.fileDirectory, this.context.device);
|
|
3669
|
+
this.setState({
|
|
3670
|
+
metadata: s,
|
|
3671
|
+
forwardReproject: h,
|
|
3672
|
+
inverseReproject: u,
|
|
3673
|
+
images: r,
|
|
3674
|
+
defaultGetTileData: l,
|
|
3675
|
+
defaultRenderTile: d
|
|
3676
|
+
});
|
|
3677
|
+
}
|
|
3678
|
+
/**
|
|
3679
|
+
* Inner callback passed in to the underlying TileLayer's `getTileData`.
|
|
3680
|
+
*/
|
|
3681
|
+
async _getTileData(t, e, s) {
|
|
3682
|
+
const { signal: i } = t, { x: o, y: r, z: a } = t.index, c = e[e.length - 1 - a], h = c.getHeight(), u = c.getWidth(), l = s.tileMatrices[a], { tileWidth: d, tileHeight: f } = l, m = uo(o, r, l), { forwardTransform: p, inverseTransform: g } = qe(m), y = [
|
|
3683
|
+
o * d,
|
|
3684
|
+
r * f,
|
|
3685
|
+
Math.min((o + 1) * d, u),
|
|
3686
|
+
Math.min((r + 1) * f, h)
|
|
3687
|
+
], _ = this.props.getTileData || this.state.defaultGetTileData, x = i && this.props.signal ? AbortSignal.any([i, this.props.signal]) : i || this.props.signal;
|
|
3688
|
+
return {
|
|
3689
|
+
// @ts-expect-error type mismatch when using provided getTileData
|
|
3690
|
+
data: await _(c, {
|
|
3691
|
+
device: this.context.device,
|
|
3692
|
+
window: y,
|
|
3693
|
+
signal: x,
|
|
3694
|
+
pool: this.props.pool || De()
|
|
3695
|
+
}),
|
|
3696
|
+
forwardTransform: p,
|
|
3697
|
+
inverseTransform: g
|
|
3698
|
+
};
|
|
3699
|
+
}
|
|
3700
|
+
_renderSubLayers(t, e, s, i) {
|
|
3701
|
+
const { maxError: o, debug: r, debugOpacity: a } = this.props, { tile: c } = t;
|
|
3702
|
+
if (!t.data)
|
|
3703
|
+
return null;
|
|
3704
|
+
const { data: h, forwardTransform: u, inverseTransform: l } = t.data, d = [];
|
|
3705
|
+
if (h) {
|
|
3706
|
+
const { height: f, width: m } = h, p = this.props.renderTile || this.state.defaultRenderTile;
|
|
3707
|
+
d.push(new Ne({
|
|
3708
|
+
id: `${t.id}-raster`,
|
|
3709
|
+
width: m,
|
|
3710
|
+
height: f,
|
|
3711
|
+
renderPipeline: p(h),
|
|
3712
|
+
maxError: o,
|
|
3713
|
+
reprojectionFns: {
|
|
3714
|
+
forwardTransform: u,
|
|
3715
|
+
inverseTransform: l,
|
|
3716
|
+
forwardReproject: s,
|
|
3717
|
+
inverseReproject: i
|
|
3718
|
+
},
|
|
3719
|
+
debug: r,
|
|
3720
|
+
debugOpacity: a
|
|
3721
|
+
}));
|
|
3722
|
+
}
|
|
3723
|
+
if (r) {
|
|
3724
|
+
const f = c?.projectedBounds;
|
|
3725
|
+
if (!f || !e)
|
|
3726
|
+
return [];
|
|
3727
|
+
const { topLeft: m, topRight: p, bottomLeft: g, bottomRight: y } = f, _ = e.projectToWgs84(m), x = e.projectToWgs84(p), w = e.projectToWgs84(y), T = e.projectToWgs84(g), S = [
|
|
3728
|
+
_,
|
|
3729
|
+
x,
|
|
3730
|
+
w,
|
|
3731
|
+
T,
|
|
3732
|
+
_
|
|
3733
|
+
// Close the path
|
|
3734
|
+
];
|
|
3735
|
+
d.push(new Se({
|
|
3736
|
+
id: `${this.id}-${c.id}-bounds`,
|
|
3737
|
+
data: [S],
|
|
3738
|
+
getPath: (L) => L,
|
|
3739
|
+
getColor: [255, 0, 0, 255],
|
|
3740
|
+
// Red
|
|
3741
|
+
getWidth: 2,
|
|
3742
|
+
widthUnits: "pixels",
|
|
3743
|
+
pickable: !1
|
|
3744
|
+
}));
|
|
3745
|
+
}
|
|
3746
|
+
return d;
|
|
3747
|
+
}
|
|
3748
|
+
renderTileLayer(t, e, s, i) {
|
|
3749
|
+
class o extends Ui {
|
|
3750
|
+
constructor(a) {
|
|
3751
|
+
super(t, a);
|
|
3752
|
+
}
|
|
3753
|
+
}
|
|
3754
|
+
return new ct({
|
|
3755
|
+
id: `cog-tile-layer-${this.id}`,
|
|
3756
|
+
TilesetClass: o,
|
|
3757
|
+
getTileData: async (r) => this._getTileData(r, i, t),
|
|
3758
|
+
renderSubLayers: (r) => this._renderSubLayers(r, t, e, s)
|
|
3759
|
+
});
|
|
3760
|
+
}
|
|
3761
|
+
renderLayers() {
|
|
3762
|
+
const { forwardReproject: t, inverseReproject: e, metadata: s, images: i } = this.state;
|
|
3763
|
+
return !t || !e || !s || !i ? null : this.renderTileLayer(s, t, e, i);
|
|
3764
|
+
}
|
|
3765
|
+
}
|
|
3766
|
+
function uo(n, t, e) {
|
|
3767
|
+
const { tileWidth: s, tileHeight: i } = e, o = n * s, r = t * i, [a, c, h, u, l, d] = e.geotransform, f = a * o + c * r + h, m = u * o + l * r + d;
|
|
3768
|
+
return [a, c, f, u, l, m];
|
|
3769
|
+
}
|
|
3770
|
+
const fo = {
|
|
3771
|
+
geoKeysParser: Dt
|
|
3772
|
+
};
|
|
3773
|
+
class Lo extends V {
|
|
3774
|
+
static layerName = "GeoTIFFLayer";
|
|
3775
|
+
static defaultProps = fo;
|
|
3776
|
+
initializeState() {
|
|
3777
|
+
this.setState({});
|
|
3778
|
+
}
|
|
3779
|
+
updateState(t) {
|
|
3780
|
+
super.updateState(t);
|
|
3781
|
+
const { props: e, oldProps: s, changeFlags: i } = t;
|
|
3782
|
+
(i.dataChanged || e.geotiff !== s.geotiff || e.maxError !== s.maxError) && this._parseGeoTIFF();
|
|
3783
|
+
}
|
|
3784
|
+
async _parseGeoTIFF() {
|
|
3785
|
+
const t = await We(this.props.geotiff), e = await t.getImage(), s = this.props.geoKeysParser, i = await s(e.getGeoKeys());
|
|
3786
|
+
if (!i)
|
|
3787
|
+
throw new Error("Could not determine source projection from GeoTIFF geo keys");
|
|
3788
|
+
const o = q(i.def, "EPSG:4326");
|
|
3789
|
+
if (this.props.onGeoTIFFLoad) {
|
|
3790
|
+
const u = Ve(e, o);
|
|
3791
|
+
this.props.onGeoTIFFLoad(t, {
|
|
3792
|
+
projection: i,
|
|
3793
|
+
geographicBounds: u
|
|
3794
|
+
});
|
|
3795
|
+
}
|
|
3796
|
+
const r = await Yi(t, i.def), { texture: a, height: c, width: h } = await Ki(e, {
|
|
3797
|
+
pool: this.props.pool || De()
|
|
3798
|
+
});
|
|
3799
|
+
this.setState({
|
|
3800
|
+
reprojectionFns: r,
|
|
3801
|
+
imageData: a,
|
|
3802
|
+
height: c,
|
|
3803
|
+
width: h
|
|
3804
|
+
});
|
|
3805
|
+
}
|
|
3806
|
+
renderLayers() {
|
|
3807
|
+
const { reprojectionFns: t, imageData: e, height: s, width: i } = this.state;
|
|
3808
|
+
if (!t || !e || !s || !i)
|
|
3809
|
+
return null;
|
|
3810
|
+
const { maxError: o, debug: r, debugOpacity: a } = this.props;
|
|
3811
|
+
return new Ne(this.getSubLayerProps({
|
|
3812
|
+
id: "raster",
|
|
3813
|
+
width: i,
|
|
3814
|
+
height: s,
|
|
3815
|
+
reprojectionFns: t,
|
|
3816
|
+
maxError: o,
|
|
3817
|
+
texture: e,
|
|
3818
|
+
debug: r,
|
|
3819
|
+
debugOpacity: a
|
|
3820
|
+
}));
|
|
3821
|
+
}
|
|
3822
|
+
}
|
|
3823
|
+
class mo {
|
|
3824
|
+
constructor() {
|
|
3825
|
+
this.ids = [], this.values = [], this.length = 0;
|
|
3826
|
+
}
|
|
3827
|
+
/** Removes all items from the queue. */
|
|
3828
|
+
clear() {
|
|
3829
|
+
this.length = 0;
|
|
3830
|
+
}
|
|
3831
|
+
/**
|
|
3832
|
+
* Adds `item` to the queue with the specified `priority`.
|
|
3833
|
+
*
|
|
3834
|
+
* `priority` must be a number. Items are sorted and returned from low to high priority. Multiple items
|
|
3835
|
+
* with the same priority value can be added to the queue, but there is no guaranteed order between these items.
|
|
3836
|
+
*
|
|
3837
|
+
* @param {T} item
|
|
3838
|
+
* @param {number} priority
|
|
3839
|
+
*/
|
|
3840
|
+
push(t, e) {
|
|
3841
|
+
let s = this.length++;
|
|
3842
|
+
for (; s > 0; ) {
|
|
3843
|
+
const i = s - 1 >> 1, o = this.values[i];
|
|
3844
|
+
if (e >= o) break;
|
|
3845
|
+
this.ids[s] = this.ids[i], this.values[s] = o, s = i;
|
|
3846
|
+
}
|
|
3847
|
+
this.ids[s] = t, this.values[s] = e;
|
|
3848
|
+
}
|
|
3849
|
+
/**
|
|
3850
|
+
* Removes and returns the item from the head of this queue, which is one of
|
|
3851
|
+
* the items with the lowest priority. If this queue is empty, returns `undefined`.
|
|
3852
|
+
*/
|
|
3853
|
+
pop() {
|
|
3854
|
+
if (this.length === 0) return;
|
|
3855
|
+
const t = this.ids, e = this.values, s = t[0], i = --this.length;
|
|
3856
|
+
if (i > 0) {
|
|
3857
|
+
const o = t[i], r = e[i];
|
|
3858
|
+
let a = 0;
|
|
3859
|
+
const c = i >> 1;
|
|
3860
|
+
for (; a < c; ) {
|
|
3861
|
+
const h = (a << 1) + 1, u = h + 1, l = h + (+(u < i) & +(e[u] < e[h]));
|
|
3862
|
+
if (e[l] >= r) break;
|
|
3863
|
+
t[a] = t[l], e[a] = e[l], a = l;
|
|
3864
|
+
}
|
|
3865
|
+
t[a] = o, e[a] = r;
|
|
3866
|
+
}
|
|
3867
|
+
return s;
|
|
3868
|
+
}
|
|
3869
|
+
/** Returns the item from the head of this queue without removing it. If this queue is empty, returns `undefined`. */
|
|
3870
|
+
peek() {
|
|
3871
|
+
return this.length > 0 ? this.ids[0] : void 0;
|
|
3872
|
+
}
|
|
3873
|
+
/**
|
|
3874
|
+
* Returns the priority value of the item at the head of this queue without
|
|
3875
|
+
* removing it. If this queue is empty, returns `undefined`.
|
|
3876
|
+
*/
|
|
3877
|
+
peekValue() {
|
|
3878
|
+
return this.length > 0 ? this.values[0] : void 0;
|
|
3879
|
+
}
|
|
3880
|
+
/**
|
|
3881
|
+
* Shrinks the internal arrays to `this.length`.
|
|
3882
|
+
*
|
|
3883
|
+
* `pop()` and `clear()` calls don't free memory automatically to avoid unnecessary resize operations.
|
|
3884
|
+
* This also means that items that have been added to the queue can't be garbage collected until
|
|
3885
|
+
* a new item is pushed in their place, or this method is called.
|
|
3886
|
+
*/
|
|
3887
|
+
shrink() {
|
|
3888
|
+
this.ids.length = this.values.length = this.length;
|
|
3889
|
+
}
|
|
3890
|
+
}
|
|
3891
|
+
const ye = [Int8Array, Uint8Array, Uint8ClampedArray, Int16Array, Uint16Array, Int32Array, Uint32Array, Float32Array, Float64Array], _t = 3;
|
|
3892
|
+
class Ut {
|
|
3893
|
+
/**
|
|
3894
|
+
* Recreate a Flatbush index from raw `ArrayBuffer` or `SharedArrayBuffer` data.
|
|
3895
|
+
* @param {ArrayBufferLike} data
|
|
3896
|
+
* @param {number} [byteOffset=0] byte offset to the start of the Flatbush buffer in the referenced ArrayBuffer.
|
|
3897
|
+
* @returns {Flatbush} index
|
|
3898
|
+
*/
|
|
3899
|
+
static from(t, e = 0) {
|
|
3900
|
+
if (e % 8 !== 0)
|
|
3901
|
+
throw new Error("byteOffset must be 8-byte aligned.");
|
|
3902
|
+
if (!t || t.byteLength === void 0 || t.buffer)
|
|
3903
|
+
throw new Error("Data must be an instance of ArrayBuffer or SharedArrayBuffer.");
|
|
3904
|
+
const [s, i] = new Uint8Array(t, e + 0, 2);
|
|
3905
|
+
if (s !== 251)
|
|
3906
|
+
throw new Error("Data does not appear to be in a Flatbush format.");
|
|
3907
|
+
const o = i >> 4;
|
|
3908
|
+
if (o !== _t)
|
|
3909
|
+
throw new Error(`Got v${o} data when expected v${_t}.`);
|
|
3910
|
+
const r = ye[i & 15];
|
|
3911
|
+
if (!r)
|
|
3912
|
+
throw new Error("Unrecognized array type.");
|
|
3913
|
+
const [a] = new Uint16Array(t, e + 2, 1), [c] = new Uint32Array(t, e + 4, 1);
|
|
3914
|
+
return new Ut(c, a, r, void 0, t, e);
|
|
3915
|
+
}
|
|
3916
|
+
/**
|
|
3917
|
+
* Create a Flatbush index that will hold a given number of items.
|
|
3918
|
+
* @param {number} numItems
|
|
3919
|
+
* @param {number} [nodeSize=16] Size of the tree node (16 by default).
|
|
3920
|
+
* @param {TypedArrayConstructor} [ArrayType=Float64Array] The array type used for coordinates storage (`Float64Array` by default).
|
|
3921
|
+
* @param {ArrayBufferConstructor | SharedArrayBufferConstructor} [ArrayBufferType=ArrayBuffer] The array buffer type used to store data (`ArrayBuffer` by default).
|
|
3922
|
+
* @param {ArrayBufferLike} [data] (Only used internally)
|
|
3923
|
+
* @param {number} [byteOffset=0] (Only used internally)
|
|
3924
|
+
*/
|
|
3925
|
+
constructor(t, e = 16, s = Float64Array, i = ArrayBuffer, o, r = 0) {
|
|
3926
|
+
if (t === void 0) throw new Error("Missing required argument: numItems.");
|
|
3927
|
+
if (isNaN(t) || t <= 0) throw new Error(`Unexpected numItems value: ${t}.`);
|
|
3928
|
+
this.numItems = +t, this.nodeSize = Math.min(Math.max(+e, 2), 65535), this.byteOffset = r;
|
|
3929
|
+
let a = t, c = a;
|
|
3930
|
+
this._levelBounds = [a * 4];
|
|
3931
|
+
do
|
|
3932
|
+
a = Math.ceil(a / this.nodeSize), c += a, this._levelBounds.push(c * 4);
|
|
3933
|
+
while (a !== 1);
|
|
3934
|
+
this.ArrayType = s, this.IndexArrayType = c < 16384 ? Uint16Array : Uint32Array;
|
|
3935
|
+
const h = ye.indexOf(s), u = c * 4 * s.BYTES_PER_ELEMENT;
|
|
3936
|
+
if (h < 0)
|
|
3937
|
+
throw new Error(`Unexpected typed array class: ${s}.`);
|
|
3938
|
+
if (o)
|
|
3939
|
+
this.data = o, this._boxes = new s(o, r + 8, c * 4), this._indices = new this.IndexArrayType(o, r + 8 + u, c), this._pos = c * 4, this.minX = this._boxes[this._pos - 4], this.minY = this._boxes[this._pos - 3], this.maxX = this._boxes[this._pos - 2], this.maxY = this._boxes[this._pos - 1];
|
|
3940
|
+
else {
|
|
3941
|
+
const l = this.data = new i(8 + u + c * this.IndexArrayType.BYTES_PER_ELEMENT);
|
|
3942
|
+
this._boxes = new s(l, 8, c * 4), this._indices = new this.IndexArrayType(l, 8 + u, c), this._pos = 0, this.minX = 1 / 0, this.minY = 1 / 0, this.maxX = -1 / 0, this.maxY = -1 / 0, new Uint8Array(l, 0, 2).set([251, (_t << 4) + h]), new Uint16Array(l, 2, 1)[0] = e, new Uint32Array(l, 4, 1)[0] = t;
|
|
3943
|
+
}
|
|
3944
|
+
this._queue = new mo();
|
|
3945
|
+
}
|
|
3946
|
+
/**
|
|
3947
|
+
* Add a given rectangle to the index.
|
|
3948
|
+
* @param {number} minX
|
|
3949
|
+
* @param {number} minY
|
|
3950
|
+
* @param {number} maxX
|
|
3951
|
+
* @param {number} maxY
|
|
3952
|
+
* @returns {number} A zero-based, incremental number that represents the newly added rectangle.
|
|
3953
|
+
*/
|
|
3954
|
+
add(t, e, s = t, i = e) {
|
|
3955
|
+
const o = this._pos >> 2, r = this._boxes;
|
|
3956
|
+
return this._indices[o] = o, r[this._pos++] = t, r[this._pos++] = e, r[this._pos++] = s, r[this._pos++] = i, t < this.minX && (this.minX = t), e < this.minY && (this.minY = e), s > this.maxX && (this.maxX = s), i > this.maxY && (this.maxY = i), o;
|
|
3957
|
+
}
|
|
3958
|
+
/** Perform indexing of the added rectangles. */
|
|
3959
|
+
finish() {
|
|
3960
|
+
if (this._pos >> 2 !== this.numItems)
|
|
3961
|
+
throw new Error(`Added ${this._pos >> 2} items when expected ${this.numItems}.`);
|
|
3962
|
+
const t = this._boxes;
|
|
3963
|
+
if (this.numItems <= this.nodeSize) {
|
|
3964
|
+
t[this._pos++] = this.minX, t[this._pos++] = this.minY, t[this._pos++] = this.maxX, t[this._pos++] = this.maxY;
|
|
3965
|
+
return;
|
|
3966
|
+
}
|
|
3967
|
+
const e = this.maxX - this.minX || 1, s = this.maxY - this.minY || 1, i = new Uint32Array(this.numItems), o = 65535;
|
|
3968
|
+
for (let r = 0, a = 0; r < this.numItems; r++) {
|
|
3969
|
+
const c = t[a++], h = t[a++], u = t[a++], l = t[a++], d = Math.floor(o * ((c + u) / 2 - this.minX) / e), f = Math.floor(o * ((h + l) / 2 - this.minY) / s);
|
|
3970
|
+
i[r] = go(d, f);
|
|
3971
|
+
}
|
|
3972
|
+
Lt(i, t, this._indices, 0, this.numItems - 1, this.nodeSize);
|
|
3973
|
+
for (let r = 0, a = 0; r < this._levelBounds.length - 1; r++) {
|
|
3974
|
+
const c = this._levelBounds[r];
|
|
3975
|
+
for (; a < c; ) {
|
|
3976
|
+
const h = a;
|
|
3977
|
+
let u = t[a++], l = t[a++], d = t[a++], f = t[a++];
|
|
3978
|
+
for (let m = 1; m < this.nodeSize && a < c; m++)
|
|
3979
|
+
u = Math.min(u, t[a++]), l = Math.min(l, t[a++]), d = Math.max(d, t[a++]), f = Math.max(f, t[a++]);
|
|
3980
|
+
this._indices[this._pos >> 2] = h, t[this._pos++] = u, t[this._pos++] = l, t[this._pos++] = d, t[this._pos++] = f;
|
|
3981
|
+
}
|
|
3982
|
+
}
|
|
3983
|
+
}
|
|
3984
|
+
/**
|
|
3985
|
+
* Search the index by a bounding box.
|
|
3986
|
+
* @param {number} minX
|
|
3987
|
+
* @param {number} minY
|
|
3988
|
+
* @param {number} maxX
|
|
3989
|
+
* @param {number} maxY
|
|
3990
|
+
* @param {(index: number, x0: number, y0: number, x1: number, y1: number) => boolean} [filterFn] An optional function that is called on every found item; if supplied, only items for which this function returns true will be included in the results array.
|
|
3991
|
+
* @returns {number[]} An array of indices of items intersecting or touching the given bounding box.
|
|
3992
|
+
*/
|
|
3993
|
+
search(t, e, s, i, o) {
|
|
3994
|
+
if (this._pos !== this._boxes.length)
|
|
3995
|
+
throw new Error("Data not yet indexed - call index.finish().");
|
|
3996
|
+
let r = this._boxes.length - 4;
|
|
3997
|
+
const a = [], c = [];
|
|
3998
|
+
for (; r !== void 0; ) {
|
|
3999
|
+
const h = Math.min(r + this.nodeSize * 4, _e(r, this._levelBounds));
|
|
4000
|
+
for (let u = r; u < h; u += 4) {
|
|
4001
|
+
const l = this._boxes[u];
|
|
4002
|
+
if (s < l) continue;
|
|
4003
|
+
const d = this._boxes[u + 1];
|
|
4004
|
+
if (i < d) continue;
|
|
4005
|
+
const f = this._boxes[u + 2];
|
|
4006
|
+
if (t > f) continue;
|
|
4007
|
+
const m = this._boxes[u + 3];
|
|
4008
|
+
if (e > m) continue;
|
|
4009
|
+
const p = this._indices[u >> 2] | 0;
|
|
4010
|
+
r >= this.numItems * 4 ? a.push(p) : (o === void 0 || o(p, l, d, f, m)) && c.push(p);
|
|
4011
|
+
}
|
|
4012
|
+
r = a.pop();
|
|
4013
|
+
}
|
|
4014
|
+
return c;
|
|
4015
|
+
}
|
|
4016
|
+
/**
|
|
4017
|
+
* Search items in order of distance from the given point.
|
|
4018
|
+
* @param {number} x
|
|
4019
|
+
* @param {number} y
|
|
4020
|
+
* @param {number} [maxResults=Infinity]
|
|
4021
|
+
* @param {number} [maxDistance=Infinity]
|
|
4022
|
+
* @param {(index: number) => boolean} [filterFn] An optional function for filtering the results.
|
|
4023
|
+
* @returns {number[]} An array of indices of items found.
|
|
4024
|
+
*/
|
|
4025
|
+
neighbors(t, e, s = 1 / 0, i = 1 / 0, o) {
|
|
4026
|
+
if (this._pos !== this._boxes.length)
|
|
4027
|
+
throw new Error("Data not yet indexed - call index.finish().");
|
|
4028
|
+
let r = this._boxes.length - 4;
|
|
4029
|
+
const a = this._queue, c = [], h = i * i;
|
|
4030
|
+
t: for (; r !== void 0; ) {
|
|
4031
|
+
const u = Math.min(r + this.nodeSize * 4, _e(r, this._levelBounds));
|
|
4032
|
+
for (let l = r; l < u; l += 4) {
|
|
4033
|
+
const d = this._indices[l >> 2] | 0, f = this._boxes[l], m = this._boxes[l + 1], p = this._boxes[l + 2], g = this._boxes[l + 3], y = t < f ? f - t : t > p ? t - p : 0, _ = e < m ? m - e : e > g ? e - g : 0, x = y * y + _ * _;
|
|
4034
|
+
x > h || (r >= this.numItems * 4 ? a.push(d << 1, x) : (o === void 0 || o(d)) && a.push((d << 1) + 1, x));
|
|
4035
|
+
}
|
|
4036
|
+
for (; a.length && a.peek() & 1; )
|
|
4037
|
+
if (a.peekValue() > h || (c.push(a.pop() >> 1), c.length === s)) break t;
|
|
4038
|
+
r = a.length ? a.pop() >> 1 : void 0;
|
|
4039
|
+
}
|
|
4040
|
+
return a.clear(), c;
|
|
4041
|
+
}
|
|
4042
|
+
}
|
|
4043
|
+
function _e(n, t) {
|
|
4044
|
+
let e = 0, s = t.length - 1;
|
|
4045
|
+
for (; e < s; ) {
|
|
4046
|
+
const i = e + s >> 1;
|
|
4047
|
+
t[i] > n ? s = i : e = i + 1;
|
|
4048
|
+
}
|
|
4049
|
+
return t[e];
|
|
4050
|
+
}
|
|
4051
|
+
function Lt(n, t, e, s, i, o) {
|
|
4052
|
+
if (Math.floor(s / o) >= Math.floor(i / o)) return;
|
|
4053
|
+
const r = n[s], a = n[s + i >> 1], c = n[i];
|
|
4054
|
+
let h = c;
|
|
4055
|
+
const u = Math.max(r, a);
|
|
4056
|
+
c > u ? h = u : u === r ? h = Math.max(a, c) : u === a && (h = Math.max(r, c));
|
|
4057
|
+
let l = s - 1, d = i + 1;
|
|
4058
|
+
for (; ; ) {
|
|
4059
|
+
do
|
|
4060
|
+
l++;
|
|
4061
|
+
while (n[l] < h);
|
|
4062
|
+
do
|
|
4063
|
+
d--;
|
|
4064
|
+
while (n[d] > h);
|
|
4065
|
+
if (l >= d) break;
|
|
4066
|
+
po(n, t, e, l, d);
|
|
4067
|
+
}
|
|
4068
|
+
Lt(n, t, e, s, d, o), Lt(n, t, e, d + 1, i, o);
|
|
4069
|
+
}
|
|
4070
|
+
function po(n, t, e, s, i) {
|
|
4071
|
+
const o = n[s];
|
|
4072
|
+
n[s] = n[i], n[i] = o;
|
|
4073
|
+
const r = 4 * s, a = 4 * i, c = t[r], h = t[r + 1], u = t[r + 2], l = t[r + 3];
|
|
4074
|
+
t[r] = t[a], t[r + 1] = t[a + 1], t[r + 2] = t[a + 2], t[r + 3] = t[a + 3], t[a] = c, t[a + 1] = h, t[a + 2] = u, t[a + 3] = l;
|
|
4075
|
+
const d = e[s];
|
|
4076
|
+
e[s] = e[i], e[i] = d;
|
|
4077
|
+
}
|
|
4078
|
+
function go(n, t) {
|
|
4079
|
+
let e = n ^ t, s = 65535 ^ e, i = 65535 ^ (n | t), o = n & (t ^ 65535), r = e | s >> 1, a = e >> 1 ^ e, c = i >> 1 ^ s & o >> 1 ^ i, h = e & i >> 1 ^ o >> 1 ^ o;
|
|
4080
|
+
e = r, s = a, i = c, o = h, r = e & e >> 2 ^ s & s >> 2, a = e & s >> 2 ^ s & (e ^ s) >> 2, c ^= e & i >> 2 ^ s & o >> 2, h ^= s & i >> 2 ^ (e ^ s) & o >> 2, e = r, s = a, i = c, o = h, r = e & e >> 4 ^ s & s >> 4, a = e & s >> 4 ^ s & (e ^ s) >> 4, c ^= e & i >> 4 ^ s & o >> 4, h ^= s & i >> 4 ^ (e ^ s) & o >> 4, e = r, s = a, i = c, o = h, c ^= e & i >> 8 ^ s & o >> 8, h ^= s & i >> 8 ^ (e ^ s) & o >> 8, e = c ^ c >> 1, s = h ^ h >> 1;
|
|
4081
|
+
let u = n ^ t, l = s | 65535 ^ (u | e);
|
|
4082
|
+
return u = (u | u << 8) & 16711935, u = (u | u << 4) & 252645135, u = (u | u << 2) & 858993459, u = (u | u << 1) & 1431655765, l = (l | l << 8) & 16711935, l = (l | l << 4) & 252645135, l = (l | l << 2) & 858993459, l = (l | l << 1) & 1431655765, (l << 1 | u) >>> 0;
|
|
4083
|
+
}
|
|
4084
|
+
class yo extends Nt {
|
|
4085
|
+
sources;
|
|
4086
|
+
index;
|
|
4087
|
+
constructor(t, e) {
|
|
4088
|
+
super(e), this.sources = t.map((i, o) => ({
|
|
4089
|
+
x: i.x === void 0 ? o : i.x,
|
|
4090
|
+
y: i.y === void 0 ? 0 : i.y,
|
|
4091
|
+
z: i.z === void 0 ? 0 : i.z,
|
|
4092
|
+
...i
|
|
4093
|
+
}));
|
|
4094
|
+
const s = new Ut(t.length);
|
|
4095
|
+
for (const i of t) {
|
|
4096
|
+
const [o, r, a, c] = i.bbox;
|
|
4097
|
+
s.add(o, r, a, c);
|
|
4098
|
+
}
|
|
4099
|
+
s.finish(), this.index = s;
|
|
4100
|
+
}
|
|
4101
|
+
getTileIndices({ viewport: t, maxZoom: e, minZoom: s }) {
|
|
4102
|
+
if (t.zoom < (s ?? -1 / 0))
|
|
4103
|
+
return [];
|
|
4104
|
+
if (t.zoom > (e ?? 1 / 0))
|
|
4105
|
+
return [];
|
|
4106
|
+
const i = t.getBounds();
|
|
4107
|
+
return this.index.search(...i).map((r) => this.sources[r]);
|
|
4108
|
+
}
|
|
4109
|
+
}
|
|
4110
|
+
const _o = {};
|
|
4111
|
+
class Eo extends V {
|
|
4112
|
+
static layerName = "MosaicLayer";
|
|
4113
|
+
static defaultProps = _o;
|
|
4114
|
+
renderTileLayer(t, e) {
|
|
4115
|
+
const { id: s, minZoom: i, maxZoom: o, extent: r, maxCacheByteSize: a, maxCacheSize: c, maxRequests: h } = this.props;
|
|
4116
|
+
class u extends yo {
|
|
4117
|
+
constructor(d) {
|
|
4118
|
+
super(t, d);
|
|
4119
|
+
}
|
|
4120
|
+
}
|
|
4121
|
+
return new ct({
|
|
4122
|
+
id: `mosaic-layer-${s}`,
|
|
4123
|
+
TilesetClass: u,
|
|
4124
|
+
minZoom: i,
|
|
4125
|
+
maxZoom: o,
|
|
4126
|
+
extent: r,
|
|
4127
|
+
...a !== void 0 && { maxCacheByteSize: a },
|
|
4128
|
+
maxCacheSize: c,
|
|
4129
|
+
maxRequests: h,
|
|
4130
|
+
getTileData: async (l) => {
|
|
4131
|
+
const d = l.index, { signal: f } = l, m = this.props.getSource && await this.props.getSource(d, { signal: f });
|
|
4132
|
+
return {
|
|
4133
|
+
source: d,
|
|
4134
|
+
data: m,
|
|
4135
|
+
signal: f
|
|
4136
|
+
};
|
|
4137
|
+
},
|
|
4138
|
+
renderSubLayers: (l) => {
|
|
4139
|
+
const { data: d } = l, { source: f, signal: m, data: p } = d;
|
|
4140
|
+
return e(f, { data: p, signal: m });
|
|
4141
|
+
}
|
|
4142
|
+
});
|
|
4143
|
+
}
|
|
4144
|
+
renderLayers() {
|
|
4145
|
+
const { sources: t, renderSource: e } = this.props;
|
|
4146
|
+
return !t || t.length === 0 ? null : this.renderTileLayer(t, e);
|
|
4147
|
+
}
|
|
4148
|
+
}
|
|
4149
|
+
const Po = { ...Hi };
|
|
4150
|
+
export {
|
|
4151
|
+
Co as COGLayer,
|
|
4152
|
+
Lo as GeoTIFFLayer,
|
|
4153
|
+
Eo as MosaicLayer,
|
|
4154
|
+
yo as MosaicTileset2D,
|
|
4155
|
+
Po as __TEST_EXPORTS,
|
|
4156
|
+
Yi as extractGeotiffReprojectors,
|
|
4157
|
+
qe as fromGeoTransform,
|
|
4158
|
+
Ki as loadRgbImage,
|
|
4159
|
+
$i as parseCOGTileMatrixSet,
|
|
4160
|
+
Qi as parseColormap,
|
|
4161
|
+
So as proj,
|
|
4162
|
+
bo as texture
|
|
4163
|
+
};
|