Skip to content

Commit

Permalink
Fetch all tiles within bounding box of user's location
Browse files Browse the repository at this point in the history
  • Loading branch information
steinbro committed Dec 10, 2023
1 parent 93a009b commit 6ce20f2
Showing 1 changed file with 13 additions and 12 deletions.
25 changes: 13 additions & 12 deletions app/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,20 @@ function vocalize(latitude, longitude) {
const tiles = enumerateTilesInBoundingBox(boundingBox, zoomLevel, zoomLevel);
//console.log('Mercator Tiles:', tiles);

// Pick one tile to fetch
const tile = tiles[0];
const urlToFetch = `${config.tileServer}/${tile.z}/${tile.x}/${tile.y}.json`;
fetchUrlIfNotCached(urlToFetch, maxAge)
.then((data) => {
data.features.forEach(feature => {
addToCache(feature);
// Populate any missing map tiles (without blocking)
for (const tile of tiles) {
const urlToFetch = `${config.tileServer}/${tile.z}/${tile.x}/${tile.y}.json`;
fetchUrlIfNotCached(urlToFetch, maxAge)
.then((data) => {
for (const feature of data.features) {
addToCache(feature);
};
console.log(`Loaded ${data.features.length} new features.`)
})
})
.catch((error) => {
console.error(error);
});

.catch((error) => {
console.error(error);
});
}
/*
const myLocation = {
type: 'Point',
Expand Down

0 comments on commit 6ce20f2

Please sign in to comment.