Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
language: node_js
node_js:
- '0.10'
- '0.12'
- '4.2.3'
addons:
apt:
sources:
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
# Changelog


## 3.9.2

- Add `EMAPNIK` error code to errors returned from `source.profile()`

## 3.9.1

- Updated to use tilelieve `~5.12.0`
Expand Down
1 change: 0 additions & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ os: Visual Studio 2015
environment:
matrix:
- nodejs_version: 0.10.40
- nodejs_version: 0.12.7
MapboxAccessToken:
secure: 01rO70zKIKzh2l8htHugNS3cCk9u3LfTu2SXojFaYkveumhZRDgRrH/BroS+fIv8T6YB5l0P2nvKAjqhdDW2yuaLWGIB5KdBmhywp4dXa0g=
AWS_ACCESS_KEY_ID:
Expand Down
41 changes: 33 additions & 8 deletions backend.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ var crypto = require('crypto');
var mapnik = require('mapnik');
var util = require('util');
var sm = new (require('sphericalmercator'))();
var queue = require('d3-queue');

module.exports = Backend;

Expand Down Expand Up @@ -75,7 +76,7 @@ Backend.prototype.getTile = function(z, x, y, callback) {

var size = 0;
var headers = {};
var lookbacks = 0;
var lookbacks = true;

// Overzooming support.
if (bz > backend._maxzoom) {
Expand All @@ -85,6 +86,20 @@ Backend.prototype.getTile = function(z, x, y, callback) {
headers['x-vector-backend-object'] = 'overzoom';
}

function loadAsync(lz, lx, ly, callback) {
source.getTile(lz, lx, ly, function (err, body, head) {
if (err && err.message !== 'Tile does not exist') return callback(err);
return callback(null, {
err: err,
body: body,
head: head,
z: lz,
x: lx,
y: ly
});
});
}

source.getTile(bz, bx, by, function sourceGet(err, body, head) {
if (typeof backend._fillzoom === 'number' &&
err && err.message === 'Tile does not exist' &&
Expand All @@ -96,13 +111,23 @@ Backend.prototype.getTile = function(z, x, y, callback) {
return source.getTile(bz, bx, by, sourceGet);
} else if (typeof backend._lookback === 'number' &&
err && err.message === 'Tile does not exist' &&
lookbacks <= backend._lookback) {
lookbacks += 1
bz = bz - 1;
bx = Math.floor(x / Math.pow(2, z - bz));
by = Math.floor(y / Math.pow(2, z - bz));
headers['x-vector-backend-object'] = 'fillzoom';
return source.getTile(bz, bx, by, sourceGet);
lookbacks === true) {
lookbacks = false;
var q = new queue.queue();
for (var lb = 1; lb <= Math.min(backend._lookback, z); lb++) {
q.defer(loadAsync, bz - lb, Math.floor(x / Math.pow(2, lb)), Math.floor(y / Math.pow(2, lb)));
}
return q.awaitAll(function(err, data) {
if (err) return callback(err);
data = data.filter(function(d, i) {
return d === null || i === data.length - 1;
});
headers['x-vector-backend-object'] = 'fillzoom';
bz = data[0].z;
bx = data[0].x;
by = data[0].y;
sourceGet(data[0].err, data[0].body, data[0].head);
});
}
if (err && err.message !== 'Tile does not exist') return callback(err);

Expand Down
5 changes: 4 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,10 @@ Vector.prototype.profile = function(callback) {
if (queue.length) {
var t = queue.shift();
s.getTile(t.z, t.x, t.y, function(err, run1, headers) {
if (err) return callback(err);
if (err) {
err.code = 'EMAPNIK';
return callback(err);
}
s.getTile(t.z, t.x, t.y, function(err, run2, headers) {
if (err) return callback(err);
t.drawtime = Math.min(run1._drawtime, run2._drawtime);
Expand Down
7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "tilelive-vector",
"version": "3.9.1",
"version": "3.9.2",
"main": "./index.js",
"description": "Vector tile => raster tile backend for tilelive",
"repository": {
Expand All @@ -14,14 +14,15 @@
],
"dependencies": {
"aws-sdk": "^2.2.30",
"d3-queue": "^2.0.3",
"s3urls": "^1.3.0",
"mapnik": "~3.5.0",
"mapnik": "~3.5.8",
"tilelive": "~5.12.0",
"tiletype": "0.3.x",
"tar": "~2.2.1",
"request": "~2.65.0",
"numeral": "~1.5.3",
"sphericalmercator": "~1.0.2",
"sphericalmercator": "~1.0.5",
"spherical": "~0.1.0",
"underscore": "~1.8.0"
},
Expand Down
2 changes: 1 addition & 1 deletion test/expected/backend-l.2.0.0.json

Large diffs are not rendered by default.

Binary file modified test/expected/l.2.0.0.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test/expected/l.2.3.3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added test/expected/l.3.1.1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added test/fixtures/tm2z/invalid.tm2z
Binary file not shown.
2 changes: 1 addition & 1 deletion test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ var tests = {
// Image sources.
'i@2x': ['0.0.0', '1.0.0'],
// Image sources for multiple lookback
l: ['0.0.0', '1.0.0', '1.1.1', '2.0.0', '2.3.3'],
l: ['0.0.0', '1.0.0', '1.1.1', '2.0.0', '2.3.3', '3.1.1'],
// Invalid tiles that are empty
invalid: ['1.1.0', '1.1.1'],

Expand Down
29 changes: 25 additions & 4 deletions test/tm2z.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,14 @@ Vector.mapnik.register_fonts(path.join(__dirname, 'fonts', 'source-sans-pro'));
});
});

test('tm2z+http ENOTFOUND', function(assert) {
test('tm2z+http ENOTFOUND or Z_DATA_ERROR', function(assert) {
tilelive.load('tm2z+http://not-a-valid-domain/patternstyle.tm2z', function(err, source) {
assert.ok(err, 'has error');
assert.equal(err.code, 'ENOTFOUND', 'code: ENOTFOUND');
if (err.code && err.code === 'Z_DATA_ERROR') {
assert.equal(err.code, 'Z_DATA_ERROR', 'code: Z_DATA_ERROR');
} else {
assert.equal(err.code, 'ENOTFOUND', 'code: ENOTFOUND');
}
assert.end();
});
});
Expand Down Expand Up @@ -175,7 +179,7 @@ test('errors out if unzipped project.xml size exceeds custom max size', function
});
test('errors out if not a directory', function(t) {
tilelive.load('tm2z://' + path.join(fixtureDir, 'nodirectory.tm2z'), function(err, source) {
t.equal(err.message.split(',')[0], 'EISDIR');
t.ok(err.message.indexOf('EISDIR') !== -1);
t.end();
});
});
Expand Down Expand Up @@ -240,12 +244,29 @@ test('profiles a tm2z file', function(t) {
t.deepEqual(['avg','min','max'], Object.keys(profile.loadtime));
t.deepEqual(['avg','min','max'], Object.keys(profile.srcbytes));
t.deepEqual(['avg','min','max'], Object.keys(profile.imgbytes));
var expected_tiles = [ '0/0/0', '1/1/0', '2/2/1', '3/4/3', '4/9/6', '5/19/12', '6/39/24', '7/79/48', '8/159/96', '9/319/193', '10/638/387', '11/1276/774', '12/2553/1548', '13/5107/3096', '14/10214/6193', '15/20428/12386', '16/40856/24772', '17/81713/49544', '18/163427/99088', '19/326855/198177', '20/653710/396354', '21/1307421/792709', '22/2614842/1585418' ];
var expected_tiles = [ '0/0/0', '1/1/0', '2/2/1', '3/4/3', '4/9/6', '5/19/12', '6/39/24', '7/79/48', '8/159/96', '9/319/193', '10/638/387', '11/1276/774', '12/2553/1548', '13/5107/3096', '14/10214/6192', '15/20429/12384', '16/40859/24769', '17/81719/49538', '18/163439/99076', '19/326879/198152', '20/653759/396305', '21/1307519/792610', '22/2615038/1585221' ];
t.deepEqual(profile.tiles.map(function(t) { return t.z + '/' + t.x + '/' + t.y }),expected_tiles);
t.end();
});
});
});
test('profiles tm2z with very southern data', function(t) {
tilelive.load('tm2z://' + path.join(fixtureDir, 'invalid.tm2z'), function(err, source) {
t.ifError(err);
source.profile(function(err, profile) {
t.ifError(err);
t.deepEqual([
'tiles',
'xmltime',
'drawtime',
'loadtime',
'srcbytes',
'imgbytes'
], Object.keys(profile), 'produced correct fields of profile');
t.end();
});
});
});

test('loads a tm2z+http url', function(t) {
tilelive.load('tm2z+' + remotePath, function(err, source) {
Expand Down