Created
May 22, 2016 10:39
-
-
Save aesqe/f3791b05e8d0401a1913b9ca8bab3b8b to your computer and use it in GitHub Desktop.
Load GL when possible or fallback to raster tiles when browser does not support webgl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset=utf-8 /> | |
<title>A simple map</title> | |
<meta name='viewport' content='initial-scale=1,maximum-scale=1,user-scalable=no' /> | |
<!-- Load Mapbox.js --> | |
<script src='https://api.mapbox.com/mapbox.js/v2.4.0/mapbox.js'></script> | |
<link href='https://api.mapbox.com/mapbox.js/v2.4.0/mapbox.css' rel='stylesheet' /> | |
<!-- Load Mapbox-gl-js --> | |
<script src='https://api.tiles.mapbox.com/mapbox-gl-js/v0.18.0/mapbox-gl.js'></script> | |
<link href='https://api.tiles.mapbox.com/mapbox-gl-js/v0.18.0/mapbox-gl.css' rel='stylesheet' /> | |
<style> | |
body { margin:0; padding:0; } | |
#map { position:absolute; top:0; bottom:0; width:100%; } | |
</style> | |
</head> | |
<body> | |
<div id='map'></div> | |
<script> | |
var accessToken = 'pk.eyJ1IjoiYm9iYnlzdWQiLCJhIjoiTi16MElIUSJ9.Clrqck--7WmHeqqvtFdYig'; | |
// | |
// To test raster support, | |
// add ?raster=true to the of the url | |
// | |
if (mapboxgl.supported() && window.location.search.split('?raster=')[1] !== 'true') { | |
mapboxgl.accessToken = accessToken; | |
var map = new mapboxgl.Map({ | |
container: 'map', | |
style: 'mapbox://styles/mapbox/streets-v9', | |
center: [-74.50, 40], | |
zoom: 9 | |
}); | |
} else { | |
// Using Mapbox.js | |
L.mapbox.accessToken = accessToken; | |
var map = L.mapbox.map('map') | |
.setView([40, -74.50], 9); | |
L.mapbox.styleLayer('mapbox://styles/mapbox/streets-v9').addTo(map); | |
// | |
// Or without Mapbox.js and Leaflet directly | |
// | |
// var retina = L.Browser.retina ? '@2x' : ''; // Check if screen is retina | |
// | |
// L.tileLayer('https://api.mapbox.com/styles/v1/mapbox/streets-v8/tiles/{z}/{x}/{y}' + retina + '?access_token=' + accessToken, { | |
// tileSize: 512, // required | |
// zoomOffset: -1 // required | |
// }).addTo(map); | |
} | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment