Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

getAllChildren #26

Closed
aaronlidman opened this issue Sep 14, 2015 · 4 comments
Closed

getAllChildren #26

aaronlidman opened this issue Sep 14, 2015 · 4 comments

Comments

@aaronlidman
Copy link

I need to invalidate a tile and get all the children below it that need to be regenerated.

I'm thinking something like this:

  • tilebelt.getAllChildren(tile, maxZoom)
  • tilebelt.getAllChildren([18, 24, 6], 14)
@morganherlocker
Copy link
Contributor

I think this would do the same thing as this proposal: #19

@aaronlidman
Copy link
Author

I believe the idea behind tilesToZoom was to get the final zoom level of all the children, not the entire pyramid. I started trying to adapt tilesToZoom to do this but found it depends on turf, so I'm trying a different approach. I think we can get a working tilesToZoom out of that as well.

If I don't lose my mind in recursion that is.

@morganherlocker
Copy link
Contributor

was to get the final zoom level of all the children, not the entire pyramid

Ah, that's right. I think the same method should work. We should probably have a note about performance in the docs on this. Performance and memory use can quickly get out of hand with a tile pyramid.

@aaronlidman
Copy link
Author

var tilebelt = require('tilebelt');

function getAllChildren(tile, maxZoom) {
    if (tile[2] >= maxZoom) return [tile];
    var zoomDiff = maxZoom - tile[2];
    var allChildren = [];
    theChildren(tile);
    return allChildren;

    function theChildren(tile) {
        var children = tilebelt.getChildren(tile);
        allChildren = allChildren.concat(children);
        if (children[0][2] === maxZoom) return;
        children.forEach(theChildren);
    }
}

console.log(getAllChildren([18,24,6], 14));

Here's what I did, it works and I'm using it in a project but it's probably not performant enough to include in tilebelt.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants