Simple example demonstrating how to use third-party raster tiles in Mapbox GL JS.
Last active
April 15, 2019 02:56
-
-
Save danswick/a4de5c170c04fdd38bb4 to your computer and use it in GitHub Desktop.
3rd party raster tiles in Mapbox GL JS
This file contains hidden or 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
<html> | |
<head> | |
<meta charset='utf-8' /> | |
<title></title> | |
<meta name='viewport' content='initial-scale=1,maximum-scale=1,user-scalable=no' /> | |
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script> | |
<script src='https://api.tiles.mapbox.com/mapbox-gl-js/v0.11.4/mapbox-gl.js'></script> | |
<link href='https://api.tiles.mapbox.com/mapbox-gl-js/v0.11.4/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.eyJ1IjoiZGFuc3dpY2siLCJhIjoieUZiWmwtVSJ9.0cPQywdbPVmvHiHJ6NwdXA'; | |
var map = new mapboxgl.Map({ | |
container: 'map', // container id | |
style: { | |
"version": 8, | |
"sources": { | |
"simple-tiles": { | |
"type": "raster", | |
// point to our third-party tiles. Note that some examples | |
// show a "url" property. This only applies to tilesets with | |
// corresponding TileJSON (such as mapbox tiles). | |
"tiles": [ | |
"http://a.tile.openstreetmap.org/{z}/{x}/{y}.png", | |
"http://b.tile.openstreetmap.org/{z}/{x}/{y}.png" | |
], | |
"tileSize": 256 | |
} | |
}, | |
"layers": [{ | |
"id": "simple-tiles", | |
"type": "raster", | |
"source": "simple-tiles", | |
"minzoom": 0, | |
"maxzoom": 22 | |
}] | |
}, | |
center: [-74.50, 40], // starting position | |
zoom: 2 // starting zoom | |
}); | |
map.addControl(new mapboxgl.Navigation()); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I think that error is a false positive, I think you actually get another error and chrome says that error.