Created
October 26, 2016 14:45
-
-
Save Scarysize/a2ab9b59d191a28f88188b80cca983a6 to your computer and use it in GitHub Desktop.
This file contains 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
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