Skip to content

Instantly share code, notes, and snippets.

@ricroberts
Created September 28, 2011 12:42
Show Gist options
  • Save ricroberts/1247835 to your computer and use it in GitHub Desktop.
Save ricroberts/1247835 to your computer and use it in GitHub Desktop.
getBoundaryData
// private functions
// ...
var getBoundaryData = function(tiles) {
var noOfTiles = tiles.length;
// nothing to do.
if(noOfTiles == 0) {
$(self).trigger('boundaryDataRetrieved');
}
var tilesRetrieved = 0;
$.each(tiles, function(idx, tile) {
var lat = tile[0][0].toString();
var lng = tile[0][1].toString();
$.ajax(
'http://opendatacommunities.org/lsoa_tiles/lat' + lat + '/long' + lng + '.json',
{
success: function(data, textStatus, jqXHR) {
for (var lsoaNotation in data) {
setBoundaryData(tile, lsoaNotation, data[lsoaNotation]);
}
tilesRetrieved+=1;
if (tilesRetrieved == tiles.length) {
// we've got all the boundaries.
$(self).trigger('boundaryDataRetrieved');
}
},
error: function(jqXHR, textStatus, errorThrown) {
window.swirrl.log("GET BOUNDARY TILE FAILURE: " + errorThrown);
$(self).trigger('dataError');
},
timeout: 10000,
dataType: 'json'
}
)
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment