Permalink
Browse files

Don't try to redownload grid data after a failed attempt. Changes the…

… API - will require updates to Google Maps and OpenLayers
  • Loading branch information...
1 parent f675073 commit 0cb32537ea87a7c210bf5328d9c5efd0c9afbbf9 @tmcw tmcw committed May 27, 2011
Showing with 71 additions and 65 deletions.
  1. +16 −15 build/wax.g.js
  2. +1 −1 build/wax.g.min.js
  3. +18 −16 build/wax.mm.js
  4. +1 −1 build/wax.mm.min.js
  5. +16 −15 build/wax.ol.js
  6. +1 −1 build/wax.ol.min.js
  7. +16 −15 control/lib/gridutil.js
  8. +2 −1 control/mm/interaction.js
View
@@ -211,7 +211,7 @@ wax.request = {
get: function(url, callback) {
// Cache hit.
if (this.cache[url]) {
- return callback(this.cache[url]);
+ return callback(this.cache[url][0], this.cache[url][1]);
// Cache miss.
} else {
this.promises[url] = this.promises[url] || [];
@@ -227,16 +227,16 @@ wax.request = {
jsonpCallback: 'callback',
success: function(data) {
that.locks[url] = false;
- that.cache[url] = data;
+ that.cache[url] = [null, data];
for (var i = 0; i < that.promises[url].length; i++) {
- that.promises[url][i](that.cache[url]);
+ that.promises[url][i](that.cache[url][0], that.cache[url][1]);
}
},
- error: function() {
+ error: function(err) {
that.locks[url] = false;
- that.cache[url] = null;
+ that.cache[url] = [err, null];
for (var i = 0; i < that.promises[url].length; i++) {
- that.promises[url][i](that.cache[url]);
+ that.promises[url][i](that.cache[url][0], that.cache[url][1]);
}
}
});
@@ -273,8 +273,8 @@ wax.GridInstance.prototype.getFeature = function(x, y, tile_element, options) {
var tileX = offset.left;
var tileY = offset.top;
- if (Math.floor((y - tileY) / this.tileRes) > 256 ||
- Math.floor((x - tileX) / this.tileRes) > 256) return;
+ if (Math.floor((y - tileY) / this.tileRes) > 256) return;
+ if (Math.floor((x - tileX) / this.tileRes) > 256) return;
var key = this.grid_tile.grid[
Math.floor((y - tileY) / this.tileRes)
@@ -309,11 +309,12 @@ wax.GridManager = function() {
// and gets grid data, and tries to avoid re-downloading either.
wax.GridManager.prototype.getGrid = function(url, callback) {
var that = this;
- that.getFormatter(that.formatterUrl(url), function(f) {
- if (!f) return callback(false);
+ that.getFormatter(that.formatterUrl(url), function(err, f) {
+ if (err || !f) return callback(err, null);
- wax.request.get(that.tileDataUrl(url), function(t) {
- callback(new wax.GridInstance(t, f));
+ wax.request.get(that.tileDataUrl(url), function(err, t) {
+ if (err) return callback(err, null);
+ callback(null, new wax.GridInstance(t, f));
});
});
};
@@ -343,16 +344,16 @@ wax.GridManager.prototype.getFormatter = function(url, callback) {
var that = this;
// Formatter is cached.
if (typeof this.formatters[url] !== 'undefined') {
- callback(this.formatters[url]);
+ callback(null, this.formatters[url]);
return;
} else {
- wax.request.get(url, function(data) {
+ wax.request.get(url, function(err, data) {
if (data && data.formatter) {
that.formatters[url] = new wax.Formatter(data);
} else {
that.formatters[url] = false;
}
- callback(that.formatters[url]);
+ callback(err, that.formatters[url]);
});
}
};
View
View
@@ -217,7 +217,7 @@ wax.request = {
get: function(url, callback) {
// Cache hit.
if (this.cache[url]) {
- return callback(this.cache[url]);
+ return callback(this.cache[url][0], this.cache[url][1]);
// Cache miss.
} else {
this.promises[url] = this.promises[url] || [];
@@ -233,16 +233,16 @@ wax.request = {
jsonpCallback: 'callback',
success: function(data) {
that.locks[url] = false;
- that.cache[url] = data;
+ that.cache[url] = [null, data];
for (var i = 0; i < that.promises[url].length; i++) {
- that.promises[url][i](that.cache[url]);
+ that.promises[url][i](that.cache[url][0], that.cache[url][1]);
}
},
- error: function() {
+ error: function(err) {
that.locks[url] = false;
- that.cache[url] = null;
+ that.cache[url] = [err, null];
for (var i = 0; i < that.promises[url].length; i++) {
- that.promises[url][i](that.cache[url]);
+ that.promises[url][i](that.cache[url][0], that.cache[url][1]);
}
}
});
@@ -279,8 +279,8 @@ wax.GridInstance.prototype.getFeature = function(x, y, tile_element, options) {
var tileX = offset.left;
var tileY = offset.top;
- if (Math.floor((y - tileY) / this.tileRes) > 256 ||
- Math.floor((x - tileX) / this.tileRes) > 256) return;
+ if (Math.floor((y - tileY) / this.tileRes) > 256) return;
+ if (Math.floor((x - tileX) / this.tileRes) > 256) return;
var key = this.grid_tile.grid[
Math.floor((y - tileY) / this.tileRes)
@@ -315,11 +315,12 @@ wax.GridManager = function() {
// and gets grid data, and tries to avoid re-downloading either.
wax.GridManager.prototype.getGrid = function(url, callback) {
var that = this;
- that.getFormatter(that.formatterUrl(url), function(f) {
- if (!f) return callback(false);
+ that.getFormatter(that.formatterUrl(url), function(err, f) {
+ if (err || !f) return callback(err, null);
- wax.request.get(that.tileDataUrl(url), function(t) {
- callback(new wax.GridInstance(t, f));
+ wax.request.get(that.tileDataUrl(url), function(err, t) {
+ if (err) return callback(err, null);
+ callback(null, new wax.GridInstance(t, f));
});
});
};
@@ -349,16 +350,16 @@ wax.GridManager.prototype.getFormatter = function(url, callback) {
var that = this;
// Formatter is cached.
if (typeof this.formatters[url] !== 'undefined') {
- callback(this.formatters[url]);
+ callback(null, this.formatters[url]);
return;
} else {
- wax.request.get(url, function(data) {
+ wax.request.get(url, function(err, data) {
if (data && data.formatter) {
that.formatters[url] = new wax.Formatter(data);
} else {
that.formatters[url] = false;
}
- callback(that.formatters[url]);
+ callback(err, that.formatters[url]);
});
}
};
@@ -992,7 +993,8 @@ wax.interaction = function(map, options) {
if (!this._onMove) this._onMove = wax.util.bind(function(evt) {
var tile = this.getTile(evt);
if (tile) {
- this.waxGM.getGrid(tile.src, wax.util.bind(function(g) {
+ this.waxGM.getGrid(tile.src, wax.util.bind(function(err, g) {
+ if (err) return;
if (g) {
var feature = g.getFeature(evt.pageX, evt.pageY, tile, {
format: 'teaser'
View
View
@@ -211,7 +211,7 @@ wax.request = {
get: function(url, callback) {
// Cache hit.
if (this.cache[url]) {
- return callback(this.cache[url]);
+ return callback(this.cache[url][0], this.cache[url][1]);
// Cache miss.
} else {
this.promises[url] = this.promises[url] || [];
@@ -227,16 +227,16 @@ wax.request = {
jsonpCallback: 'callback',
success: function(data) {
that.locks[url] = false;
- that.cache[url] = data;
+ that.cache[url] = [null, data];
for (var i = 0; i < that.promises[url].length; i++) {
- that.promises[url][i](that.cache[url]);
+ that.promises[url][i](that.cache[url][0], that.cache[url][1]);
}
},
- error: function() {
+ error: function(err) {
that.locks[url] = false;
- that.cache[url] = null;
+ that.cache[url] = [err, null];
for (var i = 0; i < that.promises[url].length; i++) {
- that.promises[url][i](that.cache[url]);
+ that.promises[url][i](that.cache[url][0], that.cache[url][1]);
}
}
});
@@ -273,8 +273,8 @@ wax.GridInstance.prototype.getFeature = function(x, y, tile_element, options) {
var tileX = offset.left;
var tileY = offset.top;
- if (Math.floor((y - tileY) / this.tileRes) > 256 ||
- Math.floor((x - tileX) / this.tileRes) > 256) return;
+ if (Math.floor((y - tileY) / this.tileRes) > 256) return;
+ if (Math.floor((x - tileX) / this.tileRes) > 256) return;
var key = this.grid_tile.grid[
Math.floor((y - tileY) / this.tileRes)
@@ -309,11 +309,12 @@ wax.GridManager = function() {
// and gets grid data, and tries to avoid re-downloading either.
wax.GridManager.prototype.getGrid = function(url, callback) {
var that = this;
- that.getFormatter(that.formatterUrl(url), function(f) {
- if (!f) return callback(false);
+ that.getFormatter(that.formatterUrl(url), function(err, f) {
+ if (err || !f) return callback(err, null);
- wax.request.get(that.tileDataUrl(url), function(t) {
- callback(new wax.GridInstance(t, f));
+ wax.request.get(that.tileDataUrl(url), function(err, t) {
+ if (err) return callback(err, null);
+ callback(null, new wax.GridInstance(t, f));
});
});
};
@@ -343,16 +344,16 @@ wax.GridManager.prototype.getFormatter = function(url, callback) {
var that = this;
// Formatter is cached.
if (typeof this.formatters[url] !== 'undefined') {
- callback(this.formatters[url]);
+ callback(null, this.formatters[url]);
return;
} else {
- wax.request.get(url, function(data) {
+ wax.request.get(url, function(err, data) {
if (data && data.formatter) {
that.formatters[url] = new wax.Formatter(data);
} else {
that.formatters[url] = false;
}
- callback(that.formatters[url]);
+ callback(err, that.formatters[url]);
});
}
};
Oops, something went wrong. Retry.

0 comments on commit 0cb3253

Please sign in to comment.