Skip to content

Commit 2e49a54

Browse files
More robust add/remove condition checks (#1840)
1 parent 1c39128 commit 2e49a54

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

examples/terrain/src/app.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ export default function App() {
2929
bearing: 80,
3030
pitch: 80
3131
}}
32+
maxPitch={85}
3233
mapStyle="mapbox://styles/mapbox/satellite-v9"
3334
mapboxAccessToken={TOKEN}
3435
terrain={{source: 'mapbox-dem', exaggeration: 1.5}}

src/components/layer.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ function updateLayer(map: MapboxMap, id: string, props: LayerProps, prevProps: L
6161

6262
function createLayer(map: MapboxMap, id: string, props: LayerProps) {
6363
// @ts-ignore
64-
if (map.style && map.style._loaded && map.getSource(props.source)) {
64+
if (map.style && map.style._loaded && (!('source' in props) || map.getSource(props.source))) {
6565
const options: LayerProps = {...props, id};
6666
delete options.beforeId;
6767

@@ -90,7 +90,7 @@ function Layer(props: LayerProps) {
9090
return () => {
9191
map.off('styledata', forceUpdate);
9292
// @ts-ignore
93-
if (map.style && map.style._loaded) {
93+
if (map.style && map.style._loaded && map.getLayer(id)) {
9494
map.removeLayer(id);
9595
}
9696
};

0 commit comments

Comments
 (0)