예제 #1
0
 def test_width_and_height(self):
     ts = TileGrid(4, 2, 1, 540, 540, GLOBAL_GEO_EXTENT, inv_y=False)
     self.assertEqual(ts.width(2), 4320)
     self.assertEqual(ts.height(2), 2160)
     self.assertEqual(ts.max_width, 8640)
     self.assertEqual(ts.max_height, 4320)
     self.assertEqual(ts.min_width, 1080)
     self.assertEqual(ts.min_height, 540)
예제 #2
0
def _tile_grid_to_ol4x_xyz_source_options(tile_grid: TileGrid, url: str):
    """
    Convert TileGrid into options to be used with ol.source.XYZ(options) of OpenLayers 4.x.

    See

    * https://openlayers.org/en/latest/apidoc/ol.source.XYZ.html
    * https://openlayers.org/en/latest/examples/xyz.html

    :param tile_grid: tile grid
    :param url: source url
    :return:
    """
    west, south, east, north = tile_grid.geo_extent

    delta_x = east - west + (0 if east >= west else 360)
    delta_y = north - south
    width = tile_grid.width(0)
    height = tile_grid.height(0)
    res0_x = delta_x / width
    res0_y = delta_y / height
    res0 = max(res0_x, res0_y)
    if abs(res0_y - res0_x) >= 1.e-5:
        warnings.warn(
            f'spatial resolutions in x and y direction differ significantly:'
            f' {res0_x} and {res0_y} degrees, using maximum {res0}')

    # https://openlayers.org/en/latest/examples/xyz.html
    # https://openlayers.org/en/latest/apidoc/ol.source.XYZ.html
    return dict(
        url=url,
        projection='EPSG:4326',
        minZoom=0,
        maxZoom=tile_grid.num_levels - 1,
        tileGrid=dict(
            extent=[west, south, east, north],
            origin=[west, south if tile_grid.inv_y else north],
            tileSize=[tile_grid.tile_size[0], tile_grid.tile_size[1]],
            resolutions=[res0 / (2**i) for i in range(tile_grid.num_levels)]))