@maplibre-yaml/core 0.1.3 → 0.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.ts CHANGED
@@ -1,7 +1,7 @@
1
- export { ColorOrExpressionSchema, ColorSchema, ContentBlockSchema, ContentElementSchema, ContentItemSchema, ExpressionSchema, GeoJSONSourceSchema, ImageSourceSchema, LatitudeSchema, LayerSourceSchema, LngLatBoundsSchema, LngLatSchema, LoadingConfigSchema, LongitudeSchema, NumberOrExpressionSchema, RasterSourceSchema, StreamConfigSchema, ValidTagNames, VectorSourceSchema, VideoSourceSchema, ZoomLevelSchema } from './schemas/index.js';
2
- import { L as LayerSchema, P as PopupContentSchema, C as ControlsConfigSchema, c as MapConfig, G as GlobalConfig, d as MapBlock } from './page.schema-EBT_0Ojm.js';
3
- export { m as BackgroundLayerSchema, B as BaseLayerPropertiesSchema, Q as Block, J as BlockSchema, y as Chapter, z as ChapterAction, v as ChapterActionSchema, A as ChapterLayers, w as ChapterLayersSchema, x as ChapterSchema, g as CircleLayerSchema, r as ControlPosition, p as ControlPositionSchema, s as ControlsConfig, k as FillExtrusionLayerSchema, F as FillLayerSchema, N as GlobalConfigSchema, H as HeatmapLayerSchema, l as HillshadeLayerSchema, I as InteractiveConfigSchema, o as LayerOrReferenceSchema, n as LayerReferenceSchema, t as LegendConfig, a as LegendConfigSchema, f as LegendItemSchema, h as LineLayerSchema, M as MapBlockSchema, b as MapConfigSchema, u as MapFullPageBlock, q as MapFullPageBlockSchema, O as MixedBlock, E as MixedBlockSchema, T as Page, K as PageSchema, e as PopupContentItemSchema, j as RasterLayerSchema, U as RootConfig, R as RootSchema, D as ScrollytellingBlock, S as ScrollytellingBlockSchema, i as SymbolLayerSchema } from './page.schema-EBT_0Ojm.js';
4
- export { L as LegendBuilder, M as MapRenderer, c as MapRendererEvents, b as MapRendererOptions, P as ParseError, a as ParseResult, Y as YAMLParser, p as parseYAMLConfig, s as safeParseYAMLConfig } from './map-renderer-Br4guic2.js';
1
+ export { ColorOrExpressionSchema, ColorSchema, ContentBlockSchema, ContentElementSchema, ContentItemSchema, ExpressionSchema, LatitudeSchema, LngLatBoundsSchema, LngLatSchema, LongitudeSchema, NumberOrExpressionSchema, ValidTagNames, ZoomLevelSchema } from './schemas/index.js';
2
+ import { L as LayerSchema, P as PopupContentSchema, C as ControlsConfigSchema, d as MapConfig, G as GlobalConfig, e as MapBlock } from './page.schema-Cad2FFqh.js';
3
+ export { t as BackgroundLayerSchema, B as BaseLayerPropertiesSchema, _ as Block, W as BlockSchema, N as Chapter, O as ChapterAction, E as ChapterActionSchema, Q as ChapterLayers, J as ChapterLayersSchema, K as ChapterSchema, n as CircleLayerSchema, y as ControlPosition, w as ControlPositionSchema, z as ControlsConfig, r as FillExtrusionLayerSchema, F as FillLayerSchema, h as GeoJSONSourceSchema, Y as GlobalConfigSchema, H as HeatmapLayerSchema, s as HillshadeLayerSchema, I as ImageSourceSchema, l as InteractiveConfigSchema, v as LayerOrReferenceSchema, u as LayerReferenceSchema, c as LayerSourceSchema, A as LegendConfig, a as LegendConfigSchema, m as LegendItemSchema, o as LineLayerSchema, g as LoadingConfigSchema, M as MapBlockSchema, b as MapConfigSchema, D as MapFullPageBlock, x as MapFullPageBlockSchema, Z as MixedBlock, U as MixedBlockSchema, $ as Page, X as PageSchema, k as PopupContentItemSchema, q as RasterLayerSchema, i as RasterSourceSchema, a0 as RootConfig, R as RootSchema, T as ScrollytellingBlock, S as ScrollytellingBlockSchema, f as StreamConfigSchema, p as SymbolLayerSchema, V as VectorSourceSchema, j as VideoSourceSchema } from './page.schema-Cad2FFqh.js';
4
+ export { L as LegendBuilder, M as MapRenderer, c as MapRendererEvents, b as MapRendererOptions, P as ParseError, a as ParseResult, Y as YAMLParser, p as parseYAMLConfig, s as safeParseYAMLConfig } from './map-renderer-8-c51Ww7.js';
5
5
  import { Map, LngLat } from 'maplibre-gl';
6
6
  import { z } from 'zod';
7
7
  import { FeatureCollection } from 'geojson';
package/dist/index.js CHANGED
@@ -585,6 +585,7 @@ var MapBlockSchema = z.object({
585
585
  className: z.string().optional().describe("CSS class name for container"),
586
586
  style: z.string().optional().describe("Inline CSS styles for container"),
587
587
  config: MapConfigSchema.describe("Map configuration"),
588
+ sources: z.record(z.string(), LayerSourceSchema).optional().describe("Map sources"),
588
589
  layers: z.array(LayerOrReferenceSchema).default([]).describe("Map layers"),
589
590
  controls: ControlsConfigSchema.optional().describe("Map controls"),
590
591
  legend: LegendConfigSchema.optional().describe("Legend configuration")
@@ -595,6 +596,7 @@ var MapFullPageBlockSchema = z.object({
595
596
  className: z.string().optional().describe("CSS class name for container"),
596
597
  style: z.string().optional().describe("Inline CSS styles for container"),
597
598
  config: MapConfigSchema.describe("Map configuration"),
599
+ sources: z.record(z.string(), LayerSourceSchema).optional().describe("Map sources"),
598
600
  layers: z.array(LayerOrReferenceSchema).default([]).describe("Map layers"),
599
601
  controls: ControlsConfigSchema.optional().describe("Map controls"),
600
602
  legend: LegendConfigSchema.optional().describe("Legend configuration")
@@ -3560,9 +3562,16 @@ var LayerManager = class {
3560
3562
  this.abortControllers = /* @__PURE__ */ new Map();
3561
3563
  }
3562
3564
  async addLayer(layer) {
3563
- const sourceId = `${layer.id}-source`;
3565
+ const isSourceRef = typeof layer.source === "string";
3566
+ const sourceId = isSourceRef ? layer.source : `${layer.id}-source`;
3564
3567
  this.layerToSource.set(layer.id, sourceId);
3565
- await this.addSource(sourceId, layer);
3568
+ if (!isSourceRef) {
3569
+ await this.addSource(sourceId, layer);
3570
+ } else if (!this.map.getSource(sourceId)) {
3571
+ throw new Error(
3572
+ `Source '${sourceId}' referenced by layer '${layer.id}' not found. Ensure it is defined in the block-level 'sources' map.`
3573
+ );
3574
+ }
3566
3575
  const layerSpec = {
3567
3576
  id: layer.id,
3568
3577
  type: layer.type,
@@ -3590,12 +3599,6 @@ var LayerManager = class {
3590
3599
  }
3591
3600
  }
3592
3601
  async addSource(sourceId, layer) {
3593
- if (typeof layer.source === "string") {
3594
- if (!this.map.getSource(layer.source)) {
3595
- throw new Error(`Source reference '${layer.source}' not found`);
3596
- }
3597
- return;
3598
- }
3599
3602
  const source = layer.source;
3600
3603
  if (source.type === "geojson") {
3601
3604
  const geojsonSource = source;
@@ -3815,7 +3818,10 @@ var LayerManager = class {
3815
3818
  }
3816
3819
  if (this.map.getLayer(layerId)) this.map.removeLayer(layerId);
3817
3820
  const sourceId = this.layerToSource.get(layerId) || `${layerId}-source`;
3818
- if (this.map.getSource(sourceId)) this.map.removeSource(sourceId);
3821
+ const isInlineSource = sourceId === `${layerId}-source`;
3822
+ if (isInlineSource && this.map.getSource(sourceId)) {
3823
+ this.map.removeSource(sourceId);
3824
+ }
3819
3825
  this.sourceData.delete(sourceId);
3820
3826
  this.layerToSource.delete(layerId);
3821
3827
  }
@@ -4177,7 +4183,7 @@ var MapRenderer = class {
4177
4183
  controlsManager;
4178
4184
  eventListeners;
4179
4185
  isLoaded;
4180
- constructor(container, config, layers = [], options = {}) {
4186
+ constructor(container, config, layers = [], options = {}, sources) {
4181
4187
  this.eventListeners = /* @__PURE__ */ new Map();
4182
4188
  this.isLoaded = false;
4183
4189
  this.map = new maplibregl2.Map({
@@ -4205,6 +4211,13 @@ var MapRenderer = class {
4205
4211
  this.controlsManager = new ControlsManager(this.map);
4206
4212
  this.map.on("load", () => {
4207
4213
  this.isLoaded = true;
4214
+ if (sources) {
4215
+ for (const [id, sourceSpec] of Object.entries(sources)) {
4216
+ if (!this.map.getSource(id)) {
4217
+ this.map.addSource(id, sourceSpec);
4218
+ }
4219
+ }
4220
+ }
4208
4221
  Promise.all(layers.map((layer) => this.addLayer(layer))).then(() => {
4209
4222
  this.emit("load", void 0);
4210
4223
  options.onLoad?.();