Skip to content

Instantly share code, notes, and snippets.

@Scarysize
Created October 26, 2016 14:45
Show Gist options
  • Save Scarysize/a2ab9b59d191a28f88188b80cca983a6 to your computer and use it in GitHub Desktop.
Save Scarysize/a2ab9b59d191a28f88188b80cca983a6 to your computer and use it in GitHub Desktop.
import intersect from './intersect';
export default function createTileIntersect() {
let tileCache = {};
let lastBbox = null;
return (boundingBox, tile) => {
if (!boundingBox) {
return true;
}
// bbox changed => invalidate the tile-cache
if (
JSON.stringify(lastBbox) !==
JSON.stringify(boundingBox)
) {
lastBbox = boundingBox;
tileCache = {};
}
// cache look-up
if (tileCache[tile.uid]) {
// cache hit
return tileCache[tile.uid];
}
// cache miss
tileCache[tile.uid] = intersect(
tileToBounds(tile),
boundingBox
);
return tileCache[tile.uid];
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment