Check if WebGL is supported
Check for WebGL browser support.
<!DOCTYPE html>
<html lang="en">
<head>
<title>Check if WebGL is supported</title>
<meta property="og:description" content="Check for WebGL browser support." />
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="https://unpkg.com/[email protected]/dist/trackasia-gl.css" />
<script src="https://unpkg.com/[email protected]/dist/trackasia-gl.js"></script>
<style>
body { margin: 0; padding: 0; }
html, body, #map { height: 100%; }
</style>
</head>
<body>
<div id="map"></div>
<script>
function isWebglSupported() {
if (window.WebGLRenderingContext) {
const canvas = document.createElement('canvas');
try {
// Note that { failIfMajorPerformanceCaveat: true } can be passed as a second argument
// to canvas.getContext(), causing the check to fail if hardware rendering is not available. See
// https://developer.mozilla.org/en-US/docs/Web/API/HTMLCanvasElement/getContext
// for more details.
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;
}
// WebGL not supported
return false;
}
if (!isWebglSupported()) {
alert('Your browser does not support TrackAsia GL');
} else {
const map = new trackasiagl.Map({
container: 'map',
style: 'https://maps.track-asia.com/styles/v2/streets.json?key=public_key',
center: {"lat":10.762622,"lng":106.660172},
zoom: 9
});
}
</script>
</body>
</html>