Skip to content

Commit

Permalink
Add support for OpenFreeMap vector tiles (#910)
Browse files Browse the repository at this point in the history
  • Loading branch information
giswqs authored Oct 5, 2024
1 parent 4470ee2 commit 95b0e1f
Show file tree
Hide file tree
Showing 6 changed files with 127 additions and 10 deletions.
102 changes: 102 additions & 0 deletions docs/maplibre/openfreemap.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
{
"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/openfreemap.ipynb)\n",
"[![image](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/opengeos/leafmap/blob/master/docs/maplibre/openfreemap.ipynb)\n",
"[![image](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/opengeos/leafmap/HEAD)\n",
"\n",
"**Using OpenFreeMap Vector Tiles**\n",
"\n",
"[OpenFreeMap](https://github.com/hyperknot/openfreemap) lets you display custom maps on your website and apps for free. It provides several vector tilesets for free, including:\n",
"\n",
"- liberty: https://tiles.openfreemap.org/styles/liberty\n",
"- positron: https://tiles.openfreemap.org/styles/positron\n",
"- bright: https://tiles.openfreemap.org/styles/bright\n",
"\n",
"For more information, please visit https://openfreemap.org/quick_start.\n",
"\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 leafmap.maplibregl as leafmap"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"m = leafmap.Map(style=\"liberty\")\n",
"m"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"![image](https://github.com/user-attachments/assets/0a9c8cb8-2b7e-4ca5-ba7b-183b8b3f54a6)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"m = leafmap.Map(style=\"bright\")\n",
"m"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"m = leafmap.Map(style=\"positron\")\n",
"m"
]
}
],
"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
}
8 changes: 6 additions & 2 deletions docs/maplibre/overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -410,12 +410,16 @@ Visualize ocean bathymetry in 3D.

[![](https://i.imgur.com/m6NwSWG.png)](https://leafmap.org/maplibre/ocean_bathymetry)

## Use OpenFreeMap vector tiles

Use free vector tiles from OpenFreeMap.

[![](https://github.com/user-attachments/assets/0a9c8cb8-2b7e-4ca5-ba7b-183b8b3f54a6)](https://leafmap.org/maplibre/openfreemap)

## Visualze Overture data

Visualize Overture Maps data.

[![](https://i.imgur.com/m6NwSWG.png)](https://leafmap.org/maplibre/ocean_bathymetry)

[![](https://github.com/user-attachments/assets/e07986eb-cc5a-4f25-b7e0-bed480a415d3)](https://leafmap.org/maplibre/overture)

## PMTiles source and protocol
Expand Down
23 changes: 16 additions & 7 deletions leafmap/maplibregl.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,12 @@ def __init__(
counter-clockwise from north. Defaults to 0.
style (str, optional): The style of the map. It can be a string or a URL.
If it is a string, it must be one of the following: "dark-matter",
"positron", "voyager", "positron-nolabels", "dark-matter-nolabels",
"voyager-nolabels", or "demotiles". If a MapTiler API key is set,
you can also use any of the MapTiler styles, such as aquarelle,
backdrop, basic, bright, dataviz, landscape, ocean, openstreetmap, outdoor,
satellite, streets, toner, topo, winter, etc. If it is a URL, it must point to
a MapLibre style JSON. Defaults to "dark-matter".
"carto-positron", "voyager", "positron-nolabels", "dark-matter-nolabels",
"voyager-nolabels", "demotiles", "liberty", "bright", or "positron".
If a MapTiler API key is set, you can also use any of the MapTiler styles,
such as aquarelle, backdrop, basic, bright, dataviz, landscape, ocean,
openstreetmap, outdoor, satellite, streets, toner, topo, winter, etc.
If it is a URL, it must point to a MapLibre style JSON. Defaults to "dark-matter".
height (str, optional): The height of the map. Defaults to "600px".
controls (dict, optional): The controls and their positions on the
map. Defaults to {"fullscreen": "top-right", "scale": "bottom-left"}.
Expand All @@ -78,12 +78,17 @@ def __init__(
"""
carto_basemaps = [
"dark-matter",
"positron",
"carto-positron",
"voyager",
"positron-nolabels",
"dark-matter-nolabels",
"voyager-nolabels",
]
openfreemap_basemaps = [
"liberty",
"bright",
"positron",
]
if isinstance(style, str):

if style.startswith("https"):
Expand All @@ -102,7 +107,11 @@ def __init__(
)

elif style.lower() in carto_basemaps:
if style.lower() == "carto-positron":
style = "positron"
style = construct_carto_basemap_url(style.lower())
elif style.lower() in openfreemap_basemaps:
style = f"https://tiles.openfreemap.org/styles/{style.lower()}"
elif style == "demotiles":
style = "https://demotiles.maplibre.org/style.json"
elif "background-" in style:
Expand Down
1 change: 1 addition & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ nav:
- maplibre/multiple_geometries.ipynb
- maplibre/navigation.ipynb
- maplibre/ocean_bathymetry.ipynb
- maplibre/openfreemap.ipynb
- maplibre/overture.ipynb
- maplibre/pmtiles.ipynb
- maplibre/restrict_bounds.ipynb
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ authors = [{name = "Qiusheng Wu", email = "[email protected]"}]
[project.optional-dependencies]
backends = ["bokeh", "keplergl", "maplibre", "pydeck", "plotly"]
lidar = ["ipygany", "ipyvtklink", "laspy", "panel", "pyntcloud[LAS]", "pyvista"]
raster = ["localtileserver>=0.10.0", "jupyter-server-proxy", "rio-cogeo", "rioxarray", "netcdf4", "pynhd", "py3dep"]
raster = ["localtileserver>=0.10.0", "jupyter-server-proxy", "rio-cogeo", "rioxarray", "netcdf4", "pynhd", "py3dep", "d2spy"]
sql = ["psycopg2", "sqlalchemy"]
apps = ["streamlit-folium", "voila", "solara"]
vector = ["geopandas", "osmnx", "pmtiles", "flask", "flask-cors", "lonboard", "mapclassify"]
Expand Down
1 change: 1 addition & 0 deletions requirements_dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ black[jupyter]
bokeh
boto3
cogeo-mosaic
d2spy
# earthaccess
ffmpeg-python
geopandas>=1.0.0
Expand Down

0 comments on commit 95b0e1f

Please sign in to comment.