Cloak Mapbox access tokens
This commit is contained in:
@@ -7,6 +7,8 @@ docs: >
|
||||
tags: "simple, mapbox, vector, tiles"
|
||||
resources:
|
||||
- resources/mapbox-streets-v6-style.js
|
||||
cloak:
|
||||
pk.eyJ1IjoiYWhvY2V2YXIiLCJhIjoiRk1kMWZaSSJ9.E5BkluenyWQMsBLsuByrmg: Your Mapbox access token from http://mapbox.com/ here
|
||||
---
|
||||
<div class="row-fluid">
|
||||
<div class="span12">
|
||||
|
||||
@@ -11,9 +11,7 @@ goog.require('ol.style.Style');
|
||||
goog.require('ol.style.Text');
|
||||
|
||||
|
||||
// Mapbox access token - request your own at http://mapbox.com
|
||||
var accessToken =
|
||||
'pk.eyJ1IjoiYWhvY2V2YXIiLCJhIjoiRk1kMWZaSSJ9.E5BkluenyWQMsBLsuByrmg';
|
||||
var key = 'pk.eyJ1IjoiYWhvY2V2YXIiLCJhIjoiRk1kMWZaSSJ9.E5BkluenyWQMsBLsuByrmg';
|
||||
|
||||
var map = new ol.Map({
|
||||
layers: [
|
||||
@@ -28,7 +26,7 @@ var map = new ol.Map({
|
||||
tileGrid: ol.tilegrid.createXYZ({maxZoom: 22}),
|
||||
tilePixelRatio: 16,
|
||||
url: 'http://{a-d}.tiles.mapbox.com/v4/mapbox.mapbox-streets-v6/' +
|
||||
'{z}/{x}/{y}.vector.pbf?access_token=' + accessToken
|
||||
'{z}/{x}/{y}.vector.pbf?access_token=' + key
|
||||
}),
|
||||
style: createMapboxStreetsV6Style()
|
||||
})
|
||||
|
||||
@@ -3,10 +3,12 @@ template: example.html
|
||||
title: Mapbox vector tiles example
|
||||
shortdesc: Example of a Mapbox vector tiles map.
|
||||
docs: >
|
||||
A vector tiles map which reuses the same tiles for subsequent zoom levels to save bandwith on mobile devices. **Note**: Make sure to get your own Mapbox API key when using this example. No map will be visible when the API key has expired.
|
||||
A vector tiles map which reuses the same tiles for subsequent zoom levels to save bandwith on mobile devices. **Note**: No map will be visible when the access token has expired.
|
||||
tags: "simple, mapbox, vector, tiles"
|
||||
resources:
|
||||
- resources/mapbox-streets-v6-style.js
|
||||
cloak:
|
||||
pk.eyJ1IjoiYWhvY2V2YXIiLCJhIjoiRk1kMWZaSSJ9.E5BkluenyWQMsBLsuByrmg: Your Mapbox access token from http://mapbox.com/ here
|
||||
---
|
||||
<div class="row-fluid">
|
||||
<div class="span12">
|
||||
|
||||
@@ -13,9 +13,7 @@ goog.require('ol.style.Text');
|
||||
goog.require('ol.tilegrid.TileGrid');
|
||||
|
||||
|
||||
// Mapbox access token - request your own at http://mapbox.com
|
||||
var accessToken =
|
||||
'pk.eyJ1IjoiYWhvY2V2YXIiLCJhIjoiRk1kMWZaSSJ9.E5BkluenyWQMsBLsuByrmg';
|
||||
var key = 'pk.eyJ1IjoiYWhvY2V2YXIiLCJhIjoiRk1kMWZaSSJ9.E5BkluenyWQMsBLsuByrmg';
|
||||
|
||||
// For how many zoom levels do we want to use the same vector tiles?
|
||||
// 1 means "use tiles from all zoom levels". 2 means "use the same tiles for 2
|
||||
@@ -34,7 +32,7 @@ for (var z = zoomOffset / reuseZoomLevels; z <= 22 / reuseZoomLevels; ++z) {
|
||||
}
|
||||
function tileUrlFunction(tileCoord) {
|
||||
return ('http://{a-d}.tiles.mapbox.com/v4/mapbox.mapbox-streets-v6/' +
|
||||
'{z}/{x}/{y}.vector.pbf?access_token=' + accessToken)
|
||||
'{z}/{x}/{y}.vector.pbf?access_token=' + key)
|
||||
.replace('{z}', String(tileCoord[0] * reuseZoomLevels + zoomOffset))
|
||||
.replace('{x}', String(tileCoord[1]))
|
||||
.replace('{y}', String(-tileCoord[2] - 1))
|
||||
|
||||
Reference in New Issue
Block a user