@emuanalytics/flow-rdf-core 4.1.8 → 4.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/dist/index.d.mts +322 -4
- package/dist/index.d.ts +322 -4
- package/dist/index.mjs +6 -0
- package/dist/lib/map/flow-core-map.mjs +120 -13
- package/dist/lib/map/plugins/index.d.mts +252 -223
- package/dist/lib/map/plugins/index.d.ts +252 -223
- package/dist/lib/map/plugins/selection/selection.plugin.mjs +73 -7
- package/dist/lib/map/plugins/selection/source-selection.mjs +12 -0
- package/dist/lib/map-style/composite/builder.mjs +31 -0
- package/dist/lib/map-style/composite/editing.mjs +123 -0
- package/dist/lib/map-style/composite/expand.mjs +182 -0
- package/dist/lib/map-style/composite/stored-format.mjs +18 -0
- package/dist/lib/map-style/composite/validate.mjs +376 -0
- package/dist/lib/map-style/flow-style/builder.mjs +97 -0
- package/dist/lib/map-style/flow-style/data-driven.mjs +164 -0
- package/dist/lib/map-style/flow-style/expand.mjs +145 -0
- package/dist/lib/map-style/flow-style/literals.mjs +58 -0
- package/dist/lib/map-style/flow-style/stored-format.mjs +93 -0
- package/dist/lib/map-style/flow-style/validate.mjs +117 -0
- package/dist/lib/map-style/flow-style/values.mjs +249 -0
- package/dist/lib/map-style/map-data-source.mjs +9 -0
- package/dist/lib/map-style/map-layer.mjs +555 -17
- package/dist/lib/map-style/map-style.mjs +250 -39
- package/dist/package.json.mjs +1 -1
- package/dist/shared/{flow-rdf-core.1ee62df9.d.mts → flow-rdf-core.62a36d8b.d.mts} +1077 -234
- package/dist/shared/{flow-rdf-core.1ee62df9.d.ts → flow-rdf-core.62a36d8b.d.ts} +1077 -234
- package/package.json +1 -1
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import { isPlainObject } from '../../utils/type-checks.mjs';
|
|
2
|
+
import { cloneStoredValue } from '../flow-style/builder.mjs';
|
|
3
|
+
import { dataDrivenExpression } from '../flow-style/data-driven.mjs';
|
|
4
|
+
import { loadStoredFlowStyle, setStoredFlowStyleProperty, saveStoredFlowStyle } from '../flow-style/stored-format.mjs';
|
|
5
|
+
import { flowStyleVersion, isFlowStylePropertyName, flowStylePropertyExpression, FLOW_STYLE_PROPERTIES, isNamedSize } from '../flow-style/values.mjs';
|
|
6
|
+
import { FlowCoreError } from '../../errors/flow-error.mjs';
|
|
7
|
+
|
|
8
|
+
function getCompositeFlowStyle(spec, layerId) {
|
|
9
|
+
const layer = findSubLayer(spec, layerId)?.layer;
|
|
10
|
+
if (layer === void 0) {
|
|
11
|
+
return void 0;
|
|
12
|
+
}
|
|
13
|
+
if (layer.type === "flow") {
|
|
14
|
+
return isObject(layer.style) ? cloneStoredValue(layer.style) : void 0;
|
|
15
|
+
}
|
|
16
|
+
if (isObject(layer.style) && layer.style.type === "flow") {
|
|
17
|
+
return version2View(layer.style, layer.type);
|
|
18
|
+
}
|
|
19
|
+
return void 0;
|
|
20
|
+
}
|
|
21
|
+
function updateCompositeFlowStyle(spec, layerId, changes) {
|
|
22
|
+
const { copy, layer } = editSubLayer(spec, layerId, "updateCompositeFlowStyle");
|
|
23
|
+
const isVersion2 = layer.type === "flow";
|
|
24
|
+
if (!isVersion2 && !(isObject(layer.style) && layer.style.type === "flow")) {
|
|
25
|
+
throw new FlowCoreError(`updateCompositeFlowStyle: sub-layer '${layerId}' doesn't have a flow style`);
|
|
26
|
+
}
|
|
27
|
+
let stored = loadStoredFlowStyle(isVersion2 && !isObject(layer.style) ? { version: 2 } : layer.style);
|
|
28
|
+
for (const property of Object.keys(changes)) {
|
|
29
|
+
if (property !== "type" && property !== "version") {
|
|
30
|
+
stored = setStoredFlowStyleProperty(stored, property, changes[property]);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
layer.style = saveStoredFlowStyle(stored);
|
|
34
|
+
return copy;
|
|
35
|
+
}
|
|
36
|
+
function setCompositeSubLayerFilter(spec, layerId, filter) {
|
|
37
|
+
const { copy, layer } = editSubLayer(spec, layerId, "setCompositeSubLayerFilter");
|
|
38
|
+
if (filter === null || filter === "") {
|
|
39
|
+
delete layer.filter;
|
|
40
|
+
} else {
|
|
41
|
+
layer.filter = filter;
|
|
42
|
+
}
|
|
43
|
+
return copy;
|
|
44
|
+
}
|
|
45
|
+
function findSubLayer(spec, layerId) {
|
|
46
|
+
const layers = isObject(spec) && Array.isArray(spec.layers) ? spec.layers : [];
|
|
47
|
+
const index = layers.findIndex((layer) => isObject(layer) && layer.id === layerId);
|
|
48
|
+
return index === -1 ? void 0 : { index, layer: layers[index] };
|
|
49
|
+
}
|
|
50
|
+
function editSubLayer(spec, layerId, caller) {
|
|
51
|
+
const found = findSubLayer(spec, layerId);
|
|
52
|
+
if (!found) {
|
|
53
|
+
throw new FlowCoreError(`${caller}: the composite layer spec has no sub-layer '${layerId}'`);
|
|
54
|
+
}
|
|
55
|
+
const copy = cloneStoredValue(spec);
|
|
56
|
+
return { copy, layer: copy.layers[found.index] };
|
|
57
|
+
}
|
|
58
|
+
function version2View(style, geometry) {
|
|
59
|
+
if (flowStyleVersion(style) !== 1) {
|
|
60
|
+
return cloneStoredValue(style);
|
|
61
|
+
}
|
|
62
|
+
const view = { type: geometry, version: 2 };
|
|
63
|
+
for (const key of Object.keys(style)) {
|
|
64
|
+
if (key !== "type" && key !== "version") {
|
|
65
|
+
const value = isFlowStylePropertyName(key) ? version2Value(key, style[key]) : cloneStoredValue(style[key]);
|
|
66
|
+
Object.defineProperty(view, key, { value, enumerable: true, writable: true, configurable: true });
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
return view;
|
|
70
|
+
}
|
|
71
|
+
function version2Value(property, value) {
|
|
72
|
+
const drawn = flowStylePropertyExpression(1, property, value).expression;
|
|
73
|
+
if (drawn === void 0) {
|
|
74
|
+
return cloneStoredValue(value);
|
|
75
|
+
}
|
|
76
|
+
const candidate = version2Candidate(property, value);
|
|
77
|
+
if (candidate !== void 0 && flowStylePropertyExpression(2, property, candidate).expression === drawn) {
|
|
78
|
+
return candidate;
|
|
79
|
+
}
|
|
80
|
+
return { type: "expression", value: drawn };
|
|
81
|
+
}
|
|
82
|
+
function version2Candidate(property, value) {
|
|
83
|
+
if (typeof value === "string") {
|
|
84
|
+
if (FLOW_STYLE_PROPERTIES[property] === "size" && isNamedSize(value)) {
|
|
85
|
+
return value;
|
|
86
|
+
}
|
|
87
|
+
return value.startsWith("@") ? { type: "expression", value } : value;
|
|
88
|
+
}
|
|
89
|
+
if (!isObject(value)) {
|
|
90
|
+
return value;
|
|
91
|
+
}
|
|
92
|
+
switch (value.type) {
|
|
93
|
+
case "literal":
|
|
94
|
+
return value.value;
|
|
95
|
+
case "expression":
|
|
96
|
+
return { type: "expression", value: value.value };
|
|
97
|
+
case "data-driven":
|
|
98
|
+
return dataDrivenCandidate(value);
|
|
99
|
+
default:
|
|
100
|
+
return void 0;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
function dataDrivenCandidate(table) {
|
|
104
|
+
const values = table.values;
|
|
105
|
+
const isLiteral = (item) => typeof item === "number" || typeof item === "boolean" || typeof item === "string" && !item.startsWith("@");
|
|
106
|
+
if (!Array.isArray(values) || !isLiteral(table.default) || !values.every((row) => Array.isArray(row) && isLiteral(row[1]))) {
|
|
107
|
+
return void 0;
|
|
108
|
+
}
|
|
109
|
+
const numberKeys = values.length > 0 && values.every((row) => typeof row[0] === "number");
|
|
110
|
+
const mode = table.mode === "off" || table.mode === "interpolate" ? table.mode : numberKeys ? "step" : "match";
|
|
111
|
+
const dataDriven = {
|
|
112
|
+
mode,
|
|
113
|
+
attribute: table.attribute,
|
|
114
|
+
default: table.default,
|
|
115
|
+
values: cloneStoredValue(values)
|
|
116
|
+
};
|
|
117
|
+
return { type: "expression", value: dataDrivenExpression(dataDriven), dataDriven };
|
|
118
|
+
}
|
|
119
|
+
function isObject(value) {
|
|
120
|
+
return isPlainObject(value) && !Array.isArray(value);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
export { getCompositeFlowStyle, setCompositeSubLayerFilter, updateCompositeFlowStyle };
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
import { expandFlowStyle } from '../flow-style/expand.mjs';
|
|
2
|
+
import { compositeLayerVersion } from './stored-format.mjs';
|
|
3
|
+
import { validateCompositeLayer, prefixIssues } from './validate.mjs';
|
|
4
|
+
|
|
5
|
+
const DEFAULT_MIN_ZOOM = 0;
|
|
6
|
+
const DEFAULT_MAX_ZOOM = 18;
|
|
7
|
+
const SPEC_ERROR_PATHS = ["", "version", "layers"];
|
|
8
|
+
const SUB_LAYER_ERROR_KEYS = [
|
|
9
|
+
"",
|
|
10
|
+
"id",
|
|
11
|
+
"type",
|
|
12
|
+
"source",
|
|
13
|
+
"style",
|
|
14
|
+
"style.style",
|
|
15
|
+
"style.type",
|
|
16
|
+
"style.version"
|
|
17
|
+
];
|
|
18
|
+
const DATA_SOURCE_ERROR_KEYS = ["", "id", "type", "src"];
|
|
19
|
+
function expandCompositeLayer(compositeId, spec) {
|
|
20
|
+
try {
|
|
21
|
+
return expand(compositeId, spec);
|
|
22
|
+
} catch (e) {
|
|
23
|
+
return {
|
|
24
|
+
version: void 0,
|
|
25
|
+
sources: [],
|
|
26
|
+
subLayers: [],
|
|
27
|
+
issues: [
|
|
28
|
+
{ path: "", message: `The spec could not be read: ${e?.message ?? String(e)}`, severity: "error" }
|
|
29
|
+
]
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
function expand(compositeId, spec) {
|
|
34
|
+
const issues = validateCompositeLayer(spec);
|
|
35
|
+
const version = compositeLayerVersion(spec);
|
|
36
|
+
const errorPaths = new Set(issues.filter((issue) => issue.severity === "error").map((issue) => issue.path));
|
|
37
|
+
if (version === void 0 || SPEC_ERROR_PATHS.some((path) => errorPaths.has(path))) {
|
|
38
|
+
return { version, sources: [], subLayers: [], issues };
|
|
39
|
+
}
|
|
40
|
+
const object = spec;
|
|
41
|
+
const sources = errorPaths.has("dataSources") ? [] : expandDataSources(version, object.dataSources ?? [], errorPaths);
|
|
42
|
+
const subLayers = [];
|
|
43
|
+
const maplibreIds = /* @__PURE__ */ new Map();
|
|
44
|
+
object.layers.forEach((layer, index) => {
|
|
45
|
+
const path = `layers[${index}]`;
|
|
46
|
+
if (SUB_LAYER_ERROR_KEYS.some((key) => errorPaths.has(join(path, key)))) {
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
const options = layer;
|
|
50
|
+
if (typeof options.filter === "string" && errorPaths.has(join(path, "filter"))) {
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
const expanded = expandSubLayer(version, compositeId, options, path, issues);
|
|
54
|
+
const taken = expanded.find((subLayer) => maplibreIds.has(subLayer.id));
|
|
55
|
+
if (taken) {
|
|
56
|
+
issues.push({
|
|
57
|
+
path: join(path, "id"),
|
|
58
|
+
message: `Sub-layer '${options.id}' would add MapLibre layer '${taken.id}', which sub-layer '${maplibreIds.get(taken.id)}' adds already. It isn't rendered.`,
|
|
59
|
+
severity: "error"
|
|
60
|
+
});
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
expanded.forEach((subLayer) => maplibreIds.set(subLayer.id, options.id));
|
|
64
|
+
subLayers.push(...expanded);
|
|
65
|
+
});
|
|
66
|
+
return { version, sources, subLayers, issues };
|
|
67
|
+
}
|
|
68
|
+
function expandSubLayer(version, compositeId, layer, path, issues) {
|
|
69
|
+
const id = layer.id;
|
|
70
|
+
const style = layer.style;
|
|
71
|
+
const shared = {
|
|
72
|
+
source: layer.source,
|
|
73
|
+
...typeof layer.filter === "string" && layer.filter.trim() !== "" ? { filter: layer.filter } : {},
|
|
74
|
+
minZoom: zoom(layer.minZoom, DEFAULT_MIN_ZOOM),
|
|
75
|
+
maxZoom: zoom(layer.maxZoom, DEFAULT_MAX_ZOOM),
|
|
76
|
+
metadata: { composite: true, compositeParentLayer: compositeId, compositeSubLayer: id }
|
|
77
|
+
};
|
|
78
|
+
const maplibreId = `${compositeId}__${id}`;
|
|
79
|
+
const flowStyle = version === 1 ? isObject(style) && style.type === "flow" : layer.type === "flow";
|
|
80
|
+
if (flowStyle) {
|
|
81
|
+
const expanded = expandFlowStyle(maplibreId, style, {
|
|
82
|
+
geometry: version === 1 ? layer.type : void 0,
|
|
83
|
+
// validateCompositeLayer warns about a non-boolean `interactive`; the default applies
|
|
84
|
+
interactive: typeof layer.interactive === "boolean" ? layer.interactive : true
|
|
85
|
+
});
|
|
86
|
+
addNewIssues(issues, prefixIssues(expanded.issues, join(path, "style")));
|
|
87
|
+
return expanded.subLayers.map((subLayer) => ({
|
|
88
|
+
id: subLayer.id,
|
|
89
|
+
type: subLayer.type,
|
|
90
|
+
style: subLayer.style,
|
|
91
|
+
interactive: subLayer.interactive,
|
|
92
|
+
...shared
|
|
93
|
+
}));
|
|
94
|
+
}
|
|
95
|
+
const interactive = version === 1 ? !!layer.interactive : layer.interactive !== false;
|
|
96
|
+
return [
|
|
97
|
+
{
|
|
98
|
+
id: maplibreId,
|
|
99
|
+
type: layer.type,
|
|
100
|
+
style: version === 1 ? style.style : style,
|
|
101
|
+
interactive,
|
|
102
|
+
...shared
|
|
103
|
+
}
|
|
104
|
+
];
|
|
105
|
+
}
|
|
106
|
+
function expandDataSources(version, dataSources, errorPaths) {
|
|
107
|
+
return dataSources.flatMap((dataSource, index) => {
|
|
108
|
+
const path = `dataSources[${index}]`;
|
|
109
|
+
if (DATA_SOURCE_ERROR_KEYS.some((key) => errorPaths.has(join(path, key)))) {
|
|
110
|
+
return [];
|
|
111
|
+
}
|
|
112
|
+
const source = dataSource;
|
|
113
|
+
const option = (key) => errorPaths.has(join(path, key)) ? void 0 : source[key];
|
|
114
|
+
const options = {
|
|
115
|
+
id: source.id,
|
|
116
|
+
type: source.type ?? (version === 1 ? "vector" : void 0),
|
|
117
|
+
src: srcExpression(source.src)
|
|
118
|
+
};
|
|
119
|
+
const mapped = [
|
|
120
|
+
["featureId", "featureId"],
|
|
121
|
+
["limit", "limit"],
|
|
122
|
+
["apiKey", "flowApiKey"],
|
|
123
|
+
["cluster", "cluster"],
|
|
124
|
+
["clusterRadius", "clusterRadius"],
|
|
125
|
+
["clusterMaxZoom", "clusterMaxZoom"]
|
|
126
|
+
];
|
|
127
|
+
for (const [from, to] of mapped) {
|
|
128
|
+
if (option(from) !== void 0) {
|
|
129
|
+
options[to] = option(from);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
const selection = selectionOptions(option);
|
|
133
|
+
if (selection) {
|
|
134
|
+
options.selection = selection;
|
|
135
|
+
}
|
|
136
|
+
return [options];
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
function selectionOptions(option) {
|
|
140
|
+
const mode = option("selectionMode");
|
|
141
|
+
if (mode !== "single" && mode !== "multi") {
|
|
142
|
+
return void 0;
|
|
143
|
+
}
|
|
144
|
+
const selection = { mode };
|
|
145
|
+
const clear = option("selectionClear");
|
|
146
|
+
const group = option("selectionGroup");
|
|
147
|
+
const state = option("selectionState")?.replace(/^\$/, "");
|
|
148
|
+
if (clear !== void 0) {
|
|
149
|
+
selection.clear = clear;
|
|
150
|
+
}
|
|
151
|
+
if (group !== void 0) {
|
|
152
|
+
selection.group = group;
|
|
153
|
+
}
|
|
154
|
+
if (state) {
|
|
155
|
+
selection.selectionState = state;
|
|
156
|
+
}
|
|
157
|
+
return selection;
|
|
158
|
+
}
|
|
159
|
+
function srcExpression(src) {
|
|
160
|
+
if (src.startsWith("$")) {
|
|
161
|
+
return src;
|
|
162
|
+
}
|
|
163
|
+
return src.includes("'") ? `"${src}"` : `'${src}'`;
|
|
164
|
+
}
|
|
165
|
+
function zoom(value, defaultZoom) {
|
|
166
|
+
return typeof value === "number" && Number.isFinite(value) ? value : defaultZoom;
|
|
167
|
+
}
|
|
168
|
+
function addNewIssues(issues, found) {
|
|
169
|
+
const known = new Set(issues.map(issueKey));
|
|
170
|
+
issues.push(...found.filter((issue) => !known.has(issueKey(issue))));
|
|
171
|
+
}
|
|
172
|
+
function issueKey(issue) {
|
|
173
|
+
return `${issue.severity} ${issue.path} ${issue.message}`;
|
|
174
|
+
}
|
|
175
|
+
function join(path, key) {
|
|
176
|
+
return key ? `${path}.${key}` : path;
|
|
177
|
+
}
|
|
178
|
+
function isObject(value) {
|
|
179
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
export { expandCompositeLayer };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { isPlainObject } from '../../utils/type-checks.mjs';
|
|
2
|
+
import { cloneStoredValue } from '../flow-style/builder.mjs';
|
|
3
|
+
|
|
4
|
+
function compositeLayerVersion(spec) {
|
|
5
|
+
const version = isPlainObject(spec) && !Array.isArray(spec) ? spec.version : void 0;
|
|
6
|
+
if (version === void 0 || version === 1) {
|
|
7
|
+
return 1;
|
|
8
|
+
}
|
|
9
|
+
return version === 2 ? 2 : void 0;
|
|
10
|
+
}
|
|
11
|
+
function loadCompositeLayerSpec(spec) {
|
|
12
|
+
return { version: compositeLayerVersion(spec), spec: cloneStoredValue(spec) };
|
|
13
|
+
}
|
|
14
|
+
function saveCompositeLayerSpec(stored) {
|
|
15
|
+
return cloneStoredValue(stored.spec);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export { compositeLayerVersion, loadCompositeLayerSpec, saveCompositeLayerSpec };
|