Skip to content

Commit

Permalink
Merge pull request #78 from fxjung/master
Browse files Browse the repository at this point in the history
Fix zoom level argument of mercantile.tiles()
  • Loading branch information
sgillies authored May 17, 2018
2 parents a78ea3b + 31564eb commit c97a28b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
4 changes: 4 additions & 0 deletions mercantile/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""Web mercator XYZ tile utilities"""

from collections import namedtuple
from collections import Sequence
import math


Expand Down Expand Up @@ -314,6 +315,9 @@ def tiles(west, south, east, north, zooms, truncate=False):
e = min(180.0, e)
n = min(85.051129, n)

if not isinstance(zooms, Sequence):
zooms = [zooms]

for z in zooms:
ll = tile(w, s, z)
ur = tile(e, n, z)
Expand Down
8 changes: 8 additions & 0 deletions tests/test_funcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,14 @@ def test_tiles():
assert sorted(tiles) == sorted(expect)


def test_tiles_single_zoom():
bounds = (-105, 39.99, -104.99, 40)
tiles = list(mercantile.tiles(*bounds, zooms=14))
expect = [mercantile.Tile(x=3413, y=6202, z=14),
mercantile.Tile(x=3413, y=6203, z=14)]
assert sorted(tiles) == sorted(expect)


def test_tiles_truncate():
"""Input is truncated"""
assert list(mercantile.tiles(-181.0, 0.0, -170.0, 10.0, zooms=[2], truncate=True)) \
Expand Down

0 comments on commit c97a28b

Please sign in to comment.