mirror of
https://github.com/visgl/react-map-gl.git
synced 2026-01-18 15:54:22 +00:00
More robust add/remove condition checks (#1840)
This commit is contained in:
parent
1c391281a1
commit
2e49a545c8
@ -29,6 +29,7 @@ export default function App() {
|
||||
bearing: 80,
|
||||
pitch: 80
|
||||
}}
|
||||
maxPitch={85}
|
||||
mapStyle="mapbox://styles/mapbox/satellite-v9"
|
||||
mapboxAccessToken={TOKEN}
|
||||
terrain={{source: 'mapbox-dem', exaggeration: 1.5}}
|
||||
|
||||
@ -61,7 +61,7 @@ function updateLayer(map: MapboxMap, id: string, props: LayerProps, prevProps: L
|
||||
|
||||
function createLayer(map: MapboxMap, id: string, props: LayerProps) {
|
||||
// @ts-ignore
|
||||
if (map.style && map.style._loaded && map.getSource(props.source)) {
|
||||
if (map.style && map.style._loaded && (!('source' in props) || map.getSource(props.source))) {
|
||||
const options: LayerProps = {...props, id};
|
||||
delete options.beforeId;
|
||||
|
||||
@ -90,7 +90,7 @@ function Layer(props: LayerProps) {
|
||||
return () => {
|
||||
map.off('styledata', forceUpdate);
|
||||
// @ts-ignore
|
||||
if (map.style && map.style._loaded) {
|
||||
if (map.style && map.style._loaded && map.getLayer(id)) {
|
||||
map.removeLayer(id);
|
||||
}
|
||||
};
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user