@urban-toolkit/autk-grammar 5.2.0 → 5.3.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/README.md +133 -0
- package/build/autk-grammar-schema.json +182 -15
- package/dist/autk-grammar.js +731 -580
- package/dist/autk-grammar.js.map +1 -1
- package/dist/autk-grammar.umd.cjs +2 -2
- package/dist/autk-grammar.umd.cjs.map +1 -1
- package/dist/data/autk-grammar-data.cjs +1 -1
- package/dist/data/autk-grammar-data.cjs.map +1 -1
- package/dist/data/autk-grammar-data.js +48 -48
- package/dist/data/autk-grammar-data.js.map +1 -1
- package/dist/index.d.ts +144 -10
- package/package.json +1 -1
package/dist/autk-grammar.js
CHANGED
|
@@ -1,51 +1,51 @@
|
|
|
1
|
-
import { DEFAULT_WORKSPACE_NAME as
|
|
2
|
-
import { AutkMap as
|
|
3
|
-
import { AutkPlot as
|
|
4
|
-
import { ColorMapDomainStrategy as
|
|
5
|
-
import { AutkComputeEngine as
|
|
6
|
-
function
|
|
1
|
+
import { DEFAULT_WORKSPACE_NAME as U, isVectorTable as Ht, AutkDb as Jt, isRenderableTable as Et, DEFAULT_WORKSPACE_COORDINATE_FORMAT as qt } from "@urban-toolkit/autk-db";
|
|
2
|
+
import { AutkMap as nt, MapEvent as J } from "@urban-toolkit/autk-map";
|
|
3
|
+
import { AutkPlot as Kt, PlotStyle as F, PlotEvent as B } from "@urban-toolkit/autk-plot";
|
|
4
|
+
import { ColorMapDomainStrategy as A, ColorMapInterpolator as _t, ColorMap as P, valueAtPath as zt } from "@urban-toolkit/autk-core";
|
|
5
|
+
import { AutkComputeEngine as at } from "@urban-toolkit/autk-compute";
|
|
6
|
+
function Xt(t) {
|
|
7
7
|
const { spec: e, adapters: o } = t;
|
|
8
8
|
let r;
|
|
9
9
|
async function n() {
|
|
10
|
-
let
|
|
11
|
-
if (e.workspaces?.length && o.db.resolveWorkspaces && (
|
|
12
|
-
for (const
|
|
13
|
-
|
|
10
|
+
let l;
|
|
11
|
+
if (e.workspaces?.length && o.db.resolveWorkspaces && (l = await o.db.resolveWorkspaces(l, e.workspaces)), e.data)
|
|
12
|
+
for (const s of e.data)
|
|
13
|
+
l = await o.db.resolveSource(l, s);
|
|
14
14
|
if (e.compute)
|
|
15
|
-
for (const
|
|
16
|
-
|
|
15
|
+
for (const s of e.compute)
|
|
16
|
+
l = await o.compute.resolveCompute(l, s);
|
|
17
17
|
if (e.map)
|
|
18
18
|
if (Array.isArray(e.map))
|
|
19
|
-
for (let
|
|
20
|
-
let u = e.map[
|
|
21
|
-
await o.map.resolveMap(
|
|
19
|
+
for (let s = 0; s < e.map.length; s++) {
|
|
20
|
+
let u = e.map[s];
|
|
21
|
+
await o.map.resolveMap(l, u, s);
|
|
22
22
|
}
|
|
23
23
|
else
|
|
24
|
-
await o.map.resolveMap(
|
|
24
|
+
await o.map.resolveMap(l, e.map);
|
|
25
25
|
if (e.plot)
|
|
26
26
|
if (Array.isArray(e.plot))
|
|
27
|
-
for (let
|
|
28
|
-
await o.plot.resolvePlot(
|
|
27
|
+
for (let s = 0; s < e.plot.length; s++)
|
|
28
|
+
await o.plot.resolvePlot(l, e.plot[s], s);
|
|
29
29
|
else
|
|
30
|
-
await o.plot.resolvePlot(
|
|
31
|
-
r =
|
|
30
|
+
await o.plot.resolvePlot(l, e.plot);
|
|
31
|
+
r = l;
|
|
32
32
|
}
|
|
33
|
-
function l
|
|
34
|
-
return console.log("Spec to update",
|
|
35
|
-
|
|
33
|
+
function i(l) {
|
|
34
|
+
return console.log("Spec to update", l), new Promise((s) => {
|
|
35
|
+
s();
|
|
36
36
|
});
|
|
37
37
|
}
|
|
38
38
|
function a() {
|
|
39
39
|
console.log("Function not implemented yet");
|
|
40
40
|
}
|
|
41
|
-
return { run: n, updatedSpec:
|
|
41
|
+
return { run: n, updatedSpec: i, destroy: a, get context() {
|
|
42
42
|
return r;
|
|
43
43
|
} };
|
|
44
44
|
}
|
|
45
|
-
function
|
|
45
|
+
function it(t) {
|
|
46
46
|
return t === void 0 ? [] : Array.isArray(t) ? t : [t];
|
|
47
47
|
}
|
|
48
|
-
function
|
|
48
|
+
function go(t) {
|
|
49
49
|
const e = t.layout ?? {}, o = e.type ?? "vertical";
|
|
50
50
|
if (o !== "vertical" && o !== "horizontal" && o !== "grid")
|
|
51
51
|
throw new Error(`Layout type must be vertical, horizontal or grid, not ${JSON.stringify(o)}.`);
|
|
@@ -55,226 +55,226 @@ function to(t) {
|
|
|
55
55
|
const n = e.columns ?? 2;
|
|
56
56
|
if (!Number.isInteger(n) || n < 1)
|
|
57
57
|
throw new Error(`Layout columns must be a whole number, 1 or more, not ${JSON.stringify(n)}.`);
|
|
58
|
-
const
|
|
59
|
-
...
|
|
60
|
-
...
|
|
61
|
-
], a = o === "vertical" ? 1 : o === "horizontal" ? Math.max(
|
|
62
|
-
kind:
|
|
58
|
+
const i = [
|
|
59
|
+
...it(t.map).map((s, u) => ({ kind: "map", index: u, id: s.id, key: s.id ?? u })),
|
|
60
|
+
...it(t.plot).map((s, u) => ({ kind: "plot", index: u, id: s.id, key: s.id ?? s.dataRef }))
|
|
61
|
+
], a = o === "vertical" ? 1 : o === "horizontal" ? Math.max(i.length, 1) : n, l = i.map(({ kind: s, index: u, id: d, key: f }, c) => ({
|
|
62
|
+
kind: s,
|
|
63
63
|
index: u,
|
|
64
64
|
...d !== void 0 && { id: d },
|
|
65
|
-
key:
|
|
66
|
-
row: Math.floor(
|
|
67
|
-
column:
|
|
65
|
+
key: f,
|
|
66
|
+
row: Math.floor(c / a),
|
|
67
|
+
column: c % a
|
|
68
68
|
}));
|
|
69
|
-
return { type: o, rows: Math.ceil(
|
|
69
|
+
return { type: o, rows: Math.ceil(i.length / a), columns: a, gap: r, panes: l };
|
|
70
70
|
}
|
|
71
|
-
var
|
|
72
|
-
async function
|
|
73
|
-
const o = e ??
|
|
71
|
+
var Zt = /* @__PURE__ */ ((t) => (t.CAT_ACCENT = "schemeAccent", t.CAT_DARK2 = "schemeDark2", t.CAT_CATEGORY10 = "schemeCategory10", t.CAT_OBSERVABLE10 = "schemeObservable10", t.CAT_PAIRED = "schemePaired", t.CAT_PASTEL1 = "schemePastel1", t.CAT_PASTEL2 = "schemePastel2", t.CAT_SET1 = "schemeSet1", t.CAT_SET2 = "schemeSet2", t.CAT_SET3 = "schemeSet3", t.CAT_TABLEAU10 = "schemeTableau10", t.SEQ_REDS = "interpolateReds", t.SEQ_BLUES = "interpolateBlues", t.SEQ_GREENS = "interpolateGreens", t.SEQ_GREYS = "interpolateGreys", t.SEQ_ORANGES = "interpolateOranges", t.SEQ_PURPLES = "interpolatePurples", t.SEQ_TURBO = "interpolateTurbo", t.SEQ_VIRIDIS = "interpolateViridis", t.SEQ_INFERNO = "interpolateInferno", t.SEQ_MAGMA = "interpolateMagma", t.SEQ_PLASMA = "interpolatePlasma", t.SEQ_CIVIDIS = "interpolateCividis", t.SEQ_WARM = "interpolateWarm", t.SEQ_COOL = "interpolateCool", t.SEQ_CUBEHELIX_DEFAULT = "interpolateCubehelixDefault", t.SEQ_BU_GN = "interpolateBuGn", t.SEQ_BU_PU = "interpolateBuPu", t.SEQ_GN_BU = "interpolateGnBu", t.SEQ_OR_RD = "interpolateOrRd", t.SEQ_PU_BU_GN = "interpolatePuBuGn", t.SEQ_PU_BU = "interpolatePuBu", t.SEQ_PU_RD = "interpolatePuRd", t.SEQ_RD_PU = "interpolateRdPu", t.SEQ_YL_GN_BU = "interpolateYlGnBu", t.SEQ_YL_GN = "interpolateYlGn", t.SEQ_YL_OR_BR = "interpolateYlOrBr", t.SEQ_YL_OR_RD = "interpolateYlOrRd", t.DIV_BR_BG = "interpolateBrBG", t.DIV_PR_GN = "interpolatePRGn", t.DIV_PI_YG = "interpolatePiYG", t.DIV_PU_OR = "interpolatePuOr", t.DIV_RED_BLUE = "interpolateRdBu", t.DIV_RED_GREY = "interpolateRdGy", t.DIV_RED_YELLOW_BLUE = "interpolateRdYlBu", t.DIV_RED_YELLOW_GREEN = "interpolateRdYlGn", t.DIV_SPECTRAL = "interpolateSpectral", t))(Zt || {}), Ct = /* @__PURE__ */ ((t) => (t.MIN_MAX = "minMax", t.PERCENTILE = "percentile", t))(Ct || {});
|
|
72
|
+
async function I(t, e) {
|
|
73
|
+
const o = e ?? U;
|
|
74
74
|
t.getCurrentWorkspace() !== o && await t.setWorkspace(o);
|
|
75
75
|
}
|
|
76
|
-
function
|
|
77
|
-
return t === void 0 || t ===
|
|
76
|
+
function E(t, e) {
|
|
77
|
+
return t === void 0 || t === U ? e : `${t}/${e}`;
|
|
78
78
|
}
|
|
79
|
-
const
|
|
80
|
-
function
|
|
81
|
-
|
|
79
|
+
const te = /* @__PURE__ */ Symbol.for("@urban-toolkit/autk-grammar:source-crs"), ee = globalThis, $t = ee[te] ??= /* @__PURE__ */ new WeakMap();
|
|
80
|
+
function oe(t, e) {
|
|
81
|
+
$t.set(t, e);
|
|
82
82
|
}
|
|
83
|
-
function
|
|
84
|
-
const o = t &&
|
|
83
|
+
function re(t, e) {
|
|
84
|
+
const o = t && $t.get(t);
|
|
85
85
|
return o !== void 0 && o.toUpperCase() === e.toUpperCase() ? t : void 0;
|
|
86
86
|
}
|
|
87
|
-
function
|
|
87
|
+
function Mt(t) {
|
|
88
88
|
const e = /* @__PURE__ */ new Set();
|
|
89
89
|
for (const r of t)
|
|
90
90
|
r?.id != null && e.add(JSON.stringify(r.id));
|
|
91
91
|
const o = /* @__PURE__ */ new Set();
|
|
92
92
|
return t.map((r, n) => {
|
|
93
93
|
if (r?.id != null) return r.id;
|
|
94
|
-
let
|
|
95
|
-
for (; e.has(JSON.stringify(
|
|
96
|
-
return o.add(JSON.stringify(
|
|
94
|
+
let i = `autk-feature-${n}`;
|
|
95
|
+
for (; e.has(JSON.stringify(i)) || o.has(JSON.stringify(i)); ) i = `${i}-generated`;
|
|
96
|
+
return o.add(JSON.stringify(i)), i;
|
|
97
97
|
});
|
|
98
98
|
}
|
|
99
|
-
function
|
|
99
|
+
function kt(t) {
|
|
100
100
|
const e = /* @__PURE__ */ new Map();
|
|
101
|
-
return
|
|
101
|
+
return Mt(t).map((o) => {
|
|
102
102
|
const r = JSON.stringify(o), n = e.get(r) ?? 0;
|
|
103
103
|
return e.set(r, n + 1), n === 0 ? r : `${r} ${n}`;
|
|
104
104
|
});
|
|
105
105
|
}
|
|
106
|
-
const
|
|
107
|
-
function
|
|
108
|
-
let e =
|
|
106
|
+
const st = /* @__PURE__ */ new WeakMap();
|
|
107
|
+
function ne(t) {
|
|
108
|
+
let e = st.get(t);
|
|
109
109
|
return e || (e = /* @__PURE__ */ new Map(), t.forEach((o, r) => {
|
|
110
110
|
const n = e.get(o);
|
|
111
111
|
n ? n.push(r) : e.set(o, [r]);
|
|
112
|
-
}),
|
|
112
|
+
}), st.set(t, e), e);
|
|
113
113
|
}
|
|
114
114
|
function D(t, e, o) {
|
|
115
|
-
const r =
|
|
116
|
-
for (const
|
|
117
|
-
const a = e[
|
|
115
|
+
const r = ne(o), n = /* @__PURE__ */ new Set();
|
|
116
|
+
for (const i of t) {
|
|
117
|
+
const a = e[i];
|
|
118
118
|
if (a !== void 0)
|
|
119
|
-
for (const
|
|
119
|
+
for (const l of r.get(a) ?? []) n.add(l);
|
|
120
120
|
}
|
|
121
121
|
return [...n];
|
|
122
122
|
}
|
|
123
|
-
const
|
|
124
|
-
function
|
|
125
|
-
const e = t.features ?? [], o =
|
|
123
|
+
const ae = { type: "GeometryCollection", geometries: [] };
|
|
124
|
+
function ie(t) {
|
|
125
|
+
const e = t.features ?? [], o = Mt(e);
|
|
126
126
|
let r = !1;
|
|
127
|
-
const n = e.map((a,
|
|
128
|
-
return
|
|
127
|
+
const n = e.map((a, l) => a == null || a.id != null && a.geometry != null ? a : (r = !0, { ...a, id: o[l], geometry: a.geometry ?? ae })), i = e.findIndex((a) => a?.geometry != null);
|
|
128
|
+
return i > 0 && e[0] != null && e[0].geometry == null && ([n[0], n[i]] = [n[i], n[0]], r = !0), r ? { ...t, features: n } : t;
|
|
129
129
|
}
|
|
130
|
-
function
|
|
130
|
+
function se(t) {
|
|
131
131
|
const { queryArea: e } = t;
|
|
132
132
|
if (e.bbox === void 0) return { geocodeArea: e.geocodeArea, areas: e.areas };
|
|
133
|
-
const o = (
|
|
133
|
+
const o = (s) => new Error(`OSM source "${t.outputTableName}": ${s}`);
|
|
134
134
|
if (e.geocodeArea !== void 0 || e.areas !== void 0)
|
|
135
135
|
throw o("queryArea takes either bbox or geocodeArea with areas, not both.");
|
|
136
136
|
const r = e.bbox;
|
|
137
|
-
if (!Array.isArray(r) || r.length !== 4 || !r.every((
|
|
137
|
+
if (!Array.isArray(r) || r.length !== 4 || !r.every((s) => typeof s == "number" && Number.isFinite(s)))
|
|
138
138
|
throw o("queryArea.bbox must hold four numbers, [west, south, east, north] in degrees.");
|
|
139
|
-
const [n,
|
|
139
|
+
const [n, i, a, l] = e.bbox;
|
|
140
140
|
if (Math.abs(n) > 180 || Math.abs(a) > 180)
|
|
141
141
|
throw o("queryArea.bbox west and east must be longitudes from -180 to 180.");
|
|
142
|
-
if (Math.abs(
|
|
142
|
+
if (Math.abs(i) > 90 || Math.abs(l) > 90)
|
|
143
143
|
throw o("queryArea.bbox south and north must be latitudes from -90 to 90.");
|
|
144
144
|
if (n >= a)
|
|
145
145
|
throw o(`queryArea.bbox west (${n}) must be less than east (${a}); a box across the antimeridian is not supported.`);
|
|
146
|
-
if (
|
|
147
|
-
throw o(`queryArea.bbox south (${
|
|
148
|
-
return { bbox: [n,
|
|
146
|
+
if (i >= l)
|
|
147
|
+
throw o(`queryArea.bbox south (${i}) must be less than north (${l}).`);
|
|
148
|
+
return { bbox: [n, i, a, l] };
|
|
149
149
|
}
|
|
150
|
-
function
|
|
150
|
+
function le(t) {
|
|
151
151
|
const { autoLoadLayers: e, ...o } = t;
|
|
152
152
|
if (t.pbfFileUrl !== void 0 && (t.tagSets?.length ?? 0) > 0)
|
|
153
153
|
throw new Error(`OSM source "${t.outputTableName}": tagSets are read from the Overpass API only, so a source with pbfFileUrl cannot take them.`);
|
|
154
154
|
return {
|
|
155
155
|
...o,
|
|
156
|
-
queryArea:
|
|
156
|
+
queryArea: se(t),
|
|
157
157
|
autoLoadLayers: {
|
|
158
158
|
layers: e?.layers ?? [],
|
|
159
159
|
...e?.coordinateFormat !== void 0 && { coordinateFormat: e.coordinateFormat }
|
|
160
160
|
}
|
|
161
161
|
};
|
|
162
162
|
}
|
|
163
|
-
function
|
|
163
|
+
function lt(t) {
|
|
164
164
|
return `${t ? `coordinateFormat is set to "${t}"` : "no coordinateFormat was specified, so it defaults to EPSG:4326 (WGS84 per RFC 7946)"}. Verify that coordinateFormat matches the actual CRS of the input data.`;
|
|
165
165
|
}
|
|
166
|
-
function
|
|
167
|
-
return t === void 0 || t ===
|
|
166
|
+
function V(t) {
|
|
167
|
+
return t === void 0 || t === U ? "the default workspace" : `the workspace "${t}"`;
|
|
168
168
|
}
|
|
169
|
-
function
|
|
169
|
+
function ut(t) {
|
|
170
170
|
if (t != null)
|
|
171
171
|
return typeof t == "string" ? t : JSON.stringify(t);
|
|
172
172
|
}
|
|
173
|
-
async function
|
|
173
|
+
async function ue(t, e, o, r) {
|
|
174
174
|
const n = /* @__PURE__ */ new Map();
|
|
175
|
-
for (const
|
|
176
|
-
const
|
|
177
|
-
if (
|
|
178
|
-
if (
|
|
175
|
+
for (const l of (await t.getLayer(e.name)).features) {
|
|
176
|
+
const s = ut(l.properties?.[r]);
|
|
177
|
+
if (s !== void 0) {
|
|
178
|
+
if (l.id === void 0 || l.id === null)
|
|
179
179
|
throw new Error("its rows have no feature id to update them by.");
|
|
180
|
-
n.set(
|
|
180
|
+
n.set(s, [...n.get(s) ?? [], l.id]);
|
|
181
181
|
}
|
|
182
182
|
}
|
|
183
|
-
const
|
|
184
|
-
const
|
|
185
|
-
return
|
|
186
|
-
}), a = e.columns.some((
|
|
187
|
-
return { data: { ...o, features:
|
|
183
|
+
const i = o.features.flatMap((l) => {
|
|
184
|
+
const s = ut(l.properties?.[r]);
|
|
185
|
+
return s === void 0 ? [] : (n.get(s) ?? []).map((u) => ({ ...l, id: u }));
|
|
186
|
+
}), a = e.columns.some((l) => l.name === "geojson_id") ? "geojson_id" : "id";
|
|
187
|
+
return { data: { ...o, features: i }, idColumn: a };
|
|
188
188
|
}
|
|
189
|
-
async function
|
|
189
|
+
async function ft(t) {
|
|
190
190
|
if (t) return t;
|
|
191
|
-
const e = new
|
|
191
|
+
const e = new Jt();
|
|
192
192
|
return await e.init(), e;
|
|
193
193
|
}
|
|
194
|
-
function
|
|
194
|
+
function Rt(t) {
|
|
195
195
|
let e = 1 / 0, o = 1 / 0, r = -1 / 0, n = -1 / 0;
|
|
196
|
-
const
|
|
197
|
-
if (Array.isArray(
|
|
198
|
-
if (typeof
|
|
199
|
-
const [
|
|
200
|
-
|
|
196
|
+
const i = (l) => {
|
|
197
|
+
if (Array.isArray(l)) {
|
|
198
|
+
if (typeof l[0] == "number") {
|
|
199
|
+
const [s, u] = l;
|
|
200
|
+
s < e && (e = s), s > r && (r = s), u < o && (o = u), u > n && (n = u);
|
|
201
201
|
return;
|
|
202
202
|
}
|
|
203
|
-
for (const
|
|
203
|
+
for (const s of l) i(s);
|
|
204
204
|
}
|
|
205
|
-
}, a = (
|
|
206
|
-
|
|
205
|
+
}, a = (l) => {
|
|
206
|
+
l && (l.type === "GeometryCollection" ? l.geometries.forEach(a) : i(l.coordinates));
|
|
207
207
|
};
|
|
208
|
-
for (const
|
|
208
|
+
for (const l of t.features ?? []) a(l?.geometry);
|
|
209
209
|
return e <= r ? [e, o, r, n] : void 0;
|
|
210
210
|
}
|
|
211
|
-
function
|
|
212
|
-
function o(n,
|
|
213
|
-
if (!
|
|
211
|
+
function fe(t, e) {
|
|
212
|
+
function o(n, i) {
|
|
213
|
+
if (!i || !i.db)
|
|
214
214
|
return;
|
|
215
|
-
const a = document.getElementById(
|
|
215
|
+
const a = document.getElementById(i.db);
|
|
216
216
|
if (a) {
|
|
217
|
-
const
|
|
217
|
+
const l = n.getTablesMetadata();
|
|
218
218
|
a.innerHTML += "<ul>";
|
|
219
|
-
for (const
|
|
220
|
-
a.innerHTML += `<li>${
|
|
221
|
-
a.innerHTML += "</ul>", a.innerHTML += `<p>Number of tables: ${
|
|
219
|
+
for (const s of l)
|
|
220
|
+
a.innerHTML += `<li>${s.name}: (${s.source}, ${s.type}) </li>`;
|
|
221
|
+
a.innerHTML += "</ul>", a.innerHTML += `<p>Number of tables: ${l.length}</p>`;
|
|
222
222
|
}
|
|
223
223
|
}
|
|
224
|
-
async function r(n,
|
|
224
|
+
async function r(n, i, a) {
|
|
225
225
|
if (!e) return;
|
|
226
|
-
const
|
|
227
|
-
|
|
226
|
+
const l = E(i, a), s = n.getTablesMetadata().find((u) => u.name === a);
|
|
227
|
+
s && Et(s) ? e.set(l, await n.getLayer(a)) : e.delete(l);
|
|
228
228
|
}
|
|
229
229
|
return {
|
|
230
|
-
async resolveWorkspaces(n,
|
|
231
|
-
const a = await
|
|
232
|
-
for (const { name:
|
|
233
|
-
const
|
|
234
|
-
if (
|
|
235
|
-
throw new Error(`workspaces sets ${
|
|
236
|
-
|
|
230
|
+
async resolveWorkspaces(n, i) {
|
|
231
|
+
const a = await ft(n), l = /* @__PURE__ */ new Set();
|
|
232
|
+
for (const { name: s, coordinateFormat: u, precisionGrid: d } of i) {
|
|
233
|
+
const f = s ?? U;
|
|
234
|
+
if (l.has(f))
|
|
235
|
+
throw new Error(`workspaces sets ${V(s)} twice; give each workspace one entry.`);
|
|
236
|
+
l.add(f);
|
|
237
237
|
try {
|
|
238
|
-
await a.setWorkspace(
|
|
239
|
-
} catch (
|
|
240
|
-
throw new Error(`workspaces, ${
|
|
238
|
+
await a.setWorkspace(f, { coordinateFormat: u, precisionGrid: d });
|
|
239
|
+
} catch (c) {
|
|
240
|
+
throw new Error(`workspaces, ${V(s)}: ${c instanceof Error ? c.message : String(c)}`);
|
|
241
241
|
}
|
|
242
242
|
}
|
|
243
|
-
return await
|
|
243
|
+
return await I(a), a;
|
|
244
244
|
},
|
|
245
|
-
async resolveSource(n,
|
|
246
|
-
const a = await
|
|
247
|
-
await
|
|
248
|
-
let { type:
|
|
249
|
-
switch (
|
|
245
|
+
async resolveSource(n, i) {
|
|
246
|
+
const a = await ft(n), { workspace: l } = i;
|
|
247
|
+
await I(a, l);
|
|
248
|
+
let { type: s, workspace: u, ...d } = i;
|
|
249
|
+
switch (s) {
|
|
250
250
|
case "osm":
|
|
251
|
-
return await a.loadOsm(
|
|
251
|
+
return await a.loadOsm(le(d)), o(a, t), a;
|
|
252
252
|
case "csv":
|
|
253
253
|
return await a.loadCsv(d), o(a, t), a;
|
|
254
254
|
case "json":
|
|
255
255
|
return await a.loadJson(d), o(a, t), a;
|
|
256
256
|
case "geojson": {
|
|
257
|
-
const
|
|
258
|
-
let
|
|
259
|
-
|
|
260
|
-
const
|
|
261
|
-
const p = { ...
|
|
257
|
+
const f = d;
|
|
258
|
+
let c;
|
|
259
|
+
f.geojsonFileUrl ? c = await (await fetch(f.geojsonFileUrl)).json() : c = f.geojsonObject, e && c && (e.set(E(l, f.outputTableName), c), oe(c, f.coordinateFormat ?? "EPSG:4326"));
|
|
260
|
+
const h = c ? (() => {
|
|
261
|
+
const p = { ...f, geojsonObject: ie(c) };
|
|
262
262
|
return delete p.geojsonFileUrl, p;
|
|
263
|
-
})() :
|
|
263
|
+
})() : f, m = /^EPSG:4326$/i.test(h.coordinateFormat ?? "EPSG:4326"), y = c && m ? Rt(c) : void 0;
|
|
264
264
|
if (y && (y[1] < -90 || y[3] > 90))
|
|
265
265
|
throw new Error(
|
|
266
|
-
`GeoJSON layer "${
|
|
266
|
+
`GeoJSON layer "${h.outputTableName}" has y coordinates outside -90 to 90 (bbox: [${y.join(", ")}]), so they cannot be EPSG:4326 degrees. ${lt(h.coordinateFormat)}`
|
|
267
267
|
);
|
|
268
268
|
try {
|
|
269
|
-
await a.loadGeojson(
|
|
269
|
+
await a.loadGeojson(h);
|
|
270
270
|
} catch (p) {
|
|
271
|
-
throw new Error(`Failed to load GeoJSON layer "${
|
|
271
|
+
throw new Error(`Failed to load GeoJSON layer "${h.outputTableName}": ${p instanceof Error ? p.message : String(p)}`);
|
|
272
272
|
}
|
|
273
273
|
try {
|
|
274
|
-
const p = await a.getBoundingBoxFromLayer(
|
|
274
|
+
const p = await a.getBoundingBoxFromLayer(h.outputTableName), g = 25e6;
|
|
275
275
|
if (!isFinite(p.minLon) || !isFinite(p.minLat) || !isFinite(p.maxLon) || !isFinite(p.maxLat) || Math.abs(p.minLon) > g || Math.abs(p.maxLon) > g || Math.abs(p.minLat) > g || Math.abs(p.maxLat) > g)
|
|
276
276
|
throw new Error(
|
|
277
|
-
`Geometry bounding box after transform is invalid for layer "${
|
|
277
|
+
`Geometry bounding box after transform is invalid for layer "${h.outputTableName}" (bbox: [${p.minLon}, ${p.minLat}, ${p.maxLon}, ${p.maxLat}]). ${lt(h.coordinateFormat)} The workspace uses ${a.getWorkspaceConfiguration().coordinateFormat}; input is expected in EPSG:4326 by default.`
|
|
278
278
|
);
|
|
279
279
|
} catch (p) {
|
|
280
280
|
if (p instanceof Error && p.message.includes("bounding box after transform")) throw p;
|
|
@@ -284,133 +284,133 @@ function oe(t, e) {
|
|
|
284
284
|
case "geotiff":
|
|
285
285
|
return await a.loadGeoTiff(d), o(a, t), a;
|
|
286
286
|
case "heatmap": {
|
|
287
|
-
const
|
|
288
|
-
if (
|
|
289
|
-
throw new Error(`Heatmap "${
|
|
287
|
+
const f = d;
|
|
288
|
+
if (f.groupBy?.some((c) => c.aggregateFn === "collect"))
|
|
289
|
+
throw new Error(`Heatmap "${f.outputTableName}": aggregateFn "collect" lists the rows near a cell, and a cell holds one value; use sum, avg, count, min, max or weighted.`);
|
|
290
290
|
return await a.buildHeatmap({
|
|
291
|
-
tableJoinName:
|
|
292
|
-
near:
|
|
293
|
-
outputTableName:
|
|
294
|
-
grid:
|
|
295
|
-
...
|
|
291
|
+
tableJoinName: f.joinDataRef,
|
|
292
|
+
near: f.near,
|
|
293
|
+
outputTableName: f.outputTableName,
|
|
294
|
+
grid: f.grid,
|
|
295
|
+
...f.groupBy && { groupBy: f.groupBy }
|
|
296
296
|
}), o(a, t), a;
|
|
297
297
|
}
|
|
298
298
|
case "join": {
|
|
299
|
-
const
|
|
299
|
+
const f = d;
|
|
300
300
|
if (await a.spatialQuery({
|
|
301
|
-
tableRootName:
|
|
302
|
-
tableJoinName:
|
|
303
|
-
...
|
|
304
|
-
...
|
|
301
|
+
tableRootName: f.dataRef,
|
|
302
|
+
tableJoinName: f.joinDataRef,
|
|
303
|
+
...f.near && { near: f.near },
|
|
304
|
+
...f.groupBy && { groupBy: f.groupBy }
|
|
305
305
|
}), e) {
|
|
306
|
-
const
|
|
307
|
-
e.set(
|
|
306
|
+
const c = await a.getLayer(f.dataRef);
|
|
307
|
+
e.set(E(l, f.dataRef), c);
|
|
308
308
|
}
|
|
309
309
|
return o(a, t), a;
|
|
310
310
|
}
|
|
311
311
|
case "sql": {
|
|
312
|
-
const
|
|
312
|
+
const f = d;
|
|
313
313
|
try {
|
|
314
314
|
await a.rawQuery({
|
|
315
|
-
query:
|
|
315
|
+
query: f.query,
|
|
316
316
|
output: {
|
|
317
317
|
type: "CREATE_TABLE",
|
|
318
|
-
tableName:
|
|
318
|
+
tableName: f.outputTableName,
|
|
319
319
|
source: "user",
|
|
320
|
-
...
|
|
320
|
+
...f.layerType !== void 0 && { tableType: f.layerType }
|
|
321
321
|
}
|
|
322
322
|
});
|
|
323
|
-
} catch (
|
|
324
|
-
throw new Error(`SQL source "${
|
|
323
|
+
} catch (c) {
|
|
324
|
+
throw new Error(`SQL source "${f.outputTableName}": ${c instanceof Error ? c.message : String(c)}`);
|
|
325
325
|
}
|
|
326
|
-
return e?.delete(
|
|
326
|
+
return e?.delete(E(l, f.outputTableName)), o(a, t), a;
|
|
327
327
|
}
|
|
328
328
|
case "update": {
|
|
329
|
-
const
|
|
330
|
-
if (
|
|
331
|
-
throw
|
|
332
|
-
if (
|
|
333
|
-
throw
|
|
334
|
-
let
|
|
329
|
+
const f = d, c = (y) => new Error(`Update of "${f.dataRef}": ${y}`);
|
|
330
|
+
if (f.geojsonObject === void 0 == (f.jsonObject === void 0))
|
|
331
|
+
throw c("give its rows in geojsonObject or in jsonObject, one of the two.");
|
|
332
|
+
if (f.strategy === "update" && !f.idColumn)
|
|
333
|
+
throw c("the update strategy needs an idColumn, the column that matches a given row to the table's rows.");
|
|
334
|
+
let h = f.geojsonObject ?? f.jsonObject, m = f.idColumn;
|
|
335
335
|
try {
|
|
336
|
-
const y = a.getTablesMetadata().find((p) => p.name ===
|
|
337
|
-
if (
|
|
336
|
+
const y = a.getTablesMetadata().find((p) => p.name === f.dataRef);
|
|
337
|
+
if (f.strategy === "update" && f.geojsonObject && m?.startsWith("properties.") && y && Ht(y) && ({ data: h, idColumn: m } = await ue(a, y, f.geojsonObject, m.slice(11)), h.features.length === 0))
|
|
338
338
|
return o(a, t), a;
|
|
339
339
|
await a.updateTable({
|
|
340
|
-
tableName:
|
|
341
|
-
data:
|
|
342
|
-
strategy:
|
|
343
|
-
...
|
|
340
|
+
tableName: f.dataRef,
|
|
341
|
+
data: h,
|
|
342
|
+
strategy: f.strategy,
|
|
343
|
+
...m !== void 0 && { idColumn: m }
|
|
344
344
|
});
|
|
345
345
|
} catch (y) {
|
|
346
|
-
throw
|
|
346
|
+
throw c(y instanceof Error ? y.message : String(y));
|
|
347
347
|
}
|
|
348
|
-
return await r(a,
|
|
348
|
+
return await r(a, l, f.dataRef), o(a, t), a;
|
|
349
349
|
}
|
|
350
350
|
case "drop": {
|
|
351
|
-
const
|
|
352
|
-
if (!a.getTablesMetadata().some((
|
|
353
|
-
throw new Error(`Drop of "${
|
|
354
|
-
return await a.removeLayer(
|
|
351
|
+
const f = d;
|
|
352
|
+
if (!a.getTablesMetadata().some((c) => c.name === f.dataRef))
|
|
353
|
+
throw new Error(`Drop of "${f.dataRef}": ${V(l)} holds no table of that name.`);
|
|
354
|
+
return await a.removeLayer(f.dataRef), e?.delete(E(l, f.dataRef)), o(a, t), a;
|
|
355
355
|
}
|
|
356
356
|
default:
|
|
357
|
-
throw new Error(`Unknown data source type "${String(
|
|
357
|
+
throw new Error(`Unknown data source type "${String(s)}".`);
|
|
358
358
|
}
|
|
359
359
|
}
|
|
360
360
|
};
|
|
361
361
|
}
|
|
362
|
-
function
|
|
362
|
+
function St(t, e) {
|
|
363
363
|
return e === !0 ? `${t} osm-elements` : t;
|
|
364
364
|
}
|
|
365
365
|
function At(t) {
|
|
366
366
|
return t === !0 ? { osmElements: !0 } : void 0;
|
|
367
367
|
}
|
|
368
|
-
function
|
|
368
|
+
function It(t, e, o) {
|
|
369
369
|
if (!t) return o();
|
|
370
370
|
let r = t.get(e);
|
|
371
371
|
return r || (r = o(), t.set(e, r)), r;
|
|
372
372
|
}
|
|
373
|
-
function
|
|
373
|
+
function Lt(t, e) {
|
|
374
374
|
return t?.id ?? e;
|
|
375
375
|
}
|
|
376
|
-
function
|
|
376
|
+
function Y(t, e) {
|
|
377
377
|
return e === void 0 ? !0 : typeof e == "number" ? t.mapIndex === e : t.mapId === e;
|
|
378
378
|
}
|
|
379
|
-
function
|
|
379
|
+
function Pt(t, e, o) {
|
|
380
380
|
const r = t?.get(e) ?? [];
|
|
381
381
|
r.includes(o) || t?.set(e, [...r, o]);
|
|
382
382
|
}
|
|
383
|
-
const
|
|
384
|
-
function
|
|
383
|
+
const Nt = 6378137, q = 0.0818191908426215;
|
|
384
|
+
function ce(t, e) {
|
|
385
385
|
if (t === void 0 || typeof t == "number" && Number.isFinite(t) && t > 0) return;
|
|
386
386
|
const o = typeof t == "number" ? String(t) : JSON.stringify(t);
|
|
387
387
|
throw new Error(`Layer "${e}": pointSize must be a number of meters greater than 0, not ${o}.`);
|
|
388
388
|
}
|
|
389
|
-
function
|
|
390
|
-
const e = Math.exp(-t /
|
|
389
|
+
function de(t) {
|
|
390
|
+
const e = Math.exp(-t / Nt);
|
|
391
391
|
let o = Math.PI / 2 - 2 * Math.atan(e);
|
|
392
392
|
for (let r = 0; r < 10; r++) {
|
|
393
|
-
const n =
|
|
394
|
-
if (Math.abs(
|
|
395
|
-
o =
|
|
393
|
+
const n = q * Math.sin(o), i = Math.PI / 2 - 2 * Math.atan(e * ((1 - n) / (1 + n)) ** (q / 2));
|
|
394
|
+
if (Math.abs(i - o) < 1e-12) return i;
|
|
395
|
+
o = i;
|
|
396
396
|
}
|
|
397
397
|
return o;
|
|
398
398
|
}
|
|
399
|
-
function
|
|
399
|
+
function pe(t, e) {
|
|
400
400
|
if (/^EPSG:3395$/i.test(t)) {
|
|
401
|
-
const o =
|
|
401
|
+
const o = de(e), r = q * Math.sin(o);
|
|
402
402
|
return Math.sqrt(1 - r * r) / Math.cos(o);
|
|
403
403
|
}
|
|
404
|
-
return /^EPSG:3857$/i.test(t) ? Math.cosh(e /
|
|
404
|
+
return /^EPSG:3857$/i.test(t) ? Math.cosh(e / Nt) : 1;
|
|
405
405
|
}
|
|
406
|
-
function
|
|
406
|
+
function he(t, e, o, r) {
|
|
407
407
|
if (t === void 0 || e !== "points") return;
|
|
408
408
|
const n = r();
|
|
409
409
|
if (n)
|
|
410
|
-
return t *
|
|
410
|
+
return t * pe(o, (n[1] + n[3]) / 2);
|
|
411
411
|
}
|
|
412
|
-
const
|
|
413
|
-
function
|
|
412
|
+
const G = /^#[0-9a-fA-F]{6}$/;
|
|
413
|
+
function Tt(t, e) {
|
|
414
414
|
if (t === void 0) return;
|
|
415
415
|
if (!Array.isArray(t) || t.length !== 2 || !t.every((n) => typeof n == "number" && Number.isFinite(n)))
|
|
416
416
|
return "colorMapRange must hold two numbers, [low, high].";
|
|
@@ -420,215 +420,340 @@ function Pt(t, e) {
|
|
|
420
420
|
if (e !== void 0)
|
|
421
421
|
return "set colorMapRange or colorMapDomain, not both.";
|
|
422
422
|
}
|
|
423
|
-
function
|
|
424
|
-
return e && e.length > 0 ? { type:
|
|
425
|
-
type:
|
|
423
|
+
function Ot(t, e) {
|
|
424
|
+
return e && e.length > 0 ? { type: A.USER, params: e } : t?.mode === Ct.PERCENTILE ? t.lowerPercentile !== void 0 || t.upperPercentile !== void 0 ? {
|
|
425
|
+
type: A.PERCENTILE,
|
|
426
426
|
params: [t.lowerPercentile ?? 0, t.upperPercentile ?? 100]
|
|
427
|
-
} : { type:
|
|
427
|
+
} : { type: A.PERCENTILE } : { type: A.MIN_MAX };
|
|
428
428
|
}
|
|
429
|
-
function
|
|
429
|
+
function b(t) {
|
|
430
430
|
return typeof t.title == "string" && t.title !== "" ? t.title : t.dataRef;
|
|
431
431
|
}
|
|
432
|
-
function
|
|
432
|
+
function me(t, e) {
|
|
433
433
|
const o = /* @__PURE__ */ new Set();
|
|
434
434
|
for (const r of t.layerRefs) {
|
|
435
|
-
const n =
|
|
435
|
+
const n = b(r);
|
|
436
436
|
if (o.has(n))
|
|
437
437
|
throw new Error(`Map ${e} draws two layers with the id "${n}". A layer's id is its title, else its dataRef: give each layer of a map its own title.`);
|
|
438
438
|
o.add(n);
|
|
439
439
|
}
|
|
440
440
|
}
|
|
441
|
-
function
|
|
442
|
-
if (
|
|
441
|
+
function ct(t, e, o) {
|
|
442
|
+
if (!G.test(t))
|
|
443
443
|
throw new Error(`Layer "${o}": ${e} must be a color written #rrggbb, not "${t}".`);
|
|
444
|
-
return
|
|
444
|
+
return P.hexToRgb(t);
|
|
445
445
|
}
|
|
446
|
-
function
|
|
446
|
+
function ye(t, e) {
|
|
447
447
|
const o = {};
|
|
448
|
-
return t.color != null && (o.color =
|
|
448
|
+
return t.color != null && (o.color = ct(t.color, "color", e)), t.stroke === !1 ? o.showBorders = !1 : t.stroke != null && (o.strokeColor = ct(t.stroke, "stroke", e)), t.width != null && (o.polylinesWidth = t.width), o;
|
|
449
449
|
}
|
|
450
|
-
function
|
|
451
|
-
return t.isColorMap != null ? t.isColorMap : e === "raster" ? t.colorMapInterpolator != null || t.colorMapRange != null || t.colorMapCenter != null || t.colorMapReverse === !0 : t.color != null ? !1 : t.colorMapInterpolator != null || t.getFnv != null;
|
|
450
|
+
function ge(t, e) {
|
|
451
|
+
return t.isColorMap != null ? t.isColorMap : e === "raster" ? t.colorMapInterpolator != null || t.colorMapRange != null || t.colorMapCenter != null || t.colorMapReverse === !0 || t.legend === !0 : t.color != null ? !1 : t.colorMapInterpolator != null || t.getFnv != null;
|
|
452
452
|
}
|
|
453
|
-
function
|
|
453
|
+
function we(t, e) {
|
|
454
454
|
const o = t.features?.[0]?.properties?.[e];
|
|
455
455
|
return o instanceof Float32Array ? o : ArrayBuffer.isView(o) && !(o instanceof DataView) || Array.isArray(o) ? Float32Array.from(o, (r) => Number.isFinite(Number(r)) ? Number(r) : NaN) : null;
|
|
456
456
|
}
|
|
457
|
-
function
|
|
458
|
-
if (
|
|
457
|
+
function be(t, e, o, r, n) {
|
|
458
|
+
if (P.isCategorical(e.interpolator)) return;
|
|
459
459
|
if (n != null) {
|
|
460
460
|
const u = o != null ? [n[0], o, n[1]] : [n[0], n[1]];
|
|
461
461
|
return r === !0 ? u.reverse() : u;
|
|
462
462
|
}
|
|
463
463
|
if (!t) return;
|
|
464
|
-
let
|
|
464
|
+
let i = 0, a = 0;
|
|
465
465
|
for (let u = 0; u < t.length; u++) {
|
|
466
466
|
const d = t[u];
|
|
467
|
-
Number.isFinite(d) && (a++, o != null && (
|
|
467
|
+
Number.isFinite(d) && (a++, o != null && (i = Math.max(i, Math.abs(d - o))));
|
|
468
468
|
}
|
|
469
|
-
const
|
|
470
|
-
if (a === 0 || !
|
|
471
|
-
const
|
|
472
|
-
return r === !0 ? [...
|
|
469
|
+
const l = o != null && i > 0;
|
|
470
|
+
if (a === 0 || !l && r !== !0) return;
|
|
471
|
+
const s = l && o != null ? [o - i, o, o + i] : P.resolveDomainFromData(t, e);
|
|
472
|
+
return r === !0 ? [...s].reverse() : s;
|
|
473
473
|
}
|
|
474
|
-
function
|
|
475
|
-
if (!(e == null ||
|
|
474
|
+
function ve(t, e) {
|
|
475
|
+
if (!(e == null || P.isCategorical(t.interpolator)))
|
|
476
476
|
return [e[0], e[1]];
|
|
477
477
|
}
|
|
478
|
-
function
|
|
478
|
+
function Ee(t) {
|
|
479
479
|
const e = t.colorMapRange;
|
|
480
480
|
if (e === void 0) return;
|
|
481
|
-
const o = (
|
|
481
|
+
const o = (l) => new Error(`Layer "${b(t)}": ${l}`), r = Tt(e, t.colorMapDomain);
|
|
482
482
|
if (r)
|
|
483
483
|
throw o(r);
|
|
484
|
-
const [n,
|
|
485
|
-
if (a != null && (a < n || a >
|
|
486
|
-
throw o(`colorMapCenter (${a}) must lie within colorMapRange [${n}, ${
|
|
484
|
+
const [n, i] = e, a = t.colorMapCenter;
|
|
485
|
+
if (a != null && (a < n || a > i))
|
|
486
|
+
throw o(`colorMapCenter (${a}) must lie within colorMapRange [${n}, ${i}].`);
|
|
487
|
+
}
|
|
488
|
+
const H = ["background", "surface", "parks", "water", "roads", "buildings", "points", "polylines", "polygons"];
|
|
489
|
+
function _e(t, e) {
|
|
490
|
+
const o = (n) => new Error(`Map ${e}: ${n}`), r = t.style;
|
|
491
|
+
if (r !== void 0 && typeof r != "string") {
|
|
492
|
+
if (r === null || typeof r != "object" || Array.isArray(r))
|
|
493
|
+
throw o(`style must be the name of one of autk-map's styles or the colors of a style, not ${JSON.stringify(r)}.`);
|
|
494
|
+
const n = H.filter((i) => !(i in r));
|
|
495
|
+
if (n.length > 0)
|
|
496
|
+
throw o(`style gives no color for ${n.join(", ")}: a style of the spec's own gives each of ${H.join(", ")}.`);
|
|
497
|
+
for (const i of H) {
|
|
498
|
+
const a = r[i];
|
|
499
|
+
if (typeof a != "string" || !G.test(a))
|
|
500
|
+
throw o(`style.${i} must be a color written #rrggbb, not ${JSON.stringify(a)}.`);
|
|
501
|
+
}
|
|
502
|
+
}
|
|
503
|
+
for (const n of ["highlightColor", "invalidValueColor"]) {
|
|
504
|
+
const i = t[n];
|
|
505
|
+
if (i !== void 0 && (typeof i != "string" || !G.test(i)))
|
|
506
|
+
throw o(`${n} must be a color written #rrggbb, not ${JSON.stringify(i)}.`);
|
|
507
|
+
}
|
|
487
508
|
}
|
|
488
|
-
function
|
|
509
|
+
function Ce(t, e) {
|
|
510
|
+
typeof e.style == "string" ? t.style.setPredefinedStyle(e.style) : e.style && t.style.setCustomStyle(e.style), e.highlightColor !== void 0 && t.style.setHighlightColor(e.highlightColor), e.invalidValueColor !== void 0 && t.style.setInvalidValueColor(e.invalidValueColor);
|
|
511
|
+
}
|
|
512
|
+
function $e(t, e) {
|
|
513
|
+
const o = t.widthBy;
|
|
514
|
+
if (o !== void 0) {
|
|
515
|
+
if (typeof o != "string" || o === "")
|
|
516
|
+
throw new Error(`Layer "${e}": widthBy must be the dot path to each line's width, not ${JSON.stringify(o)}.`);
|
|
517
|
+
if (t.width !== void 0)
|
|
518
|
+
throw new Error(`Layer "${e}": set width or widthBy, not both: width gives every line one width.`);
|
|
519
|
+
}
|
|
520
|
+
}
|
|
521
|
+
function Me(t, e, o, r, n) {
|
|
522
|
+
if (r !== "roads")
|
|
523
|
+
throw new Error(`Layer "${e}": widthBy sets the width of each line of a roads layer, and the layer is drawn as ${r}: draw a table of lines as roads with layerType: 'roads'.`);
|
|
524
|
+
const i = t.layerManager.searchByLayerId(e), a = i?.components ?? [], l = new Float32Array(a.length);
|
|
525
|
+
l.set(i?.layerRenderInfo.polylinesWidthByComponent?.subarray(0, a.length) ?? []);
|
|
526
|
+
const s = o.startsWith("properties.") ? o.slice(11) : o;
|
|
527
|
+
let u = 0;
|
|
528
|
+
if (a.forEach((d, f) => {
|
|
529
|
+
const c = n.features[d.featureIndex ?? f], h = Number(Bt(c?.properties, s));
|
|
530
|
+
Number.isFinite(h) && h > 0 && (l[f] = h, u++);
|
|
531
|
+
}), u === 0)
|
|
532
|
+
throw new Error(`Layer "${e}": widthBy "${o}" gives no line of the layer a width: none has a positive number there.`);
|
|
533
|
+
t.updateRenderInfo(e, { polylinesWidthByComponent: l });
|
|
534
|
+
}
|
|
535
|
+
function ke(t, e) {
|
|
536
|
+
const o = t.layerRefs.filter((r) => r.legend === !0).map(b);
|
|
537
|
+
if (o.length > 1)
|
|
538
|
+
throw new Error(`Map ${e}: layers ${o.map((r) => `"${r}"`).join(" and ")} each set legend: a map shows one legend.`);
|
|
539
|
+
if (o.length === 1 && t.showUi === !1)
|
|
540
|
+
throw new Error(`Layer "${o[0]}": legend shows the layer in the map's legend, and the map's showUi is false, which hides the legend.`);
|
|
541
|
+
}
|
|
542
|
+
function Re(t, e) {
|
|
543
|
+
const o = e.layerRefs.find((i) => i.legend === !0);
|
|
544
|
+
if (!o) return;
|
|
545
|
+
const r = b(o), n = t.layerManager.searchByLayerId(r);
|
|
546
|
+
if (!n?.layerRenderInfo.isColorMap)
|
|
547
|
+
throw new Error(`Layer "${r}": legend shows the color scale of a layer colored by value, and the layer is drawn in one color.`);
|
|
548
|
+
t.ui.activeLayer = n, t.ui.refreshLegend(null);
|
|
549
|
+
}
|
|
550
|
+
const Se = [
|
|
551
|
+
{ types: ["points"], drawn: "a table of points is drawn as points" },
|
|
552
|
+
{ types: ["polylines", "roads"], drawn: "a table of lines is drawn as polylines or roads" },
|
|
553
|
+
{ types: ["polygons", "surface", "parks", "water", "buildings"], drawn: "a table of polygons is drawn as polygons, surface, parks, water or buildings" },
|
|
554
|
+
{ types: ["raster"], drawn: "a raster table is drawn as raster" }
|
|
555
|
+
];
|
|
556
|
+
function Ae(t, e, o) {
|
|
557
|
+
const r = t.layerType;
|
|
558
|
+
if (r === void 0 || e === void 0) return r ?? e;
|
|
559
|
+
const n = Se.find((i) => i.types.includes(e));
|
|
560
|
+
if (!n || n.types.includes(r)) return r;
|
|
561
|
+
throw new Error(`Layer "${o}": layerType "${r}" cannot draw the table "${t.dataRef}", a ${e} table: ${n.drawn}.`);
|
|
562
|
+
}
|
|
563
|
+
function Ft(t, e, o) {
|
|
564
|
+
if (!Array.isArray(t) || !t.every((r) => Number.isInteger(r) && r >= 0))
|
|
565
|
+
throw new Error(`Layer "${o}": ${e} must list the positions of features the layer draws, whole numbers from 0, not ${JSON.stringify(t)}.`);
|
|
566
|
+
}
|
|
567
|
+
function dt(t, e, o, r, n) {
|
|
568
|
+
if (r === "raster")
|
|
569
|
+
throw new Error(`Layer "${o}": ${e} names features, and a raster layer has none.`);
|
|
570
|
+
const i = t.find((a) => a >= n);
|
|
571
|
+
if (i !== void 0)
|
|
572
|
+
throw new Error(`Layer "${o}": ${e} names position ${i}, past the ${n} features the layer draws.`);
|
|
573
|
+
}
|
|
574
|
+
function Ie(t) {
|
|
575
|
+
t.layerRefs.forEach((e, o) => {
|
|
576
|
+
if (e.pickedComps === void 0) return;
|
|
577
|
+
const r = b(e);
|
|
578
|
+
if (Ft(e.pickedComps, "pickedComps", r), e.isPick !== !0)
|
|
579
|
+
throw new Error(`Layer "${r}": pickedComps draws features as picked, which autk-map does only on the layer that picks: set isPick: true.`);
|
|
580
|
+
const n = t.layerRefs.slice(o + 1).find((i) => i.isPick === !0);
|
|
581
|
+
if (n)
|
|
582
|
+
throw new Error(`Layer "${r}": pickedComps draws features as picked on the layer that picks, but layer "${b(n)}", after it, picks too: autk-map lets one layer of a map pick, the last.`);
|
|
583
|
+
});
|
|
584
|
+
}
|
|
585
|
+
function Bt(t, e) {
|
|
489
586
|
return e.split(".").reduce((o, r) => {
|
|
490
587
|
if (!(o == null || typeof o != "object"))
|
|
491
588
|
return o[r];
|
|
492
589
|
}, t);
|
|
493
590
|
}
|
|
494
|
-
function
|
|
591
|
+
function Le(t, e, o) {
|
|
495
592
|
const r = e.split("."), n = { ...t };
|
|
496
|
-
let
|
|
593
|
+
let i = n;
|
|
497
594
|
for (let a = 0; a < r.length - 1; a++)
|
|
498
|
-
|
|
499
|
-
return
|
|
500
|
-
}
|
|
501
|
-
function
|
|
502
|
-
const
|
|
503
|
-
|
|
595
|
+
i[r[a]] = { ...i[r[a]] ?? {} }, i = i[r[a]];
|
|
596
|
+
return i[r[r.length - 1]] = o, n;
|
|
597
|
+
}
|
|
598
|
+
function jt(t, e, o) {
|
|
599
|
+
const n = t.features?.[0]?.properties?.bands ?? [];
|
|
600
|
+
if (e === void 0) return n[0]?.id ?? "";
|
|
601
|
+
const i = n.find((a) => a.id === e || a.label === e.replace(/\./g, "_"));
|
|
602
|
+
if (i) return i.id;
|
|
603
|
+
if (n.length > 1) {
|
|
604
|
+
const a = n.map((l) => l.label && l.label !== l.id ? `${l.id} (${l.label})` : l.id);
|
|
605
|
+
throw o(`"${e}" names none of its ${n.length} bands: ${a.join(", ")}.`);
|
|
606
|
+
}
|
|
607
|
+
return n[0]?.id ?? e;
|
|
504
608
|
}
|
|
505
|
-
function
|
|
609
|
+
function xt(t) {
|
|
506
610
|
const { pitch: e } = t;
|
|
507
611
|
return e === void 0 || typeof e == "number" && e >= 0 && e < 90 ? void 0 : `camera.pitch must be at least 0 and less than 90 degrees, not ${typeof e == "number" ? String(e) : JSON.stringify(e)}: at 90 the eye would sit on the ground, edge-on to the map's flat layers, and the map could not pan.`;
|
|
508
612
|
}
|
|
509
|
-
function
|
|
510
|
-
const o =
|
|
613
|
+
function Pe(t, e) {
|
|
614
|
+
const o = xt(e);
|
|
511
615
|
if (o) throw new Error(o);
|
|
512
616
|
if (e.zoom === void 0 && !e.pitch && !e.bearing) return;
|
|
513
|
-
const r = t.camera, [n,
|
|
514
|
-
n - a * Math.sin(
|
|
515
|
-
|
|
516
|
-
a * Math.cos(
|
|
517
|
-
], d = [Math.cos(
|
|
518
|
-
r.resetCamera(d, [n,
|
|
519
|
-
}
|
|
520
|
-
function
|
|
521
|
-
const
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
617
|
+
const r = t.camera, [n, i] = r.getLookAt(), a = e.zoom !== void 0 ? 1e4 / Math.pow(2, e.zoom - 10) : Math.abs(r.getEye()[2]), l = (e.pitch ?? 0) * Math.PI / 180, s = (e.bearing ?? 0) * Math.PI / 180, u = [
|
|
618
|
+
n - a * Math.sin(l) * Math.sin(s),
|
|
619
|
+
i - a * Math.sin(l) * Math.cos(s),
|
|
620
|
+
a * Math.cos(l)
|
|
621
|
+
], d = [Math.cos(l) * Math.sin(s), Math.cos(l) * Math.cos(s), Math.sin(l)];
|
|
622
|
+
r.resetCamera(d, [n, i, 0], u);
|
|
623
|
+
}
|
|
624
|
+
async function Ne(t, e, o, r) {
|
|
625
|
+
const n = (s) => new Error(`Map ${r}: terrain ${s}`), i = e.getTablesMetadata().find((s) => s.name === o.dataRef);
|
|
626
|
+
if (!i)
|
|
627
|
+
throw n(`dataRef "${o.dataRef}" names no table of the map's workspace.`);
|
|
628
|
+
if (i.type !== "raster")
|
|
629
|
+
throw n(`dataRef "${o.dataRef}" names a ${i.type ?? "plain"} table, and a terrain takes its heights from a raster table, such as a geotiff source's.`);
|
|
630
|
+
const a = await e.getRaster(o.dataRef), l = jt(a, o.band, (s) => n(`band ${s}`));
|
|
631
|
+
try {
|
|
632
|
+
t.enableTerrainMode(a, l);
|
|
633
|
+
} catch (s) {
|
|
634
|
+
throw n(`"${o.dataRef}": ${s instanceof Error ? s.message : String(s)}`);
|
|
635
|
+
}
|
|
636
|
+
}
|
|
637
|
+
function Te(t, e, o, r) {
|
|
638
|
+
const i = t.layerManager.searchByLayerId(e)?.components;
|
|
639
|
+
return Array.isArray(i) ? i.map((a, l) => {
|
|
640
|
+
const s = Number.isInteger(a?.featureIndex) ? a.featureIndex : l;
|
|
641
|
+
return o[r[s]] ?? "";
|
|
525
642
|
}) : r.map((a) => o[a] ?? "");
|
|
526
643
|
}
|
|
527
|
-
function
|
|
528
|
-
async function a(
|
|
644
|
+
function Oe(t, e, o, r, n, i) {
|
|
645
|
+
async function a(l, s, u) {
|
|
529
646
|
let d = {};
|
|
530
|
-
for (const
|
|
531
|
-
|
|
532
|
-
const
|
|
533
|
-
for (const
|
|
534
|
-
const
|
|
535
|
-
p === "raster"
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
647
|
+
for (const c of s.getTablesMetadata())
|
|
648
|
+
c.type !== void 0 && (d[c.name] = c.type);
|
|
649
|
+
const f = [];
|
|
650
|
+
for (const c of u.layerRefs) {
|
|
651
|
+
const h = c.dataRef, m = b(c), y = E(u.workspace, h), p = Ae(c, n?.get(y) ?? d[h], m), g = c.getFnv, _ = o?.get(y) ?? (p === "raster" ? await s.getRaster(h) : await It(i, St(y, c.osmElements), () => s.getLayer(h, At(c.osmElements)))), $ = _.features ?? [], S = p === "raster" ? [] : $.flatMap((w, M) => w?.geometry != null ? [M] : []), k = p === "raster" ? _ : { ..._, features: S.map((w) => $[w]) }, K = p === "raster" ? jt(k, g, (w) => new Error(`Layer "${m}": getFnv ${w}`)) : "";
|
|
652
|
+
if (p === "raster")
|
|
653
|
+
l.loadCollection(m, { collection: k, type: "raster", property: K });
|
|
654
|
+
else {
|
|
655
|
+
const w = p === "buildings" && c.buildingsZeroHeight === !0;
|
|
656
|
+
l.loadCollection(m, { collection: k, type: p, ...w ? { loadConfig: { buildingsZeroHeight: !0 } } : {} });
|
|
657
|
+
}
|
|
658
|
+
c.opacity != null && l.updateRenderInfo(m, { opacity: c.opacity });
|
|
659
|
+
const z = ye(c, m);
|
|
660
|
+
Object.keys(z).length > 0 && l.updateRenderInfo(m, z), c.widthBy !== void 0 && Me(l, m, c.widthBy, p, k);
|
|
661
|
+
const Yt = s.getWorkspaceConfiguration().coordinateFormat, X = he(c.pointSize, p, Yt, () => Rt(k));
|
|
662
|
+
X !== void 0 && l.updateRenderInfo(m, { pointSize: X }), ge(c, p) && l.updateRenderInfo(m, { isColorMap: !0 }), c.isPick && l.updateRenderInfo(m, { isPick: !0 }), c.isSkip && l.updateRenderInfo(m, { isSkip: !0 });
|
|
663
|
+
const { catchAllCategory: T, colorMapDomain: L } = c;
|
|
664
|
+
let Z = k, tt = L;
|
|
542
665
|
if (g && T && L?.length) {
|
|
543
666
|
const w = new Set(L);
|
|
544
|
-
|
|
545
|
-
...
|
|
546
|
-
features:
|
|
547
|
-
const
|
|
548
|
-
return
|
|
667
|
+
Z = {
|
|
668
|
+
...k,
|
|
669
|
+
features: k.features.map((M) => {
|
|
670
|
+
const rt = M.properties, Q = Bt(rt, g);
|
|
671
|
+
return Q == null || !w.has(String(Q)) ? { ...M, properties: Le(rt, g, T) } : M;
|
|
549
672
|
})
|
|
550
|
-
},
|
|
673
|
+
}, tt = w.has(T) ? L : [...L, T];
|
|
551
674
|
}
|
|
552
|
-
const
|
|
553
|
-
|
|
554
|
-
const O =
|
|
555
|
-
if (
|
|
675
|
+
const et = p === "raster" && c.transferFunction != null;
|
|
676
|
+
et && l.layerManager.searchByLayerId(m)?.setTransferFunction?.(c.transferFunction);
|
|
677
|
+
const O = c.colorMapRange, ot = p === "raster" && (O != null || c.colorMapCenter != null || c.colorMapReverse === !0);
|
|
678
|
+
if (c.colorMapInterpolator || ot || O) {
|
|
556
679
|
const w = {
|
|
557
680
|
// urban-grammar ColorMapInterpolator values are string-compatible
|
|
558
681
|
// with autk-core ColorMapInterpolator at runtime
|
|
559
|
-
interpolator:
|
|
560
|
-
domainSpec:
|
|
682
|
+
interpolator: c.colorMapInterpolator ?? l.layerManager.searchByLayerId(m)?.layerRenderInfo.colormap.config.interpolator ?? _t.SEQ_REDS,
|
|
683
|
+
domainSpec: Ot(c.normalization, tt)
|
|
561
684
|
};
|
|
562
|
-
let
|
|
563
|
-
|
|
564
|
-
} else
|
|
685
|
+
let M;
|
|
686
|
+
ot ? M = be(we(k, K), w, c.colorMapCenter, c.colorMapReverse, O) : p !== "raster" && (M = ve(w, O)), M && (w.domainSpec = { type: A.USER, params: M }), l.updateColorMap(m, { colorMap: w });
|
|
687
|
+
} else et && l.updateColorMap(m, { colorMap: {} });
|
|
565
688
|
if (g && p !== "raster") {
|
|
566
689
|
const w = g.startsWith("properties.") ? g : `properties.${g}`;
|
|
567
|
-
|
|
690
|
+
l.updateThematic(m, { collection: Z, property: w });
|
|
568
691
|
}
|
|
569
|
-
|
|
692
|
+
const W = p === "raster" ? [] : Te(l, m, kt($), S);
|
|
693
|
+
c.pickedComps && dt(c.pickedComps, "pickedComps", m, p, W.length), c.skippedComps && (dt(c.skippedComps, "skippedComps", m, p, W.length), l.layerManager.searchByLayerId(m)?.setSkippedIds(c.skippedComps)), f.push(W);
|
|
570
694
|
}
|
|
571
|
-
return
|
|
695
|
+
return f;
|
|
572
696
|
}
|
|
573
697
|
return {
|
|
574
|
-
async resolveMap(
|
|
575
|
-
if (t && t.map &&
|
|
576
|
-
|
|
577
|
-
for (const y of
|
|
578
|
-
|
|
579
|
-
|
|
698
|
+
async resolveMap(l, s, u = 0) {
|
|
699
|
+
if (t && t.map && l) {
|
|
700
|
+
me(s, u);
|
|
701
|
+
for (const y of s.layerRefs)
|
|
702
|
+
Ee(y), ce(y.pointSize, b(y)), y.skippedComps !== void 0 && Ft(y.skippedComps, "skippedComps", b(y)), $e(y, b(y));
|
|
703
|
+
Ie(s), _e(s, u), ke(s, u);
|
|
704
|
+
const d = s.camera && xt(s.camera);
|
|
580
705
|
if (d)
|
|
581
706
|
throw new Error(`Map ${u}: ${d}`);
|
|
582
|
-
let
|
|
583
|
-
if (Array.isArray(t.map) ?
|
|
707
|
+
let f;
|
|
708
|
+
if (Array.isArray(t.map) ? f = document.getElementById(t.map[u]) : f = document.getElementById(t.map), !f)
|
|
584
709
|
throw new Error("Could not find rendering target for map: " + t.map);
|
|
585
|
-
if (!(
|
|
710
|
+
if (!(f instanceof HTMLCanvasElement))
|
|
586
711
|
throw new Error("Target for map is not a canvas: " + t.map);
|
|
587
|
-
const
|
|
588
|
-
let
|
|
712
|
+
const c = s.showUi === !1 ? new nt(f, !1) : new nt(f);
|
|
713
|
+
let h;
|
|
589
714
|
try {
|
|
590
|
-
|
|
715
|
+
Ce(c, s), await c.init(), await I(l, s.workspace), h = await a(c, l, s), s.terrain && await Ne(c, l, s.terrain, u), Re(c, s);
|
|
591
716
|
} catch (y) {
|
|
592
717
|
try {
|
|
593
|
-
|
|
718
|
+
c.destroy();
|
|
594
719
|
} catch {
|
|
595
720
|
}
|
|
596
721
|
throw y;
|
|
597
722
|
}
|
|
598
|
-
const
|
|
599
|
-
|
|
600
|
-
map:
|
|
723
|
+
const m = Lt(s, u);
|
|
724
|
+
s.layerRefs.forEach((y, p) => e?.push({
|
|
725
|
+
map: c,
|
|
601
726
|
mapIndex: u,
|
|
602
|
-
mapId:
|
|
603
|
-
layerId:
|
|
727
|
+
mapId: m,
|
|
728
|
+
layerId: b(y),
|
|
604
729
|
dataRef: y.dataRef,
|
|
605
|
-
rows:
|
|
606
|
-
})), r && (r[u] =
|
|
730
|
+
rows: h[p]
|
|
731
|
+
})), r && (r[u] = c), s.camera && Pe(c, s.camera), c.draw();
|
|
607
732
|
}
|
|
608
733
|
}
|
|
609
734
|
};
|
|
610
735
|
}
|
|
611
|
-
function
|
|
736
|
+
function C(t) {
|
|
612
737
|
return t.id ?? t.dataRef;
|
|
613
738
|
}
|
|
614
|
-
const
|
|
615
|
-
function
|
|
739
|
+
const Fe = new Set(Object.values(_t));
|
|
740
|
+
function pt(t, e, o) {
|
|
616
741
|
if (e !== void 0) {
|
|
617
|
-
if (typeof e != "string" || !
|
|
618
|
-
if (
|
|
742
|
+
if (typeof e != "string" || !Fe.has(e)) return `${t} ${JSON.stringify(e)} is not a color scheme.`;
|
|
743
|
+
if (P.isCategorical(e) !== o)
|
|
619
744
|
return o ? `${t} "${e}" is not a categorical scheme: categories take a scheme* scheme, such as schemeTableau10.` : `${t} "${e}" is a categorical scheme: numbers take an interpolate* scheme, and categories take categoricalColorMapInterpolator.`;
|
|
620
745
|
}
|
|
621
746
|
}
|
|
622
|
-
const
|
|
623
|
-
function
|
|
747
|
+
const Be = /^(?:.?[<>=^])?[-+( ]?[$#]?0?\d*,?(?:\.\d+)?~?[a-zA-Z%]?$/;
|
|
748
|
+
function je(t) {
|
|
624
749
|
if (t === void 0) return;
|
|
625
750
|
if (!Array.isArray(t) || t.length !== 2)
|
|
626
751
|
return "tickFormats must hold two d3-format specifiers, [x, y].";
|
|
627
|
-
const e = t.findIndex((o) => typeof o != "string" || !
|
|
752
|
+
const e = t.findIndex((o) => typeof o != "string" || !Be.test(o));
|
|
628
753
|
if (e >= 0)
|
|
629
754
|
return `tickFormats[${e}] ${JSON.stringify(t[e])} is not a d3-format specifier, such as "~s", ",d" or ".0%".`;
|
|
630
755
|
}
|
|
631
|
-
function
|
|
756
|
+
function xe(t, e) {
|
|
632
757
|
if (t === void 0) return;
|
|
633
758
|
if (!Array.isArray(t) || !t.every((r) => typeof r == "string"))
|
|
634
759
|
return "axisLabels must be a list of titles, one for each column of axis.";
|
|
@@ -638,59 +763,59 @@ function Me(t, e) {
|
|
|
638
763
|
if (o !== void 0)
|
|
639
764
|
return `axisLabels gives two axes the title ${JSON.stringify(o)}.`;
|
|
640
765
|
}
|
|
641
|
-
function
|
|
642
|
-
if (!(e === void 0 || typeof e == "string" &&
|
|
766
|
+
function ht(t, e) {
|
|
767
|
+
if (!(e === void 0 || typeof e == "string" && G.test(e)))
|
|
643
768
|
return `${t} must be a color written #rrggbb, not ${JSON.stringify(e)}.`;
|
|
644
769
|
}
|
|
645
|
-
function
|
|
770
|
+
function De(t) {
|
|
646
771
|
if (t !== void 0 && (!Array.isArray(t) || !t.every((e) => Number.isInteger(e) && e >= 0)))
|
|
647
772
|
return "selection must list the positions of rows, whole numbers from 0.";
|
|
648
773
|
}
|
|
649
|
-
function
|
|
650
|
-
const e =
|
|
651
|
-
if (e) throw new Error(`Plot "${
|
|
774
|
+
function Ge(t) {
|
|
775
|
+
const e = pt("colorMapInterpolator", t.colorMapInterpolator, !1) ?? pt("categoricalColorMapInterpolator", t.categoricalColorMapInterpolator, !0) ?? Tt(t.colorMapRange, t.colorMapDomain) ?? je(t.tickFormats) ?? xe(t.axisLabels, t.axis) ?? De(t.selection) ?? ht("markColor", t.markColor) ?? ht("highlightColor", t.highlightColor);
|
|
776
|
+
if (e) throw new Error(`Plot "${C(t)}": ${e}`);
|
|
652
777
|
}
|
|
653
|
-
function
|
|
778
|
+
function Ue(t) {
|
|
654
779
|
const e = {};
|
|
655
780
|
for (const [o, r] of [["markColor", "mark"], ["highlightColor", "highlight"]]) {
|
|
656
781
|
let n;
|
|
657
|
-
for (const
|
|
658
|
-
const a =
|
|
782
|
+
for (const i of t) {
|
|
783
|
+
const a = i[o];
|
|
659
784
|
if (a !== void 0) {
|
|
660
785
|
if (n && n[o].toLowerCase() !== a.toLowerCase())
|
|
661
|
-
throw new Error(`Plots "${
|
|
662
|
-
n ??=
|
|
786
|
+
throw new Error(`Plots "${C(n)}" and "${C(i)}" set different ${o} values, "${n[o]}" and "${a}": autk-plot draws every plot of a page in one ${r} color.`);
|
|
787
|
+
n ??= i;
|
|
663
788
|
}
|
|
664
789
|
}
|
|
665
790
|
n && (e[o] = n[o]);
|
|
666
791
|
}
|
|
667
792
|
return e;
|
|
668
793
|
}
|
|
669
|
-
function
|
|
794
|
+
function We(t, e) {
|
|
670
795
|
const o = t.selection?.find((r) => r >= e);
|
|
671
796
|
if (o !== void 0)
|
|
672
|
-
throw new Error(`Plot "${
|
|
797
|
+
throw new Error(`Plot "${C(t)}": selection names row ${o}, but the plot draws ${e === 1 ? "1 row" : `${e} rows`}.`);
|
|
673
798
|
}
|
|
674
|
-
function
|
|
799
|
+
function Qe(t, e) {
|
|
675
800
|
return t === void 0 || t === "@transform" ? !1 : e.some((o) => {
|
|
676
|
-
const r =
|
|
801
|
+
const r = zt(o?.properties ?? {}, t);
|
|
677
802
|
return typeof r == "string" && isNaN(Number(r));
|
|
678
803
|
});
|
|
679
804
|
}
|
|
680
|
-
function
|
|
805
|
+
function Ve(t, e) {
|
|
681
806
|
const o = t.colorMapRange;
|
|
682
|
-
if (o !== void 0 && !
|
|
683
|
-
return { type:
|
|
807
|
+
if (o !== void 0 && !Qe(t.color, e))
|
|
808
|
+
return { type: A.USER, params: [o[0], o[1]] };
|
|
684
809
|
if (!(t.normalization === void 0 && t.colorMapDomain === void 0))
|
|
685
|
-
return
|
|
810
|
+
return Ot(t.normalization, t.colorMapDomain);
|
|
686
811
|
}
|
|
687
|
-
function
|
|
812
|
+
function Ye(t) {
|
|
688
813
|
return t.axis.map((e, o) => t.axisLabels?.[o] ?? (e === "@transform" ? "value" : e));
|
|
689
814
|
}
|
|
690
|
-
function
|
|
691
|
-
const o =
|
|
815
|
+
function He(t, e) {
|
|
816
|
+
const o = Ve(t, e);
|
|
692
817
|
return {
|
|
693
|
-
labels: { axis:
|
|
818
|
+
labels: { axis: Ye(t), title: t.title },
|
|
694
819
|
// The grammar's scheme names are autk-core's, as strings.
|
|
695
820
|
...t.colorMapInterpolator !== void 0 && { colorMapInterpolator: t.colorMapInterpolator },
|
|
696
821
|
...t.categoricalColorMapInterpolator !== void 0 && {
|
|
@@ -700,7 +825,7 @@ function Le(t, e) {
|
|
|
700
825
|
...t.tickFormats !== void 0 && { tickFormats: [...t.tickFormats] }
|
|
701
826
|
};
|
|
702
827
|
}
|
|
703
|
-
function
|
|
828
|
+
function Je(t) {
|
|
704
829
|
return {
|
|
705
830
|
scatter: "scatterplot",
|
|
706
831
|
bar: "barchart",
|
|
@@ -711,283 +836,283 @@ function Ne(t) {
|
|
|
711
836
|
heatmatrix: "heatmatrix"
|
|
712
837
|
}[t];
|
|
713
838
|
}
|
|
714
|
-
let
|
|
715
|
-
function
|
|
716
|
-
t.markColor === void 0 && t.highlightColor === void 0 && !
|
|
839
|
+
let j;
|
|
840
|
+
function qe(t) {
|
|
841
|
+
t.markColor === void 0 && t.highlightColor === void 0 && !j || (j ??= { markColor: F.default, highlightColor: F.highlight }, F.setDefaultColor(t.markColor ?? j.markColor), F.setHighlightColor(t.highlightColor ?? j.highlightColor));
|
|
717
842
|
}
|
|
718
|
-
function
|
|
719
|
-
const { map: n, layerId:
|
|
720
|
-
n.updateRenderInfo(
|
|
721
|
-
a ===
|
|
843
|
+
function Dt(t, e, o, r) {
|
|
844
|
+
const { map: n, layerId: i } = r;
|
|
845
|
+
n.updateRenderInfo(i, { isPick: !0 }), n.events.on(J.PICKING, ({ layerId: a, selection: l }) => {
|
|
846
|
+
a === i && t.setSelection(D(l, r.rows, e));
|
|
722
847
|
});
|
|
723
848
|
for (const a of o)
|
|
724
|
-
t.events.on(a, ({ selection:
|
|
725
|
-
n.setHighlightedIds(
|
|
849
|
+
t.events.on(a, ({ selection: l }) => {
|
|
850
|
+
n.setHighlightedIds(i, D(l, e, r.rows));
|
|
726
851
|
});
|
|
727
852
|
}
|
|
728
|
-
async function
|
|
729
|
-
const
|
|
730
|
-
return
|
|
853
|
+
async function Ke(t, e, o, r, n) {
|
|
854
|
+
const i = t.getTablesMetadata().find((a) => a.name === e);
|
|
855
|
+
return i && !Et(i) ? { type: "FeatureCollection", features: (await t.getTable(e)).map((l) => ({ type: "Feature", geometry: null, properties: l })) } : It(r, St(o, n), () => t.getLayer(e, At(n)));
|
|
731
856
|
}
|
|
732
|
-
function
|
|
857
|
+
function ze(t, e, o, r, n, i, a, l) {
|
|
733
858
|
return {
|
|
734
|
-
async resolvePlot(
|
|
859
|
+
async resolvePlot(s, u, d = 0) {
|
|
735
860
|
if (!t || !t.plot) return;
|
|
736
|
-
const
|
|
737
|
-
if (
|
|
738
|
-
const
|
|
739
|
-
if (!
|
|
740
|
-
const
|
|
741
|
-
if (!
|
|
742
|
-
await
|
|
743
|
-
const
|
|
744
|
-
|
|
745
|
-
const g = u.events ?? [],
|
|
746
|
-
type:
|
|
861
|
+
const f = Array.isArray(t.plot) ? t.plot[d] : t.plot;
|
|
862
|
+
if (f === void 0) throw new Error(`Plot ${d} has no target: the plot targets name ${t.plot.length} elements.`);
|
|
863
|
+
const c = document.getElementById(f);
|
|
864
|
+
if (!c) throw new Error(`Could not find plot target: ${f}`);
|
|
865
|
+
const h = s;
|
|
866
|
+
if (!h) throw new Error("No data context available for plot.");
|
|
867
|
+
await I(h, u.workspace);
|
|
868
|
+
const m = E(u.workspace, u.dataRef), y = u.osmElements === !0 ? void 0 : n?.get(m), p = i?.get(m) ?? y ?? await Ke(h, u.dataRef, m, l, u.osmElements);
|
|
869
|
+
We(u, p.features?.length ?? 0);
|
|
870
|
+
const g = u.events ?? [], _ = new Kt(c, {
|
|
871
|
+
type: Je(u.mark),
|
|
747
872
|
collection: p,
|
|
748
873
|
attributes: { axis: u.axis, ...u.color && { color: u.color } },
|
|
749
874
|
events: g,
|
|
750
|
-
...
|
|
875
|
+
...He(u, p.features ?? []),
|
|
751
876
|
...u.width && { width: u.width },
|
|
752
877
|
...u.height && { height: u.height },
|
|
753
878
|
...u.margins && { margins: u.margins },
|
|
754
879
|
...u.transform && { transform: u.transform }
|
|
755
880
|
});
|
|
756
|
-
u.mark === "scatter" && u.color !== void 0 &&
|
|
757
|
-
const
|
|
758
|
-
a?.set(
|
|
759
|
-
for (const
|
|
760
|
-
!u.mapRef ||
|
|
881
|
+
u.mark === "scatter" && u.color !== void 0 && _.setSelection([]), o?.set(C(u), _);
|
|
882
|
+
const $ = kt(p.features ?? []);
|
|
883
|
+
a?.set(C(u), $);
|
|
884
|
+
for (const S of e ?? [])
|
|
885
|
+
!u.mapRef || S.dataRef !== u.mapRef || (Dt(_, $, g, S), Pt(r, C(u), S));
|
|
761
886
|
}
|
|
762
887
|
};
|
|
763
888
|
}
|
|
764
|
-
const
|
|
765
|
-
function
|
|
889
|
+
const Gt = 134217728, Xe = 4, Ze = 32;
|
|
890
|
+
function to(t) {
|
|
766
891
|
return Array.isArray(t) ? t.join(`
|
|
767
892
|
`) : t;
|
|
768
893
|
}
|
|
769
|
-
function
|
|
894
|
+
function R(t) {
|
|
770
895
|
return !!t && typeof t == "object" && !Array.isArray(t) && typeof t.fromFeature == "object" && t.fromFeature !== null;
|
|
771
896
|
}
|
|
772
|
-
function
|
|
897
|
+
function N(t, e) {
|
|
773
898
|
return t instanceof Map ? t.get(e) : t[e];
|
|
774
899
|
}
|
|
775
|
-
function
|
|
900
|
+
function x(t, e) {
|
|
776
901
|
return e.split(".").reduce((o, r) => {
|
|
777
902
|
if (!(o == null || typeof o != "object"))
|
|
778
903
|
return o[r];
|
|
779
904
|
}, t);
|
|
780
905
|
}
|
|
781
|
-
function
|
|
906
|
+
function Ut(t) {
|
|
782
907
|
const e = [];
|
|
783
908
|
for (const o of [t.uniforms, t.uniformMatrices])
|
|
784
909
|
for (const r of Object.values(o ?? {}))
|
|
785
|
-
|
|
910
|
+
R(r) && e.push(r);
|
|
786
911
|
return e;
|
|
787
912
|
}
|
|
788
|
-
function
|
|
789
|
-
return [.../* @__PURE__ */ new Set([t.dataRef, ...
|
|
913
|
+
function eo(t) {
|
|
914
|
+
return [.../* @__PURE__ */ new Set([t.dataRef, ...Ut(t).map((e) => e.fromFeature.layer)])];
|
|
790
915
|
}
|
|
791
|
-
function
|
|
792
|
-
for (const e of
|
|
916
|
+
function Wt(t) {
|
|
917
|
+
for (const e of Ut(t)) {
|
|
793
918
|
const { iterate: o, layer: r } = e.fromFeature;
|
|
794
919
|
if (o === "all" || o === "batched") return { mode: o, layer: r };
|
|
795
920
|
}
|
|
796
921
|
return null;
|
|
797
922
|
}
|
|
798
|
-
function
|
|
799
|
-
const r = t.fromFeature, n = o !== void 0 && r.iterate === "all" ? o : r.index ?? 0,
|
|
800
|
-
return
|
|
923
|
+
function Qt(t, e, o) {
|
|
924
|
+
const r = t.fromFeature, n = o !== void 0 && r.iterate === "all" ? o : r.index ?? 0, i = N(e, r.layer)?.features?.[n];
|
|
925
|
+
return i ? x(i, r.path) : void 0;
|
|
801
926
|
}
|
|
802
|
-
function
|
|
927
|
+
function mt(t, e, o) {
|
|
803
928
|
if (!t) return;
|
|
804
929
|
const r = {};
|
|
805
|
-
for (const [n,
|
|
806
|
-
if (!
|
|
807
|
-
r[n] =
|
|
930
|
+
for (const [n, i] of Object.entries(t)) {
|
|
931
|
+
if (!R(i)) {
|
|
932
|
+
r[n] = i;
|
|
808
933
|
continue;
|
|
809
934
|
}
|
|
810
|
-
const a = Number(
|
|
811
|
-
Number.isFinite(a) ? r[n] = a : typeof
|
|
935
|
+
const a = Number(Qt(i, e, o) ?? NaN);
|
|
936
|
+
Number.isFinite(a) ? r[n] = a : typeof i.default == "number" && (r[n] = i.default);
|
|
812
937
|
}
|
|
813
938
|
return r;
|
|
814
939
|
}
|
|
815
|
-
function
|
|
940
|
+
function yt(t, e, o) {
|
|
816
941
|
if (!t) return;
|
|
817
942
|
const r = {};
|
|
818
|
-
for (const [n,
|
|
819
|
-
if (!
|
|
820
|
-
r[n] =
|
|
943
|
+
for (const [n, i] of Object.entries(t)) {
|
|
944
|
+
if (!R(i)) {
|
|
945
|
+
r[n] = i;
|
|
821
946
|
continue;
|
|
822
947
|
}
|
|
823
|
-
const a =
|
|
824
|
-
if (!
|
|
825
|
-
const
|
|
826
|
-
|
|
948
|
+
const a = Qt(i, e, o), l = Array.isArray(a) ? a : Array.isArray(i.default) ? i.default : void 0;
|
|
949
|
+
if (!l) continue;
|
|
950
|
+
const s = i.cols ?? (Array.isArray(l[0]) ? l[0].length : 0);
|
|
951
|
+
s > 0 ? r[n] = { data: l, cols: s } : console.warn(`[autk-grammar] uniform matrix "${n}" has no column count; entry dropped`);
|
|
827
952
|
}
|
|
828
953
|
return r;
|
|
829
954
|
}
|
|
830
|
-
function
|
|
955
|
+
function oo(t) {
|
|
831
956
|
return t != null && !(typeof t == "number" && !Number.isFinite(t));
|
|
832
957
|
}
|
|
833
|
-
function
|
|
834
|
-
return
|
|
958
|
+
function gt(t) {
|
|
959
|
+
return R(t) && t.fromFeature.iterate === "batched";
|
|
835
960
|
}
|
|
836
|
-
function
|
|
837
|
-
return Object.values(e ?? {}).some(
|
|
961
|
+
function Vt(t, e) {
|
|
962
|
+
return Object.values(e ?? {}).some(gt) ? Ze : Object.values(t ?? {}).some(gt) ? Xe : 0;
|
|
838
963
|
}
|
|
839
|
-
function
|
|
840
|
-
const r =
|
|
964
|
+
function ro(t, e, o = Gt) {
|
|
965
|
+
const r = Vt(t, e);
|
|
841
966
|
return r > 0 ? Math.floor(o / r) : Number.POSITIVE_INFINITY;
|
|
842
967
|
}
|
|
843
|
-
function
|
|
844
|
-
const n = {},
|
|
845
|
-
for (const
|
|
846
|
-
for (const u of Object.values(
|
|
847
|
-
|
|
968
|
+
function no(t, e, o, r = Gt) {
|
|
969
|
+
const n = {}, i = {}, a = [];
|
|
970
|
+
for (const s of [t, e])
|
|
971
|
+
for (const u of Object.values(s ?? {}))
|
|
972
|
+
R(u) && u.fromFeature.iterate === "batched" && u.fromFeature.required && a.push(u.fromFeature.path);
|
|
848
973
|
if (a.length > 0) {
|
|
849
|
-
const
|
|
850
|
-
o = o.filter((u) => a.every((d) =>
|
|
974
|
+
const s = o.length;
|
|
975
|
+
o = o.filter((u) => a.every((d) => oo(x(u, d)))), o.length < s && console.info(`[autk-grammar] batched compute dropped ${s - o.length} feature(s) missing ${a.join(", ")}`);
|
|
851
976
|
}
|
|
852
|
-
const
|
|
853
|
-
o.length >
|
|
854
|
-
`[autk-grammar] batched compute capped at ${
|
|
855
|
-
), o = o.slice(0,
|
|
856
|
-
for (const [
|
|
857
|
-
if (
|
|
977
|
+
const l = ro(t, e, r);
|
|
978
|
+
o.length > l && (console.warn(
|
|
979
|
+
`[autk-grammar] batched compute capped at ${l} features (got ${o.length}): its largest packed array takes ${Vt(t, e)} B per feature, and a storage buffer binding holds ${r} B`
|
|
980
|
+
), o = o.slice(0, l));
|
|
981
|
+
for (const [s, u] of Object.entries(t ?? {}))
|
|
982
|
+
if (R(u) && u.fromFeature.iterate === "batched") {
|
|
858
983
|
const d = typeof u.default == "number" ? u.default : void 0;
|
|
859
|
-
|
|
860
|
-
const
|
|
861
|
-
return Number.isFinite(
|
|
984
|
+
i[s] = o.map((f) => {
|
|
985
|
+
const c = Number(x(f, u.fromFeature.path) ?? d);
|
|
986
|
+
return Number.isFinite(c) ? c : 0;
|
|
862
987
|
});
|
|
863
|
-
} else typeof u == "number" && (n[
|
|
864
|
-
for (const [
|
|
865
|
-
if (!
|
|
988
|
+
} else typeof u == "number" && (n[s] = u);
|
|
989
|
+
for (const [s, u] of Object.entries(e ?? {})) {
|
|
990
|
+
if (!R(u) || u.fromFeature.iterate !== "batched") continue;
|
|
866
991
|
const d = [];
|
|
867
|
-
for (const
|
|
868
|
-
const
|
|
869
|
-
let
|
|
870
|
-
if (Array.isArray(
|
|
871
|
-
for (const g of
|
|
992
|
+
for (const f of o) {
|
|
993
|
+
const c = x(f, u.fromFeature.path);
|
|
994
|
+
let h = 1 / 0, m = 1 / 0, y = -1 / 0, p = -1 / 0;
|
|
995
|
+
if (Array.isArray(c))
|
|
996
|
+
for (const g of c) {
|
|
872
997
|
if (!Array.isArray(g) || g.length < 2) continue;
|
|
873
|
-
const
|
|
874
|
-
!Number.isFinite(
|
|
998
|
+
const _ = Number(g[0]), $ = Number(g[1]);
|
|
999
|
+
!Number.isFinite(_) || !Number.isFinite($) || (h = Math.min(h, _), m = Math.min(m, $), y = Math.max(y, _), p = Math.max(p, $));
|
|
875
1000
|
}
|
|
876
|
-
Number.isFinite(
|
|
1001
|
+
Number.isFinite(h) || (h = 0, m = 0, y = 0, p = 0), d.push(h, m, y, m, y, p, h, p);
|
|
877
1002
|
}
|
|
878
|
-
|
|
1003
|
+
i[s] = d;
|
|
879
1004
|
}
|
|
880
|
-
return n.num_features = o.length, { uniforms: n, uniformArrays:
|
|
1005
|
+
return n.num_features = o.length, { uniforms: n, uniformArrays: i };
|
|
881
1006
|
}
|
|
882
|
-
function
|
|
883
|
-
const r =
|
|
1007
|
+
function wt(t, e, o) {
|
|
1008
|
+
const r = N(e, t.dataRef);
|
|
884
1009
|
if (!r) throw new Error(`compute: table "${t.dataRef}" is not loaded`);
|
|
885
1010
|
const n = {
|
|
886
1011
|
collection: r,
|
|
887
1012
|
variableMapping: t.attributes,
|
|
888
|
-
wgslBody:
|
|
1013
|
+
wgslBody: to(t.wgslFunction)
|
|
889
1014
|
};
|
|
890
1015
|
t.attributeArrays && (n.attributeArrays = t.attributeArrays), t.attributeMatrices && (n.attributeMatrices = t.attributeMatrices), t.uniformArrays && (n.uniformArrays = t.uniformArrays), t.outputColumnName && (n.resultField = t.outputColumnName), t.outputColumns && (n.outputColumns = t.outputColumns);
|
|
891
|
-
const
|
|
892
|
-
if (
|
|
893
|
-
const u =
|
|
894
|
-
return n.uniforms = { ...
|
|
1016
|
+
const i = Wt(t);
|
|
1017
|
+
if (i?.mode === "batched") {
|
|
1018
|
+
const u = N(e, i.layer)?.features ?? [], d = no(t.uniforms, t.uniformMatrices, u), f = mt(bt(t.uniforms), e) ?? {}, c = yt(bt(t.uniformMatrices), e);
|
|
1019
|
+
return n.uniforms = { ...f, ...d.uniforms }, n.uniformArrays = { ...n.uniformArrays ?? {}, ...d.uniformArrays }, c && Object.keys(c).length > 0 && (n.uniformMatrices = c), n;
|
|
895
1020
|
}
|
|
896
|
-
const a =
|
|
897
|
-
return
|
|
1021
|
+
const a = i?.mode === "all" ? o : void 0, l = mt(t.uniforms, e, a), s = yt(t.uniformMatrices, e, a);
|
|
1022
|
+
return l && (n.uniforms = l), s && (n.uniformMatrices = s), n;
|
|
898
1023
|
}
|
|
899
|
-
function
|
|
1024
|
+
function bt(t) {
|
|
900
1025
|
if (t)
|
|
901
|
-
return Object.fromEntries(Object.entries(t).filter(([, e]) => !(
|
|
1026
|
+
return Object.fromEntries(Object.entries(t).filter(([, e]) => !(R(e) && e.fromFeature.iterate === "batched")));
|
|
902
1027
|
}
|
|
903
|
-
function
|
|
1028
|
+
function ao(t) {
|
|
904
1029
|
return t.outputColumns ?? (t.outputColumnName ? [t.outputColumnName] : []);
|
|
905
1030
|
}
|
|
906
|
-
async function
|
|
907
|
-
const r =
|
|
908
|
-
if (r?.mode !== "all") return o(
|
|
909
|
-
const n =
|
|
1031
|
+
async function io(t, e, o) {
|
|
1032
|
+
const r = Wt(t);
|
|
1033
|
+
if (r?.mode !== "all") return o(wt(t, e));
|
|
1034
|
+
const n = N(e, t.dataRef);
|
|
910
1035
|
if (!n) throw new Error(`compute: table "${t.dataRef}" is not loaded`);
|
|
911
|
-
const
|
|
912
|
-
for (const
|
|
913
|
-
const u =
|
|
914
|
-
for (const
|
|
1036
|
+
const i = ao(t), a = structuredClone(n);
|
|
1037
|
+
for (const s of a.features) {
|
|
1038
|
+
const u = s.properties ??= {}, d = u.compute ??= {};
|
|
1039
|
+
for (const f of i) d[f] = 0;
|
|
915
1040
|
}
|
|
916
|
-
const
|
|
917
|
-
for (let
|
|
918
|
-
const u = await o({ ...
|
|
919
|
-
a.features.forEach((d,
|
|
920
|
-
const
|
|
921
|
-
if (!(!
|
|
922
|
-
for (const
|
|
923
|
-
const y = Number(m
|
|
924
|
-
Number.isFinite(y) && (
|
|
1041
|
+
const l = N(e, r.layer)?.features?.length ?? 0;
|
|
1042
|
+
for (let s = 0; s < l; s++) {
|
|
1043
|
+
const u = await o({ ...wt(t, e, s), collection: a });
|
|
1044
|
+
a.features.forEach((d, f) => {
|
|
1045
|
+
const c = d.properties?.compute, h = u.features[f]?.properties?.compute;
|
|
1046
|
+
if (!(!c || !h))
|
|
1047
|
+
for (const m of i) {
|
|
1048
|
+
const y = Number(h[m]);
|
|
1049
|
+
Number.isFinite(y) && (c[m] += y);
|
|
925
1050
|
}
|
|
926
1051
|
});
|
|
927
1052
|
}
|
|
928
1053
|
return a;
|
|
929
1054
|
}
|
|
930
|
-
const
|
|
931
|
-
function
|
|
932
|
-
return r?.get(
|
|
1055
|
+
const vt = ["surface", "parks", "water", "roads", "buildings", "polygons", "polylines"];
|
|
1056
|
+
function so(t, e, o, r) {
|
|
1057
|
+
return r?.get(E(o, e)) ?? t.getTablesMetadata().find((n) => n.name === e)?.type;
|
|
933
1058
|
}
|
|
934
|
-
function
|
|
935
|
-
async function r(
|
|
936
|
-
return t?.get(
|
|
1059
|
+
function lo(t, e, o) {
|
|
1060
|
+
async function r(l, s, u) {
|
|
1061
|
+
return t?.get(E(u, s)) ?? await l.getLayer(s);
|
|
937
1062
|
}
|
|
938
|
-
function n(
|
|
1063
|
+
function n(l, s, u, d, f) {
|
|
939
1064
|
if (!t) return;
|
|
940
|
-
const
|
|
941
|
-
t.set(
|
|
942
|
-
const
|
|
943
|
-
d.outputTableName &&
|
|
1065
|
+
const c = d.outputTableName ?? u;
|
|
1066
|
+
t.set(E(d.workspace, c), s);
|
|
1067
|
+
const h = d.layerType ?? f ?? so(l, u, d.workspace, e);
|
|
1068
|
+
d.outputTableName && h && e?.set(E(d.workspace, c), h);
|
|
944
1069
|
}
|
|
945
|
-
async function l
|
|
946
|
-
for (const
|
|
947
|
-
if (!
|
|
948
|
-
throw new Error(`Render pass "${
|
|
949
|
-
const u = await Promise.all(
|
|
950
|
-
id:
|
|
951
|
-
collection: await r(
|
|
952
|
-
type:
|
|
953
|
-
objectIdProperty:
|
|
954
|
-
}))), d = await new
|
|
1070
|
+
async function i(l, s) {
|
|
1071
|
+
for (const f of s.layers)
|
|
1072
|
+
if (!vt.includes(f.type))
|
|
1073
|
+
throw new Error(`Render pass "${s.outputTableName}": layer "${f.id}" has the type "${f.type}", which a render pass cannot draw. A layer's type is one of ${vt.join(", ")}.`);
|
|
1074
|
+
const u = await Promise.all(s.layers.map(async (f) => ({
|
|
1075
|
+
id: f.id,
|
|
1076
|
+
collection: await r(l, f.dataRef, s.workspace),
|
|
1077
|
+
type: f.type,
|
|
1078
|
+
objectIdProperty: f.objectIdProperty
|
|
1079
|
+
}))), d = await new at().renderPipeline({
|
|
955
1080
|
layers: u,
|
|
956
1081
|
viewpoints: {
|
|
957
|
-
collection: await r(
|
|
958
|
-
strategy:
|
|
959
|
-
sampling:
|
|
1082
|
+
collection: await r(l, s.viewpoints.dataRef, s.workspace),
|
|
1083
|
+
strategy: s.viewpoints.strategy,
|
|
1084
|
+
sampling: s.viewpoints.sampling
|
|
960
1085
|
},
|
|
961
|
-
aggregation:
|
|
962
|
-
camera:
|
|
963
|
-
tileSize:
|
|
1086
|
+
aggregation: s.aggregation,
|
|
1087
|
+
camera: s.camera,
|
|
1088
|
+
tileSize: s.tileSize
|
|
964
1089
|
});
|
|
965
|
-
n(
|
|
1090
|
+
n(l, d, s.viewpoints.dataRef, s, s.viewpoints.strategy?.type === "building-windows" ? "points" : void 0);
|
|
966
1091
|
}
|
|
967
|
-
async function a(
|
|
968
|
-
const u = {}, d =
|
|
969
|
-
for (const
|
|
970
|
-
const
|
|
971
|
-
if (y) u[
|
|
972
|
-
else if (
|
|
1092
|
+
async function a(l, s) {
|
|
1093
|
+
const u = {}, d = l.getWorkspaceConfiguration().coordinateFormat;
|
|
1094
|
+
for (const h of eo(s)) {
|
|
1095
|
+
const m = E(s.workspace, h), y = t?.get(m) ?? (h === s.dataRef ? void 0 : re(o?.get(m), d));
|
|
1096
|
+
if (y) u[h] = y;
|
|
1097
|
+
else if (h === s.dataRef) u[h] = await l.getLayer(h);
|
|
973
1098
|
else
|
|
974
1099
|
try {
|
|
975
|
-
u[
|
|
1100
|
+
u[h] = await l.getLayer(h);
|
|
976
1101
|
} catch {
|
|
977
|
-
u[
|
|
1102
|
+
u[h] = void 0;
|
|
978
1103
|
}
|
|
979
1104
|
}
|
|
980
|
-
const
|
|
981
|
-
n(
|
|
1105
|
+
const f = new at(), c = await io(s, u, (h) => f.gpgpuPipeline(h));
|
|
1106
|
+
n(l, c, s.dataRef, s);
|
|
982
1107
|
}
|
|
983
1108
|
return {
|
|
984
|
-
async resolveCompute(
|
|
985
|
-
if (
|
|
986
|
-
return await
|
|
1109
|
+
async resolveCompute(l, s) {
|
|
1110
|
+
if (l)
|
|
1111
|
+
return await I(l, s.workspace), s.type === "render" ? await i(l, s) : await a(l, s), l;
|
|
987
1112
|
}
|
|
988
1113
|
};
|
|
989
1114
|
}
|
|
990
|
-
class
|
|
1115
|
+
class uo {
|
|
991
1116
|
_listeners = /* @__PURE__ */ new Map();
|
|
992
1117
|
on(e, o) {
|
|
993
1118
|
this._listeners.has(e) || this._listeners.set(e, /* @__PURE__ */ new Set());
|
|
@@ -999,26 +1124,26 @@ class He {
|
|
|
999
1124
|
this._listeners.get(e)?.forEach((r) => r(o));
|
|
1000
1125
|
}
|
|
1001
1126
|
}
|
|
1002
|
-
function
|
|
1127
|
+
function v(t) {
|
|
1003
1128
|
return t === void 0 ? [] : Array.isArray(t) ? t : [t];
|
|
1004
1129
|
}
|
|
1005
|
-
function
|
|
1130
|
+
function fo(t) {
|
|
1006
1131
|
const e = /* @__PURE__ */ new Set();
|
|
1007
|
-
for (const r of [...
|
|
1132
|
+
for (const r of [...v(t.map), ...v(t.plot)])
|
|
1008
1133
|
if (r.id !== void 0) {
|
|
1009
1134
|
if (r.id === "") throw new Error("A map or plot has an empty id.");
|
|
1010
1135
|
if (e.has(r.id)) throw new Error(`Two maps or plots have the id "${r.id}"; an id names one view.`);
|
|
1011
1136
|
e.add(r.id);
|
|
1012
1137
|
}
|
|
1013
1138
|
const o = /* @__PURE__ */ new Map();
|
|
1014
|
-
for (const r of
|
|
1015
|
-
const n =
|
|
1016
|
-
if (
|
|
1017
|
-
throw new Error(
|
|
1139
|
+
for (const r of v(t.plot)) {
|
|
1140
|
+
const n = C(r), i = o.get(n);
|
|
1141
|
+
if (i)
|
|
1142
|
+
throw new Error(i.id === void 0 && r.id === void 0 ? `Two plots of the table "${n}" have no id; give each plot an id.` : `A plot's id "${n}" is the dataRef of a plot without an id; give each plot an id.`);
|
|
1018
1143
|
o.set(n, r);
|
|
1019
1144
|
}
|
|
1020
1145
|
}
|
|
1021
|
-
class
|
|
1146
|
+
class wo {
|
|
1022
1147
|
dataAdapter;
|
|
1023
1148
|
mapAdapter;
|
|
1024
1149
|
plotAdapter;
|
|
@@ -1036,9 +1161,9 @@ class eo {
|
|
|
1036
1161
|
_exports = /* @__PURE__ */ new Map();
|
|
1037
1162
|
/** Each GeoJSON table a run loaded and each table a join wrote, which its plots read before the database. */
|
|
1038
1163
|
_geojsonCache = /* @__PURE__ */ new Map();
|
|
1039
|
-
interactions = new
|
|
1164
|
+
interactions = new uo();
|
|
1040
1165
|
constructor(e) {
|
|
1041
|
-
this.dataAdapter =
|
|
1166
|
+
this.dataAdapter = fe(e, this._geojsonCache), this.mapAdapter = Oe(e, this._layers, this._computeCache, this._maps, this._computeTypes, this._exports), this.plotAdapter = ze(e, this._layers, this._plotRegistry, this._plotLinks, this._geojsonCache, this._computeCache, this._plotRows, this._exports), this.computeAdapter = lo(this._computeCache, this._computeTypes, this._geojsonCache);
|
|
1042
1167
|
}
|
|
1043
1168
|
/**
|
|
1044
1169
|
* The coordinate reference system autk-db stores a workspace's tables in, unless the spec's `workspaces` sets
|
|
@@ -1050,7 +1175,7 @@ class eo {
|
|
|
1050
1175
|
* instead of hard-coding a CRS string.
|
|
1051
1176
|
*/
|
|
1052
1177
|
get workspaceCrs() {
|
|
1053
|
-
return
|
|
1178
|
+
return qt;
|
|
1054
1179
|
}
|
|
1055
1180
|
get data() {
|
|
1056
1181
|
return this._data;
|
|
@@ -1097,7 +1222,7 @@ class eo {
|
|
|
1097
1222
|
}
|
|
1098
1223
|
/** The drawn layers of a table, on every map or on the one `mapId` names. */
|
|
1099
1224
|
_layersOf(e, o) {
|
|
1100
|
-
return this._layers.filter((r) => r.dataRef === e &&
|
|
1225
|
+
return this._layers.filter((r) => r.dataRef === e && Y(r, o));
|
|
1101
1226
|
}
|
|
1102
1227
|
/**
|
|
1103
1228
|
* Releases what the last run created: every map (its layers' GPU buffers, its textures, its canvas context, the
|
|
@@ -1121,10 +1246,10 @@ class eo {
|
|
|
1121
1246
|
throw new Error("Plot adapter not initialized. Please call the constructor first.");
|
|
1122
1247
|
if (!this.computeAdapter)
|
|
1123
1248
|
throw new Error("Compute adapter not initialized. Please call the constructor first.");
|
|
1124
|
-
|
|
1125
|
-
for (const
|
|
1126
|
-
const o =
|
|
1127
|
-
this.destroy(),
|
|
1249
|
+
fo(e);
|
|
1250
|
+
for (const i of v(e.plot)) Ge(i);
|
|
1251
|
+
const o = Ue(v(e.plot));
|
|
1252
|
+
this.destroy(), v(e.plot).length > 0 && qe(o), this.grammarEngine = Xt({
|
|
1128
1253
|
spec: e,
|
|
1129
1254
|
adapters: {
|
|
1130
1255
|
db: this.dataAdapter,
|
|
@@ -1134,23 +1259,23 @@ class eo {
|
|
|
1134
1259
|
}
|
|
1135
1260
|
}), await this.grammarEngine.run();
|
|
1136
1261
|
const r = this.grammarEngine.context;
|
|
1137
|
-
if (r && await
|
|
1262
|
+
if (r && await I(r), this._wireLinks(e), this._pickFromTheStart(e), this._selectFromTheStart(e), this._rewireInteractions(e), !r) {
|
|
1138
1263
|
console.warn("Grammar engine produced no data context."), this._data = {};
|
|
1139
1264
|
return;
|
|
1140
1265
|
}
|
|
1141
1266
|
const n = {};
|
|
1142
|
-
for (const
|
|
1143
|
-
Object.defineProperty(n,
|
|
1267
|
+
for (const i of r.getLayersMetadata())
|
|
1268
|
+
Object.defineProperty(n, i.name, {
|
|
1144
1269
|
get: () => {
|
|
1145
|
-
const a = this._computeCache.get(
|
|
1146
|
-
return a ? Promise.resolve(a) : r.getLayer(
|
|
1270
|
+
const a = this._computeCache.get(i.name);
|
|
1271
|
+
return a ? Promise.resolve(a) : r.getLayer(i.name);
|
|
1147
1272
|
},
|
|
1148
1273
|
enumerable: !0,
|
|
1149
1274
|
configurable: !0
|
|
1150
1275
|
});
|
|
1151
|
-
for (const
|
|
1152
|
-
|
|
1153
|
-
get: () => Promise.resolve(this._computeCache.get(
|
|
1276
|
+
for (const i of this._computeCache.keys())
|
|
1277
|
+
i in n || Object.defineProperty(n, i, {
|
|
1278
|
+
get: () => Promise.resolve(this._computeCache.get(i)),
|
|
1154
1279
|
enumerable: !0,
|
|
1155
1280
|
configurable: !0
|
|
1156
1281
|
});
|
|
@@ -1169,7 +1294,7 @@ class eo {
|
|
|
1169
1294
|
*/
|
|
1170
1295
|
highlightOnMap(e, o, r) {
|
|
1171
1296
|
const n = this._layersOf(e, r);
|
|
1172
|
-
for (const { map:
|
|
1297
|
+
for (const { map: i, layerId: a } of n) i.setHighlightedIds(a, o);
|
|
1173
1298
|
this._selectInLinkedPlots(n, o);
|
|
1174
1299
|
}
|
|
1175
1300
|
/**
|
|
@@ -1183,7 +1308,7 @@ class eo {
|
|
|
1183
1308
|
*/
|
|
1184
1309
|
clearHighlightOnMap(e, o) {
|
|
1185
1310
|
const r = this._layersOf(e, o);
|
|
1186
|
-
for (const { map: n, layerId:
|
|
1311
|
+
for (const { map: n, layerId: i } of r) n.clearHighlightedIds(i);
|
|
1187
1312
|
this._selectInLinkedPlots(r, []);
|
|
1188
1313
|
}
|
|
1189
1314
|
/**
|
|
@@ -1198,7 +1323,7 @@ class eo {
|
|
|
1198
1323
|
clearHighlightOnPlot(e, o) {
|
|
1199
1324
|
this._plotRegistry.get(e)?.setSelection([]);
|
|
1200
1325
|
for (const r of this._plotLinks.get(e) ?? [])
|
|
1201
|
-
|
|
1326
|
+
Y(r, o) && r.map.clearHighlightedIds(r.layerId);
|
|
1202
1327
|
}
|
|
1203
1328
|
/**
|
|
1204
1329
|
* Applies a selection to the plot `plotId` names: its `id`, else its `dataRef`.
|
|
@@ -1213,8 +1338,8 @@ class eo {
|
|
|
1213
1338
|
setPlotSelection(e, o, r) {
|
|
1214
1339
|
this._plotRegistry.get(e)?.setSelection(o);
|
|
1215
1340
|
const n = this._plotRows.get(e) ?? [];
|
|
1216
|
-
for (const
|
|
1217
|
-
|
|
1341
|
+
for (const i of this._plotLinks.get(e) ?? [])
|
|
1342
|
+
Y(i, r) && i.map.setHighlightedIds(i.layerId, D(o, n, i.rows));
|
|
1218
1343
|
}
|
|
1219
1344
|
/**
|
|
1220
1345
|
* Applies a selection made on `layers`, by their positions `featureIds`, to every plot linked to one of them, at the
|
|
@@ -1222,83 +1347,109 @@ class eo {
|
|
|
1222
1347
|
*/
|
|
1223
1348
|
_selectInLinkedPlots(e, o) {
|
|
1224
1349
|
for (const [r, n] of this._plotLinks) {
|
|
1225
|
-
const
|
|
1226
|
-
if (
|
|
1227
|
-
const a = this._plotRows.get(r) ?? [],
|
|
1228
|
-
this._plotRegistry.get(r)?.setSelection([...
|
|
1350
|
+
const i = n.filter((s) => e.includes(s));
|
|
1351
|
+
if (i.length === 0) continue;
|
|
1352
|
+
const a = this._plotRows.get(r) ?? [], l = new Set(i.flatMap((s) => D(o, s.rows, a)));
|
|
1353
|
+
this._plotRegistry.get(r)?.setSelection([...l]);
|
|
1229
1354
|
}
|
|
1230
1355
|
}
|
|
1231
1356
|
/** Wires each entry of `links` between a plot and a layer of a map, both now drawn. */
|
|
1232
1357
|
_wireLinks(e) {
|
|
1233
|
-
const o =
|
|
1358
|
+
const o = v(e.map), r = v(e.plot);
|
|
1234
1359
|
for (const n of e.links ?? []) {
|
|
1235
|
-
const
|
|
1236
|
-
if (!
|
|
1360
|
+
const i = r.find((f) => C(f) === n.source), a = this._plotRegistry.get(n.source);
|
|
1361
|
+
if (!i || !a)
|
|
1237
1362
|
throw new Error(`Link source "${n.source}" is not the id (or the dataRef) of a plot of this specification.`);
|
|
1238
|
-
const
|
|
1239
|
-
if (
|
|
1363
|
+
const l = o.findIndex((f) => f.id === n.target), s = this._maps[l];
|
|
1364
|
+
if (l < 0 || !s)
|
|
1240
1365
|
throw new Error(`Link target "${n.target}" is not the id of a map of this specification.`);
|
|
1241
|
-
const u = o[
|
|
1366
|
+
const u = o[l].layerRefs.find((f) => n.layer !== void 0 ? b(f) === n.layer : f.dataRef === i.dataRef);
|
|
1242
1367
|
if (!u)
|
|
1243
|
-
throw new Error(n.layer !== void 0 ? `Link from "${n.source}": map "${n.target}" has no layer "${n.layer}".` : `Link from "${n.source}": map "${n.target}" draws no layer of the table "${
|
|
1244
|
-
const d = this._layers.find((
|
|
1245
|
-
d && (
|
|
1368
|
+
throw new Error(n.layer !== void 0 ? `Link from "${n.source}": map "${n.target}" has no layer "${n.layer}".` : `Link from "${n.source}": map "${n.target}" draws no layer of the table "${i.dataRef}"; name the layer.`);
|
|
1369
|
+
const d = this._layers.find((f) => f.mapIndex === l && f.layerId === b(u));
|
|
1370
|
+
d && (Dt(a, this._plotRows.get(n.source) ?? [], i.events ?? [], d), Pt(this._plotLinks, n.source, d));
|
|
1246
1371
|
}
|
|
1247
1372
|
}
|
|
1373
|
+
/**
|
|
1374
|
+
* Draws each layer's `pickedComps` as picked once the maps, the plots and their links exist, as `highlightOnMap` does
|
|
1375
|
+
* for that one layer: the layer highlights the features, and the plots linked to it select the same rows. autk-map
|
|
1376
|
+
* draws picked features only on the layer of a map that picks, and lets one layer of a map pick, so a layer that no
|
|
1377
|
+
* longer picks, since a link or a plot's `mapRef` made another layer of its map pick, is refused. So is one linked to a
|
|
1378
|
+
* plot that sets `selection`, which sets what both show too.
|
|
1379
|
+
*/
|
|
1380
|
+
_pickFromTheStart(e) {
|
|
1381
|
+
const o = v(e.plot);
|
|
1382
|
+
v(e.map).forEach((r, n) => {
|
|
1383
|
+
for (const i of r.layerRefs) {
|
|
1384
|
+
if (!i.pickedComps) continue;
|
|
1385
|
+
const a = b(i), l = this._layers.find((u) => u.mapIndex === n && u.layerId === a);
|
|
1386
|
+
if (!l) continue;
|
|
1387
|
+
const s = l.map.activePickingLayer?.layerInfo.id;
|
|
1388
|
+
if (s !== a)
|
|
1389
|
+
throw new Error(`Layer "${a}": pickedComps draws features as picked on the layer that picks, but ${s === void 0 ? "no layer of its map picks" : `a link or a plot's mapRef made layer "${s}" of its map pick`}: autk-map lets one layer of a map pick.`);
|
|
1390
|
+
for (const [u, d] of this._plotLinks) {
|
|
1391
|
+
const f = o.find((c) => C(c) === u);
|
|
1392
|
+
if (d.includes(l) && (f?.selection?.length ?? 0) > 0)
|
|
1393
|
+
throw new Error(`Layer "${a}": pickedComps and the selection of plot "${u}", which is linked to it, both set what the two show: set one of them.`);
|
|
1394
|
+
}
|
|
1395
|
+
l.map.setHighlightedIds(a, i.pickedComps), this._selectInLinkedPlots([l], i.pickedComps);
|
|
1396
|
+
}
|
|
1397
|
+
});
|
|
1398
|
+
}
|
|
1248
1399
|
/**
|
|
1249
1400
|
* Applies each plot's `selection` once the plots and their links exist, as `setPlotSelection` does: the plot selects
|
|
1250
1401
|
* the rows, and the layers it is linked to, by `mapRef` or `links`, highlight them. autk-plot's `setSelection` emits
|
|
1251
1402
|
* no event, so no `plot:selection` reports it.
|
|
1252
1403
|
*/
|
|
1253
1404
|
_selectFromTheStart(e) {
|
|
1254
|
-
for (const o of
|
|
1255
|
-
o.selection && o.selection.length > 0 && this.setPlotSelection(
|
|
1405
|
+
for (const o of v(e.plot))
|
|
1406
|
+
o.selection && o.selection.length > 0 && this.setPlotSelection(C(o), o.selection);
|
|
1256
1407
|
}
|
|
1257
1408
|
_rewireInteractions(e) {
|
|
1258
1409
|
for (const r of this._fwdCleanups) r();
|
|
1259
1410
|
this._fwdCleanups = [];
|
|
1260
|
-
const o =
|
|
1411
|
+
const o = v(e.map);
|
|
1261
1412
|
this._maps.forEach((r, n) => {
|
|
1262
|
-
const
|
|
1263
|
-
this.interactions.emit("map:picking", { mapId:
|
|
1413
|
+
const i = Lt(o[n], n), a = ({ layerId: l, selection: s }) => {
|
|
1414
|
+
this.interactions.emit("map:picking", { mapId: i, layerId: l, selection: s });
|
|
1264
1415
|
};
|
|
1265
|
-
r.events.on(
|
|
1416
|
+
r.events.on(J.PICKING, a), this._fwdCleanups.push(() => r.events.off(J.PICKING, a));
|
|
1266
1417
|
});
|
|
1267
1418
|
for (const [r, n] of this._plotRegistry)
|
|
1268
|
-
for (const
|
|
1269
|
-
const a = ({ selection:
|
|
1419
|
+
for (const i of [B.CLICK, B.BRUSH, B.BRUSH_X, B.BRUSH_Y]) {
|
|
1420
|
+
const a = ({ selection: l }) => {
|
|
1270
1421
|
this.interactions.emit("plot:selection", {
|
|
1271
1422
|
plotId: r,
|
|
1272
|
-
event:
|
|
1273
|
-
selection:
|
|
1423
|
+
event: i,
|
|
1424
|
+
selection: l
|
|
1274
1425
|
});
|
|
1275
1426
|
};
|
|
1276
|
-
n.events.on(
|
|
1427
|
+
n.events.on(i, a), this._fwdCleanups.push(() => n.events.off(i, a));
|
|
1277
1428
|
}
|
|
1278
1429
|
}
|
|
1279
1430
|
}
|
|
1280
1431
|
export {
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1432
|
+
wo as AutkGrammar,
|
|
1433
|
+
Zt as ColorMapInterpolator,
|
|
1434
|
+
uo as GrammarEventEmitter,
|
|
1435
|
+
Ct as NormalizationMode,
|
|
1436
|
+
Gt as STORAGE_BUFFER_BINDING_SIZE,
|
|
1437
|
+
Pe as applyCamera,
|
|
1438
|
+
go as arrangeViews,
|
|
1439
|
+
no as buildBatchedUniforms,
|
|
1440
|
+
eo as computeLayerNames,
|
|
1441
|
+
lo as createComputeAdapter,
|
|
1442
|
+
fe as createDataAdapter,
|
|
1443
|
+
Xt as createEngine,
|
|
1444
|
+
I as enterWorkspace,
|
|
1445
|
+
Wt as findIterateSource,
|
|
1446
|
+
R as isFromFeature,
|
|
1447
|
+
to as joinWgsl,
|
|
1448
|
+
ro as maxBatchedFeatures,
|
|
1449
|
+
wt as resolveComputeParams,
|
|
1450
|
+
yt as resolveUniformMatrices,
|
|
1451
|
+
mt as resolveUniforms,
|
|
1452
|
+
io as runCompute,
|
|
1453
|
+
E as tableKey
|
|
1303
1454
|
};
|
|
1304
1455
|
//# sourceMappingURL=autk-grammar.js.map
|