fix(web): add shared DemSource singleton, add ErrorBoundary, and conditional view rendering to prevent WebGL crash
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
import maplibregl from 'maplibre-gl';
|
||||
import mlcontour from 'maplibre-contour';
|
||||
|
||||
let sharedDemSource: any = null;
|
||||
let isConfigured = false;
|
||||
|
||||
export function getSharedDemSource() {
|
||||
if (!sharedDemSource) {
|
||||
sharedDemSource = new mlcontour.DemSource({
|
||||
url: 'https://s3.amazonaws.com/elevation-tiles-prod/terrarium/{z}/{x}/{y}.png',
|
||||
encoding: 'terrarium',
|
||||
maxzoom: 15,
|
||||
worker: true,
|
||||
cacheSize: 100,
|
||||
});
|
||||
|
||||
if (!isConfigured) {
|
||||
try {
|
||||
sharedDemSource.setupMaplibre(maplibregl);
|
||||
isConfigured = true;
|
||||
} catch (e) {
|
||||
console.warn('DemSource setup warning:', e);
|
||||
}
|
||||
}
|
||||
}
|
||||
return sharedDemSource;
|
||||
}
|
||||
Reference in New Issue
Block a user