This commit is contained in:
Niklas Hösl 2017-11-15 15:29:29 +00:00 committed by GitHub
commit ebc2ddaf55
5 changed files with 100 additions and 2 deletions

View file

@ -35,7 +35,10 @@ Static images
* e.g. ``5.9,45.8|5.9,47.8|10.5,47.8|10.5,45.8|5.9,45.8`` * e.g. ``5.9,45.8|5.9,47.8|10.5,47.8|10.5,45.8|5.9,45.8``
* ``latlng`` - indicates the ``path`` coordinates are in ``lat,lng`` order rather than the usual ``lng,lat`` * ``encodedpath`` - an alternative way to provide a path using Google's polyline encoding. Only used if ``path`` is not provided.
* more details: https://developers.google.com/maps/documentation/utilities/polylinealgorithm
* ``latlng`` - indicates the ``path`` coordinates are in ``lat,lng`` order rather than the usual ``lng,lat``. possible values: ``true`` or ``1``
* ``fill`` - color to use as the fill (e.g. ``red``, ``rgba(255,255,255,0.5)``, ``#0000ff``) * ``fill`` - color to use as the fill (e.g. ``red``, ``rgba(255,255,255,0.5)``, ``#0000ff``)
* ``stroke`` - color of the path stroke * ``stroke`` - color of the path stroke
* ``width`` - width of the stroke * ``width`` - width of the stroke

View file

@ -513,6 +513,11 @@ module.exports = function(options, repo, params, id, dataResolver) {
path.push(pair); path.push(pair);
} }
}); });
if(path.length==0){
path = utils.decodePolyline(query.encodedpath);
}
return path; return path;
}; };

View file

@ -16,7 +16,10 @@ module.exports = function(options, repo, params, id, reportTiles, reportFont) {
Object.keys(styleJSON.sources).forEach(function(name) { Object.keys(styleJSON.sources).forEach(function(name) {
var source = styleJSON.sources[name]; var source = styleJSON.sources[name];
var url = source.url; var url = source.url;
if (url && url.lastIndexOf('mbtiles:', 0) === 0) {
var validateUrl = source.validate_url !=undefined ? source.validate_url : true
if (url && url.lastIndexOf('mbtiles:', 0) === 0 && validateUrl) {
var mbtilesFile = url.substring('mbtiles://'.length); var mbtilesFile = url.substring('mbtiles://'.length);
var fromData = mbtilesFile[0] == '{' && var fromData = mbtilesFile[0] == '{' &&
mbtilesFile[mbtilesFile.length - 1] == '}'; mbtilesFile[mbtilesFile.length - 1] == '}';
@ -63,7 +66,22 @@ module.exports = function(options, repo, params, id, reportTiles, reportFont) {
repo[id] = styleJSON; repo[id] = styleJSON;
app.get('/' + id + '/style.json', function(req, res, next) { app.get('/' + id + '/style.json', function(req, res, next) {
var pattern = req.query.pattern
var value = req.query.value
console.log("## Pattern: "+pattern)
console.log("## Value: "+value)
var fixUrl = function(url, opt_nokey, opt_nostyle) { var fixUrl = function(url, opt_nokey, opt_nostyle) {
console.log("## Before if "+pattern)
if(pattern != null){
console.log("## Enter replace for "+url)
url = url.replace(pattern, value)
console.log("## Url: "+url)
}
if (!url || (typeof url !== 'string') || url.indexOf('local://') !== 0) { if (!url || (typeof url !== 'string') || url.indexOf('local://') !== 0) {
return url; return url;
} }
@ -78,6 +96,7 @@ module.exports = function(options, repo, params, id, reportTiles, reportFont) {
if (queryParams.length) { if (queryParams.length) {
query = '?' + queryParams.join('&'); query = '?' + queryParams.join('&');
} }
return url.replace( return url.replace(
'local://', req.protocol + '://' + req.headers.host + '/') + query; 'local://', req.protocol + '://' + req.headers.host + '/') + query;
}; };
@ -86,6 +105,7 @@ module.exports = function(options, repo, params, id, reportTiles, reportFont) {
Object.keys(styleJSON_.sources).forEach(function(name) { Object.keys(styleJSON_.sources).forEach(function(name) {
var source = styleJSON_.sources[name]; var source = styleJSON_.sources[name];
source.url = fixUrl(source.url); source.url = fixUrl(source.url);
console.log("final url: "+source.url)
}); });
// mapbox-gl-js viewer cannot handle sprite urls with query // mapbox-gl-js viewer cannot handle sprite urls with query
if (styleJSON_.sprite) { if (styleJSON_.sprite) {
@ -94,6 +114,8 @@ module.exports = function(options, repo, params, id, reportTiles, reportFont) {
if (styleJSON_.glyphs) { if (styleJSON_.glyphs) {
styleJSON_.glyphs = fixUrl(styleJSON_.glyphs, false, true); styleJSON_.glyphs = fixUrl(styleJSON_.glyphs, false, true);
} }
return res.send(styleJSON_); return res.send(styleJSON_);
}); });

View file

@ -185,6 +185,20 @@ function start(opts) {
); );
}); });
app.get('/new-user', function(req, res){
var userId = req.query.id;
var id = "heatmap-"+userId;
var item = {
mbtiles: "heatmap-"+userId+".mbtiles"
}
serve_data(options, serving.data, item, id, serving.styles).then(function(sub) {
console.log("# serve data")
app.use('/data/', sub);
res.send("ok")
});
});
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) : ''; var query = req.query.key ? ('?key=' + req.query.key) : '';

View file

@ -114,3 +114,57 @@ module.exports.getFontsPbf = function(allowedFonts, fontPath, names, range, fall
return glyphCompose.combine(values); return glyphCompose.combine(values);
}); });
}; };
// From: https://github.com/mapbox/polyline/blob/master/src/polyline.js
module.exports.decodePolyline = function(str, precision) {
var index = 0,
lat = 0,
lng = 0,
coordinates = [],
shift = 0,
result = 0,
byte = null,
latitude_change,
longitude_change,
factor = Math.pow(10, precision || 5);
if(str==null){
return [];
}
// Coordinates have variable length when encoded, so just keep
// track of whether we've hit the end of the string. In each
// loop iteration, a single coordinate is decoded.
while (index < str.length) {
// Reset shift, result, and byte
byte = null;
shift = 0;
result = 0;
do {
byte = str.charCodeAt(index++) - 63;
result |= (byte & 0x1f) << shift;
shift += 5;
} while (byte >= 0x20);
latitude_change = ((result & 1) ? ~(result >> 1) : (result >> 1));
shift = result = 0;
do {
byte = str.charCodeAt(index++) - 63;
result |= (byte & 0x1f) << shift;
shift += 5;
} while (byte >= 0x20);
longitude_change = ((result & 1) ? ~(result >> 1) : (result >> 1));
lat += latitude_change;
lng += longitude_change;
coordinates.push([lng / factor, lat / factor]);
}
return coordinates;
};