Skip to content

Commit

Permalink
Add MapLibre 3d terrain exaggeration (#794)
Browse files Browse the repository at this point in the history
  • Loading branch information
giswqs authored Jun 29, 2024
1 parent be180dd commit f502aa0
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 12 deletions.
35 changes: 24 additions & 11 deletions leafmap/maplibregl.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,13 @@ def __init__(
style = "dark-matter"

if style == "3d-terrain":
style = self._get_3d_terrain_style()
style = self._get_3d_terrain_style(
exaggeration=kwargs.pop("exaggeration", 1.0)
)
elif style == "3d-terrain-background":
style = self._get_3d_terrain_style(
satellite=False, exaggeration=kwargs.pop("exaggeration", 1.0)
)

if isinstance(style, str) and (style.lower() in carto_basemaps):
style = construct_carto_basemap_url(style.lower())
Expand Down Expand Up @@ -2001,6 +2007,7 @@ def jump_to(self, options: Dict[str, Any] = {}, **kwargs: Any) -> None:

def _get_3d_terrain_style(
self,
satellite=True,
exaggeration: float = 1,
token: str = "MAPTILER_KEY",
api_key: Optional[str] = None,
Expand Down Expand Up @@ -2031,6 +2038,21 @@ def _get_3d_terrain_style(
print("An API key is required to use the 3D terrain feature.")
return "dark-matter"

layers = []

if satellite:
layers.append({"id": "satellite", "type": "raster", "source": "satellite"})

layers.append(
{
"id": "hills",
"type": "hillshade",
"source": "hillshadeSource",
"layout": {"visibility": "visible"},
"paint": {"hillshade-shadow-color": "#473B24"},
}
)

style = {
"version": 8,
"sources": {
Expand All @@ -2055,16 +2077,7 @@ def _get_3d_terrain_style(
"tileSize": 256,
},
},
"layers": [
{"id": "satellite", "type": "raster", "source": "satellite"},
{
"id": "hills",
"type": "hillshade",
"source": "hillshadeSource",
"layout": {"visibility": "visible"},
"paint": {"hillshade-shadow-color": "#473B24"},
},
],
"layers": layers,
"terrain": {"source": "terrainSource", "exaggeration": exaggeration},
}

Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ geojson
ipyevents
ipyfilechooser
ipyleaflet
ipyvuetify
ipywidgets
matplotlib
numpy
Expand Down
1 change: 0 additions & 1 deletion requirements_dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ h5py
ipygany
ipysheet
ipyvtklink
ipyvuetify
jupyter_bokeh
jupyterlab>=3.0.0
keplergl
Expand Down

0 comments on commit f502aa0

Please sign in to comment.