Skip to content

Commit 8722643

Browse files
committed
Bugfix for map-interface package
1 parent 04c9573 commit 8722643

File tree

4 files changed

+24
-20
lines changed

4 files changed

+24
-20
lines changed

packages/map-interface/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file. The format
44
is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this
55
project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

7+
## [1.3.2] - 2025-06-26
8+
9+
Bugfix for DevMapPage when applying custom styles
10+
711
## [1.3.1] - 2025-06-25
812

913
Small improvements to types and styles

packages/map-interface/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@macrostrat/map-interface",
3-
"version": "1.3.1",
3+
"version": "1.3.2",
44
"description": "Map interface for Macrostrat",
55
"main": "dist/cjs/index.js",
66
"module": "dist/esm/index.js",

packages/map-interface/src/dev/map-page.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,8 @@ export function MapInspectorV2({
6767
mapboxgl.accessToken = mapboxToken;
6868
}
6969

70-
style ??= useBasicMapStyle({ styleType });
70+
const basicStyle = useBasicMapStyle({ styleType });
71+
style ??= basicStyle;
7172

7273
const [isOpen, setOpen] = useState(false);
7374

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { useMapConditionalStyle, useMapRef } from "@macrostrat/mapbox-react";
1+
import { useMapStyleOperator } from "@macrostrat/mapbox-react";
22
import { tileToGeoJSON } from "@mapbox/tilebelt";
3-
import { useCallback } from "react";
3+
import { setGeoJSON } from "@macrostrat/mapbox-utils";
44

55
type TileIndex = { x: number; y: number; z: number };
66

@@ -11,36 +11,35 @@ export function TileExtentLayer({
1111
tile: TileIndex | null;
1212
color?: string;
1313
}) {
14-
const styleCallback = useCallback(
15-
(map, val: TileIndex) => {
14+
useMapStyleOperator(
15+
(map) => {
1616
const style = map.getStyle();
1717
if (style.layers == null) return;
1818
style.layers = style.layers.filter((l) => l.id != "tile-extent");
19-
if (val == null) {
19+
if (tile == null) {
2020
return map.setStyle(style);
2121
}
22-
const { x, y, z } = val;
22+
const { x, y, z } = tile;
2323
const extent = tileToGeoJSON([x, y, z]);
24-
const source = {
25-
type: "geojson",
26-
data: extent,
27-
};
28-
const layer = {
24+
25+
setGeoJSON(map, "tile-extent", extent as any);
26+
27+
if (map.getLayer("tile-extent") != null) {
28+
// If the layer already exists, we can just update it
29+
map.removeLayer("tile-extent");
30+
}
31+
32+
map.addLayer({
2933
id: "tile-extent",
3034
type: "line",
3135
source: "tile-extent",
3236
paint: {
3337
"line-color": color,
3438
"line-width": 2,
3539
},
36-
};
37-
style.sources["tile-extent"] = source;
38-
style.layers.push(layer);
39-
map.setStyle(style);
40+
});
4041
},
41-
[color],
42+
[color, tile],
4243
);
43-
const map = useMapRef();
44-
useMapConditionalStyle(map, tile, styleCallback);
4544
return null;
4645
}

0 commit comments

Comments
 (0)