Source code for holoviews.element.tiles

from types import FunctionType

import numpy as np
import param

from ..core.dimension import Dimension
from ..core.element import Element2D
from ..util.transform import easting_northing_to_lon_lat, lon_lat_to_easting_northing

[docs]class Tiles(Element2D): """ The Tiles element represents tile sources, specified as URL containing different template variables or xyzservices.TileProvider. These variables correspond to three different formats for specifying the spatial location and zoom level of the requested tiles: * Web mapping tiles sources containing {x}, {y}, and {z} variables * Bounding box tile sources containing {XMIN}, {XMAX}, {YMIN}, {YMAX} variables * Quadkey tile sources containing a {Q} variable Tiles are defined in a pseudo-Mercator projection (EPSG:3857) defined as eastings and northings. Any data overlaid on a tile source therefore has to be defined in those coordinates or be projected (e.g. using GeoViews). """ kdims = param.List(default=[Dimension('x'), Dimension('y')], bounds=(2, 2), constant=True, doc=""" The key dimensions of a geometry represent the x- and y- coordinates in a 2D space.""") group = param.String(default='Tiles', constant=True) def __init__(self, data=None, kdims=None, vdims=None, **params): from bokeh.models import MercatorTileSource if isinstance(data, MercatorTileSource): data = data.url elif data is not None and not isinstance(data, (str, dict)): raise TypeError(f'{type(self).__name__} data should be a tile service URL or ' f'xyzservices.TileProvider not a {type(data).__name__} type.' ) super().__init__(data, kdims=kdims, vdims=vdims, **params)
[docs] def range(self, dim, data_range=True, dimension_range=True): return np.nan, np.nan
[docs] def dimension_values(self, dimension, expanded=True, flat=True): return np.array([])
[docs] @staticmethod def lon_lat_to_easting_northing(longitude, latitude): """ Projects the given longitude, latitude values into Web Mercator (aka Pseudo-Mercator or EPSG:3857) coordinates. See docstring for holoviews.util.transform.lon_lat_to_easting_northing for more information """ return lon_lat_to_easting_northing(longitude, latitude)
[docs] @staticmethod def easting_northing_to_lon_lat(easting, northing): """ Projects the given easting, northing values into longitude, latitude coordinates. See docstring for holoviews.util.transform.easting_northing_to_lon_lat for more information """ return easting_northing_to_lon_lat(easting, northing)
# Mapping between patterns to match specified as tuples and tuples containing attributions _ATTRIBUTIONS = { ('openstreetmap',) : ( '&copy; <a href="">OpenStreetMap</a> contributors' ), ('cartodb',) : ( '&copy; <a href="">OpenStreetMap</a> contributors, ' '&copy; <a href="">CartoDB</a>' ), ('cartocdn',) : ( '&copy; <a href="">OpenStreetMap</a> contributors, ' '&copy; <a href="">CartoDB</a>' ), ('stamen', 'png') : ( # to match both 'toner' and 'terrain' 'Map tiles by <a href="">Stamen Design</a> / <a href="">Stadia Maps</a>, ' 'under <a href="">CC BY 3.0</a>. ' 'Data by <a href="">OpenStreetMap</a>, ' 'under <a href="">ODbL</a>.' ), ('stamen', 'jpg') : ( # watercolor 'Map tiles by <a href="">Stamen Design</a> / <a href="">Stadia Maps</a>, ' 'under <a href="">CC BY 3.0</a>. ' 'Data by <a href="">OpenStreetMap</a>, ' 'under <a href="">CC BY SA</a>.' ), ('wikimedia',) : ( '&copy; <a href="">OpenStreetMap</a> contributors' ), ('arcgis','Terrain') : ( '&copy; <a href="">Esri</a>, ' 'USGS, NOAA' ), ('arcgis','Reference') : ( '&copy; <a href="">Esri</a>, ' 'Garmin, USGS, NPS' ), ('arcgis','Imagery') : ( '&copy; <a href="">Esri</a>, ' 'Earthstar Geographics' ), ('arcgis','NatGeo') : ( '&copy; <a href="">Esri</a>, ' 'NatGeo, Garmin, HERE, UNEP-WCMC, USGS, NASA, ESA, METI, NRCAN, GEBCO, NOAA, Increment P' ), ('arcgis','USA_Topo') : ( '&copy; <a href="">Esri</a>, ' 'NatGeo, i-cubed' ), ('arcgis', 'World_Street_Map') : ( '&copy; Esri &mdash; Source: Esri, DeLorme, NAVTEQ, USGS, Intermap, iPC, NRCAN, Esri Japan, METI, Esri China (Hong Kong), Esri (Thailand), TomTom, 2012' ) } # CartoDB basemaps CartoDark = lambda: Tiles('{Z}/{X}/{Y}.png', name="CartoDark") CartoLight = lambda: Tiles('{Z}/{X}/{Y}.png', name="CartoLight") # Stamen basemaps StamenTerrain = lambda: Tiles('{Z}/{X}/{Y}.png', name="StamenTerrain") StamenTerrainRetina = lambda: Tiles('{Z}/{X}/{Y}@2x.png', name="StamenTerrainRetina") StamenWatercolor = lambda: Tiles('{Z}/{X}/{Y}.jpg', name="StamenWatercolor") StamenToner = lambda: Tiles('{Z}/{X}/{Y}.png', name="StamenToner") StamenTonerRetina = lambda: Tiles('{Z}/{X}/{Y}@2x.png', name="StamenTonerRetina") StamenTonerBackground = lambda: Tiles('{Z}/{X}/{Y}.png', name="StamenTonerBackground") StamenTonerBackgroundRetina = lambda: Tiles('{Z}/{X}/{Y}@2x.png', name="StamenTonerBackgroundRetina") StamenLabels = lambda: Tiles('{Z}/{X}/{Y}.png', name="StamenLabels") StamenLabelsRetina = lambda: Tiles('{Z}/{X}/{Y}@2x.png', name="StamenLabelsRetina") # Esri maps (see for the full list) EsriImagery = lambda: Tiles('{Z}/{Y}/{X}.jpg', name="EsriImagery") EsriNatGeo = lambda: Tiles('{Z}/{Y}/{X}', name="EsriNatGeo") EsriUSATopo = lambda: Tiles('{Z}/{Y}/{X}', name="EsriUSATopo") EsriTerrain = lambda: Tiles('{Z}/{Y}/{X}', name="EsriTerrain") EsriStreet = lambda: Tiles('{Z}/{Y}/{X}') EsriReference = lambda: Tiles('{Z}/{Y}/{X}', name="EsriReference") ESRI = EsriImagery # For backwards compatibility with gv 1.5 # Miscellaneous OSM = lambda: Tiles('{Z}/{X}/{Y}.png', name="OSM") OpenTopoMap = lambda: Tiles('{Z}/{X}/{Y}.png', name="OpenTopoMap") _all_tile_sources = {k: v for k, v in locals().items() if isinstance(v, FunctionType) and k not in ['ESRI', 'lon_lat_to_easting_northing', 'easting_northing_to_lon_lat', 'deprecation_warning', 'wikimedia_replacement']} tile_sources = {k: v for k, v in _all_tile_sources.items() if "Stamen" not in k} stamen_sources = {k: v for k, v in _all_tile_sources.items() if "Stamen" in k}