@emuanalytics/flow-rdf-core 4.1.8 → 4.2.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 CHANGED
@@ -1,5 +1,5 @@
1
- import { A as Annotation, M as MapStyleSpecification, S as StateStore, a as MapDataSource, b as MapLayer, F as FlowContextOptions, c as FlowContext } from './shared/flow-rdf-core.1ee62df9.mjs';
2
- export { B as BackgroundLayerStyleBuilder, C as CircleLayerStyleBuilder, D as DEFAULT_CONTEXT_ID, _ as FeatureStreamOptions, s as FillExtrusionLayerStyleBuilder, q as FillLayerStyleBuilder, d as FlowCoreError, h as FlowCoreExpressionCustomFunction, i as FlowCoreExpressionCustomFunctionSignature, j as FlowCoreExpressionCustomFunctions, e as FlowCoreExpressionError, a0 as FlowCoreMap, o as FlowEngineEndpoint, f as FlowMapError, H as HeatmapLayerStyleBuilder, u as HillshadeLayerStyleBuilder, L as LineLayerStyleBuilder, T as MapAnimationOptions, U as MapCenterOptions, K as MapDataSourceOptions, N as MapDataSourceSpecification, J as MapDataSourceType, a3 as MapEvent, a2 as MapEventType, a1 as MapEventTypes, V as MapFeature, W as MapFeatureIdentifier, Z as MapFeatureStream, O as MapGeojsonData, E as MapLayerExpression, z as MapLayerOptions, I as MapLayerPropertyMetadataIndex, G as MapLayerSpecification, w as MapLayerStyleBuilder, p as MapLayerType, a6 as MapLoadingEvent, a4 as MapMouseEvent, $ as MapOptions, X as MapPaddingOptions, aa as MapPopup, a9 as MapPopupOptions, a8 as MapPopupTemplateFn, g as MapRegistry, a5 as MapSourceEvent, Y as MapSourceIdentifier, a7 as MapStyleChangeEvent, P as ParserExpression, k as ParserExpressionWithIndex, l as ParserFunctionExpression, m as ParserIndex, n as ParserProgram, aq as Path, ar as PathValue, ab as Query, ag as QueryAttribute, al as QueryDefinition, an as QueryDefinitionFn, ai as QueryExtraParams, am as QueryOptions, aj as QueryOrderClause, Q as QueryRegistry, af as QueryResultFormat, ao as QueryResultTransformFn, ak as QuerySampleOptions, ah as QueryWhereClauses, t as RasterLayerStyleBuilder, R as ReactiveExpression, au as SerializationFormat, at as StoreAnnotations, as as StoreConstructor, x as StyleExpression, r as SymbolLayerStyleBuilder, y as expr, v as layerStyle, ac as query, ad as queryMany, ae as queryOne, ap as traceReaction } from './shared/flow-rdf-core.1ee62df9.mjs';
1
+ import { A as Annotation, F as FlowStyleLayerType, a as FlowLayerStyleBuilder, b as FlowStyleDataDriven, c as FlowStyleIssue, M as MapStyleSpecification, S as StateStore, d as MapDataSource, e as MapLayer, f as FlowContextOptions, g as FlowContext } from './shared/flow-rdf-core.c45eb675.mjs';
2
+ export { N as BackgroundLayerStyleBuilder, G as CircleLayerStyleBuilder, D as DEFAULT_CONTEXT_ID, aa as FeatureStreamOptions, I as FillExtrusionLayerStyleBuilder, C as FillLayerStyleBuilder, h as FlowCoreError, l as FlowCoreExpressionCustomFunction, m as FlowCoreExpressionCustomFunctionSignature, n as FlowCoreExpressionCustomFunctions, i as FlowCoreExpressionError, ac as FlowCoreMap, z as FlowEngineEndpoint, j as FlowMapError, s as FlowStyle, t as FlowStyleDataDrivenOptions, u as FlowStyleExpression, v as FlowStyleNamedSize, w as FlowStyleProperty, x as FlowStyleSize, y as FlowValue, H as HeatmapLayerStyleBuilder, K as HillshadeLayerStyleBuilder, L as LineLayerStyleBuilder, a3 as MapAnimationOptions, a4 as MapCenterOptions, a0 as MapDataSourceOptions, a1 as MapDataSourceSpecification, $ as MapDataSourceType, af as MapEvent, ae as MapEventType, ad as MapEventTypes, a5 as MapFeature, a6 as MapFeatureIdentifier, a9 as MapFeatureStream, a2 as MapGeojsonData, Y as MapLayerExpression, W as MapLayerOptions, _ as MapLayerPropertyMetadataIndex, Z as MapLayerSpecification, T as MapLayerStyleBuilder, B as MapLayerType, ai as MapLoadingEvent, ag as MapMouseEvent, ab as MapOptions, a7 as MapPaddingOptions, am as MapPopup, al as MapPopupOptions, ak as MapPopupTemplateFn, k as MapRegistry, ah as MapSourceEvent, a8 as MapSourceIdentifier, aj as MapStyleChangeEvent, X as MapSubLayerOptions, P as ParserExpression, o as ParserExpressionWithIndex, p as ParserFunctionExpression, q as ParserIndex, r as ParserProgram, aC as Path, aD as PathValue, an as Query, as as QueryAttribute, ax as QueryDefinition, az as QueryDefinitionFn, au as QueryExtraParams, ay as QueryOptions, av as QueryOrderClause, Q as QueryRegistry, ar as QueryResultFormat, aA as QueryResultTransformFn, aw as QuerySampleOptions, at as QueryWhereClauses, J as RasterLayerStyleBuilder, R as ReactiveExpression, aG as SerializationFormat, aF as StoreAnnotations, aE as StoreConstructor, U as StyleExpression, E as SymbolLayerStyleBuilder, V as expr, O as layerStyle, ao as query, ap as queryMany, aq as queryOne, aB as traceReaction } from './shared/flow-rdf-core.c45eb675.mjs';
3
3
  export { IDisposer, IObservableStream, ISubscription } from 'mobx-utils';
4
4
  export { makeAutoObservable, makeObservable } from 'mobx';
5
5
  import 'eventemitter3';
@@ -43,6 +43,97 @@ declare const computed: PropertyDecorator & ReactiveAnnotation & {
43
43
  /** @function */
44
44
  declare const action: PropertyDecorator & ReactiveAnnotation;
45
45
 
46
+ /**
47
+ * Creates a builder for a {@link FlowStyle}, as {@link layerStyle} does for MapLibre styles.
48
+ *
49
+ * A plain value is a literal, so `labelText('@name')` labels every feature with the text `@name`. Use {@link expr}
50
+ * for a reactive expression, such as `labelText(expr('@name'))`, and a {@link FlowStyleDataDriven} table for a value
51
+ * that depends on a feature property: it becomes an expression whose `value` is {@link dataDrivenExpression} of the
52
+ * table, with the table attached for editors. `build()` returns the style in its stored format, with `version` set.
53
+ *
54
+ * The builder does not check values. Use {@link validateFlowStyle} to check the result.
55
+ *
56
+ * @example
57
+ * A circle style for airports:
58
+ * ```js
59
+ * const style = flowLayerStyle('circle')
60
+ * .fillColor({ mode: 'match', attribute: 'type', default: 'gray', values: [['civil', '#1e88e5'], ['military', '#e53935']] })
61
+ * .strokeColor('white')
62
+ * .radius('medium')
63
+ * .labelText(expr('@name'))
64
+ * .build();
65
+ * ```
66
+ *
67
+ * @param type - Geometry: `circle`, `line` or `fill`.
68
+ * @param options - Builder options. `version` is the stored format version to write. Defaults to `2`, the latest.
69
+ * @returns A new flow style builder.
70
+ *
71
+ * @experimental
72
+ */
73
+ declare function flowLayerStyle(type: FlowStyleLayerType, options?: {
74
+ version?: 2;
75
+ }): FlowLayerStyleBuilder;
76
+
77
+ /**
78
+ * Returns the reactive expression that a {@link FlowStyleDataDriven} table stands for.
79
+ *
80
+ * Editors use it to keep a {@link FlowStyleExpression}'s `value` in step with its `dataDriven` table: write
81
+ * `value: dataDrivenExpression(dataDriven)` after each change. An expression whose `value` differs from
82
+ * `dataDrivenExpression(dataDriven)` was written by hand.
83
+ *
84
+ * Keys and values are literals. The feature property is read with `get()`, so its name may contain spaces and quotes.
85
+ * If the table is not valid (see {@link validateFlowStyle}), the expression is the default value.
86
+ *
87
+ * @example
88
+ * A match table and the expression it stands for:
89
+ * ```js
90
+ * dataDrivenExpression({
91
+ * mode: 'match',
92
+ * attribute: 'type',
93
+ * default: 'gray',
94
+ * values: [['civil', '#1e88e5'], ['military', '#e53935']]
95
+ * });
96
+ * // case(get("type") =* 'civil', '#1e88e5', get("type") =* 'military', '#e53935', 'gray')
97
+ * ```
98
+ *
99
+ * @typeParam T - Type of the style values.
100
+ * @param dataDriven - Data-driven table.
101
+ * @returns The reactive expression.
102
+ *
103
+ * @experimental
104
+ */
105
+ declare function dataDrivenExpression<T>(dataDriven: FlowStyleDataDriven<T>): string;
106
+
107
+ /**
108
+ * Checks a flow style and returns its problems. Use it on a style read from storage or written by hand, before
109
+ * showing it in an editor or to report why a flow layer does not draw what you expect.
110
+ *
111
+ * It accepts version 2 styles ({@link FlowStyle}) and version 1 styles, the legacy stored format whose `type` is
112
+ * `flow`. A style with no `version` is read as version 1, so a version 2 style without `version: 2` is an error.
113
+ *
114
+ * Each {@link FlowStyleIssue} has a path, a message and a severity. An `error` means the property, or the whole style
115
+ * when the path is empty, `type` or `version`, is left out when the style is drawn. A `warning` means it is drawn
116
+ * anyway: unknown keys, for example, are kept and reported as warnings. In version 2, a problem with an expression's
117
+ * `dataDriven` table is a warning, because only the expression's `value` is drawn.
118
+ *
119
+ * This function never throws.
120
+ *
121
+ * @example
122
+ * Checking a style read from storage:
123
+ * ```js
124
+ * const issues = validateFlowStyle(JSON.parse(stored));
125
+ * if (issues.some((issue) => issue.severity === 'error')) {
126
+ * console.warn(issues);
127
+ * }
128
+ * ```
129
+ *
130
+ * @param style - Flow style to check, of any type.
131
+ * @returns The problems found, or an empty array.
132
+ *
133
+ * @experimental
134
+ */
135
+ declare function validateFlowStyle(style: unknown): FlowStyleIssue[];
136
+
46
137
  interface MapStyleOptions {
47
138
  id: string;
48
139
  }
@@ -54,6 +145,22 @@ declare class MapStyle {
54
145
  private _layers;
55
146
  private _layerOrder;
56
147
  get styleSpecification(): MapStyleSpecification;
148
+ /**
149
+ * Problems found while building {@link styleSpecification}: each names a MapLibre layer that was left out, because
150
+ * another layer or the base style already has its ID, or its source isn't on the map.
151
+ *
152
+ * @internal
153
+ */
154
+ get styleProblems(): string[];
155
+ /**
156
+ * The ID of the {@link MapLayer} that rendered each MapLibre layer in {@link styleSpecification}, by MapLibre layer
157
+ * ID. Base style layers aren't included, unless a MapLayer restyled them.
158
+ *
159
+ * @internal
160
+ */
161
+ get maplibreLayerOwners(): ReadonlyMap<string, string>;
162
+ /** The style specification, the problems found while building it, and which MapLayer rendered each MapLibre layer. */
163
+ private get renderedStyle();
57
164
  get formattedName(): string;
58
165
  constructor();
59
166
  bindState(state: StateStore): this;
@@ -66,6 +173,14 @@ declare class MapStyle {
66
173
  removeLayer(id: string): this;
67
174
  getLayer(id: string): MapLayer;
68
175
  getLayers(filter?: (layer: MapLayer) => boolean): MapLayer[];
176
+ private duplicateIdProblem;
177
+ /** Defaults the source layer to 'geometry' if missing and the source type is 'vector'. */
178
+ private withDefaultSourceLayer;
179
+ /**
180
+ * Where to insert a MapLibre layer of a type for a layer: above or below the layer's `above` or `below` layer, or
181
+ * else at the base style's insertion point for the type. `above` and `below` name a MapLibre layer or a MapLayer;
182
+ * for a MapLayer with sub-layers, the group's top or bottom MapLibre layer.
183
+ */
69
184
  private layerInsertionPoint;
70
185
  }
71
186
 
@@ -103,4 +218,4 @@ declare const uninitializeContext: (contextId?: string) => void;
103
218
  /** @function */
104
219
  declare const getContext: <TState extends StateStore = StateStore>(id?: string) => Promise<FlowContext<TState>>;
105
220
 
106
- export { ContextRegistry, FlowContext, FlowContextOptions, FlowRdfCoreGlobals, MapDataSource, MapLayer, MapStyle, type MapStyleOptions, MapStyleSpecification, StateStore, action, computed, getContext, getGlobalState, initializeContext, isolateGlobalState, observable, serialize, uninitializeContext };
221
+ export { ContextRegistry, FlowContext, FlowContextOptions, FlowLayerStyleBuilder, FlowRdfCoreGlobals, FlowStyleDataDriven, FlowStyleIssue, FlowStyleLayerType, MapDataSource, MapLayer, MapStyle, type MapStyleOptions, MapStyleSpecification, StateStore, action, computed, dataDrivenExpression, flowLayerStyle, getContext, getGlobalState, initializeContext, isolateGlobalState, observable, serialize, uninitializeContext, validateFlowStyle };
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { A as Annotation, M as MapStyleSpecification, S as StateStore, a as MapDataSource, b as MapLayer, F as FlowContextOptions, c as FlowContext } from './shared/flow-rdf-core.1ee62df9.js';
2
- export { B as BackgroundLayerStyleBuilder, C as CircleLayerStyleBuilder, D as DEFAULT_CONTEXT_ID, _ as FeatureStreamOptions, s as FillExtrusionLayerStyleBuilder, q as FillLayerStyleBuilder, d as FlowCoreError, h as FlowCoreExpressionCustomFunction, i as FlowCoreExpressionCustomFunctionSignature, j as FlowCoreExpressionCustomFunctions, e as FlowCoreExpressionError, a0 as FlowCoreMap, o as FlowEngineEndpoint, f as FlowMapError, H as HeatmapLayerStyleBuilder, u as HillshadeLayerStyleBuilder, L as LineLayerStyleBuilder, T as MapAnimationOptions, U as MapCenterOptions, K as MapDataSourceOptions, N as MapDataSourceSpecification, J as MapDataSourceType, a3 as MapEvent, a2 as MapEventType, a1 as MapEventTypes, V as MapFeature, W as MapFeatureIdentifier, Z as MapFeatureStream, O as MapGeojsonData, E as MapLayerExpression, z as MapLayerOptions, I as MapLayerPropertyMetadataIndex, G as MapLayerSpecification, w as MapLayerStyleBuilder, p as MapLayerType, a6 as MapLoadingEvent, a4 as MapMouseEvent, $ as MapOptions, X as MapPaddingOptions, aa as MapPopup, a9 as MapPopupOptions, a8 as MapPopupTemplateFn, g as MapRegistry, a5 as MapSourceEvent, Y as MapSourceIdentifier, a7 as MapStyleChangeEvent, P as ParserExpression, k as ParserExpressionWithIndex, l as ParserFunctionExpression, m as ParserIndex, n as ParserProgram, aq as Path, ar as PathValue, ab as Query, ag as QueryAttribute, al as QueryDefinition, an as QueryDefinitionFn, ai as QueryExtraParams, am as QueryOptions, aj as QueryOrderClause, Q as QueryRegistry, af as QueryResultFormat, ao as QueryResultTransformFn, ak as QuerySampleOptions, ah as QueryWhereClauses, t as RasterLayerStyleBuilder, R as ReactiveExpression, au as SerializationFormat, at as StoreAnnotations, as as StoreConstructor, x as StyleExpression, r as SymbolLayerStyleBuilder, y as expr, v as layerStyle, ac as query, ad as queryMany, ae as queryOne, ap as traceReaction } from './shared/flow-rdf-core.1ee62df9.js';
1
+ import { A as Annotation, F as FlowStyleLayerType, a as FlowLayerStyleBuilder, b as FlowStyleDataDriven, c as FlowStyleIssue, M as MapStyleSpecification, S as StateStore, d as MapDataSource, e as MapLayer, f as FlowContextOptions, g as FlowContext } from './shared/flow-rdf-core.c45eb675.js';
2
+ export { N as BackgroundLayerStyleBuilder, G as CircleLayerStyleBuilder, D as DEFAULT_CONTEXT_ID, aa as FeatureStreamOptions, I as FillExtrusionLayerStyleBuilder, C as FillLayerStyleBuilder, h as FlowCoreError, l as FlowCoreExpressionCustomFunction, m as FlowCoreExpressionCustomFunctionSignature, n as FlowCoreExpressionCustomFunctions, i as FlowCoreExpressionError, ac as FlowCoreMap, z as FlowEngineEndpoint, j as FlowMapError, s as FlowStyle, t as FlowStyleDataDrivenOptions, u as FlowStyleExpression, v as FlowStyleNamedSize, w as FlowStyleProperty, x as FlowStyleSize, y as FlowValue, H as HeatmapLayerStyleBuilder, K as HillshadeLayerStyleBuilder, L as LineLayerStyleBuilder, a3 as MapAnimationOptions, a4 as MapCenterOptions, a0 as MapDataSourceOptions, a1 as MapDataSourceSpecification, $ as MapDataSourceType, af as MapEvent, ae as MapEventType, ad as MapEventTypes, a5 as MapFeature, a6 as MapFeatureIdentifier, a9 as MapFeatureStream, a2 as MapGeojsonData, Y as MapLayerExpression, W as MapLayerOptions, _ as MapLayerPropertyMetadataIndex, Z as MapLayerSpecification, T as MapLayerStyleBuilder, B as MapLayerType, ai as MapLoadingEvent, ag as MapMouseEvent, ab as MapOptions, a7 as MapPaddingOptions, am as MapPopup, al as MapPopupOptions, ak as MapPopupTemplateFn, k as MapRegistry, ah as MapSourceEvent, a8 as MapSourceIdentifier, aj as MapStyleChangeEvent, X as MapSubLayerOptions, P as ParserExpression, o as ParserExpressionWithIndex, p as ParserFunctionExpression, q as ParserIndex, r as ParserProgram, aC as Path, aD as PathValue, an as Query, as as QueryAttribute, ax as QueryDefinition, az as QueryDefinitionFn, au as QueryExtraParams, ay as QueryOptions, av as QueryOrderClause, Q as QueryRegistry, ar as QueryResultFormat, aA as QueryResultTransformFn, aw as QuerySampleOptions, at as QueryWhereClauses, J as RasterLayerStyleBuilder, R as ReactiveExpression, aG as SerializationFormat, aF as StoreAnnotations, aE as StoreConstructor, U as StyleExpression, E as SymbolLayerStyleBuilder, V as expr, O as layerStyle, ao as query, ap as queryMany, aq as queryOne, aB as traceReaction } from './shared/flow-rdf-core.c45eb675.js';
3
3
  export { IDisposer, IObservableStream, ISubscription } from 'mobx-utils';
4
4
  export { makeAutoObservable, makeObservable } from 'mobx';
5
5
  import 'eventemitter3';
@@ -43,6 +43,97 @@ declare const computed: PropertyDecorator & ReactiveAnnotation & {
43
43
  /** @function */
44
44
  declare const action: PropertyDecorator & ReactiveAnnotation;
45
45
 
46
+ /**
47
+ * Creates a builder for a {@link FlowStyle}, as {@link layerStyle} does for MapLibre styles.
48
+ *
49
+ * A plain value is a literal, so `labelText('@name')` labels every feature with the text `@name`. Use {@link expr}
50
+ * for a reactive expression, such as `labelText(expr('@name'))`, and a {@link FlowStyleDataDriven} table for a value
51
+ * that depends on a feature property: it becomes an expression whose `value` is {@link dataDrivenExpression} of the
52
+ * table, with the table attached for editors. `build()` returns the style in its stored format, with `version` set.
53
+ *
54
+ * The builder does not check values. Use {@link validateFlowStyle} to check the result.
55
+ *
56
+ * @example
57
+ * A circle style for airports:
58
+ * ```js
59
+ * const style = flowLayerStyle('circle')
60
+ * .fillColor({ mode: 'match', attribute: 'type', default: 'gray', values: [['civil', '#1e88e5'], ['military', '#e53935']] })
61
+ * .strokeColor('white')
62
+ * .radius('medium')
63
+ * .labelText(expr('@name'))
64
+ * .build();
65
+ * ```
66
+ *
67
+ * @param type - Geometry: `circle`, `line` or `fill`.
68
+ * @param options - Builder options. `version` is the stored format version to write. Defaults to `2`, the latest.
69
+ * @returns A new flow style builder.
70
+ *
71
+ * @experimental
72
+ */
73
+ declare function flowLayerStyle(type: FlowStyleLayerType, options?: {
74
+ version?: 2;
75
+ }): FlowLayerStyleBuilder;
76
+
77
+ /**
78
+ * Returns the reactive expression that a {@link FlowStyleDataDriven} table stands for.
79
+ *
80
+ * Editors use it to keep a {@link FlowStyleExpression}'s `value` in step with its `dataDriven` table: write
81
+ * `value: dataDrivenExpression(dataDriven)` after each change. An expression whose `value` differs from
82
+ * `dataDrivenExpression(dataDriven)` was written by hand.
83
+ *
84
+ * Keys and values are literals. The feature property is read with `get()`, so its name may contain spaces and quotes.
85
+ * If the table is not valid (see {@link validateFlowStyle}), the expression is the default value.
86
+ *
87
+ * @example
88
+ * A match table and the expression it stands for:
89
+ * ```js
90
+ * dataDrivenExpression({
91
+ * mode: 'match',
92
+ * attribute: 'type',
93
+ * default: 'gray',
94
+ * values: [['civil', '#1e88e5'], ['military', '#e53935']]
95
+ * });
96
+ * // case(get("type") =* 'civil', '#1e88e5', get("type") =* 'military', '#e53935', 'gray')
97
+ * ```
98
+ *
99
+ * @typeParam T - Type of the style values.
100
+ * @param dataDriven - Data-driven table.
101
+ * @returns The reactive expression.
102
+ *
103
+ * @experimental
104
+ */
105
+ declare function dataDrivenExpression<T>(dataDriven: FlowStyleDataDriven<T>): string;
106
+
107
+ /**
108
+ * Checks a flow style and returns its problems. Use it on a style read from storage or written by hand, before
109
+ * showing it in an editor or to report why a flow layer does not draw what you expect.
110
+ *
111
+ * It accepts version 2 styles ({@link FlowStyle}) and version 1 styles, the legacy stored format whose `type` is
112
+ * `flow`. A style with no `version` is read as version 1, so a version 2 style without `version: 2` is an error.
113
+ *
114
+ * Each {@link FlowStyleIssue} has a path, a message and a severity. An `error` means the property, or the whole style
115
+ * when the path is empty, `type` or `version`, is left out when the style is drawn. A `warning` means it is drawn
116
+ * anyway: unknown keys, for example, are kept and reported as warnings. In version 2, a problem with an expression's
117
+ * `dataDriven` table is a warning, because only the expression's `value` is drawn.
118
+ *
119
+ * This function never throws.
120
+ *
121
+ * @example
122
+ * Checking a style read from storage:
123
+ * ```js
124
+ * const issues = validateFlowStyle(JSON.parse(stored));
125
+ * if (issues.some((issue) => issue.severity === 'error')) {
126
+ * console.warn(issues);
127
+ * }
128
+ * ```
129
+ *
130
+ * @param style - Flow style to check, of any type.
131
+ * @returns The problems found, or an empty array.
132
+ *
133
+ * @experimental
134
+ */
135
+ declare function validateFlowStyle(style: unknown): FlowStyleIssue[];
136
+
46
137
  interface MapStyleOptions {
47
138
  id: string;
48
139
  }
@@ -54,6 +145,22 @@ declare class MapStyle {
54
145
  private _layers;
55
146
  private _layerOrder;
56
147
  get styleSpecification(): MapStyleSpecification;
148
+ /**
149
+ * Problems found while building {@link styleSpecification}: each names a MapLibre layer that was left out, because
150
+ * another layer or the base style already has its ID, or its source isn't on the map.
151
+ *
152
+ * @internal
153
+ */
154
+ get styleProblems(): string[];
155
+ /**
156
+ * The ID of the {@link MapLayer} that rendered each MapLibre layer in {@link styleSpecification}, by MapLibre layer
157
+ * ID. Base style layers aren't included, unless a MapLayer restyled them.
158
+ *
159
+ * @internal
160
+ */
161
+ get maplibreLayerOwners(): ReadonlyMap<string, string>;
162
+ /** The style specification, the problems found while building it, and which MapLayer rendered each MapLibre layer. */
163
+ private get renderedStyle();
57
164
  get formattedName(): string;
58
165
  constructor();
59
166
  bindState(state: StateStore): this;
@@ -66,6 +173,14 @@ declare class MapStyle {
66
173
  removeLayer(id: string): this;
67
174
  getLayer(id: string): MapLayer;
68
175
  getLayers(filter?: (layer: MapLayer) => boolean): MapLayer[];
176
+ private duplicateIdProblem;
177
+ /** Defaults the source layer to 'geometry' if missing and the source type is 'vector'. */
178
+ private withDefaultSourceLayer;
179
+ /**
180
+ * Where to insert a MapLibre layer of a type for a layer: above or below the layer's `above` or `below` layer, or
181
+ * else at the base style's insertion point for the type. `above` and `below` name a MapLibre layer or a MapLayer;
182
+ * for a MapLayer with sub-layers, the group's top or bottom MapLibre layer.
183
+ */
69
184
  private layerInsertionPoint;
70
185
  }
71
186
 
@@ -103,4 +218,4 @@ declare const uninitializeContext: (contextId?: string) => void;
103
218
  /** @function */
104
219
  declare const getContext: <TState extends StateStore = StateStore>(id?: string) => Promise<FlowContext<TState>>;
105
220
 
106
- export { ContextRegistry, FlowContext, FlowContextOptions, FlowRdfCoreGlobals, MapDataSource, MapLayer, MapStyle, type MapStyleOptions, MapStyleSpecification, StateStore, action, computed, getContext, getGlobalState, initializeContext, isolateGlobalState, observable, serialize, uninitializeContext };
221
+ export { ContextRegistry, FlowContext, FlowContextOptions, FlowLayerStyleBuilder, FlowRdfCoreGlobals, FlowStyleDataDriven, FlowStyleIssue, FlowStyleLayerType, MapDataSource, MapLayer, MapStyle, type MapStyleOptions, MapStyleSpecification, StateStore, action, computed, dataDrivenExpression, flowLayerStyle, getContext, getGlobalState, initializeContext, isolateGlobalState, observable, serialize, uninitializeContext, validateFlowStyle };
package/dist/index.mjs CHANGED
@@ -7,6 +7,9 @@ export { DEFAULT_CONTEXT_ID, FlowContext } from './lib/context/flow-context.mjs'
7
7
  export { MapRegistry } from './lib/context/map-registry.mjs';
8
8
  export { QueryRegistry } from './lib/context/query-registry.mjs';
9
9
  export { ReactiveExpression } from './lib/expressions/reactive-expression.mjs';
10
+ export { flowLayerStyle } from './lib/map-style/flow-style/builder.mjs';
11
+ export { dataDrivenExpression } from './lib/map-style/flow-style/data-driven.mjs';
12
+ export { validateFlowStyle } from './lib/map-style/flow-style/validate.mjs';
10
13
  export { MapDataSource } from './lib/map-style/map-data-source.mjs';
11
14
  export { BackgroundLayerStyleBuilder, CircleLayerStyleBuilder, FillExtrusionLayerStyleBuilder, FillLayerStyleBuilder, HeatmapLayerStyleBuilder, HillshadeLayerStyleBuilder, LineLayerStyleBuilder, RasterLayerStyleBuilder, SymbolLayerStyleBuilder, layerStyle } from './lib/map-style/map-layer-style-builder-generated.mjs';
12
15
  export { MapLayerStyleBuilder, StyleExpression, expr } from './lib/map-style/map-layer-style-builder.mjs';
@@ -64,6 +64,7 @@ const _FlowCoreMap = class _FlowCoreMap extends EventEmitter {
64
64
  });
65
65
  __publicField(this, "_style");
66
66
  __publicField(this, "_styleUpdateSubscription", null);
67
+ __publicField(this, "_reportedStyleProblems", /* @__PURE__ */ new Set());
67
68
  __publicField(this, "_throttledMouseMove", throttle(this.handleMouseMove, MOUSE_MOVE_THROTTLE_DURATION, { context: this }));
68
69
  __publicField(this, "_maplibreMap");
69
70
  __publicField(this, "updateMapStyle", (style) => {
@@ -75,6 +76,7 @@ const _FlowCoreMap = class _FlowCoreMap extends EventEmitter {
75
76
  this.emit(beforeEvent.type, beforeEvent);
76
77
  debug(`${this.formattedName}: Updating style`, style);
77
78
  this._maplibreMap.setStyle(style);
79
+ this.reportStyleProblems();
78
80
  this.emitEvent(new MapStyleChangeEvent("styleChanged", this, oldStyle, style));
79
81
  });
80
82
  this._options = {
@@ -666,25 +668,48 @@ const _FlowCoreMap = class _FlowCoreMap extends EventEmitter {
666
668
  });
667
669
  });
668
670
  }
669
- featureFromMaplibreFeature(feature) {
671
+ featureFromMaplibreFeature(feature, layer) {
670
672
  return {
671
673
  id: feature.id,
672
674
  geometry: feature.geometry,
673
675
  source: feature.source,
674
676
  sourceLayer: feature.sourceLayer,
675
- layer: feature.layer.id,
677
+ layer,
676
678
  properties: feature.properties,
677
679
  state: feature.state
678
680
  };
679
681
  }
680
682
  /**
681
683
  * Queries the rendered features of interactive layers at the mouse position, in top-down draw order so the first
682
- * is the one drawn on top.
684
+ * is the one drawn on top. A feature from a sub-layer reports the {@link MapLayer} it belongs to.
683
685
  */
684
686
  queryFeatures(event) {
685
- const layerIds = this._style.getLayers((layer) => layer.interactive).map((layer) => layer.id);
687
+ const owners = this._style.maplibreLayerOwners;
688
+ const logicalIds = /* @__PURE__ */ new Map();
689
+ this._style.getLayers((layer) => layer.interactive).forEach((layer) => {
690
+ layer.interactiveLayerIds.filter((id) => owners.get(id) === layer.id).forEach((id) => logicalIds.set(id, layer.id));
691
+ });
692
+ const layerIds = [...logicalIds.keys()];
686
693
  const maplibreFeatures = this._maplibreMap.queryRenderedFeatures(this.featureQueryBox(event), { layers: layerIds });
687
- return sortFeaturesByDrawOrder(maplibreFeatures).map(this.featureFromMaplibreFeature.bind(this));
694
+ const reported = /* @__PURE__ */ new Map();
695
+ return sortFeaturesByDrawOrder(maplibreFeatures).flatMap((feature) => {
696
+ const layer = logicalIds.get(feature.layer.id) ?? feature.layer.id;
697
+ if (isDefined(feature.id)) {
698
+ const key = JSON.stringify([layer, feature.source, feature.sourceLayer, feature.id]);
699
+ const reportedFrom = reported.get(key);
700
+ if (isDefined(reportedFrom) && reportedFrom !== feature.layer.id) {
701
+ return [];
702
+ }
703
+ reported.set(key, feature.layer.id);
704
+ }
705
+ return [this.featureFromMaplibreFeature(feature, layer)];
706
+ });
707
+ }
708
+ /** Reports each new problem that {@link MapStyle} found while building the style as a map error. */
709
+ reportStyleProblems() {
710
+ const problems = this._style.styleProblems;
711
+ problems.filter((problem) => !this._reportedStyleProblems.has(problem)).forEach((problem) => this.emitError(problem));
712
+ this._reportedStyleProblems = new Set(problems);
688
713
  }
689
714
  featureQueryBox(event) {
690
715
  const queryBox = this._options.featureClickTolerance ? [
@@ -1,5 +1,5 @@
1
- import { a3 as MapEvent, a0 as FlowCoreMap, Y as MapSourceIdentifier, av as MapFeatureId, aw as MapPluginBase, ax as PluginManager, a5 as MapSourceEvent, a4 as MapMouseEvent, Z as MapFeatureStream, ay as PartialBy, T as MapAnimationOptions, a7 as MapStyleChangeEvent, M as MapStyleSpecification, S as StateStore, a9 as MapPopupOptions, aa as MapPopup, W as MapFeatureIdentifier } from '../../../shared/flow-rdf-core.1ee62df9.mjs';
2
- export { aC as EventHandlers, aB as PluginConstructor, aA as PluginEventsType, az as PluginOptionsType } from '../../../shared/flow-rdf-core.1ee62df9.mjs';
1
+ import { af as MapEvent, ac as FlowCoreMap, a8 as MapSourceIdentifier, aH as MapFeatureId, aI as MapPluginBase, aJ as PluginManager, ah as MapSourceEvent, ag as MapMouseEvent, a9 as MapFeatureStream, aK as PartialBy, a3 as MapAnimationOptions, aj as MapStyleChangeEvent, M as MapStyleSpecification, S as StateStore, al as MapPopupOptions, am as MapPopup, a6 as MapFeatureIdentifier } from '../../../shared/flow-rdf-core.c45eb675.mjs';
2
+ export { aO as EventHandlers, aN as PluginConstructor, aM as PluginEventsType, aL as PluginOptionsType } from '../../../shared/flow-rdf-core.c45eb675.mjs';
3
3
  import { F as Func } from '../../../shared/flow-rdf-core.63162669.mjs';
4
4
  import 'eventemitter3';
5
5
  import 'lit-html';
@@ -1,5 +1,5 @@
1
- import { a3 as MapEvent, a0 as FlowCoreMap, Y as MapSourceIdentifier, av as MapFeatureId, aw as MapPluginBase, ax as PluginManager, a5 as MapSourceEvent, a4 as MapMouseEvent, Z as MapFeatureStream, ay as PartialBy, T as MapAnimationOptions, a7 as MapStyleChangeEvent, M as MapStyleSpecification, S as StateStore, a9 as MapPopupOptions, aa as MapPopup, W as MapFeatureIdentifier } from '../../../shared/flow-rdf-core.1ee62df9.js';
2
- export { aC as EventHandlers, aB as PluginConstructor, aA as PluginEventsType, az as PluginOptionsType } from '../../../shared/flow-rdf-core.1ee62df9.js';
1
+ import { af as MapEvent, ac as FlowCoreMap, a8 as MapSourceIdentifier, aH as MapFeatureId, aI as MapPluginBase, aJ as PluginManager, ah as MapSourceEvent, ag as MapMouseEvent, a9 as MapFeatureStream, aK as PartialBy, a3 as MapAnimationOptions, aj as MapStyleChangeEvent, M as MapStyleSpecification, S as StateStore, al as MapPopupOptions, am as MapPopup, a6 as MapFeatureIdentifier } from '../../../shared/flow-rdf-core.c45eb675.js';
2
+ export { aO as EventHandlers, aN as PluginConstructor, aM as PluginEventsType, aL as PluginOptionsType } from '../../../shared/flow-rdf-core.c45eb675.js';
3
3
  import { F as Func } from '../../../shared/flow-rdf-core.63162669.js';
4
4
  import 'eventemitter3';
5
5
  import 'lit-html';
@@ -0,0 +1,97 @@
1
+ import { isPlainObject } from '../../utils/type-checks.mjs';
2
+ import { dataDrivenExpression } from './data-driven.mjs';
3
+
4
+ var __defProp = Object.defineProperty;
5
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
6
+ var __publicField = (obj, key, value) => {
7
+ __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
8
+ return value;
9
+ };
10
+ function cloneStoredValue(value) {
11
+ if (Array.isArray(value)) {
12
+ return value.map((item) => cloneStoredValue(item));
13
+ }
14
+ if (isPlainObject(value)) {
15
+ const copy = {};
16
+ for (const key of Object.keys(value)) {
17
+ Object.defineProperty(copy, key, {
18
+ value: cloneStoredValue(value[key]),
19
+ enumerable: true,
20
+ writable: true,
21
+ configurable: true
22
+ });
23
+ }
24
+ return copy;
25
+ }
26
+ return value;
27
+ }
28
+ function isStyleExpression(value) {
29
+ return typeof value === "object" && value !== null && !!value.__styleExpression;
30
+ }
31
+ function isDataDrivenTable(value) {
32
+ if (!isPlainObject(value) || Array.isArray(value) || "type" in value) {
33
+ return false;
34
+ }
35
+ return "mode" in value || "attribute" in value || "values" in value;
36
+ }
37
+ function isFlowStyleExpression(value) {
38
+ return isPlainObject(value) && value.type === "expression";
39
+ }
40
+ function toStoredValueV2(value) {
41
+ if (isStyleExpression(value)) {
42
+ return { type: "expression", value: value.toString() };
43
+ }
44
+ if (isDataDrivenTable(value)) {
45
+ const dataDriven = cloneStoredValue(value);
46
+ return { type: "expression", value: dataDrivenExpression(dataDriven), dataDriven };
47
+ }
48
+ return cloneStoredValue(value);
49
+ }
50
+ class FlowStyleBuilder {
51
+ constructor(type, version) {
52
+ __publicField(this, "style");
53
+ this.style = { type, version };
54
+ }
55
+ fillColor(value) {
56
+ return this.set("fillColor", value);
57
+ }
58
+ strokeColor(value) {
59
+ return this.set("strokeColor", value);
60
+ }
61
+ strokeWidth(value) {
62
+ return this.set("strokeWidth", value);
63
+ }
64
+ radius(value) {
65
+ return this.set("radius", value);
66
+ }
67
+ opacity(value) {
68
+ return this.set("opacity", value);
69
+ }
70
+ labelText(value) {
71
+ return this.set("labelText", value);
72
+ }
73
+ labelColor(value) {
74
+ return this.set("labelColor", value);
75
+ }
76
+ labelHaloColor(value) {
77
+ return this.set("labelHaloColor", value);
78
+ }
79
+ labelSize(value) {
80
+ return this.set("labelSize", value);
81
+ }
82
+ visibility(value) {
83
+ return this.set("visibility", value);
84
+ }
85
+ build() {
86
+ return cloneStoredValue(this.style);
87
+ }
88
+ set(property, value) {
89
+ this.style[property] = toStoredValueV2(value);
90
+ return this;
91
+ }
92
+ }
93
+ function flowLayerStyle(type, options) {
94
+ return new FlowStyleBuilder(type, options?.version ?? 2);
95
+ }
96
+
97
+ export { cloneStoredValue, flowLayerStyle, isDataDrivenTable, isFlowStyleExpression, isStyleExpression, toStoredValueV2 };