Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 30 additions & 10 deletions maplibre/map.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@ class MapOptions(MapLibreBaseModel):
See [MapOptions](https://maplibre.org/maplibre-gl-js/docs/API/type-aliases/MapOptions) for details.
"""

model_config = ConfigDict(validate_assignment=True, extra="forbid", use_enum_values=False)
model_config = ConfigDict(
validate_assignment=True, extra="forbid", use_enum_values=False
)

antialias: bool = None
attribution_control: bool = Field(None, serialization_alias="attributionControl")
Expand All @@ -75,7 +77,9 @@ class MapOptions(MapLibreBaseModel):
min_zoom: int = Field(None, serialization_alias="minZoom")
pitch: Union[int, float] = None
scroll_zoom: bool = Field(None, serialization_alias="scrollZoom")
style: Union[str, Carto, MapTiler, OpenFreeMap, dict, Basemap] = Field(Carto.DARK_MATTER, validate_default=True)
style: Union[str, Carto, MapTiler, OpenFreeMap, dict, Basemap] = Field(
Carto.DARK_MATTER, validate_default=True
)
zoom: Union[int, float] = None

@field_validator("style")
Expand Down Expand Up @@ -208,7 +212,7 @@ def add_source(self, id: str, source: Source | dict | gpd.GeoDataFrame) -> None:
id (str): The unique ID of the source.
source (Source | dict | gpd.GeoDataFrame): The source to be added to the map.
"""
if GEOPANDAS is not None and isinstance(source, gpd.GeoDataFrame):
if GEOPANDAS and isinstance(source, gpd.GeoDataFrame):
source = SimpleFeatures(source).to_source()

if isinstance(source, Source):
Expand Down Expand Up @@ -257,7 +261,9 @@ def add_popup(self, layer_id: str, prop: str = None, template: str = None) -> No
"""
self.add_call("addPopup", layer_id, prop, template)

def add_tooltip(self, layer_id: str, prop: str = None, template: str = None) -> None:
def add_tooltip(
self, layer_id: str, prop: str = None, template: str = None
) -> None:
"""Add a tooltip to the map

Args:
Expand Down Expand Up @@ -337,7 +343,9 @@ def fit_bounds(

self.add_call("fitBounds", bounds, kwargs)

def set_projection(self, type: str | ProjectionType | list = ProjectionType.GLOBE) -> None:
def set_projection(
self, type: str | ProjectionType | list = ProjectionType.GLOBE
) -> None:
"""Set the projection of the map"""
self.add_call("setProjection", dict(type=type))

Expand Down Expand Up @@ -378,12 +386,18 @@ def to_html(self, title: str = "My Awesome Map", **kwargs) -> str:
"""
js_lib = read_internal_file("srcjs", "pywidget.js")
js_snippet = Template(js_template).render(data=json.dumps(self.to_dict()))
css_file = "ipywidget.maplibre-geocoder.css" if self._geocoder_type == GeocoderType.MAPLIBRE else "pywidget.css"
css_file = (
"ipywidget.maplibre-geocoder.css"
if self._geocoder_type == GeocoderType.MAPLIBRE
else "pywidget.css"
)
css = read_internal_file("srcjs", css_file)
headers = [f"<style>{css}</style>"]

# Deck.GL headers
add_deckgl_headers = "addDeckOverlay" in [item[0] for item in self._message_queue]
add_deckgl_headers = "addDeckOverlay" in [
item[0] for item in self._message_queue
]
# TODO: Set version in constants
deckgl_headers = (
[
Expand All @@ -397,7 +411,9 @@ def to_html(self, title: str = "My Awesome Map", **kwargs) -> str:
)

# Mapbox Draw headers
add_mapbox_draw_headers = "addMapboxDraw" in [item[0] for item in self._message_queue]
add_mapbox_draw_headers = "addMapboxDraw" in [
item[0] for item in self._message_queue
]
# TODO: Set version in constants
mapbox_draw_headers = (
[
Expand Down Expand Up @@ -425,7 +441,9 @@ def save(self, filename: str = None, preview=True, **kwargs):
# -------------------------
# Plugins
# -------------------------
def add_deck_layers(self, layers: list[dict | pdk.Layer], tooltip: str | dict = None) -> None:
def add_deck_layers(
self, layers: list[dict | pdk.Layer], tooltip: str | dict = None
) -> None:
"""Add Deck.GL layers to the layer stack

Args:
Expand All @@ -436,7 +454,9 @@ def add_deck_layers(self, layers: list[dict | pdk.Layer], tooltip: str | dict =
layers = parse_deck_layers(layers)
self.add_call("addDeckOverlay", layers, tooltip)

def set_deck_layers(self, layers: list[dict | pdk.Layer], tooltip: str | dict = None) -> None:
def set_deck_layers(
self, layers: list[dict | pdk.Layer], tooltip: str | dict = None
) -> None:
"""Update Deck.GL layers

Args:
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "maplibre"
version = "0.3.5"
version = "0.3.6"
description = "Python bindings for MapLibre GL JS"
authors = ["Stefan Kuethe <stefan.kuethe@eoda.de>"]
readme = "README.md"
Expand Down