Skip to content

Commit

Permalink
Add 3D PMTiles example (#830)
Browse files Browse the repository at this point in the history
* Add 3D PMTiles example

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
giswqs and pre-commit-ci[bot] authored Jul 16, 2024
1 parent 9f27657 commit 92260aa
Show file tree
Hide file tree
Showing 3 changed files with 145 additions and 0 deletions.
138 changes: 138 additions & 0 deletions docs/maplibre/3d_pmtiles.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
{
"cells": [
{
"cell_type": "markdown",
"id": "0",
"metadata": {},
"source": [
"[![image](https://jupyterlite.rtfd.io/en/latest/_static/badge.svg)](https://demo.leafmap.org/lab/index.html?path=maplibre/3d_pmtiles.ipynb)\n",
"[![image](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/opengeos/leafmap/blob/master/docs/maplibre/3d_pmtiles.ipynb)\n",
"[![image](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/opengeos/leafmap/HEAD)\n",
"\n",
"**Visualize PMTiles in 3D**\n",
"\n",
"This notebook demonstrates how to visualize [Overture Open Buildings](https://beta.source.coop/cholmes/overture/overture-buildings.pmtiles) in 3D.\n",
"\n",
"Uncomment the following line to install [leafmap](https://leafmap.org) if needed."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "1",
"metadata": {},
"outputs": [],
"source": [
"# %pip install -U \"leafmap[maplibre]\""
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "2",
"metadata": {},
"outputs": [],
"source": [
"import leafmap.maplibregl as leafmap"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "3",
"metadata": {},
"outputs": [],
"source": [
"url = \"https://data.source.coop/cholmes/overture/overture-buildings.pmtiles\"\n",
"metadata = leafmap.pmtiles_metadata(url)\n",
"print(f\"layer names: {metadata['layer_names']}\")\n",
"print(f\"bounds: {metadata['bounds']}\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "4",
"metadata": {},
"outputs": [],
"source": [
"m = leafmap.Map(\n",
" center=[-74.0095, 40.7046], zoom=16, pitch=60, bearing=-17, style=\"positron\"\n",
")\n",
"m.add_basemap(\"OpenStreetMap.Mapnik\")\n",
"m.add_basemap(\"Esri.WorldImagery\", visible=False)\n",
"\n",
"style = {\n",
" \"layers\": [\n",
" {\n",
" \"id\": \"buildings\",\n",
" \"source\": \"example_source\",\n",
" \"source-layer\": \"buildings\",\n",
" \"type\": \"fill-extrusion\",\n",
" \"filter\": [\n",
" \">\",\n",
" [\"get\", \"height\"],\n",
" 0,\n",
" ], # only show buildings with height info\n",
" \"paint\": {\n",
" \"fill-extrusion-color\": [\n",
" \"interpolate\",\n",
" [\"linear\"],\n",
" [\"get\", \"height\"],\n",
" 0,\n",
" \"lightgray\",\n",
" 200,\n",
" \"royalblue\",\n",
" 400,\n",
" \"lightblue\",\n",
" ],\n",
" \"fill-extrusion-height\": [\"*\", [\"get\", \"height\"], 1],\n",
" },\n",
" },\n",
" ],\n",
"}\n",
"\n",
"m.add_pmtiles(\n",
" url,\n",
" style=style,\n",
" visible=True,\n",
" opacity=1.0,\n",
" tooltip=True,\n",
" template=\"Height: {{height}}<br>Country: {{country_iso}}\",\n",
" fit_bounds=False,\n",
")\n",
"m.add_layer_control()\n",
"m"
]
},
{
"cell_type": "markdown",
"id": "5",
"metadata": {},
"source": [
"![](https://i.imgur.com/113bGei.png)"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.9"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
6 changes: 6 additions & 0 deletions docs/maplibre/overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@ Create a 3D indoor map with the fill-extrude-height paint property.

[![](https://i.imgur.com/eYhSWaT.png)](https://leafmap.org/maplibre/3d_indoor_mapping)

## Visualize PMTiles in 3D

Visualize polygons from a PMTiles source in 3D.

[![](https://i.imgur.com/113bGei.png)](https://leafmap.org/maplibre/3d_pmtiles)

## Construct 3D map styles with MapTiler

[![](https://i.imgur.com/3Q2Q3CG.png)](https://leafmap.org/maplibre/3d_style)
Expand Down
1 change: 1 addition & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ nav:
- maplibre/3d_buildings.ipynb
- maplibre/3d_choropleth.ipynb
- maplibre/3d_indoor_mapping.ipynb
- maplibre/3d_pmtiles.ipynb
- maplibre/3d_style.ipynb
- maplibre/3d_terrain.ipynb
- maplibre/add_3d_buildings.ipynb
Expand Down

0 comments on commit 92260aa

Please sign in to comment.