Skip to content

Commit

Permalink
Merge pull request #31 from zerebubuth/zerebubuth/zoom-0-meta-and-offset
Browse files Browse the repository at this point in the history
Zoom zero tile substitution
  • Loading branch information
zerebubuth authored Jul 5, 2018
2 parents adc804f + f1df8d9 commit c45f745
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 10 deletions.
21 changes: 11 additions & 10 deletions server.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import hashlib
import logging
import math
import sys
import time
import zipfile
from collections import namedtuple
Expand Down Expand Up @@ -50,8 +49,6 @@ def setup_logging():
StorageResponse = namedtuple('StorageResponse', ['data', 'cache_info'])




class MetatileNotModifiedException(Exception):
pass

Expand Down Expand Up @@ -93,9 +90,11 @@ def meta_and_offset(requested_tile, meta_size, tile_size,

delta_z = int(meta_zoom - tile_zoom)

# clip the top of the range, as we don't ever have tiles with negative
# zooms. this might change the effective delta between the zoom level of
# the request and the zoom level of the metatile.
if requested_tile.z < delta_z:
meta = TileRequest(0, 0, 0, 'zip')
offset = TileRequest(0, 0, 0, requested_tile.format)
else:

# allows setting a maximum detail level beyond which all features are
Expand All @@ -116,12 +115,14 @@ def meta_and_offset(requested_tile, meta_size, tile_size,
requested_tile.y >> delta_z,
'zip',
)
offset = TileRequest(
requested_tile.z - meta.z,
requested_tile.x - (meta.x << delta_z),
requested_tile.y - (meta.y << delta_z),
requested_tile.format,
)

actual_delta_z = requested_tile.z - meta.z
offset = TileRequest(
actual_delta_z,
requested_tile.x - (meta.x << actual_delta_z),
requested_tile.y - (meta.y << actual_delta_z),
requested_tile.format,
)

return meta, offset

Expand Down
23 changes: 23 additions & 0 deletions tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,29 @@ def check_overzoom(request, meta_z, offset_z):
self.assertTileEquals(TileRequest(16, 0, 0, 'zip'), meta)
self.assertTileEquals(TileRequest(0, 0, 0, 'json'), offset)

def test_zoom_zero(self):
from server import meta_and_offset

# check that when the metatile size is larger (e.g: 8), we can still
# access the low zoom tiles 0-3.
meta, offset = meta_and_offset(TileRequest(0, 0, 0, 'json'), 8, 2)
self.assertTileEquals(TileRequest(0, 0, 0, 'zip'), meta)
self.assertTileEquals(TileRequest(0, 0, 0, 'json'), offset)

meta, offset = meta_and_offset(TileRequest(1, 0, 1, 'json'), 8, 2)
self.assertTileEquals(TileRequest(0, 0, 0, 'zip'), meta)
self.assertTileEquals(TileRequest(1, 0, 1, 'json'), offset)

meta, offset = meta_and_offset(TileRequest(2, 1, 3, 'json'), 8, 2)
self.assertTileEquals(TileRequest(0, 0, 0, 'zip'), meta)
self.assertTileEquals(TileRequest(2, 1, 3, 'json'), offset)

# only once the offset exceeds the metatile size (at the request tile
# size) does it start to shift down zooms.
meta, offset = meta_and_offset(TileRequest(3, 2, 7, 'json'), 8, 2)
self.assertTileEquals(TileRequest(1, 0, 1, 'zip'), meta)
self.assertTileEquals(TileRequest(2, 2, 3, 'json'), offset)

def test_compute_key(self):
from server import compute_key

Expand Down

0 comments on commit c45f745

Please sign in to comment.