Skip to content

Commit

Permalink
Add more MapLibre examples
Browse files Browse the repository at this point in the history
  • Loading branch information
giswqs committed Jun 19, 2024
1 parent 327c264 commit e4178be
Show file tree
Hide file tree
Showing 10 changed files with 270 additions and 6 deletions.
2 changes: 1 addition & 1 deletion docs/maplibre/3d_buildings.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
"metadata": {},
"outputs": [],
"source": [
"# os.environ[\"MAPBOX_API_KEY\"] = \"YOUR_API_KEY\""
"# os.environ[\"MAPTILER_KEY\"] = \"YOUR_API_KEY\""
]
},
{
Expand Down
2 changes: 1 addition & 1 deletion docs/maplibre/3d_indoor_mapping.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"[![image](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/opengeos/leafmap/blob/master/docs/maplibre/3d_indoor_mapping.ipynb)\n",
"[![image](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/opengeos/leafmap/HEAD)\n",
"\n",
"**Display buildings in 3D**\n",
"**Extrude polygons for 3D indoor mapping**\n",
"\n",
"This source code of this example is adapted from the MapLibre GL JS example - [Extrude polygons for 3D indoor mapping](https://maplibre.org/maplibre-gl-js/docs/examples/3d-extrusion-floorplan).\n",
"\n",
Expand Down
2 changes: 1 addition & 1 deletion docs/maplibre/3d_terrain.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"[![image](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/opengeos/leafmap/blob/master/docs/maplibre/3d_terrain.ipynb)\n",
"[![image](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/opengeos/leafmap/HEAD)\n",
"\n",
"**Display buildings in 3D**\n",
"**3D Terrain**\n",
"\n",
"This source code of this example is adapted from the MapLibre GL JS example - [3D Terrain](https://maplibre.org/maplibre-gl-js/docs/examples/3d-terrain).\n",
"\n",
Expand Down
2 changes: 1 addition & 1 deletion docs/maplibre/_template.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
"metadata": {},
"outputs": [],
"source": [
"# os.environ[\"MAPBOX_API_KEY\"] = \"YOUR_API_KEY\""
"# os.environ[\"MAPTILER_KEY\"] = \"YOUR_API_KEY\""
]
},
{
Expand Down
2 changes: 1 addition & 1 deletion docs/maplibre/add_marker.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"[![image](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/opengeos/leafmap/blob/master/docs/maplibre/add_marker.ipynb)\n",
"[![image](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/opengeos/leafmap/HEAD)\n",
"\n",
"**Display buildings in 3D**\n",
"**Add a default marker**\n",
"\n",
"This source code of this example is adapted from the MapLibre GL JS example - [Add a default marker](https://maplibre.org/maplibre-gl-js/docs/examples/add-a-marker).\n",
"\n",
Expand Down
2 changes: 1 addition & 1 deletion docs/maplibre/add_video.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
"metadata": {},
"outputs": [],
"source": [
"# os.environ[\"MAPBOX_API_KEY\"] = \"YOUR_API_KEY\""
"# os.environ[\"MAPTILER_KEY\"] = \"YOUR_API_KEY\""
]
},
{
Expand Down
12 changes: 12 additions & 0 deletions docs/maplibre/overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,15 @@ Add a default marker to the map.
Display a video on top of a satellite raster baselayer.

[![](https://i.imgur.com/8YGYanS.jpeg)](https://leafmap.org/maplibre/add_video)

## Add a vector tile source

Add a vector source to a map.

[![](https://i.imgur.com/svfZwFh.jpeg)](https://leafmap.org/maplibre/vector_tile)

## Add a WMS source

Add an external Web Map Service raster layer to the map using addSource's tiles option.

[![](https://i.imgur.com/itFOq8z.png)](https://leafmap.org/maplibre/wms_source)
132 changes: 132 additions & 0 deletions docs/maplibre/vector_tile.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"[![image](https://jupyterlite.rtfd.io/en/latest/_static/badge.svg)](https://demo.leafmap.org/lab/index.html?path=maplibre/maplibre_xxx.ipynb)\n",
"[![image](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/opengeos/leafmap/blob/master/docs/maplibre/maplibre_xxx.ipynb)\n",
"[![image](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/opengeos/leafmap/HEAD)\n",
"\n",
"**Add a vector tile source**\n",
"\n",
"This source code of this example is adapted from the MapLibre GL JS example - [Add a vector tile source](https://maplibre.org/maplibre-gl-js/docs/examples/vector-source).\n",
"\n",
"Uncomment the following line to install [leafmap](https://leafmap.org) if needed."
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"# %pip install \"leafmap[maplibre]\""
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"import os\n",
"import leafmap.maplibregl as leafmap"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"To run this notebook, you will need an [API key](https://docs.maptiler.com/cloud/api/authentication-key/) from [MapTiler](https://www.maptiler.com/cloud/). Once you have the API key, you can set it as an environment variable in your notebook or script as follows:"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
"# os.environ[\"MAPTILER_KEY\"] = \"YOUR_API_KEY\""
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [],
"source": [
"MAPTILER_KEY = os.environ.get(\"MAPTILER_KEY\")\n",
"style = f\"https://api.maptiler.com/maps/streets/style.json?key={MAPTILER_KEY}\""
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "29d4ee4e6b0e4efd82d544f41900f307",
"version_major": 2,
"version_minor": 1
},
"text/plain": [
"Map(height='600px', map_options={'bearing': 0.0, 'center': (-122.447303, 37.753574), 'pitch': 0.0, 'style': 'h…"
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"m = leafmap.Map(center=[37.753574, -122.447303], zoom=13, style=style)\n",
"source = {\n",
" 'type': 'vector',\n",
" 'url': f'https://api.maptiler.com/tiles/contours/tiles.json?key={MAPTILER_KEY}',\n",
"}\n",
"layer = {\n",
" 'id': 'terrain-data',\n",
" 'type': 'line',\n",
" 'source': 'contours',\n",
" 'source-layer': 'contour',\n",
" 'layout': {'line-join': 'round', 'line-cap': 'round'},\n",
" 'paint': {'line-color': '#ff69b4', 'line-width': 1},\n",
"}\n",
"m.add_source('contours', source)\n",
"m.add_layer(layer)\n",
"m"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"![](https://i.imgur.com/svfZwFh.jpeg)"
]
}
],
"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": 4
}
118 changes: 118 additions & 0 deletions docs/maplibre/wms_source.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"[![image](https://jupyterlite.rtfd.io/en/latest/_static/badge.svg)](https://demo.leafmap.org/lab/index.html?path=maplibre/maplibre_xxx.ipynb)\n",
"[![image](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/opengeos/leafmap/blob/master/docs/maplibre/maplibre_xxx.ipynb)\n",
"[![image](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/opengeos/leafmap/HEAD)\n",
"\n",
"**Add a WMS source**\n",
"\n",
"This source code of this example is adapted from the MapLibre GL JS example - [Add a WMS source](https://maplibre.org/maplibre-gl-js/docs/examples/wms/).\n",
"\n",
"Uncomment the following line to install [leafmap](https://leafmap.org) if needed."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# %pip install \"leafmap[maplibre]\""
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import os\n",
"import leafmap.maplibregl as leafmap"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"To run this notebook, you will need an [API key](https://docs.maptiler.com/cloud/api/authentication-key/) from [MapTiler](https://www.maptiler.com/cloud/). Once you have the API key, you can set it as an environment variable in your notebook or script as follows:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# os.environ[\"MAPTILER_KEY\"] = \"YOUR_API_KEY\""
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"MAPTILER_KEY = os.environ.get(\"MAPTILER_KEY\")\n",
"style = f\"https://api.maptiler.com/maps/streets/style.json?key={MAPTILER_KEY}\""
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"m = leafmap.Map(center=[40.6892, -74.5447], zoom=8, style=style)\n",
"\n",
"source = {\n",
" 'type': 'raster',\n",
" 'tiles': [\n",
" 'https://img.nj.gov/imagerywms/Natural2015?bbox={bbox-epsg-3857}&format=image/png&service=WMS&version=1.1.1&request=GetMap&srs=EPSG:3857&transparent=true&width=256&height=256&layers=Natural2015'\n",
" ],\n",
" 'tileSize': 256,\n",
"}\n",
"layer = {\n",
" 'id': 'wms-test-layer',\n",
" 'type': 'raster',\n",
" 'source': 'wms-test-source',\n",
" 'paint': {},\n",
"}\n",
"m.add_source(\"wms-test-source\", source)\n",
"m.add_layer(layer, before_id=\"aeroway_fill\")\n",
"m"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"![](https://i.imgur.com/itFOq8z.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": 4
}
2 changes: 2 additions & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,9 @@ nav:
- maplibre/3d_indoor_mapping.ipynb
- maplibre/3d_terrain.ipynb
- maplibre/add_marker.ipynb
- maplibre/vector_tile.ipynb
- maplibre/add_video.ipynb
- maplibre/wms_source.ipynb
- Notebooks:
- notebooks/00_key_features.ipynb
- notebooks/01_leafmap_intro.ipynb
Expand Down

0 comments on commit e4178be

Please sign in to comment.