Skip to content

Instantly share code, notes, and snippets.

@dnomadb
Created February 20, 2018 20:25
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 dnomadb/bf328fa5fc43975be018dd7eb2aa7068 to your computer and use it in GitHub Desktop.
Save dnomadb/bf328fa5fc43975be018dd7eb2aa7068 to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html>
<head>
<meta charset='utf-8' />
<title></title>
<meta name='viewport' content='initial-scale=1,maximum-scale=1,user-scalable=no' />
<script src='https://api.tiles.mapbox.com/mapbox-gl-js/v0.44.1/mapbox-gl.js'></script>
<link href='https://api.tiles.mapbox.com/mapbox-gl-js/v0.44.1/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>
mapboxgl.accessToken = 'pk.eyJ1IjoibWF0dCIsImEiOiJTUHZkajU0In0.oB-OGTMFtpkga8vC48HjIg';
var map = new mapboxgl.Map({
container: 'map', // container id
style: {
"version": 8,
"sources": {
"sat-tiles": {
"type": "raster",
"tiles": [
"https://a.tiles.mapbox.com/v4/mapbox.satellite/{z}/{x}/{y}.jpg70?access_token=pk.eyJ1IjoibWF0dCIsImEiOiJTUHZkajU0In0.oB-OGTMFtpkga8vC48HjIg"
],
"tileSize": 128
}
},
"layers": [{
"id": "sat-tiles",
"type": "raster",
"source": "sat-tiles",
"minzoom": 0,
"maxzoom": 22
}]
},
center: [-122, 40],
zoom: 12,
hash: true,
transformRequest: (url, resourceType) => {
const match = /satellite\/(\d+)\/(\d+)\/(\d+)/.exec(url)
if (match) {
var z = parseInt(match[1]);
var x = parseInt(match[2]);
var y = parseInt(match[3]);
x = x + Math.floor(((Math.random() * 3) - 1));
y = y + Math.floor(((Math.random() * 3) - 1));
return {
url: url.replace(/satellite\/\d+\/\d+\/\d+/, `satellite/${z}/${x}/${y}`)
}
}
}
});
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment