Created
September 28, 2011 12:42
-
-
Save ricroberts/1247835 to your computer and use it in GitHub Desktop.
getBoundaryData
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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