@maplibre-yaml/core 0.1.3 → 0.2.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 +44 -0
- package/dist/components/index.d.ts +2 -2
- package/dist/components/index.js +32 -19
- package/dist/components/index.js.map +1 -1
- package/dist/index.d.ts +4 -4
- package/dist/index.js +30 -17
- package/dist/index.js.map +1 -1
- package/dist/{map-renderer-Br4guic2.d.ts → map-renderer-SjO3KQmx.d.ts} +6 -5
- package/dist/{page.schema-EBT_0Ojm.d.ts → page.schema-Cad2FFqh.d.ts} +1637 -1
- package/dist/register.browser.js +32 -19
- package/dist/register.browser.js.map +1 -1
- package/dist/register.d.ts +2 -2
- package/dist/register.js +32 -19
- package/dist/register.js.map +1 -1
- package/dist/schemas/index.d.ts +2 -1638
- package/dist/schemas/index.js +2 -0
- package/dist/schemas/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
export { ColorOrExpressionSchema, ColorSchema, ContentBlockSchema, ContentElementSchema, ContentItemSchema, ExpressionSchema,
|
|
2
|
-
import { L as LayerSchema, P as PopupContentSchema, C as ControlsConfigSchema,
|
|
3
|
-
export {
|
|
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-
|
|
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-SjO3KQmx.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
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { z, ZodError } from 'zod';
|
|
2
2
|
import { parse } from 'yaml';
|
|
3
|
-
import
|
|
3
|
+
import { Popup, NavigationControl, GeolocateControl, ScaleControl, FullscreenControl, Map as Map$1 } from 'maplibre-gl';
|
|
4
4
|
|
|
5
5
|
// @maplibre-yaml/core - Declarative web maps with YAML
|
|
6
6
|
|
|
@@ -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
|
|
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
|
-
|
|
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
|
-
|
|
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
|
}
|
|
@@ -4023,7 +4029,7 @@ var EventHandler = class {
|
|
|
4023
4029
|
showPopup(content, feature, lngLat) {
|
|
4024
4030
|
this.activePopup?.remove();
|
|
4025
4031
|
const html = this.popupBuilder.build(content, feature.properties);
|
|
4026
|
-
this.activePopup = new
|
|
4032
|
+
this.activePopup = new Popup().setLngLat(lngLat).setHTML(html).addTo(this.map);
|
|
4027
4033
|
}
|
|
4028
4034
|
/**
|
|
4029
4035
|
* Detach events for a layer
|
|
@@ -4128,14 +4134,14 @@ var ControlsManager = class {
|
|
|
4128
4134
|
if (config.navigation) {
|
|
4129
4135
|
const options = typeof config.navigation === "object" ? config.navigation : {};
|
|
4130
4136
|
const position = options.position || "top-right";
|
|
4131
|
-
const control = new
|
|
4137
|
+
const control = new NavigationControl();
|
|
4132
4138
|
this.map.addControl(control, position);
|
|
4133
4139
|
this.addedControls.push(control);
|
|
4134
4140
|
}
|
|
4135
4141
|
if (config.geolocate) {
|
|
4136
4142
|
const options = typeof config.geolocate === "object" ? config.geolocate : {};
|
|
4137
4143
|
const position = options.position || "top-right";
|
|
4138
|
-
const control = new
|
|
4144
|
+
const control = new GeolocateControl({
|
|
4139
4145
|
positionOptions: { enableHighAccuracy: true },
|
|
4140
4146
|
trackUserLocation: true
|
|
4141
4147
|
});
|
|
@@ -4145,14 +4151,14 @@ var ControlsManager = class {
|
|
|
4145
4151
|
if (config.scale) {
|
|
4146
4152
|
const options = typeof config.scale === "object" ? config.scale : {};
|
|
4147
4153
|
const position = options.position || "bottom-left";
|
|
4148
|
-
const control = new
|
|
4154
|
+
const control = new ScaleControl();
|
|
4149
4155
|
this.map.addControl(control, position);
|
|
4150
4156
|
this.addedControls.push(control);
|
|
4151
4157
|
}
|
|
4152
4158
|
if (config.fullscreen) {
|
|
4153
4159
|
const options = typeof config.fullscreen === "object" ? config.fullscreen : {};
|
|
4154
4160
|
const position = options.position || "top-right";
|
|
4155
|
-
const control = new
|
|
4161
|
+
const control = new FullscreenControl();
|
|
4156
4162
|
this.map.addControl(control, position);
|
|
4157
4163
|
this.addedControls.push(control);
|
|
4158
4164
|
}
|
|
@@ -4177,10 +4183,10 @@ 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
|
-
this.map = new
|
|
4189
|
+
this.map = new Map$1({
|
|
4184
4190
|
...config,
|
|
4185
4191
|
container: typeof container === "string" ? container : container,
|
|
4186
4192
|
style: config.mapStyle,
|
|
@@ -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?.();
|