@maplibre-yaml/core 0.1.0-alpha.0 → 0.1.1
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 +1214 -0
- package/dist/components/index.d.ts +4 -83
- package/dist/components/index.js +4318 -3919
- package/dist/components/index.js.map +1 -1
- package/dist/index.d.ts +6 -315
- package/dist/index.js +115 -18
- package/dist/index.js.map +1 -1
- package/dist/map-renderer-DOLO9y-3.d.ts +522 -0
- package/dist/{map.schema-EnZRrtIh.d.ts → page.schema-CzdCyPFI.d.ts} +775 -368
- package/dist/register.browser.js +16004 -0
- package/dist/register.browser.js.map +1 -0
- package/dist/register.d.ts +205 -0
- package/dist/register.js +4704 -0
- package/dist/register.js.map +1 -0
- package/dist/schemas/index.d.ts +12 -419
- package/dist/schemas/index.js +4 -2
- package/dist/schemas/index.js.map +1 -1
- package/package.json +18 -13
- package/LICENSE.md +0 -21
- package/dist/map-renderer-RQc5_bdo.d.ts +0 -149
package/dist/index.d.ts
CHANGED
|
@@ -1,320 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
export {
|
|
5
|
-
import { z } from 'zod';
|
|
6
|
-
export { L as LegendBuilder, M as MapRenderer, b as MapRendererEvents, a as MapRendererOptions } from './map-renderer-RQc5_bdo.js';
|
|
1
|
+
export { ChapterActionSchema, ChapterLayersSchema, ChapterSchema, ColorOrExpressionSchema, ColorSchema, ContentBlockSchema, ContentElementSchema, ContentItemSchema, ExpressionSchema, GeoJSONSourceSchema, ImageSourceSchema, LatitudeSchema, LayerSourceSchema, LngLatBoundsSchema, LngLatSchema, LoadingConfigSchema, LongitudeSchema, NumberOrExpressionSchema, RasterSourceSchema, ScrollytellingBlockSchema, StreamConfigSchema, ValidTagNames, VectorSourceSchema, VideoSourceSchema, ZoomLevelSchema } from './schemas/index.js';
|
|
2
|
+
import { L as LayerSchema, P as PopupContentSchema, C as ControlsConfigSchema } from './page.schema-CzdCyPFI.js';
|
|
3
|
+
export { j as BackgroundLayerSchema, B as BaseLayerPropertiesSchema, p as BlockSchema, e as CircleLayerSchema, m as ControlPositionSchema, h as FillExtrusionLayerSchema, F as FillLayerSchema, G as GlobalConfigSchema, H as HeatmapLayerSchema, i as HillshadeLayerSchema, I as InteractiveConfigSchema, l as LayerOrReferenceSchema, k as LayerReferenceSchema, a as LegendConfigSchema, d as LegendItemSchema, f as LineLayerSchema, M as MapBlockSchema, b as MapConfigSchema, n as MapFullPageBlockSchema, o as MixedBlockSchema, q as PageSchema, c as PopupContentItemSchema, g as RasterLayerSchema, R as RootSchema, S as SymbolLayerSchema } from './page.schema-CzdCyPFI.js';
|
|
4
|
+
export { L as LegendBuilder, M as MapBlock, b as MapRenderer, d as MapRendererEvents, c as MapRendererOptions, P as ParseError, a as ParseResult, R as RootConfig, Y as YAMLParser, p as parseYAMLConfig, s as safeParseYAMLConfig } from './map-renderer-DOLO9y-3.js';
|
|
7
5
|
import { Map, LngLat } from 'maplibre-gl';
|
|
6
|
+
import { z } from 'zod';
|
|
8
7
|
import { FeatureCollection } from 'geojson';
|
|
9
8
|
|
|
10
|
-
/**
|
|
11
|
-
* @file YAML parser for MapLibre configuration files
|
|
12
|
-
* @module @maplibre-yaml/core/parser
|
|
13
|
-
*
|
|
14
|
-
* @description
|
|
15
|
-
* This module provides YAML parsing, schema validation, and reference resolution
|
|
16
|
-
* for MapLibre YAML configuration files. It converts YAML strings into validated
|
|
17
|
-
* TypeScript objects ready for rendering.
|
|
18
|
-
*
|
|
19
|
-
* ## Features
|
|
20
|
-
*
|
|
21
|
-
* - **YAML Parsing**: Converts YAML strings to JavaScript objects
|
|
22
|
-
* - **Schema Validation**: Validates against Zod schemas with detailed error messages
|
|
23
|
-
* - **Reference Resolution**: Resolves `$ref` pointers to global layers and sources
|
|
24
|
-
* - **Error Formatting**: Transforms Zod errors into user-friendly messages with paths
|
|
25
|
-
*
|
|
26
|
-
* @example
|
|
27
|
-
* Basic parsing
|
|
28
|
-
* ```typescript
|
|
29
|
-
* import { YAMLParser } from '@maplibre-yaml/core/parser';
|
|
30
|
-
*
|
|
31
|
-
* const yaml = `
|
|
32
|
-
* pages:
|
|
33
|
-
* - path: "/"
|
|
34
|
-
* title: "My Map"
|
|
35
|
-
* blocks:
|
|
36
|
-
* - type: map
|
|
37
|
-
* id: main
|
|
38
|
-
* config:
|
|
39
|
-
* center: [0, 0]
|
|
40
|
-
* zoom: 2
|
|
41
|
-
* mapStyle: "https://example.com/style.json"
|
|
42
|
-
* `;
|
|
43
|
-
*
|
|
44
|
-
* const config = YAMLParser.parse(yaml);
|
|
45
|
-
* ```
|
|
46
|
-
*
|
|
47
|
-
* @example
|
|
48
|
-
* Safe parsing with error handling
|
|
49
|
-
* ```typescript
|
|
50
|
-
* const result = YAMLParser.safeParse(yaml);
|
|
51
|
-
* if (result.success) {
|
|
52
|
-
* console.log('Valid config:', result.data);
|
|
53
|
-
* } else {
|
|
54
|
-
* result.errors.forEach(err => {
|
|
55
|
-
* console.error(`${err.path}: ${err.message}`);
|
|
56
|
-
* });
|
|
57
|
-
* }
|
|
58
|
-
* ```
|
|
59
|
-
*
|
|
60
|
-
* @example
|
|
61
|
-
* Reference resolution
|
|
62
|
-
* ```typescript
|
|
63
|
-
* const yaml = `
|
|
64
|
-
* layers:
|
|
65
|
-
* myLayer:
|
|
66
|
-
* id: shared
|
|
67
|
-
* type: circle
|
|
68
|
-
* source: { type: geojson, data: {...} }
|
|
69
|
-
*
|
|
70
|
-
* pages:
|
|
71
|
-
* - path: "/"
|
|
72
|
-
* blocks:
|
|
73
|
-
* - type: map
|
|
74
|
-
* layers:
|
|
75
|
-
* - $ref: "#/layers/myLayer"
|
|
76
|
-
* `;
|
|
77
|
-
*
|
|
78
|
-
* const config = YAMLParser.parse(yaml);
|
|
79
|
-
* // References are automatically resolved
|
|
80
|
-
* ```
|
|
81
|
-
*/
|
|
82
|
-
|
|
83
|
-
/**
|
|
84
|
-
* Type alias for the root configuration object
|
|
85
|
-
*
|
|
86
|
-
* @remarks
|
|
87
|
-
* Inferred from the RootSchema Zod schema
|
|
88
|
-
*/
|
|
89
|
-
type RootConfig = z.infer<typeof RootSchema>;
|
|
90
|
-
/**
|
|
91
|
-
* Error information for a single validation or parsing error
|
|
92
|
-
*
|
|
93
|
-
* @property path - JSON path to the error location (e.g., "pages[0].blocks[1].config.center")
|
|
94
|
-
* @property message - Human-readable error description
|
|
95
|
-
* @property line - Optional line number in the YAML file where error occurred
|
|
96
|
-
* @property column - Optional column number in the YAML file where error occurred
|
|
97
|
-
*/
|
|
98
|
-
interface ParseError {
|
|
99
|
-
path: string;
|
|
100
|
-
message: string;
|
|
101
|
-
line?: number;
|
|
102
|
-
column?: number;
|
|
103
|
-
}
|
|
104
|
-
/**
|
|
105
|
-
* Result object returned by safeParse operations
|
|
106
|
-
*
|
|
107
|
-
* @property success - Whether parsing and validation succeeded
|
|
108
|
-
* @property data - Validated configuration object (only present if success is true)
|
|
109
|
-
* @property errors - Array of errors (only present if success is false)
|
|
110
|
-
*/
|
|
111
|
-
interface ParseResult {
|
|
112
|
-
success: boolean;
|
|
113
|
-
data?: RootConfig;
|
|
114
|
-
errors: ParseError[];
|
|
115
|
-
}
|
|
116
|
-
/**
|
|
117
|
-
* YAML parser with schema validation and reference resolution
|
|
118
|
-
*
|
|
119
|
-
* @remarks
|
|
120
|
-
* This class provides static methods for parsing YAML configuration files,
|
|
121
|
-
* validating them against schemas, and resolving references between configuration
|
|
122
|
-
* sections. All methods are static as the parser maintains no internal state.
|
|
123
|
-
*
|
|
124
|
-
* @example
|
|
125
|
-
* Parse and validate YAML (throws on error)
|
|
126
|
-
* ```typescript
|
|
127
|
-
* const config = YAMLParser.parse(yamlString);
|
|
128
|
-
* ```
|
|
129
|
-
*
|
|
130
|
-
* @example
|
|
131
|
-
* Safe parse (returns result object)
|
|
132
|
-
* ```typescript
|
|
133
|
-
* const result = YAMLParser.safeParse(yamlString);
|
|
134
|
-
* if (!result.success) {
|
|
135
|
-
* console.error('Validation errors:', result.errors);
|
|
136
|
-
* }
|
|
137
|
-
* ```
|
|
138
|
-
*/
|
|
139
|
-
declare class YAMLParser {
|
|
140
|
-
/**
|
|
141
|
-
* Parse YAML string and validate against schema
|
|
142
|
-
*
|
|
143
|
-
* @param yaml - YAML string to parse
|
|
144
|
-
* @returns Validated configuration object
|
|
145
|
-
* @throws {Error} If YAML syntax is invalid
|
|
146
|
-
* @throws {ZodError} If validation fails
|
|
147
|
-
*
|
|
148
|
-
* @remarks
|
|
149
|
-
* This method parses the YAML, validates it against the RootSchema,
|
|
150
|
-
* resolves all references, and returns the validated config. If any
|
|
151
|
-
* step fails, it throws an error.
|
|
152
|
-
*
|
|
153
|
-
* @example
|
|
154
|
-
* ```typescript
|
|
155
|
-
* try {
|
|
156
|
-
* const config = YAMLParser.parse(yamlString);
|
|
157
|
-
* console.log('Valid config:', config);
|
|
158
|
-
* } catch (error) {
|
|
159
|
-
* console.error('Parse error:', error.message);
|
|
160
|
-
* }
|
|
161
|
-
* ```
|
|
162
|
-
*/
|
|
163
|
-
static parse(yaml: string): RootConfig;
|
|
164
|
-
/**
|
|
165
|
-
* Parse YAML string and validate, returning a result object
|
|
166
|
-
*
|
|
167
|
-
* @param yaml - YAML string to parse
|
|
168
|
-
* @returns Result object with success flag and either data or errors
|
|
169
|
-
*
|
|
170
|
-
* @remarks
|
|
171
|
-
* This is the non-throwing version of {@link parse}. Instead of throwing
|
|
172
|
-
* errors, it returns a result object that indicates success or failure.
|
|
173
|
-
* Use this when you want to handle errors gracefully without try/catch.
|
|
174
|
-
*
|
|
175
|
-
* @example
|
|
176
|
-
* ```typescript
|
|
177
|
-
* const result = YAMLParser.safeParse(yamlString);
|
|
178
|
-
* if (result.success) {
|
|
179
|
-
* console.log('Config:', result.data);
|
|
180
|
-
* } else {
|
|
181
|
-
* result.errors.forEach(err => {
|
|
182
|
-
* console.error(`Error at ${err.path}: ${err.message}`);
|
|
183
|
-
* });
|
|
184
|
-
* }
|
|
185
|
-
* ```
|
|
186
|
-
*/
|
|
187
|
-
static safeParse(yaml: string): ParseResult;
|
|
188
|
-
/**
|
|
189
|
-
* Validate a JavaScript object against the schema
|
|
190
|
-
*
|
|
191
|
-
* @param config - JavaScript object to validate
|
|
192
|
-
* @returns Validated configuration object
|
|
193
|
-
* @throws {ZodError} If validation fails
|
|
194
|
-
*
|
|
195
|
-
* @remarks
|
|
196
|
-
* This method bypasses YAML parsing and directly validates a JavaScript object.
|
|
197
|
-
* Useful when you already have a parsed object (e.g., from JSON.parse) and just
|
|
198
|
-
* want to validate and resolve references.
|
|
199
|
-
*
|
|
200
|
-
* @example
|
|
201
|
-
* ```typescript
|
|
202
|
-
* const jsConfig = JSON.parse(jsonString);
|
|
203
|
-
* const validated = YAMLParser.validate(jsConfig);
|
|
204
|
-
* ```
|
|
205
|
-
*/
|
|
206
|
-
static validate(config: unknown): RootConfig;
|
|
207
|
-
/**
|
|
208
|
-
* Resolve $ref references to global layers and sources
|
|
209
|
-
*
|
|
210
|
-
* @param config - Configuration object with potential references
|
|
211
|
-
* @returns Configuration with all references resolved
|
|
212
|
-
* @throws {Error} If a reference cannot be resolved
|
|
213
|
-
*
|
|
214
|
-
* @remarks
|
|
215
|
-
* References use JSON Pointer-like syntax: `#/layers/layerName` or `#/sources/sourceName`.
|
|
216
|
-
* This method walks the configuration tree, finds all objects with a `$ref` property,
|
|
217
|
-
* looks up the referenced item in `config.layers` or `config.sources`, and replaces
|
|
218
|
-
* the reference object with the actual item.
|
|
219
|
-
*
|
|
220
|
-
* ## Reference Syntax
|
|
221
|
-
*
|
|
222
|
-
* - `#/layers/myLayer` - Reference to a layer in the global `layers` section
|
|
223
|
-
* - `#/sources/mySource` - Reference to a source in the global `sources` section
|
|
224
|
-
*
|
|
225
|
-
* @example
|
|
226
|
-
* ```typescript
|
|
227
|
-
* const config = {
|
|
228
|
-
* layers: {
|
|
229
|
-
* myLayer: { id: 'layer1', type: 'circle', ... }
|
|
230
|
-
* },
|
|
231
|
-
* pages: [{
|
|
232
|
-
* blocks: [{
|
|
233
|
-
* type: 'map',
|
|
234
|
-
* layers: [{ $ref: '#/layers/myLayer' }]
|
|
235
|
-
* }]
|
|
236
|
-
* }]
|
|
237
|
-
* };
|
|
238
|
-
*
|
|
239
|
-
* const resolved = YAMLParser.resolveReferences(config);
|
|
240
|
-
* // resolved.pages[0].blocks[0].layers[0] now contains the full layer object
|
|
241
|
-
* ```
|
|
242
|
-
*/
|
|
243
|
-
static resolveReferences(config: RootConfig): RootConfig;
|
|
244
|
-
/**
|
|
245
|
-
* Format Zod validation errors into user-friendly messages
|
|
246
|
-
*
|
|
247
|
-
* @param error - Zod validation error
|
|
248
|
-
* @returns Array of formatted error objects
|
|
249
|
-
*
|
|
250
|
-
* @remarks
|
|
251
|
-
* This method transforms Zod's internal error format into human-readable
|
|
252
|
-
* messages with clear paths and descriptions. It handles various Zod error
|
|
253
|
-
* types and provides appropriate messages for each.
|
|
254
|
-
*
|
|
255
|
-
* ## Error Type Handling
|
|
256
|
-
*
|
|
257
|
-
* - `invalid_type`: Type mismatch (e.g., expected number, got string)
|
|
258
|
-
* - `invalid_union_discriminator`: Invalid discriminator for union types
|
|
259
|
-
* - `invalid_union`: None of the union options matched
|
|
260
|
-
* - `too_small`: Value below minimum (arrays, strings, numbers)
|
|
261
|
-
* - `too_big`: Value above maximum
|
|
262
|
-
* - `invalid_string`: String format validation failed
|
|
263
|
-
* - `custom`: Custom validation refinement failed
|
|
264
|
-
*
|
|
265
|
-
* @example
|
|
266
|
-
* ```typescript
|
|
267
|
-
* try {
|
|
268
|
-
* RootSchema.parse(invalidConfig);
|
|
269
|
-
* } catch (error) {
|
|
270
|
-
* if (error instanceof ZodError) {
|
|
271
|
-
* const formatted = YAMLParser.formatZodErrors(error);
|
|
272
|
-
* formatted.forEach(err => {
|
|
273
|
-
* console.error(`${err.path}: ${err.message}`);
|
|
274
|
-
* });
|
|
275
|
-
* }
|
|
276
|
-
* }
|
|
277
|
-
* ```
|
|
278
|
-
*/
|
|
279
|
-
private static formatZodErrors;
|
|
280
|
-
}
|
|
281
|
-
/**
|
|
282
|
-
* Convenience function to parse YAML config
|
|
283
|
-
*
|
|
284
|
-
* @param yaml - YAML string to parse
|
|
285
|
-
* @returns Validated configuration object
|
|
286
|
-
* @throws {Error} If parsing or validation fails
|
|
287
|
-
*
|
|
288
|
-
* @remarks
|
|
289
|
-
* This is an alias for {@link YAMLParser.parse} for convenient imports.
|
|
290
|
-
*
|
|
291
|
-
* @example
|
|
292
|
-
* ```typescript
|
|
293
|
-
* import { parseYAMLConfig } from '@maplibre-yaml/core/parser';
|
|
294
|
-
* const config = parseYAMLConfig(yamlString);
|
|
295
|
-
* ```
|
|
296
|
-
*/
|
|
297
|
-
declare const parseYAMLConfig: typeof YAMLParser.parse;
|
|
298
|
-
/**
|
|
299
|
-
* Convenience function to safely parse YAML config
|
|
300
|
-
*
|
|
301
|
-
* @param yaml - YAML string to parse
|
|
302
|
-
* @returns Result object with success flag and data or errors
|
|
303
|
-
*
|
|
304
|
-
* @remarks
|
|
305
|
-
* This is an alias for {@link YAMLParser.safeParse} for convenient imports.
|
|
306
|
-
*
|
|
307
|
-
* @example
|
|
308
|
-
* ```typescript
|
|
309
|
-
* import { safeParseYAMLConfig } from '@maplibre-yaml/core/parser';
|
|
310
|
-
* const result = safeParseYAMLConfig(yamlString);
|
|
311
|
-
* if (result.success) {
|
|
312
|
-
* console.log(result.data);
|
|
313
|
-
* }
|
|
314
|
-
* ```
|
|
315
|
-
*/
|
|
316
|
-
declare const safeParseYAMLConfig: typeof YAMLParser.safeParse;
|
|
317
|
-
|
|
318
9
|
/**
|
|
319
10
|
* @file Layer manager for MapLibre map layers
|
|
320
11
|
* @module @maplibre-yaml/core/renderer
|
|
@@ -2714,4 +2405,4 @@ declare const loadingStyles = "\n/* Loading Overlay */\n.mly-loading-overlay {\n
|
|
|
2714
2405
|
*/
|
|
2715
2406
|
declare function injectLoadingStyles(): void;
|
|
2716
2407
|
|
|
2717
|
-
export { BaseConnection, type CacheConfig, type CacheEntry, type CacheStats, type ConnectionConfig, type ConnectionEvents, type ConnectionState, ControlsConfigSchema, ControlsManager, DataFetcher, DataMerger, EventEmitter, type EventHandler, type EventHandlerCallbacks, type FetchOptions, type FetchResult, type FetcherConfig, LayerManager, type LayerManagerCallbacks, LayerSchema, type LoadingConfig, type LoadingEvents, LoadingManager, type LoadingState, MaxRetriesExceededError, MemoryCache, type MergeOptions, type MergeResult, type MergeStrategy, type
|
|
2408
|
+
export { BaseConnection, type CacheConfig, type CacheEntry, type CacheStats, type ConnectionConfig, type ConnectionEvents, type ConnectionState, ControlsConfigSchema, ControlsManager, DataFetcher, DataMerger, EventEmitter, type EventHandler, type EventHandlerCallbacks, type FetchOptions, type FetchResult, type FetcherConfig, LayerManager, type LayerManagerCallbacks, LayerSchema, type LoadingConfig, type LoadingEvents, LoadingManager, type LoadingState, MaxRetriesExceededError, MemoryCache, type MergeOptions, type MergeResult, type MergeStrategy, type PollingConfig, PollingManager, type PollingState, PopupBuilder, PopupContentSchema, type RetryCallbacks, type RetryConfig, RetryManager, type SSEConfig, SSEConnection, type StreamConfig, StreamManager, type StreamState, type WebSocketConfig, WebSocketConnection, injectLoadingStyles, loadingStyles };
|
package/dist/index.js
CHANGED
|
@@ -82,7 +82,9 @@ var GeoJSONSourceSchema = z.object({
|
|
|
82
82
|
"Polling refresh configuration"
|
|
83
83
|
),
|
|
84
84
|
// Legacy support for direct refresh properties
|
|
85
|
-
refreshInterval: z.number().min(1e3).optional().describe(
|
|
85
|
+
refreshInterval: z.number().min(1e3).optional().describe(
|
|
86
|
+
"Polling interval in milliseconds (legacy, use refresh.refreshInterval)"
|
|
87
|
+
),
|
|
86
88
|
updateStrategy: z.enum(["replace", "merge", "append-window"]).optional().describe("Update strategy (legacy, use refresh.updateStrategy)"),
|
|
87
89
|
updateKey: z.string().optional().describe("Update key (legacy, use refresh.updateKey)"),
|
|
88
90
|
loading: LoadingConfigSchema.optional().describe(
|
|
@@ -91,7 +93,7 @@ var GeoJSONSourceSchema = z.object({
|
|
|
91
93
|
cache: CacheConfigSchema.optional().describe("Cache configuration"),
|
|
92
94
|
// MapLibre clustering options
|
|
93
95
|
cluster: z.boolean().optional().describe("Enable point clustering"),
|
|
94
|
-
clusterRadius: z.number().int().min(0).
|
|
96
|
+
clusterRadius: z.number().int().min(0).optional().describe("Cluster radius in pixels (default: 50)"),
|
|
95
97
|
clusterMaxZoom: z.number().min(0).max(24).optional().describe("Maximum zoom level to cluster points"),
|
|
96
98
|
clusterMinPoints: z.number().int().min(2).optional().describe("Minimum points to form a cluster"),
|
|
97
99
|
clusterProperties: z.record(z.any()).optional().describe("Aggregate cluster properties"),
|
|
@@ -813,6 +815,99 @@ var YAMLParser = class {
|
|
|
813
815
|
const validated = RootSchema.parse(config);
|
|
814
816
|
return this.resolveReferences(validated);
|
|
815
817
|
}
|
|
818
|
+
/**
|
|
819
|
+
* Parse YAML string for a single map block and validate against MapBlockSchema
|
|
820
|
+
*
|
|
821
|
+
* @param yaml - YAML string to parse (should be a map block, not a full document)
|
|
822
|
+
* @returns Validated map block object
|
|
823
|
+
* @throws {Error} If YAML syntax is invalid
|
|
824
|
+
* @throws {ZodError} If validation fails
|
|
825
|
+
*
|
|
826
|
+
* @remarks
|
|
827
|
+
* This method is specifically for parsing individual map blocks (e.g., in documentation
|
|
828
|
+
* or component usage). Unlike {@link parse}, it validates against MapBlockSchema rather
|
|
829
|
+
* than RootSchema, so it expects a single map configuration without the pages array wrapper.
|
|
830
|
+
*
|
|
831
|
+
* @example
|
|
832
|
+
* ```typescript
|
|
833
|
+
* const yaml = `
|
|
834
|
+
* type: map
|
|
835
|
+
* id: example
|
|
836
|
+
* config:
|
|
837
|
+
* center: [0, 0]
|
|
838
|
+
* zoom: 2
|
|
839
|
+
* mapStyle: "https://example.com/style.json"
|
|
840
|
+
* layers:
|
|
841
|
+
* - id: points
|
|
842
|
+
* type: circle
|
|
843
|
+
* source:
|
|
844
|
+
* type: geojson
|
|
845
|
+
* data: { type: "FeatureCollection", features: [] }
|
|
846
|
+
* `;
|
|
847
|
+
*
|
|
848
|
+
* const mapBlock = YAMLParser.parseMapBlock(yaml);
|
|
849
|
+
* ```
|
|
850
|
+
*/
|
|
851
|
+
static parseMapBlock(yaml) {
|
|
852
|
+
let parsed;
|
|
853
|
+
try {
|
|
854
|
+
parsed = parse(yaml);
|
|
855
|
+
} catch (error) {
|
|
856
|
+
throw new Error(
|
|
857
|
+
`YAML syntax error: ${error instanceof Error ? error.message : String(error)}`
|
|
858
|
+
);
|
|
859
|
+
}
|
|
860
|
+
return MapBlockSchema.parse(parsed);
|
|
861
|
+
}
|
|
862
|
+
/**
|
|
863
|
+
* Parse YAML string for a single map block, returning a result object
|
|
864
|
+
*
|
|
865
|
+
* @param yaml - YAML string to parse (should be a map block, not a full document)
|
|
866
|
+
* @returns Result object with success flag and either data or errors
|
|
867
|
+
*
|
|
868
|
+
* @remarks
|
|
869
|
+
* This is the non-throwing version of {@link parseMapBlock}. Instead of throwing
|
|
870
|
+
* errors, it returns a result object that indicates success or failure.
|
|
871
|
+
* Use this when you want to handle errors gracefully without try/catch.
|
|
872
|
+
*
|
|
873
|
+
* @example
|
|
874
|
+
* ```typescript
|
|
875
|
+
* const result = YAMLParser.safeParseMapBlock(yamlString);
|
|
876
|
+
* if (result.success) {
|
|
877
|
+
* console.log('Map config:', result.data);
|
|
878
|
+
* } else {
|
|
879
|
+
* result.errors.forEach(err => {
|
|
880
|
+
* console.error(`Error at ${err.path}: ${err.message}`);
|
|
881
|
+
* });
|
|
882
|
+
* }
|
|
883
|
+
* ```
|
|
884
|
+
*/
|
|
885
|
+
static safeParseMapBlock(yaml) {
|
|
886
|
+
try {
|
|
887
|
+
const data = this.parseMapBlock(yaml);
|
|
888
|
+
return {
|
|
889
|
+
success: true,
|
|
890
|
+
data,
|
|
891
|
+
errors: []
|
|
892
|
+
};
|
|
893
|
+
} catch (error) {
|
|
894
|
+
if (error instanceof ZodError) {
|
|
895
|
+
return {
|
|
896
|
+
success: false,
|
|
897
|
+
errors: this.formatZodErrors(error)
|
|
898
|
+
};
|
|
899
|
+
}
|
|
900
|
+
return {
|
|
901
|
+
success: false,
|
|
902
|
+
errors: [
|
|
903
|
+
{
|
|
904
|
+
path: "",
|
|
905
|
+
message: error instanceof Error ? error.message : String(error)
|
|
906
|
+
}
|
|
907
|
+
]
|
|
908
|
+
};
|
|
909
|
+
}
|
|
910
|
+
}
|
|
816
911
|
/**
|
|
817
912
|
* Resolve $ref references to global layers and sources
|
|
818
913
|
*
|
|
@@ -3403,15 +3498,16 @@ var LayerManager = class {
|
|
|
3403
3498
|
if (geojsonSource.url) {
|
|
3404
3499
|
await this.addGeoJSONSourceFromURL(sourceId, layer.id, geojsonSource);
|
|
3405
3500
|
} else if (geojsonSource.data) {
|
|
3406
|
-
|
|
3501
|
+
const sourceSpec = {
|
|
3407
3502
|
type: "geojson",
|
|
3408
|
-
data: geojsonSource.data
|
|
3409
|
-
|
|
3410
|
-
|
|
3411
|
-
|
|
3412
|
-
|
|
3413
|
-
|
|
3414
|
-
|
|
3503
|
+
data: geojsonSource.data
|
|
3504
|
+
};
|
|
3505
|
+
if (geojsonSource.cluster !== void 0) sourceSpec.cluster = geojsonSource.cluster;
|
|
3506
|
+
if (geojsonSource.clusterRadius !== void 0) sourceSpec.clusterRadius = geojsonSource.clusterRadius;
|
|
3507
|
+
if (geojsonSource.clusterMaxZoom !== void 0) sourceSpec.clusterMaxZoom = geojsonSource.clusterMaxZoom;
|
|
3508
|
+
if (geojsonSource.clusterMinPoints !== void 0) sourceSpec.clusterMinPoints = geojsonSource.clusterMinPoints;
|
|
3509
|
+
if (geojsonSource.clusterProperties !== void 0) sourceSpec.clusterProperties = geojsonSource.clusterProperties;
|
|
3510
|
+
this.map.addSource(sourceId, sourceSpec);
|
|
3415
3511
|
} else if (geojsonSource.stream) {
|
|
3416
3512
|
this.map.addSource(sourceId, {
|
|
3417
3513
|
type: "geojson",
|
|
@@ -3472,15 +3568,16 @@ var LayerManager = class {
|
|
|
3472
3568
|
} else if (config.data) {
|
|
3473
3569
|
initialData = config.data;
|
|
3474
3570
|
}
|
|
3475
|
-
|
|
3571
|
+
const sourceSpec = {
|
|
3476
3572
|
type: "geojson",
|
|
3477
|
-
data: initialData
|
|
3478
|
-
|
|
3479
|
-
|
|
3480
|
-
|
|
3481
|
-
|
|
3482
|
-
|
|
3483
|
-
|
|
3573
|
+
data: initialData
|
|
3574
|
+
};
|
|
3575
|
+
if (config.cluster !== void 0) sourceSpec.cluster = config.cluster;
|
|
3576
|
+
if (config.clusterRadius !== void 0) sourceSpec.clusterRadius = config.clusterRadius;
|
|
3577
|
+
if (config.clusterMaxZoom !== void 0) sourceSpec.clusterMaxZoom = config.clusterMaxZoom;
|
|
3578
|
+
if (config.clusterMinPoints !== void 0) sourceSpec.clusterMinPoints = config.clusterMinPoints;
|
|
3579
|
+
if (config.clusterProperties !== void 0) sourceSpec.clusterProperties = config.clusterProperties;
|
|
3580
|
+
this.map.addSource(sourceId, sourceSpec);
|
|
3484
3581
|
this.sourceData.set(sourceId, initialData);
|
|
3485
3582
|
if (config.url && !config.prefetchedData) {
|
|
3486
3583
|
this.callbacks.onDataLoading?.(layerId);
|