Skip to content

Instantly share code, notes, and snippets.

@elenatorro
Last active April 1, 2019 12:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save elenatorro/6ba3dc4df19f6eb20404bfec0fce1082 to your computer and use it in GitHub Desktop.
Save elenatorro/6ba3dc4df19f6eb20404bfec0fce1082 to your computer and use it in GitHub Desktop.
Test Browser Support
<!DOCTYPE html>
<html>
<head>
<title>Check for browser support | CARTO</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta charset="UTF-8">
<script src="https://libs.cartocdn.com/carto-vl/v1.2.4/carto-vl.min.js"></script>
<script src="https://api.tiles.mapbox.com/mapbox-gl-js/v0.52.0/mapbox-gl.js"></script>
<link href="https://api.tiles.mapbox.com/mapbox-gl-js/v0.52.0/mapbox-gl.css" rel="stylesheet" />
<style>
html,
body {
margin: 0;
}
#map {
position: absolute;
width: 100%;
height: 100%;
}
</style>
</head>
<body>
<div id="map"></div>
<aside class="toolbox">
<div class="box">
<header>
<h1>Check for browser support</h1>
</header>
<section>
<p class="description open-sans">Check if the browser supports CARTO VL and get the reasons if it doesn't.</p>
</section>
<footer class="js-footer"></footer>
</div>
</aside>
<div id="loader">
<div class="CDB-LoaderIcon CDB-LoaderIcon--big">
<svg class="CDB-LoaderIcon-spinner" viewBox="0 0 50 50">
<circle class="CDB-LoaderIcon-path" cx="25" cy="25" r="20" fill="none"></circle>
</svg>
</div>
</div>
<script>
if (!carto.isBrowserSupported()) {
const reasons = carto.unsupportedBrowserReasons();
document.getElementById('loader').innerHTML = `
<div class="open-sans text-white">
<h3>Oops! Something went wrong.</h3>
<p>Your browser doesn't support CARTO VL:</p>
<ul>
${reasons.map(r => `<li>${r.message}.</li>`).join('')}
</ul>
</div>
`;
} else {
const map = new mapboxgl.Map({
container: 'map',
style: carto.basemaps.voyager,
center: [0, 0],
zoom: 1,
scrollZoom: false
});
carto.setDefaultAuth({
username: 'cartovl',
apiKey: 'default_public'
});
const source = new carto.source.Dataset('populated_places');
const viz = new carto.Viz();
const layer = new carto.Layer('layer', source, viz);
layer.addTo(map, 'watername_ocean');
layer.on('loaded', hideLoader);
function hideLoader() {
document.getElementById('loader').style.opacity = '0';
}
}
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment