@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/register.browser.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { Map as Map$1, Popup, NavigationControl, GeolocateControl, ScaleControl, FullscreenControl } from 'maplibre-gl';
|
|
2
2
|
|
|
3
3
|
// @maplibre-yaml/core - Browser build with bundled dependencies
|
|
4
4
|
var __create = Object.create;
|
|
@@ -11887,6 +11887,7 @@ var MapBlockSchema = external_exports.object({
|
|
|
11887
11887
|
className: external_exports.string().optional().describe("CSS class name for container"),
|
|
11888
11888
|
style: external_exports.string().optional().describe("Inline CSS styles for container"),
|
|
11889
11889
|
config: MapConfigSchema.describe("Map configuration"),
|
|
11890
|
+
sources: external_exports.record(external_exports.string(), LayerSourceSchema).optional().describe("Map sources"),
|
|
11890
11891
|
layers: external_exports.array(LayerOrReferenceSchema).default([]).describe("Map layers"),
|
|
11891
11892
|
controls: ControlsConfigSchema.optional().describe("Map controls"),
|
|
11892
11893
|
legend: LegendConfigSchema.optional().describe("Legend configuration")
|
|
@@ -11897,6 +11898,7 @@ var MapFullPageBlockSchema = external_exports.object({
|
|
|
11897
11898
|
className: external_exports.string().optional().describe("CSS class name for container"),
|
|
11898
11899
|
style: external_exports.string().optional().describe("Inline CSS styles for container"),
|
|
11899
11900
|
config: MapConfigSchema.describe("Map configuration"),
|
|
11901
|
+
sources: external_exports.record(external_exports.string(), LayerSourceSchema).optional().describe("Map sources"),
|
|
11900
11902
|
layers: external_exports.array(LayerOrReferenceSchema).default([]).describe("Map layers"),
|
|
11901
11903
|
controls: ControlsConfigSchema.optional().describe("Map controls"),
|
|
11902
11904
|
legend: LegendConfigSchema.optional().describe("Legend configuration")
|
|
@@ -14868,9 +14870,16 @@ var LayerManager = class {
|
|
|
14868
14870
|
this.abortControllers = /* @__PURE__ */ new Map();
|
|
14869
14871
|
}
|
|
14870
14872
|
async addLayer(layer) {
|
|
14871
|
-
const
|
|
14873
|
+
const isSourceRef = typeof layer.source === "string";
|
|
14874
|
+
const sourceId = isSourceRef ? layer.source : `${layer.id}-source`;
|
|
14872
14875
|
this.layerToSource.set(layer.id, sourceId);
|
|
14873
|
-
|
|
14876
|
+
if (!isSourceRef) {
|
|
14877
|
+
await this.addSource(sourceId, layer);
|
|
14878
|
+
} else if (!this.map.getSource(sourceId)) {
|
|
14879
|
+
throw new Error(
|
|
14880
|
+
`Source '${sourceId}' referenced by layer '${layer.id}' not found. Ensure it is defined in the block-level 'sources' map.`
|
|
14881
|
+
);
|
|
14882
|
+
}
|
|
14874
14883
|
const layerSpec = {
|
|
14875
14884
|
id: layer.id,
|
|
14876
14885
|
type: layer.type,
|
|
@@ -14898,12 +14907,6 @@ var LayerManager = class {
|
|
|
14898
14907
|
}
|
|
14899
14908
|
}
|
|
14900
14909
|
async addSource(sourceId, layer) {
|
|
14901
|
-
if (typeof layer.source === "string") {
|
|
14902
|
-
if (!this.map.getSource(layer.source)) {
|
|
14903
|
-
throw new Error(`Source reference '${layer.source}' not found`);
|
|
14904
|
-
}
|
|
14905
|
-
return;
|
|
14906
|
-
}
|
|
14907
14910
|
const source = layer.source;
|
|
14908
14911
|
if (source.type === "geojson") {
|
|
14909
14912
|
const geojsonSource = source;
|
|
@@ -15123,7 +15126,10 @@ var LayerManager = class {
|
|
|
15123
15126
|
}
|
|
15124
15127
|
if (this.map.getLayer(layerId)) this.map.removeLayer(layerId);
|
|
15125
15128
|
const sourceId = this.layerToSource.get(layerId) || `${layerId}-source`;
|
|
15126
|
-
|
|
15129
|
+
const isInlineSource = sourceId === `${layerId}-source`;
|
|
15130
|
+
if (isInlineSource && this.map.getSource(sourceId)) {
|
|
15131
|
+
this.map.removeSource(sourceId);
|
|
15132
|
+
}
|
|
15127
15133
|
this.sourceData.delete(sourceId);
|
|
15128
15134
|
this.layerToSource.delete(layerId);
|
|
15129
15135
|
}
|
|
@@ -15331,7 +15337,7 @@ var EventHandler = class {
|
|
|
15331
15337
|
showPopup(content, feature, lngLat) {
|
|
15332
15338
|
this.activePopup?.remove();
|
|
15333
15339
|
const html = this.popupBuilder.build(content, feature.properties);
|
|
15334
|
-
this.activePopup = new
|
|
15340
|
+
this.activePopup = new Popup().setLngLat(lngLat).setHTML(html).addTo(this.map);
|
|
15335
15341
|
}
|
|
15336
15342
|
/**
|
|
15337
15343
|
* Detach events for a layer
|
|
@@ -15436,14 +15442,14 @@ var ControlsManager = class {
|
|
|
15436
15442
|
if (config.navigation) {
|
|
15437
15443
|
const options = typeof config.navigation === "object" ? config.navigation : {};
|
|
15438
15444
|
const position = options.position || "top-right";
|
|
15439
|
-
const control = new
|
|
15445
|
+
const control = new NavigationControl();
|
|
15440
15446
|
this.map.addControl(control, position);
|
|
15441
15447
|
this.addedControls.push(control);
|
|
15442
15448
|
}
|
|
15443
15449
|
if (config.geolocate) {
|
|
15444
15450
|
const options = typeof config.geolocate === "object" ? config.geolocate : {};
|
|
15445
15451
|
const position = options.position || "top-right";
|
|
15446
|
-
const control = new
|
|
15452
|
+
const control = new GeolocateControl({
|
|
15447
15453
|
positionOptions: { enableHighAccuracy: true },
|
|
15448
15454
|
trackUserLocation: true
|
|
15449
15455
|
});
|
|
@@ -15453,14 +15459,14 @@ var ControlsManager = class {
|
|
|
15453
15459
|
if (config.scale) {
|
|
15454
15460
|
const options = typeof config.scale === "object" ? config.scale : {};
|
|
15455
15461
|
const position = options.position || "bottom-left";
|
|
15456
|
-
const control = new
|
|
15462
|
+
const control = new ScaleControl();
|
|
15457
15463
|
this.map.addControl(control, position);
|
|
15458
15464
|
this.addedControls.push(control);
|
|
15459
15465
|
}
|
|
15460
15466
|
if (config.fullscreen) {
|
|
15461
15467
|
const options = typeof config.fullscreen === "object" ? config.fullscreen : {};
|
|
15462
15468
|
const position = options.position || "top-right";
|
|
15463
|
-
const control = new
|
|
15469
|
+
const control = new FullscreenControl();
|
|
15464
15470
|
this.map.addControl(control, position);
|
|
15465
15471
|
this.addedControls.push(control);
|
|
15466
15472
|
}
|
|
@@ -15485,10 +15491,10 @@ var MapRenderer = class {
|
|
|
15485
15491
|
controlsManager;
|
|
15486
15492
|
eventListeners;
|
|
15487
15493
|
isLoaded;
|
|
15488
|
-
constructor(container, config, layers = [], options = {}) {
|
|
15494
|
+
constructor(container, config, layers = [], options = {}, sources) {
|
|
15489
15495
|
this.eventListeners = /* @__PURE__ */ new Map();
|
|
15490
15496
|
this.isLoaded = false;
|
|
15491
|
-
this.map = new
|
|
15497
|
+
this.map = new Map$1({
|
|
15492
15498
|
...config,
|
|
15493
15499
|
container: typeof container === "string" ? container : container,
|
|
15494
15500
|
style: config.mapStyle,
|
|
@@ -15513,6 +15519,13 @@ var MapRenderer = class {
|
|
|
15513
15519
|
this.controlsManager = new ControlsManager(this.map);
|
|
15514
15520
|
this.map.on("load", () => {
|
|
15515
15521
|
this.isLoaded = true;
|
|
15522
|
+
if (sources) {
|
|
15523
|
+
for (const [id, sourceSpec] of Object.entries(sources)) {
|
|
15524
|
+
if (!this.map.getSource(id)) {
|
|
15525
|
+
this.map.addSource(id, sourceSpec);
|
|
15526
|
+
}
|
|
15527
|
+
}
|
|
15528
|
+
}
|
|
15516
15529
|
Promise.all(layers.map((layer) => this.addLayer(layer))).then(() => {
|
|
15517
15530
|
this.emit("load", void 0);
|
|
15518
15531
|
options.onLoad?.();
|
|
@@ -15812,7 +15825,7 @@ var MLMap = class extends HTMLElement {
|
|
|
15812
15825
|
}
|
|
15813
15826
|
this.appendChild(this.mapContainer);
|
|
15814
15827
|
try {
|
|
15815
|
-
const { config, layers = [] } = mapBlock;
|
|
15828
|
+
const { config, sources, layers = [] } = mapBlock;
|
|
15816
15829
|
this.renderer = new MapRenderer(this.mapContainer, config, layers, {
|
|
15817
15830
|
onLoad: () => {
|
|
15818
15831
|
},
|
|
@@ -15824,7 +15837,7 @@ var MLMap = class extends HTMLElement {
|
|
|
15824
15837
|
})
|
|
15825
15838
|
);
|
|
15826
15839
|
}
|
|
15827
|
-
});
|
|
15840
|
+
}, sources);
|
|
15828
15841
|
this.setupEventForwarding();
|
|
15829
15842
|
} catch (error) {
|
|
15830
15843
|
this.handleError([
|