Skip to content
Closed
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
13 changes: 6 additions & 7 deletions lib/tilejson.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@ function TileJSON(uri, callback) {
else if (typeof uri.query === 'string') uri.query = qs.parse(uri.query);

if (!uri.pathname && !uri.data) {
callback(new Error('Invalid URI ' + url.format(uri)));
return;
return setImmediate(callback, new Error('Invalid URI ' + url.format(uri)));
}

if (uri.hostname === '.' || uri.hostname == '..') {
Expand Down Expand Up @@ -94,7 +93,7 @@ function TileJSON(uri, callback) {
}

TileJSON.prototype.close = function(callback) {
if (callback) callback(null);
if (callback) setImmediate(callback);
};

TileJSON.registerProtocols = function(tilelive) {
Expand Down Expand Up @@ -127,14 +126,14 @@ TileJSON.findID = function(filepath, id, callback) {
};

TileJSON.prototype.getInfo = function(callback) {
if (!this.data) callback(new Error('Tilesource not loaded'));
else callback(null, this.data);
if (!this.data) setImmediate(callback, new Error('Tilesource not loaded'));
else setImmediate(callback, null, this.data);
};

// z, x, y are XYZ coordinates.
TileJSON.prototype.getTile = function(z, x, y, callback) {
if (!this.data) return callback(new Error('Tilesource not loaded'));
if (!this.data.tiles) return callback(new Error('Tile does not exist'));
if (!this.data) return setImmediate(callback, new Error('Tilesource not loaded'));
if (!this.data.tiles) return setImmediate(callback, new Error('Tile does not exist'));

var url = this._prepareURL(this.data.tiles[0], z, x, y);
this.get(url, function(err, data, headers) {
Expand Down