Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/big-views-flow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'svelte-maplibre': patch
---

fix: check if webgl is enabled and call onerror otherwise
23 changes: 22 additions & 1 deletion src/lib/MapLibre.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -253,9 +253,30 @@
}
}

function isWebglSupported() {
if (!window.WebGLRenderingContext) {
return false;
}
const canvas = document.createElement('canvas');
try {
const context = canvas.getContext('webgl2') || canvas.getContext('webgl');
if (context && typeof context.getParameter == 'function') {
return true;
}
} catch (e) {
// WebGL is supported, but disabled
}
return false;
}

function createMap(element: HTMLDivElement) {
onHashChange();

if (!isWebglSupported()) {
handleError(new ErrorEvent('', { error: new Error('WebGL is disabled or not supported') }));
return;
}

map = mapContext.map = new maplibre.Map(
flush({
container: element,
Expand All @@ -282,7 +303,7 @@
attributionControl,
transformRequest,
cooperativeGestures,
aroundCenter
aroundCenter,
})
);

Expand Down