@geospatial-sdk/maplibre 0.0.5-dev.41 → 0.0.5-dev.42
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/helpers/map.helpers.d.ts +1 -1
- package/dist/helpers/map.helpers.d.ts.map +1 -1
- package/dist/helpers/map.helpers.js +13 -10
- package/dist/helpers/style.helpers.d.ts +1 -1
- package/dist/helpers/style.helpers.d.ts.map +1 -1
- package/dist/helpers/style.helpers.js +10 -6
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -2
- package/dist/map/apply-context-diff.js +47 -58
- package/dist/map/create-map.d.ts +1 -1
- package/dist/map/create-map.d.ts.map +1 -1
- package/dist/map/create-map.js +96 -112
- package/dist/map/index.d.ts +2 -2
- package/dist/map/index.d.ts.map +1 -1
- package/dist/map/index.js +2 -2
- package/lib/helpers/map.helpers.ts +3 -3
- package/lib/helpers/style.helpers.ts +2 -2
- package/lib/index.ts +2 -2
- package/lib/map/apply-context-diff.ts +5 -5
- package/lib/map/create-map.ts +2 -2
- package/lib/map/index.ts +2 -2
- package/package.json +3 -3
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Map } from "maplibre-gl";
|
|
2
|
-
import { Dataset, LayerContextWithStyle, LayerSpecificationWithSource } from "../maplibre.models";
|
|
2
|
+
import { Dataset, LayerContextWithStyle, LayerSpecificationWithSource } from "../maplibre.models.js";
|
|
3
3
|
import { FeatureCollection, Geometry } from "geojson";
|
|
4
4
|
import { MapContextLayer } from "@geospatial-sdk/core";
|
|
5
5
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"map.helpers.d.ts","sourceRoot":"","sources":["../../lib/helpers/map.helpers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAsB,MAAM,aAAa,CAAC;AACtD,OAAO,EACL,OAAO,EACP,qBAAqB,EAErB,4BAA4B,EAC7B,MAAM,
|
|
1
|
+
{"version":3,"file":"map.helpers.d.ts","sourceRoot":"","sources":["../../lib/helpers/map.helpers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAsB,MAAM,aAAa,CAAC;AACtD,OAAO,EACL,OAAO,EACP,qBAAqB,EAErB,4BAA4B,EAC7B,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,iBAAiB,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAGtD,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAEvD;;;;GAIG;AACH,wBAAgB,sBAAsB,CAAC,GAAG,EAAE,GAAG,EAAE,QAAQ,EAAE,MAAM,QAWhE;AAED;;;;;GAKG;AACH,wBAAgB,6BAA6B,CAC3C,UAAU,EAAE,qBAAqB,EACjC,OAAO,EAAE,iBAAiB,CAAC,QAAQ,GAAG,IAAI,CAAC,GAAG,MAAM,EACpD,cAAc,EAAE,MAAM,GACrB,OAAO,CAuBT;AAED,wBAAgB,mBAAmB,CACjC,GAAG,EAAE,GAAG,EACR,QAAQ,EAAE,MAAM,GACf,4BAA4B,EAAE,CAUhC;AAED,wBAAgB,WAAW,CAAC,GAAG,EAAE,GAAG,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAS1E;AAED,wBAAgB,eAAe,CAAC,UAAU,EAAE,eAAe,UAS1D"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { contextStyleToMaplibreLayers } from "./style.helpers";
|
|
2
|
-
import { getHash } from "@geospatial-sdk/core/dist/utils/hash";
|
|
1
|
+
import { contextStyleToMaplibreLayers } from "./style.helpers.js";
|
|
2
|
+
import { getHash } from "@geospatial-sdk/core/dist/utils/hash.js";
|
|
3
3
|
/**
|
|
4
4
|
* Remove all layers from a given source in the map.
|
|
5
5
|
* @param map
|
|
@@ -22,11 +22,17 @@ export function removeLayersFromSource(map, sourceId) {
|
|
|
22
22
|
export function createDatasetFromGeoJsonLayer(layerModel, geojson, sourcePosition) {
|
|
23
23
|
const sourceId = generateLayerId(layerModel);
|
|
24
24
|
const partialLayers = contextStyleToMaplibreLayers(layerModel.style);
|
|
25
|
-
const layers = partialLayers.map((layer) => (
|
|
25
|
+
const layers = partialLayers.map((layer) => ({
|
|
26
|
+
...layer,
|
|
27
|
+
id: `${sourceId}-${layer.type}`,
|
|
28
|
+
source: sourceId,
|
|
29
|
+
layout: {
|
|
26
30
|
visibility: layerModel.visibility === false ? "none" : "visible",
|
|
27
|
-
},
|
|
31
|
+
},
|
|
32
|
+
metadata: {
|
|
28
33
|
sourcePosition,
|
|
29
|
-
}
|
|
34
|
+
},
|
|
35
|
+
}));
|
|
30
36
|
return {
|
|
31
37
|
sources: {
|
|
32
38
|
[sourceId]: {
|
|
@@ -40,11 +46,8 @@ export function createDatasetFromGeoJsonLayer(layerModel, geojson, sourcePositio
|
|
|
40
46
|
export function getLayersAtPosition(map, position) {
|
|
41
47
|
const layers = map.getStyle().layers;
|
|
42
48
|
const layersWithSource = layers.filter((layer) => layer.type !== "background");
|
|
43
|
-
return layersWithSource.filter((layer) =>
|
|
44
|
-
|
|
45
|
-
return ((_a = layer.metadata) === null || _a === void 0 ? void 0 : _a.sourcePosition) ===
|
|
46
|
-
position;
|
|
47
|
-
});
|
|
49
|
+
return layersWithSource.filter((layer) => layer.metadata?.sourcePosition ===
|
|
50
|
+
position);
|
|
48
51
|
}
|
|
49
52
|
export function getBeforeId(map, position) {
|
|
50
53
|
const beforeLayer = map
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { VectorStyle } from "@geospatial-sdk/core/dist/model/style";
|
|
1
|
+
import { VectorStyle } from "@geospatial-sdk/core/dist/model/style.js";
|
|
2
2
|
import { LayerSpecification } from "maplibre-gl";
|
|
3
3
|
export declare function contextStyleToMaplibreLayers(style?: VectorStyle): Partial<LayerSpecification>[];
|
|
4
4
|
//# sourceMappingURL=style.helpers.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"style.helpers.d.ts","sourceRoot":"","sources":["../../lib/helpers/style.helpers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"style.helpers.d.ts","sourceRoot":"","sources":["../../lib/helpers/style.helpers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,0CAA0C,CAAC;AACvE,OAAO,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAajD,wBAAgB,4BAA4B,CAC1C,KAAK,GAAE,WAAgB,GACtB,OAAO,CAAC,kBAAkB,CAAC,EAAE,CAmD/B"}
|
|
@@ -18,7 +18,7 @@ export function contextStyleToMaplibreLayers(style = {}) {
|
|
|
18
18
|
return contextStyleToMaplibreLayers(style_);
|
|
19
19
|
});
|
|
20
20
|
}
|
|
21
|
-
style =
|
|
21
|
+
style = { ...defaultOltStyle, ...style };
|
|
22
22
|
if (style["fill-color"]) {
|
|
23
23
|
layers.push({
|
|
24
24
|
type: "fill",
|
|
@@ -31,11 +31,15 @@ export function contextStyleToMaplibreLayers(style = {}) {
|
|
|
31
31
|
if (style["stroke-color"] || style["stroke-width"]) {
|
|
32
32
|
layers.push({
|
|
33
33
|
type: "line",
|
|
34
|
-
paint:
|
|
35
|
-
"line-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
34
|
+
paint: {
|
|
35
|
+
"line-color": style["stroke-color"],
|
|
36
|
+
...(style["stroke-width"] !== undefined && {
|
|
37
|
+
"line-width": style["stroke-width"],
|
|
38
|
+
}),
|
|
39
|
+
...(style["stroke-line-dash"] !== undefined && {
|
|
40
|
+
"line-dasharray": style["stroke-line-dash"],
|
|
41
|
+
}),
|
|
42
|
+
},
|
|
39
43
|
});
|
|
40
44
|
}
|
|
41
45
|
if (style["circle-radius"]) {
|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export * from "./map";
|
|
2
|
-
export * from "./maplibre.models";
|
|
1
|
+
export * from "./map/index.js";
|
|
2
|
+
export * from "./maplibre.models.js";
|
|
3
3
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../lib/index.ts"],"names":[],"mappings":"AAAA,cAAc,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../lib/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,sBAAsB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export * from "./map";
|
|
2
|
-
export * from "./maplibre.models";
|
|
1
|
+
export * from "./map/index.js";
|
|
2
|
+
export * from "./maplibre.models.js";
|
|
@@ -1,71 +1,60 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
|
-
import { createLayer } from "./create-map";
|
|
11
|
-
import { generateLayerId, getBeforeId, getLayersAtPosition, removeLayersFromSource, } from "../helpers/map.helpers";
|
|
1
|
+
import { createLayer } from "./create-map.js";
|
|
2
|
+
import { generateLayerId, getBeforeId, getLayersAtPosition, removeLayersFromSource, } from "../helpers/map.helpers.js";
|
|
12
3
|
/**
|
|
13
4
|
* Apply a context diff to an MapLibre map
|
|
14
5
|
* @param map
|
|
15
6
|
* @param contextDiff
|
|
16
7
|
*/
|
|
17
|
-
export function applyContextDiffToMap(map, contextDiff) {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
continue;
|
|
27
|
-
}
|
|
28
|
-
const sourceId = mlLayers[0].source;
|
|
29
|
-
mlLayers.forEach((layer) => {
|
|
30
|
-
map.removeLayer(layer.id);
|
|
31
|
-
});
|
|
32
|
-
map.removeSource(sourceId);
|
|
8
|
+
export async function applyContextDiffToMap(map, contextDiff) {
|
|
9
|
+
// removed layers (sorted by descending position)
|
|
10
|
+
if (contextDiff.layersRemoved.length > 0) {
|
|
11
|
+
const removed = contextDiff.layersRemoved.sort((a, b) => b.position - a.position);
|
|
12
|
+
for (const layerRemoved of removed) {
|
|
13
|
+
const mlLayers = getLayersAtPosition(map, layerRemoved.position);
|
|
14
|
+
if (mlLayers.length === 0) {
|
|
15
|
+
console.warn(`[Warning] applyContextDiffToMap: no layer found at position ${layerRemoved.position} to remove.`);
|
|
16
|
+
continue;
|
|
33
17
|
}
|
|
18
|
+
const sourceId = mlLayers[0].source;
|
|
19
|
+
mlLayers.forEach((layer) => {
|
|
20
|
+
map.removeLayer(layer.id);
|
|
21
|
+
});
|
|
22
|
+
map.removeSource(sourceId);
|
|
34
23
|
}
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
24
|
+
}
|
|
25
|
+
// insert added layers
|
|
26
|
+
const newLayers = await Promise.all(contextDiff.layersAdded.map((layerAdded) => createLayer(layerAdded.layer, layerAdded.position)));
|
|
27
|
+
newLayers.forEach((style, index) => {
|
|
28
|
+
const position = contextDiff.layersAdded[index].position;
|
|
29
|
+
const beforeId = getBeforeId(map, position);
|
|
30
|
+
Object.keys(style.sources).forEach((sourceId) => map.addSource(sourceId, style.sources[sourceId]));
|
|
31
|
+
style.layers.map((layer) => {
|
|
32
|
+
map.addLayer(layer, beforeId);
|
|
33
|
+
});
|
|
34
|
+
});
|
|
35
|
+
// recreate changed layers
|
|
36
|
+
for (const layerChanged of contextDiff.layersChanged) {
|
|
37
|
+
const { layer, position } = layerChanged;
|
|
38
|
+
const sourceId = generateLayerId(layer);
|
|
39
|
+
removeLayersFromSource(map, sourceId);
|
|
40
|
+
const beforeId = getBeforeId(map, position);
|
|
41
|
+
createLayer(layer, position).then((styleDiff) => {
|
|
42
|
+
styleDiff.layers.map((layer) => {
|
|
42
43
|
map.addLayer(layer, beforeId);
|
|
43
44
|
});
|
|
44
45
|
});
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
46
|
+
}
|
|
47
|
+
if (typeof contextDiff.viewChanges !== "undefined") {
|
|
48
|
+
const { viewChanges } = contextDiff;
|
|
49
|
+
if (viewChanges && "extent" in viewChanges) {
|
|
50
|
+
const { extent } = viewChanges;
|
|
51
|
+
map.fitBounds([
|
|
52
|
+
[extent[0], extent[1]],
|
|
53
|
+
[extent[2], extent[3]],
|
|
54
|
+
], {
|
|
55
|
+
padding: 20,
|
|
56
|
+
duration: 1000,
|
|
55
57
|
});
|
|
56
58
|
}
|
|
57
|
-
|
|
58
|
-
const { viewChanges } = contextDiff;
|
|
59
|
-
if (viewChanges && "extent" in viewChanges) {
|
|
60
|
-
const { extent } = viewChanges;
|
|
61
|
-
map.fitBounds([
|
|
62
|
-
[extent[0], extent[1]],
|
|
63
|
-
[extent[2], extent[3]],
|
|
64
|
-
], {
|
|
65
|
-
padding: 20,
|
|
66
|
-
duration: 1000,
|
|
67
|
-
});
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
});
|
|
59
|
+
}
|
|
71
60
|
}
|
package/dist/map/create-map.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { MapContext, MapContextLayer } from "@geospatial-sdk/core";
|
|
2
2
|
import { Map, MapOptions } from "maplibre-gl";
|
|
3
|
-
import { PartialStyleSpecification } from "../maplibre.models";
|
|
3
|
+
import { PartialStyleSpecification } from "../maplibre.models.js";
|
|
4
4
|
export declare function createLayer(layerModel: MapContextLayer, sourcePosition: number): Promise<PartialStyleSpecification>;
|
|
5
5
|
/**
|
|
6
6
|
* Create an Maplibre map from a context; optionally specify a target (root element) for the map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create-map.d.ts","sourceRoot":"","sources":["../../lib/map/create-map.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,UAAU,EACV,eAAe,EAGhB,MAAM,sBAAsB,CAAC;AAE9B,OAAO,EAEL,GAAG,EACH,UAAU,EAEX,MAAM,aAAa,CAAC;AAWrB,OAAO,EAAW,yBAAyB,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"create-map.d.ts","sourceRoot":"","sources":["../../lib/map/create-map.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,UAAU,EACV,eAAe,EAGhB,MAAM,sBAAsB,CAAC;AAE9B,OAAO,EAEL,GAAG,EACH,UAAU,EAEX,MAAM,aAAa,CAAC;AAWrB,OAAO,EAAW,yBAAyB,EAAE,MAAM,uBAAuB,CAAC;AAO3E,wBAAsB,WAAW,CAC/B,UAAU,EAAE,eAAe,EAC3B,cAAc,EAAE,MAAM,GACrB,OAAO,CAAC,yBAAyB,CAAC,CAgGpC;AAED;;;;GAIG;AACH,wBAAsB,oBAAoB,CACxC,OAAO,EAAE,UAAU,EACnB,UAAU,EAAE,UAAU,GACrB,OAAO,CAAC,GAAG,CAAC,CAGd;AAED;;;;GAIG;AACH,wBAAsB,mBAAmB,CACvC,GAAG,EAAE,GAAG,EACR,OAAO,EAAE,UAAU,GAClB,OAAO,CAAC,GAAG,CAAC,CAoBd"}
|
package/dist/map/create-map.js
CHANGED
|
@@ -1,144 +1,128 @@
|
|
|
1
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
1
|
import { removeSearchParams, } from "@geospatial-sdk/core";
|
|
11
2
|
import { Map, } from "maplibre-gl";
|
|
12
3
|
import { OgcApiEndpoint, WfsEndpoint, WmsEndpoint, } from "@camptocamp/ogc-client";
|
|
13
|
-
import { createDatasetFromGeoJsonLayer, generateLayerId, } from "../helpers/map.helpers";
|
|
4
|
+
import { createDatasetFromGeoJsonLayer, generateLayerId, } from "../helpers/map.helpers.js";
|
|
14
5
|
const featureCollection = {
|
|
15
6
|
type: "FeatureCollection",
|
|
16
7
|
features: [],
|
|
17
8
|
};
|
|
18
|
-
export function createLayer(layerModel, sourcePosition) {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
[
|
|
39
|
-
|
|
40
|
-
tiles: [url],
|
|
41
|
-
tileSize: 256,
|
|
42
|
-
},
|
|
9
|
+
export async function createLayer(layerModel, sourcePosition) {
|
|
10
|
+
const { type } = layerModel;
|
|
11
|
+
switch (type) {
|
|
12
|
+
case "wms": {
|
|
13
|
+
const layerId = generateLayerId(layerModel);
|
|
14
|
+
const sourceId = layerId;
|
|
15
|
+
const endpoint = await new WmsEndpoint(layerModel.url).isReady();
|
|
16
|
+
let url = endpoint.getMapUrl([layerModel.name], {
|
|
17
|
+
widthPx: 256,
|
|
18
|
+
heightPx: 256,
|
|
19
|
+
extent: [0, 0, 0, 0], // will be replaced by maplibre-gl
|
|
20
|
+
outputFormat: "image/png",
|
|
21
|
+
crs: "EPSG:3857",
|
|
22
|
+
});
|
|
23
|
+
url = removeSearchParams(url, ["bbox"]);
|
|
24
|
+
url = `${url.toString()}&BBOX={bbox-epsg-3857}`;
|
|
25
|
+
const dataset = {
|
|
26
|
+
sources: {
|
|
27
|
+
[sourceId]: {
|
|
28
|
+
type: "raster",
|
|
29
|
+
tiles: [url],
|
|
30
|
+
tileSize: 256,
|
|
43
31
|
},
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
32
|
+
},
|
|
33
|
+
layers: [
|
|
34
|
+
{
|
|
35
|
+
id: layerId,
|
|
36
|
+
type: "raster",
|
|
37
|
+
source: sourceId,
|
|
38
|
+
paint: {},
|
|
39
|
+
metadata: {
|
|
40
|
+
sourcePosition,
|
|
53
41
|
},
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
42
|
+
},
|
|
43
|
+
],
|
|
44
|
+
};
|
|
45
|
+
return dataset;
|
|
46
|
+
}
|
|
47
|
+
case "wfs": {
|
|
48
|
+
const entryPoint = await new WfsEndpoint(layerModel.url).isReady();
|
|
49
|
+
const url = entryPoint.getFeatureUrl(layerModel.featureType, {
|
|
50
|
+
asJson: true,
|
|
51
|
+
outputCrs: "EPSG:4326",
|
|
52
|
+
});
|
|
53
|
+
return createDatasetFromGeoJsonLayer(layerModel, url, sourcePosition);
|
|
54
|
+
}
|
|
55
|
+
case "geojson": {
|
|
56
|
+
let geojson;
|
|
57
|
+
if (layerModel.url !== undefined) {
|
|
58
|
+
geojson = layerModel.url;
|
|
65
59
|
}
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
if (
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
else {
|
|
72
|
-
const data = layerModel.data;
|
|
73
|
-
if (typeof data === "string") {
|
|
74
|
-
try {
|
|
75
|
-
geojson = JSON.parse(data);
|
|
76
|
-
}
|
|
77
|
-
catch (e) {
|
|
78
|
-
console.warn("A layer could not be created", layerModel, e);
|
|
79
|
-
geojson = featureCollection;
|
|
80
|
-
}
|
|
60
|
+
else {
|
|
61
|
+
const data = layerModel.data;
|
|
62
|
+
if (typeof data === "string") {
|
|
63
|
+
try {
|
|
64
|
+
geojson = JSON.parse(data);
|
|
81
65
|
}
|
|
82
|
-
|
|
83
|
-
|
|
66
|
+
catch (e) {
|
|
67
|
+
console.warn("A layer could not be created", layerModel, e);
|
|
68
|
+
geojson = featureCollection;
|
|
84
69
|
}
|
|
85
70
|
}
|
|
86
|
-
return createDatasetFromGeoJsonLayer(layerModel, geojson, sourcePosition);
|
|
87
|
-
}
|
|
88
|
-
case "ogcapi": {
|
|
89
|
-
const ogcEndpoint = new OgcApiEndpoint(layerModel.url);
|
|
90
|
-
let layerUrl;
|
|
91
|
-
if (layerModel.useTiles) {
|
|
92
|
-
console.warn("[Warning] OGC API - Tiles not yet implemented.");
|
|
93
|
-
}
|
|
94
71
|
else {
|
|
95
|
-
|
|
96
|
-
return createDatasetFromGeoJsonLayer(layerModel, layerUrl, sourcePosition);
|
|
72
|
+
geojson = data;
|
|
97
73
|
}
|
|
98
|
-
break;
|
|
99
74
|
}
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
75
|
+
return createDatasetFromGeoJsonLayer(layerModel, geojson, sourcePosition);
|
|
76
|
+
}
|
|
77
|
+
case "ogcapi": {
|
|
78
|
+
const ogcEndpoint = new OgcApiEndpoint(layerModel.url);
|
|
79
|
+
let layerUrl;
|
|
80
|
+
if (layerModel.useTiles) {
|
|
81
|
+
console.warn("[Warning] OGC API - Tiles not yet implemented.");
|
|
82
|
+
}
|
|
83
|
+
else {
|
|
84
|
+
layerUrl = await ogcEndpoint.getCollectionItemsUrl(layerModel.collection, { ...layerModel.options, asJson: true });
|
|
85
|
+
return createDatasetFromGeoJsonLayer(layerModel, layerUrl, sourcePosition);
|
|
105
86
|
}
|
|
87
|
+
break;
|
|
106
88
|
}
|
|
107
|
-
|
|
108
|
-
|
|
89
|
+
case "maplibre-style": {
|
|
90
|
+
console.warn("[Warning] Maplibre style - Not yet fully implemented.");
|
|
91
|
+
const style = await fetch(layerModel.styleUrl).then((res) => res.json());
|
|
92
|
+
style.layers?.forEach((layer) => (layer.metadata = { sourcePosition }));
|
|
93
|
+
return style;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
return {};
|
|
109
97
|
}
|
|
110
98
|
/**
|
|
111
99
|
* Create an Maplibre map from a context; optionally specify a target (root element) for the map
|
|
112
100
|
* @param context
|
|
113
101
|
* @param target
|
|
114
102
|
*/
|
|
115
|
-
export function createMapFromContext(context, mapOptions) {
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
return yield resetMapFromContext(map, context);
|
|
119
|
-
});
|
|
103
|
+
export async function createMapFromContext(context, mapOptions) {
|
|
104
|
+
const map = new Map(mapOptions);
|
|
105
|
+
return await resetMapFromContext(map, context);
|
|
120
106
|
}
|
|
121
107
|
/**
|
|
122
108
|
* Resets a Maplibre map from a context; existing content will be cleared
|
|
123
109
|
* @param map
|
|
124
110
|
* @param context
|
|
125
111
|
*/
|
|
126
|
-
export function resetMapFromContext(map, context) {
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
map.setSprite(partialMLStyle.sprite);
|
|
138
|
-
}
|
|
139
|
-
Object.keys(partialMLStyle.sources).forEach((sourceId) => map.addSource(sourceId, partialMLStyle.sources[sourceId]));
|
|
140
|
-
partialMLStyle.layers.map((layer) => map.addLayer(layer));
|
|
112
|
+
export async function resetMapFromContext(map, context) {
|
|
113
|
+
map.setZoom(context.view.zoom);
|
|
114
|
+
map.setCenter(context.view.center);
|
|
115
|
+
for (let i = 0; i < context.layers.length; i++) {
|
|
116
|
+
const layerModel = context.layers[i];
|
|
117
|
+
const partialMLStyle = await createLayer(layerModel, i);
|
|
118
|
+
if (partialMLStyle.glyphs) {
|
|
119
|
+
map.setGlyphs(partialMLStyle.glyphs);
|
|
120
|
+
}
|
|
121
|
+
if (partialMLStyle.sprite) {
|
|
122
|
+
map.setSprite(partialMLStyle.sprite);
|
|
141
123
|
}
|
|
142
|
-
|
|
143
|
-
|
|
124
|
+
Object.keys(partialMLStyle.sources).forEach((sourceId) => map.addSource(sourceId, partialMLStyle.sources[sourceId]));
|
|
125
|
+
partialMLStyle.layers.map((layer) => map.addLayer(layer));
|
|
126
|
+
}
|
|
127
|
+
return map;
|
|
144
128
|
}
|
package/dist/map/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export { createMapFromContext, resetMapFromContext } from "./create-map";
|
|
2
|
-
export { applyContextDiffToMap } from "./apply-context-diff";
|
|
1
|
+
export { createMapFromContext, resetMapFromContext } from "./create-map.js";
|
|
2
|
+
export { applyContextDiffToMap } from "./apply-context-diff.js";
|
|
3
3
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/map/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../lib/map/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,mBAAmB,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../lib/map/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AAC5E,OAAO,EAAE,qBAAqB,EAAE,MAAM,yBAAyB,CAAC"}
|
package/dist/map/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { createMapFromContext, resetMapFromContext } from "./create-map";
|
|
2
|
-
export { applyContextDiffToMap } from "./apply-context-diff";
|
|
1
|
+
export { createMapFromContext, resetMapFromContext } from "./create-map.js";
|
|
2
|
+
export { applyContextDiffToMap } from "./apply-context-diff.js";
|
|
@@ -4,10 +4,10 @@ import {
|
|
|
4
4
|
LayerContextWithStyle,
|
|
5
5
|
LayerMetadataSpecification,
|
|
6
6
|
LayerSpecificationWithSource,
|
|
7
|
-
} from "../maplibre.models";
|
|
7
|
+
} from "../maplibre.models.js";
|
|
8
8
|
import { FeatureCollection, Geometry } from "geojson";
|
|
9
|
-
import { contextStyleToMaplibreLayers } from "./style.helpers";
|
|
10
|
-
import { getHash } from "@geospatial-sdk/core/dist/utils/hash";
|
|
9
|
+
import { contextStyleToMaplibreLayers } from "./style.helpers.js";
|
|
10
|
+
import { getHash } from "@geospatial-sdk/core/dist/utils/hash.js";
|
|
11
11
|
import { MapContextLayer } from "@geospatial-sdk/core";
|
|
12
12
|
|
|
13
13
|
/**
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { VectorStyle } from "@geospatial-sdk/core/dist/model/style";
|
|
1
|
+
import { VectorStyle } from "@geospatial-sdk/core/dist/model/style.js";
|
|
2
2
|
import { LayerSpecification } from "maplibre-gl";
|
|
3
|
-
import { FlatFill, FlatStyle, Rule } from "ol/style/flat";
|
|
3
|
+
import { FlatFill, FlatStyle, Rule } from "ol/style/flat.js";
|
|
4
4
|
|
|
5
5
|
const defaultOltStyle: FlatStyle = {
|
|
6
6
|
"fill-color": "rgba(255,255,255,0.4)",
|
package/lib/index.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export * from "./map";
|
|
2
|
-
export * from "./maplibre.models";
|
|
1
|
+
export * from "./map/index.js";
|
|
2
|
+
export * from "./maplibre.models.js";
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { MapContextDiff } from "@geospatial-sdk/core";
|
|
2
2
|
import { Map } from "maplibre-gl";
|
|
3
|
-
import { createLayer } from "./create-map";
|
|
3
|
+
import { createLayer } from "./create-map.js";
|
|
4
4
|
import {
|
|
5
5
|
generateLayerId,
|
|
6
6
|
getBeforeId,
|
|
7
7
|
getLayersAtPosition,
|
|
8
8
|
removeLayersFromSource,
|
|
9
|
-
} from "../helpers/map.helpers";
|
|
9
|
+
} from "../helpers/map.helpers.js";
|
|
10
10
|
|
|
11
11
|
/**
|
|
12
12
|
* Apply a context diff to an MapLibre map
|
|
@@ -44,13 +44,13 @@ export async function applyContextDiffToMap(
|
|
|
44
44
|
createLayer(layerAdded.layer, layerAdded.position),
|
|
45
45
|
),
|
|
46
46
|
);
|
|
47
|
-
newLayers.forEach((style, index) => {
|
|
47
|
+
newLayers.forEach((style: any, index: any) => {
|
|
48
48
|
const position = contextDiff.layersAdded[index].position;
|
|
49
49
|
const beforeId = getBeforeId(map, position);
|
|
50
50
|
Object.keys(style.sources).forEach((sourceId) =>
|
|
51
51
|
map.addSource(sourceId, style.sources[sourceId]),
|
|
52
52
|
);
|
|
53
|
-
style.layers.map((layer) => {
|
|
53
|
+
style.layers.map((layer: any) => {
|
|
54
54
|
map.addLayer(layer, beforeId);
|
|
55
55
|
});
|
|
56
56
|
});
|
|
@@ -62,7 +62,7 @@ export async function applyContextDiffToMap(
|
|
|
62
62
|
removeLayersFromSource(map, sourceId);
|
|
63
63
|
const beforeId = getBeforeId(map, position);
|
|
64
64
|
createLayer(layer, position).then((styleDiff) => {
|
|
65
|
-
styleDiff.layers.map((layer) => {
|
|
65
|
+
styleDiff.layers.map((layer: any) => {
|
|
66
66
|
map.addLayer(layer, beforeId);
|
|
67
67
|
});
|
|
68
68
|
});
|
package/lib/map/create-map.ts
CHANGED
|
@@ -20,8 +20,8 @@ import {
|
|
|
20
20
|
import {
|
|
21
21
|
createDatasetFromGeoJsonLayer,
|
|
22
22
|
generateLayerId,
|
|
23
|
-
} from "../helpers/map.helpers";
|
|
24
|
-
import { Dataset, PartialStyleSpecification } from "../maplibre.models";
|
|
23
|
+
} from "../helpers/map.helpers.js";
|
|
24
|
+
import { Dataset, PartialStyleSpecification } from "../maplibre.models.js";
|
|
25
25
|
|
|
26
26
|
const featureCollection: FeatureCollection<Geometry | null> = {
|
|
27
27
|
type: "FeatureCollection",
|
package/lib/map/index.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { createMapFromContext, resetMapFromContext } from "./create-map";
|
|
2
|
-
export { applyContextDiffToMap } from "./apply-context-diff";
|
|
1
|
+
export { createMapFromContext, resetMapFromContext } from "./create-map.js";
|
|
2
|
+
export { applyContextDiffToMap } from "./apply-context-diff.js";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@geospatial-sdk/maplibre",
|
|
3
|
-
"version": "0.0.5-dev.
|
|
3
|
+
"version": "0.0.5-dev.42+baa75c1",
|
|
4
4
|
"description": "Maplibre-related utilities",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"maplibre",
|
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
"maplibre-gl": "^5.7.3"
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"@geospatial-sdk/core": "^0.0.5-dev.
|
|
36
|
+
"@geospatial-sdk/core": "^0.0.5-dev.42+baa75c1"
|
|
37
37
|
},
|
|
38
|
-
"gitHead": "
|
|
38
|
+
"gitHead": "baa75c1fed77ed160f6a2d94bfeb5358cc91d63a"
|
|
39
39
|
}
|