If key
present in query, propagate it to other linked urls
This commit is contained in:
parent
2d5dccc1e0
commit
1d4503b507
5 changed files with 37 additions and 28 deletions
|
@ -4,8 +4,8 @@
|
||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8">
|
||||||
<title>{{name}} - TileServer GL</title>
|
<title>{{name}} - TileServer GL</title>
|
||||||
{{#is_vector}}
|
{{#is_vector}}
|
||||||
<link rel="stylesheet" type="text/css" href="/mapbox-gl.css" />
|
<link rel="stylesheet" type="text/css" href="/mapbox-gl.css{{&access_key_query}}" />
|
||||||
<script src="/mapbox-gl.js"></script>
|
<script src="/mapbox-gl.js{{&access_key_query}}"></script>
|
||||||
<style>
|
<style>
|
||||||
body {background:#000;color:#ccc;}
|
body {background:#000;color:#ccc;}
|
||||||
#map {position:absolute;top:0;left:0;right:250px;bottom:0;}
|
#map {position:absolute;top:0;left:0;right:250px;bottom:0;}
|
||||||
|
@ -16,9 +16,9 @@
|
||||||
</style>
|
</style>
|
||||||
{{/is_vector}}
|
{{/is_vector}}
|
||||||
{{^is_vector}}
|
{{^is_vector}}
|
||||||
<link rel="stylesheet" type="text/css" href="/mapbox.css" />
|
<link rel="stylesheet" type="text/css" href="/mapbox.css{{&access_key_query}}" />
|
||||||
<script src="/mapbox.js"></script>
|
<script src="/mapbox.js{{&access_key_query}}"></script>
|
||||||
<script src="/leaflet-hash.js"></script>
|
<script src="/leaflet-hash.js{{&access_key_query}}"></script>
|
||||||
<style>
|
<style>
|
||||||
body { margin:0; padding:0; }
|
body { margin:0; padding:0; }
|
||||||
#map { position:absolute; top:0; bottom:0; width:100%; }
|
#map { position:absolute; top:0; bottom:0; width:100%; }
|
||||||
|
@ -97,7 +97,7 @@
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
xhttp.responseType = 'json';
|
xhttp.responseType = 'json';
|
||||||
xhttp.open('GET', '/data/{{id}}.json', true);
|
xhttp.open('GET', '/data/{{id}}.json{{&access_key_query}}', true);
|
||||||
xhttp.send();
|
xhttp.send();
|
||||||
|
|
||||||
var propertyList = document.getElementById('propertyList');
|
var propertyList = document.getElementById('propertyList');
|
||||||
|
@ -116,7 +116,7 @@
|
||||||
<h1 style="display:none;">{{name}}</h1>
|
<h1 style="display:none;">{{name}}</h1>
|
||||||
<div id='map'></div>
|
<div id='map'></div>
|
||||||
<script>
|
<script>
|
||||||
var map = L.mapbox.map('map', '/data/{{id}}.json', { zoomControl: false });
|
var map = L.mapbox.map('map', '/data/{{id}}.json{{&access_key_query}}', { zoomControl: false });
|
||||||
new L.Control.Zoom({ position: 'topright' }).addTo(map);
|
new L.Control.Zoom({ position: 'topright' }).addTo(map);
|
||||||
setTimeout(function() {
|
setTimeout(function() {
|
||||||
new L.Hash(map);
|
new L.Hash(map);
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
<head>
|
<head>
|
||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8">
|
||||||
<title>TileServerGL</title>
|
<title>TileServerGL</title>
|
||||||
<link rel="stylesheet" type="text/css" href="/index.css" />
|
<link rel="stylesheet" type="text/css" href="/index.css{{&access_key_query}}" />
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<section>
|
<section>
|
||||||
|
@ -13,25 +13,25 @@
|
||||||
{{#each styles}}
|
{{#each styles}}
|
||||||
<div class="item">
|
<div class="item">
|
||||||
{{#if thumbnail}}
|
{{#if thumbnail}}
|
||||||
<img src="/styles/{{@key}}/rendered/{{thumbnail}}" alt="{{name}} preview" />
|
<img src="/styles/{{@key}}/rendered/{{thumbnail}}{{&../access_key_query}}" alt="{{name}} preview" />
|
||||||
{{else}}
|
{{else}}
|
||||||
<div class="sample-img"></div>
|
<div class="sample-img"></div>
|
||||||
{{/if}}
|
{{/if}}
|
||||||
<h3>{{name}}</h3>
|
<h3>{{name}}</h3>
|
||||||
<p>Id: {{@key}}
|
<p>Id: {{@key}}
|
||||||
{{#if serving_rendered}}
|
{{#if serving_rendered}}
|
||||||
| <a href="/styles/{{@key}}/rendered.json">TileJSON</a>
|
| <a href="/styles/{{@key}}/rendered.json{{&../access_key_query}}">TileJSON</a>
|
||||||
{{/if}}
|
{{/if}}
|
||||||
</p>
|
</p>
|
||||||
{{#if serving_data}}
|
{{#if serving_data}}
|
||||||
<a class="btn" href="/styles/{{@key}}/?vector{{viewer_hash}}">Vector view</a>
|
<a class="btn" href="/styles/{{@key}}/?key={{&../access_key}}&vector{{viewer_hash}}">Vector view</a>
|
||||||
{{/if}}
|
{{/if}}
|
||||||
{{#if serving_rendered}}
|
{{#if serving_rendered}}
|
||||||
<a class="btn" href="/styles/{{@key}}/?raster{{viewer_hash}}">Raster view</a>
|
<a class="btn" href="/styles/{{@key}}/?key={{&../access_key}}&raster{{viewer_hash}}">Raster view</a>
|
||||||
{{/if}}
|
{{/if}}
|
||||||
{{#if serving_data}}
|
{{#if serving_data}}
|
||||||
{{#if serving_rendered}}
|
{{#if serving_rendered}}
|
||||||
<a class="btn" href="/styles/{{@key}}/{{viewer_hash}}">Auto view</a>
|
<a class="btn" href="/styles/{{@key}}/{{&../access_key_query}}{{viewer_hash}}">Auto view</a>
|
||||||
{{/if}}
|
{{/if}}
|
||||||
{{/if}}
|
{{/if}}
|
||||||
</div>
|
</div>
|
||||||
|
@ -42,17 +42,17 @@
|
||||||
{{#each data}}
|
{{#each data}}
|
||||||
<div class="item">
|
<div class="item">
|
||||||
{{#if thumbnail}}
|
{{#if thumbnail}}
|
||||||
<img src="/data/{{@key}}/{{thumbnail}}" alt="{{name}} preview" />
|
<img src="/data/{{@key}}/{{thumbnail}}{{&../access_key_query}}" alt="{{name}} preview" />
|
||||||
{{else}}
|
{{else}}
|
||||||
<div class="sample-img"></div>
|
<div class="sample-img"></div>
|
||||||
{{/if}}
|
{{/if}}
|
||||||
<h3>{{name}}</h3>
|
<h3>{{name}}</h3>
|
||||||
<p>Id: {{@key}} |{{#if formatted_filesize}} {{formatted_filesize}} |{{/if}} {{#is_vector}}Vector{{/is_vector}}{{^is_vector}}Raster{{/is_vector}} data | <a href="/data/{{@key}}.json">TileJSON</a></p>
|
<p>Id: {{@key}} |{{#if formatted_filesize}} {{formatted_filesize}} |{{/if}} {{#is_vector}}Vector{{/is_vector}}{{^is_vector}}Raster{{/is_vector}} data | <a href="/data/{{@key}}.json{{&../access_key_query}}">TileJSON</a></p>
|
||||||
{{#is_vector}}
|
{{#is_vector}}
|
||||||
<a class="btn" href="/data/{{@key}}/{{viewer_hash}}">X-Ray view</a>
|
<a class="btn" href="/data/{{@key}}/{{&../access_key_query}}{{viewer_hash}}">X-Ray view</a>
|
||||||
{{/is_vector}}
|
{{/is_vector}}
|
||||||
{{^is_vector}}
|
{{^is_vector}}
|
||||||
<a class="btn" href="/data/{{@key}}/{{viewer_hash}}">Raster view</a>
|
<a class="btn" href="/data/{{@key}}/{{&../access_key_query}}{{viewer_hash}}">Raster view</a>
|
||||||
{{/is_vector}}
|
{{/is_vector}}
|
||||||
</div>
|
</div>
|
||||||
{{/each}}
|
{{/each}}
|
||||||
|
|
|
@ -3,11 +3,11 @@
|
||||||
<head>
|
<head>
|
||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8">
|
||||||
<title>{{name}} - TileServer GL</title>
|
<title>{{name}} - TileServer GL</title>
|
||||||
<link rel="stylesheet" type="text/css" href="/mapbox-gl.css" />
|
<link rel="stylesheet" type="text/css" href="/mapbox-gl.css{{&access_key_query}}" />
|
||||||
<script src="/mapbox-gl.js"></script>
|
<script src="/mapbox-gl.js{{&access_key_query}}"></script>
|
||||||
<link rel="stylesheet" type="text/css" href="/mapbox.css" />
|
<link rel="stylesheet" type="text/css" href="/mapbox.css{{&access_key_query}}" />
|
||||||
<script src="/mapbox.js"></script>
|
<script src="/mapbox.js{{&access_key_query}}"></script>
|
||||||
<script src="/leaflet-hash.js"></script>
|
<script src="/leaflet-hash.js{{&access_key_query}}"></script>
|
||||||
<style>
|
<style>
|
||||||
body { margin:0; padding:0; }
|
body { margin:0; padding:0; }
|
||||||
#map { position:absolute; top:0; bottom:0; width:100%; }
|
#map { position:absolute; top:0; bottom:0; width:100%; }
|
||||||
|
@ -24,12 +24,12 @@
|
||||||
if (preference == 'vector') {
|
if (preference == 'vector') {
|
||||||
var map = new mapboxgl.Map({
|
var map = new mapboxgl.Map({
|
||||||
container: 'map',
|
container: 'map',
|
||||||
style: '/styles/{{id}}.json',
|
style: '/styles/{{id}}.json{{&access_key_query}}',
|
||||||
hash: true
|
hash: true
|
||||||
});
|
});
|
||||||
map.addControl(new mapboxgl.Navigation());
|
map.addControl(new mapboxgl.Navigation());
|
||||||
} else {
|
} else {
|
||||||
var map = L.mapbox.map('map', '/styles/{{id}}/rendered.json', { zoomControl: false });
|
var map = L.mapbox.map('map', '/styles/{{id}}/rendered.json{{&access_key_query}}', { zoomControl: false });
|
||||||
new L.Control.Zoom({ position: 'topright' }).addTo(map);
|
new L.Control.Zoom({ position: 'topright' }).addTo(map);
|
||||||
setTimeout(function() {
|
setTimeout(function() {
|
||||||
new L.Hash(map);
|
new L.Hash(map);
|
||||||
|
|
|
@ -46,9 +46,13 @@ module.exports = function(options, repo, params, id, reportTiles, reportFont) {
|
||||||
repo[id] = styleJSON;
|
repo[id] = styleJSON;
|
||||||
|
|
||||||
app.get('/' + id + '.json', function(req, res, next) {
|
app.get('/' + id + '.json', function(req, res, next) {
|
||||||
var fixUrl = function(url) {
|
var fixUrl = function(url, opt_nokey) {
|
||||||
|
var query = '';
|
||||||
|
if (!opt_nokey && req.query.key) {
|
||||||
|
query = '?key=' + req.query.key;
|
||||||
|
}
|
||||||
return url.replace(
|
return url.replace(
|
||||||
'local://', req.protocol + '://' + req.headers.host + '/');
|
'local://', req.protocol + '://' + req.headers.host + '/') + query;
|
||||||
};
|
};
|
||||||
|
|
||||||
var styleJSON_ = clone(styleJSON);
|
var styleJSON_ = clone(styleJSON);
|
||||||
|
@ -56,7 +60,8 @@ module.exports = function(options, repo, params, id, reportTiles, reportFont) {
|
||||||
var source = styleJSON_.sources[name];
|
var source = styleJSON_.sources[name];
|
||||||
source.url = fixUrl(source.url);
|
source.url = fixUrl(source.url);
|
||||||
});
|
});
|
||||||
styleJSON_.sprite = fixUrl(styleJSON_.sprite);
|
// mapbox-gl-js viewer cannot handle sprite urls with query
|
||||||
|
styleJSON_.sprite = fixUrl(styleJSON_.sprite, true);
|
||||||
styleJSON_.glyphs = fixUrl(styleJSON_.glyphs);
|
styleJSON_.glyphs = fixUrl(styleJSON_.glyphs);
|
||||||
return res.send(styleJSON_);
|
return res.send(styleJSON_);
|
||||||
});
|
});
|
||||||
|
|
|
@ -118,13 +118,15 @@ module.exports = function(opts, callback) {
|
||||||
|
|
||||||
app.get('/styles.json', function(req, res, next) {
|
app.get('/styles.json', function(req, res, next) {
|
||||||
var result = [];
|
var result = [];
|
||||||
|
var query = req.query.key ? ('?key=' + req.query.key) : '';
|
||||||
Object.keys(serving.styles).forEach(function(id) {
|
Object.keys(serving.styles).forEach(function(id) {
|
||||||
var styleJSON = serving.styles[id];
|
var styleJSON = serving.styles[id];
|
||||||
result.push({
|
result.push({
|
||||||
version: styleJSON.version,
|
version: styleJSON.version,
|
||||||
name: styleJSON.name,
|
name: styleJSON.name,
|
||||||
id: id,
|
id: id,
|
||||||
url: req.protocol + '://' + req.headers.host + '/styles/' + id + '.json'
|
url: req.protocol + '://' + req.headers.host +
|
||||||
|
'/styles/' + id + '.json' + query
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
res.send(result);
|
res.send(result);
|
||||||
|
@ -170,6 +172,8 @@ module.exports = function(opts, callback) {
|
||||||
return res.status(404).send('Not found');
|
return res.status(404).send('Not found');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
data['access_key'] = req.query.key;
|
||||||
|
data['access_key_query'] = req.query.key ? '?key=' + req.query.key : '';
|
||||||
return res.status(200).send(compiled(data));
|
return res.status(200).send(compiled(data));
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue