Skip to content

Commit 6749ef6

Browse files
feat(maplibre): handle zoom (= viewChanges.extent in contextDiff)
1 parent 29037db commit 6749ef6

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

packages/maplibre/lib/map/apply-context-diff.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,4 +58,23 @@ export async function applyContextDiffToMap(
5858
styleDiff.layers.map((layer) => map.addLayer(layer));
5959
});
6060
}
61+
62+
if (typeof contextDiff.viewChanges !== "undefined") {
63+
const { viewChanges } = contextDiff;
64+
65+
if (viewChanges && "extent" in viewChanges) {
66+
const { extent } = viewChanges;
67+
68+
map.fitBounds(
69+
[
70+
[extent[0], extent[1]],
71+
[extent[2], extent[3]],
72+
],
73+
{
74+
padding: 20,
75+
duration: 1000,
76+
},
77+
);
78+
}
79+
}
6180
}

packages/maplibre/lib/map/create-map.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ export async function createLayer(
123123
*/
124124
export async function createMapFromContext(
125125
context: MapContext,
126-
container: string | HTMLElement
126+
container: string | HTMLElement,
127127
): Promise<Map> {
128128
const map = new Map({
129129
container,

0 commit comments

Comments
 (0)