Skip to content

Commit 1aa91d5

Browse files
committed
Fix null reference errors in MapLibreMap by initializing map variable and adding checks
1 parent 4974cfb commit 1aa91d5

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

frontend/src/screens/App/screens/MapPane/components/MainMap/MapLibreMap.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class MapLibreMap
2424
implements MapInterface
2525
{
2626
private mapContainer: HTMLElement;
27-
private map: maplibregl.Map;
27+
private map: maplibregl.Map | null = null;
2828

2929
async componentDidMount(): Promise<void> {
3030
const map: maplibregl.Map = new maplibregl.Map({
@@ -82,7 +82,7 @@ class MapLibreMap
8282

8383
componentDidUpdate(prevProps: PropsWithRouter): void {
8484
// Update the conditional color expression to make the active dot a different color
85-
if (!this.map.isStyleLoaded()) {
85+
if (this.map && !this.map.isStyleLoaded()) {
8686
void this.map.once('style.load', () => this.syncUI());
8787
}
8888
if (
@@ -95,6 +95,7 @@ class MapLibreMap
9595
}
9696

9797
syncUI(): void {
98+
if (!this.map) return;
9899
this.map.setFilter(PHOTO_LAYER + '-active', [
99100
'==',
100101
['get', 'photoIdentifier'],
@@ -112,10 +113,12 @@ class MapLibreMap
112113
* Call if container has resized
113114
*/
114115
resize(): void {
116+
if (!this.map) return;
115117
this.map.resize();
116118
}
117119

118120
goTo(center: maplibregl.LngLatLike): void {
121+
if (!this.map) return;
119122
this.map.easeTo({
120123
zoom: 17.5,
121124
center,

0 commit comments

Comments
 (0)