Skip to content

Basemaps

maplibre.basemaps.Carto

Bases: Enum

Carto basemap styles

Attributes:

  • DARK_MATTER

    dark-matter

  • POSITRON

    positron

  • VOYAGER

    voyager

  • POSITRON_NOLABELS

    positron-nolabels

  • DARK_MATTER_NOLABELS

    dark-matter-nolabels

  • VOYAGER_NOLABELS

    voyager-nolabels

Examples:

>>> from maplibre import Map, MapOptions
>>> from maplibre.basemaps import Carto
>>> m = Map(MapOptions(style=Carto.DARK_MATTER))
Source code in maplibre/basemaps.py
class Carto(Enum):
    """Carto basemap styles

    Attributes:
        DARK_MATTER: dark-matter
        POSITRON: positron
        VOYAGER: voyager
        POSITRON_NOLABELS: positron-nolabels
        DARK_MATTER_NOLABELS: dark-matter-nolabels
        VOYAGER_NOLABELS: voyager-nolabels

    Examples:
        >>> from maplibre import Map, MapOptions
        >>> from maplibre.basemaps import Carto

        >>> m = Map(MapOptions(style=Carto.DARK_MATTER))
    """

    DARK_MATTER = "dark-matter"
    POSITRON = "positron"
    VOYAGER = "voyager"
    POSITRON_NOLABELS = "positron-nolabels"
    DARK_MATTER_NOLABELS = "dark-matter-nolabels"
    VOYAGER_NOLABELS = "voyager-nolabels"

maplibre.basemaps.OpenFreeMap

Bases: Enum

OpenFreeMap basemap styles

Attributes:

  • POSITRON

    positron

  • LIBERTY

    liberty

  • BRIGHT

    bright

Examples:

>>> from maplibre import Map, MapOptions
>>> from maplibre.basemaps import OpenFreeMap
>>> m = Map(MapOptions(style=OpenFreeMap.LIBERTY))
Source code in maplibre/basemaps.py
class OpenFreeMap(Enum):
    """OpenFreeMap basemap styles

    Attributes:
        POSITRON: positron
        LIBERTY: liberty
        BRIGHT: bright

    Examples:
        >>> from maplibre import Map, MapOptions
        >>> from maplibre.basemaps import OpenFreeMap

        >>> m = Map(MapOptions(style=OpenFreeMap.LIBERTY))
    """

    POSITRON = "positron"
    LIBERTY = "liberty"
    BRIGHT = "bright"

maplibre.basemaps.MapTiler

Bases: Enum

MapTiler basemap styles

Examples:

>>> import os
>>> from maplibre import Map, MapOptions
>>> from maplibre.basemaps import MapTiler
>>> os.environ["MAPTILER_API_KEY"] = "your-api-key"
>>> m = Map(MapOptions(style=MapTiler.AQUARELLE))
Source code in maplibre/basemaps.py
class MapTiler(Enum):
    """MapTiler basemap styles

    Examples:
        >>> import os
        >>> from maplibre import Map, MapOptions
        >>> from maplibre.basemaps import MapTiler

        >>> os.environ["MAPTILER_API_KEY"] = "your-api-key"
        >>> m = Map(MapOptions(style=MapTiler.AQUARELLE))
    """

    AQUARELLE = "aquarelle"
    BACKDROP = "backdrop"
    BASIC = "basic"
    BRIGHT = "bright"
    DATAVIZ = "dataviz"
    LANDSCAPE = "landscape"
    OCEAN = "ocean"
    OPEN_STREET_MAP = "openstreetmap"
    OUTDOOR = "outdoor"
    SATELLITE = "satellite"
    STREETS = "streets"
    TONER = "toner"
    TOPO = "topo"
    WINTER = "winter"

maplibre.basemaps.BasemapStyle

Bases: BaseModel

Basemap style

Note

See maplibre-style-spec/root for more details.

Source code in maplibre/basemaps.py
class BasemapStyle(BaseModel):
    """Basemap style

    Note:
        See [maplibre-style-spec/root](https://maplibre.org/maplibre-style-spec/root/) for more details.
    """

    _version = 8

    sources: dict[str, dict | SourceT] | None = None
    layers: list[Layer | dict]
    name: str = "my-basemap"
    sky: dict | Sky | None = None
    terrain: dict | Terrain | None = None
    light: dict | Light | None = None
    glyphs: str | None = None
    sprite: str | None = None
    center: tuple[float, float] | list[float, float] | None = None
    zoom: int | float | None = None
    bearing: int | float | None = None
    pitch: int | float | None = None

    @computed_field
    def version(self) -> int:
        return self._version

    def to_dict(self) -> dict:
        return self.model_dump(exclude_none=True, by_alias=True)

    @property
    def symbol_layers(self) -> list[str]:
        return [layer["id"] for layer in self.to_dict()["layers"] if layer["type"] == "symbol"]

    @classmethod
    def from_url(cls, url: str) -> BasemapStyle:
        import requests as req

        resp = req.get(url)
        data = resp.json()
        resp.close()
        return cls(**data)

    @staticmethod
    def carto_url(style_name: str | Carto) -> str:
        return f"https://basemaps.cartocdn.com/gl/{Carto(style_name).value}-gl-style/style.json"
        # return construct_carto_basemap_url(style_name)

    @staticmethod
    def openfreemap_url(style_name: str | OpenFreeMap) -> str:
        return f"https://tiles.openfreemap.org/styles/{OpenFreeMap(style_name).value}"
        # return construct_openfreemap_basemap_url(style_name)

    @staticmethod
    def maptiler_url(style_name: str | MapTiler) -> str:
        maptiler_api_key = options.maptiler_api_key
        return f"https://api.maptiler.com/maps/{MapTiler(style_name).value}/style.json?key={maptiler_api_key}"

maplibre.sky.Sky

Bases: MapLibreBaseModel

Sky configuration

Note

See maplibre-style-spec/sky for details.

Source code in maplibre/sky.py
class Sky(MapLibreBaseModel):
    """Sky configuration

    Note:
        See [maplibre-style-spec/sky](https://maplibre.org/maplibre-style-spec/sky/) for details.
    """

    sky_color: str | list | None = Field("#88C6FC", serialization_alias="sky-color")
    sky_horizon_blend: float | None = Field(0.8, serialization_alias="sky-horizon-blend")
    horizon_color: str | list | None = Field("#ffffff", serialization_alias="horizon-color")
    horizon_fog_blend: float | None = Field(0.8, serialization_alias="horizon-fog-blend")
    fog_color: str | list | None = Field("#ffffff", serialization_alias="fog-color")
    fog_ground_blend: float | list | None = Field(0.5, serialization_alias="fog-ground-blend")
    atmosphere_blend: float | list | None = Field(0.8, serialization_alias="atmosphere-blend")

    def to_dict(self) -> dict:
        return fix_keys(self.model_dump(by_alias=True, exclude_none=True))

maplibre.light.Light

Bases: MapLibreBaseModel

Light configuration

Note

See maplibre-style-spec/light for details.

Source code in maplibre/light.py
class Light(MapLibreBaseModel):
    """Light configuration

    Note:
        See  [maplibre-style-spec/light](https://maplibre.org/maplibre-style-spec/light/) for details.
    """

    anchor: Literal["map", "viewport"] = "map"
    position: list[float, float, float] = [1.15, 210, 30]
    color: str = "#ffffff"
    intensity: float = Field(0.5, ge=0, le=1)

maplibre.terrain.Terrain

Bases: MapLibreBaseModel

Terrain configuration

Note

See maplibre-style-spec/terrain for details.

Source code in maplibre/terrain.py
class Terrain(MapLibreBaseModel):
    """Terrain configuration

    Note:
        See [maplibre-style-spec/terrain](https://maplibre.org/maplibre-style-spec/terrain/) for details.
    """

    source: str
    exaggeration: int | float | None = 1