예제 #1
0
 def check_overzoom(request, meta_z, offset_z):
     tile_px, request_z = map(int, request.split("/"))
     tile_size = tile_px // 256
     meta, offset = meta_and_offset(
         TileRequest(request_z, 0, 0, 'json'), 4, tile_size,
         metatile_max_detail_zoom=14)
     self.assertTileEquals(TileRequest(meta_z, 0, 0, 'zip'), meta)
     self.assertTileEquals(TileRequest(offset_z, 0, 0, 'json'), offset)
예제 #2
0
    def test_meta_and_offset(self):
        from server import meta_and_offset

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

        meta, offset = meta_and_offset(TileRequest(12, 637, 936, 1, 'json'), 1)
        self.assertTileEquals(TileRequest(12, 637, 936, 1, 'zip'), meta)
        self.assertTileEquals(TileRequest(0, 0, 0, 1, 'json'), offset)

        meta, offset = meta_and_offset(TileRequest(12, 637, 936, 1, 'json'), 2)
        self.assertTileEquals(TileRequest(11, 318, 468, 1, 'zip'), meta)
        self.assertTileEquals(TileRequest(1, 1, 0, 1, 'json'), offset)

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

        meta, offset = meta_and_offset(TileRequest(12, 637, 935, 1, 'json'), 8)
        self.assertTileEquals(TileRequest(9, 79, 116, 1, 'zip'), meta)
        self.assertTileEquals(TileRequest(3, 5, 7, 1, 'json'), offset)

        # check that the "512px" 0/0/0 tile is accessible.
        meta, offset = meta_and_offset(TileRequest(0, 0, 0, 2, 'json'), 2)
        self.assertTileEquals(TileRequest(0, 0, 0, 1, 'zip'), meta)
        self.assertTileEquals(TileRequest(0, 0, 0, 1, 'json'), offset)

        # check that when the metatile would be smaller than the world (i.e:
        # zoom < 0) then it just stops at 0 and we get the offset to the 0/0/0
        # tile.
        meta, offset = meta_and_offset(TileRequest(0, 0, 0, 1, 'json'), 2)
        self.assertTileEquals(TileRequest(0, 0, 0, 1, 'zip'), meta)
        self.assertTileEquals(TileRequest(0, 0, 0, 1, 'json'), offset)
예제 #3
0
    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, 2, 'json'), 8)
        self.assertTileEquals(TileRequest(0, 0, 0, 1, 'zip'), meta)
        self.assertTileEquals(TileRequest(0, 0, 0, 1, 'json'), offset)

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

        meta, offset = meta_and_offset(TileRequest(2, 1, 3, 2, 'json'), 8)
        self.assertTileEquals(TileRequest(0, 0, 0, 1, 'zip'), meta)
        self.assertTileEquals(TileRequest(2, 1, 3, 1, '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, 2, 'json'), 8)
        self.assertTileEquals(TileRequest(1, 0, 1, 1, 'zip'), meta)
        self.assertTileEquals(TileRequest(2, 2, 3, 1, 'json'), offset)
예제 #4
0
    def test_max_detail_zoom(self):
        from server import meta_and_offset

        def check_overzoom(request, meta_z, offset_z):
            tile_px, request_z = map(int, request.split("/"))
            tile_size = tile_px // 256
            meta, offset = meta_and_offset(TileRequest(request_z, 0, 0,
                                                       tile_size, 'json'),
                                           4,
                                           metatile_max_detail_zoom=14)
            self.assertTileEquals(TileRequest(meta_z, 0, 0, 1, 'zip'), meta)
            self.assertTileEquals(TileRequest(offset_z, 0, 0, 1, 'json'),
                                  offset)

        # check that when the requested tile is past the max level of detail,
        # then it falls back to "smaller" tiles.
        #
        # base tile:
        check_overzoom("1024/14", meta_z=14, offset_z=0)

        # first fallback level, actually returning a "512px" tile, rather than
        # the requested "1024px", but it's at the max detail level, so the
        # content is the same.
        check_overzoom("1024/15", meta_z=14, offset_z=1)

        # second fallback level, actually returning a "256px" tile.
        check_overzoom("1024/16", meta_z=14, offset_z=2)

        # returning a "256px" tile for a "512px" request at the maximum
        # detail level.
        check_overzoom("512/16", meta_z=14, offset_z=2)

        # there is no third level of fallback (with the metatile size tested
        # here, at least), so it should clamp to the minimum tile size. this
        # will probably result in a 404 anyway.
        check_overzoom("1024/17", meta_z=15, offset_z=2)

        # check that passing None (the default) as the max detail zoom
        # disables this behaviour.
        meta, offset = meta_and_offset(TileRequest(16, 0, 0, 4, 'json'), 4)
        self.assertTileEquals(TileRequest(16, 0, 0, 1, 'zip'), meta)
        self.assertTileEquals(TileRequest(0, 0, 0, 1, 'json'), offset)