mapbox / tile-cover

Generate the minimum number of tiles to cover a geojson geometry
MIT License
189 stars 40 forks source link

doesn't return parent tiles for linestring geometry #80

Closed jleppert closed 6 years ago

jleppert commented 6 years ago
var lineString = JSON.parse({"type":"LineString","coordinates":[[-108.26427566201939,36.75702521044819],[-108.26403464291892,36.757277943582835],[-108.26342500637065,36.757280783278546],[-108.2631946204629,36.756971256087695],[-108.26329031922049,36.75658789498523],[-108.26388932257603,36.75649986363004]]});

cover.tiles(lineString, { min_zoom: 17, max_zoom: 20 });
// --> [[208945,409022,20],[208945,409021,20],[208946,409021,20],[208947,409021,20],[208948,409021,20],[208948,409022,20],[208948,409023,20],[208947,409023,20],[208946,409023,20]]

// correct output should be:
[[208945,409022,20],[208945,409021,20],[208946,409021,20],[208947,409021,20],[208948,409021,20],[208948,409022,20],[208948,409023,20],[208947,409023,20],[208946,409023,20],[104472,204511,19],[104472,204510,19],[104473,204510,19],[104474,204510,19],[104474,204511,19],[104473,204511,19],[52236,102255,18],[52237,102255,18],[26118,51127,17]]

I started to debug this, and the problem is in https://github.com/mapbox/tile-cover/blob/master/index.js#L120. That condition never seems to pass so parent tiles are never traversed.

mourner commented 6 years ago

It will only return a parent tile if all 4 of its children cover the geometry, which is how it's intended to work. Is that the case in your example? It looks like it isn't.

jleppert commented 6 years ago

Ah okay, that makes sense. In my case I needed to get the minimum tiles for each zoom level.