├── .gitignore ├── .pre-commit-config.yaml ├── Home.py ├── LICENSE ├── README.md ├── packages.txt ├── pages ├── 1_🌍_Interactive_Map.py ├── 2_🪟_Split_Map.py ├── 3_📍_Marker_Cluster.py ├── 4_🔥_Heatmap.py ├── 5_🔍_Basemaps.py └── 6_📦_Web_Map_Service.py └── requirements.txt /.gitignore: -------------------------------------------------------------------------------- 1 | # Byte-compiled / optimized / DLL files 2 | __pycache__/ 3 | *.py[cod] 4 | *$py.class 5 | 6 | # C extensions 7 | *.so 8 | 9 | # Distribution / packaging 10 | .Python 11 | build/ 12 | develop-eggs/ 13 | dist/ 14 | downloads/ 15 | eggs/ 16 | .eggs/ 17 | lib/ 18 | lib64/ 19 | parts/ 20 | sdist/ 21 | var/ 22 | wheels/ 23 | pip-wheel-metadata/ 24 | share/python-wheels/ 25 | *.egg-info/ 26 | .installed.cfg 27 | *.egg 28 | MANIFEST 29 | 30 | # PyInstaller 31 | # Usually these files are written by a python script from a template 32 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 33 | *.manifest 34 | *.spec 35 | 36 | # Installer logs 37 | pip-log.txt 38 | pip-delete-this-directory.txt 39 | 40 | # Unit test / coverage reports 41 | htmlcov/ 42 | .tox/ 43 | .nox/ 44 | .coverage 45 | .coverage.* 46 | .cache 47 | nosetests.xml 48 | coverage.xml 49 | *.cover 50 | *.py,cover 51 | .hypothesis/ 52 | .pytest_cache/ 53 | 54 | # Translations 55 | *.mo 56 | *.pot 57 | 58 | # Django stuff: 59 | *.log 60 | local_settings.py 61 | db.sqlite3 62 | db.sqlite3-journal 63 | 64 | # Flask stuff: 65 | instance/ 66 | .webassets-cache 67 | 68 | # Scrapy stuff: 69 | .scrapy 70 | 71 | # Sphinx documentation 72 | docs/_build/ 73 | 74 | # PyBuilder 75 | target/ 76 | 77 | # Jupyter Notebook 78 | .ipynb_checkpoints 79 | 80 | # IPython 81 | profile_default/ 82 | ipython_config.py 83 | 84 | # pyenv 85 | .python-version 86 | 87 | # pipenv 88 | # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. 89 | # However, in case of collaboration, if having platform-specific dependencies or dependencies 90 | # having no cross-platform support, pipenv may install dependencies that don't work, or not 91 | # install all needed dependencies. 92 | #Pipfile.lock 93 | 94 | # PEP 582; used by e.g. github.com/David-OConnor/pyflow 95 | __pypackages__/ 96 | 97 | # Celery stuff 98 | celerybeat-schedule 99 | celerybeat.pid 100 | 101 | # SageMath parsed files 102 | *.sage.py 103 | 104 | # Environments 105 | .env 106 | .venv 107 | env/ 108 | venv/ 109 | ENV/ 110 | env.bak/ 111 | venv.bak/ 112 | 113 | # Spyder project settings 114 | .spyderproject 115 | .spyproject 116 | 117 | # Rope project settings 118 | .ropeproject 119 | 120 | # mkdocs documentation 121 | /site 122 | 123 | # mypy 124 | .mypy_cache/ 125 | .dmypy.json 126 | dmypy.json 127 | 128 | # Pyre type checker 129 | .pyre/ 130 | -------------------------------------------------------------------------------- /.pre-commit-config.yaml: -------------------------------------------------------------------------------- 1 | repos: 2 | - repo: https://github.com/pre-commit/pre-commit-hooks 3 | rev: v6.0.0 4 | hooks: 5 | - id: check-toml 6 | - id: check-yaml 7 | - id: end-of-file-fixer 8 | types: [python] 9 | - id: trailing-whitespace 10 | - id: requirements-txt-fixer 11 | - id: check-added-large-files 12 | args: ["--maxkb=500"] 13 | 14 | - repo: https://github.com/psf/black 15 | rev: 25.1.0 16 | hooks: 17 | - id: black-jupyter 18 | language_version: python3.11 19 | 20 | - repo: https://github.com/kynan/nbstripout 21 | rev: 0.8.1 22 | hooks: 23 | - id: nbstripout 24 | -------------------------------------------------------------------------------- /Home.py: -------------------------------------------------------------------------------- 1 | import streamlit as st 2 | import leafmap.foliumap as leafmap 3 | 4 | st.set_page_config(layout="wide") 5 | 6 | # Customize the sidebar 7 | markdown = """ 8 | A Streamlit map template 9 | 10 | """ 11 | 12 | st.sidebar.title("About") 13 | st.sidebar.info(markdown) 14 | logo = "https://i.imgur.com/UbOXYAU.png" 15 | st.sidebar.image(logo) 16 | 17 | # Customize page title 18 | st.title("Streamlit for Geospatial Applications") 19 | 20 | st.markdown( 21 | """ 22 | This multipage app template demonstrates various interactive web apps created using [streamlit](https://streamlit.io) and [leafmap](https://leafmap.org). It is an open-source project and you are very welcome to contribute to the [GitHub repository](https://github.com/opengeos/streamlit-map-template). 23 | """ 24 | ) 25 | 26 | st.header("Instructions") 27 | 28 | markdown = """ 29 | 1. For the [GitHub repository](https://github.com/opengeos/streamlit-map-template) or [use it as a template](https://github.com/opengeos/streamlit-map-template/generate) for your own project. 30 | 2. Customize the sidebar by changing the sidebar text and logo in each Python files. 31 | 3. Find your favorite emoji from https://emojipedia.org. 32 | 4. Add a new app to the `pages/` directory with an emoji in the file name, e.g., `1_🚀_Chart.py`. 33 | 34 | """ 35 | 36 | st.markdown(markdown) 37 | 38 | m = leafmap.Map(minimap_control=True) 39 | m.add_basemap("OpenTopoMap") 40 | m.to_streamlit(height=500) 41 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2022 Qiusheng Wu 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # streamlit-map-template 2 | 3 | A streamlit template for mapping applications. It can be deployed to [Streamlit Cloud](https://streamlit.io/cloud). 4 | 5 | Web App URL: 6 | 7 | ## Instructions 8 | 9 | 1. For the GitHub repository or use it as a template for your own project. 10 | 2. Customize the sidebar by changing the sidebar text and logo in each Python file. 11 | 3. Find your favorite emoji from https://emojipedia.org. 12 | 4. Add a new app to the `pages/` directory with an emoji in the file name, e.g., 1_🚀_Chart.py. 13 | 14 | ## Demo 15 | 16 | ![](https://i.imgur.com/6lj0oAO.png) 17 | -------------------------------------------------------------------------------- /packages.txt: -------------------------------------------------------------------------------- 1 | gdal-bin 2 | libgdal-dev -------------------------------------------------------------------------------- /pages/1_🌍_Interactive_Map.py: -------------------------------------------------------------------------------- 1 | import streamlit as st 2 | import leafmap.foliumap as leafmap 3 | 4 | markdown = """ 5 | A Streamlit map template 6 | 7 | """ 8 | 9 | st.sidebar.title("About") 10 | st.sidebar.info(markdown) 11 | logo = "https://i.imgur.com/UbOXYAU.png" 12 | st.sidebar.image(logo) 13 | 14 | 15 | st.title("Interactive Map") 16 | 17 | col1, col2 = st.columns([4, 1]) 18 | options = list(leafmap.basemaps.keys()) 19 | index = options.index("OpenTopoMap") 20 | 21 | with col2: 22 | 23 | basemap = st.selectbox("Select a basemap:", options, index) 24 | 25 | 26 | with col1: 27 | 28 | m = leafmap.Map( 29 | locate_control=True, latlon_control=True, draw_export=True, minimap_control=True 30 | ) 31 | m.add_basemap(basemap) 32 | m.to_streamlit(height=700) 33 | -------------------------------------------------------------------------------- /pages/2_🪟_Split_Map.py: -------------------------------------------------------------------------------- 1 | import streamlit as st 2 | import leafmap.foliumap as leafmap 3 | 4 | st.set_page_config(layout="wide") 5 | 6 | markdown = """ 7 | A Streamlit map template 8 | 9 | """ 10 | 11 | st.sidebar.title("About") 12 | st.sidebar.info(markdown) 13 | logo = "https://i.imgur.com/UbOXYAU.png" 14 | st.sidebar.image(logo) 15 | 16 | st.title("Split-panel Map") 17 | 18 | with st.expander("See source code"): 19 | with st.echo(): 20 | m = leafmap.Map() 21 | m.split_map( 22 | left_layer="ESA WorldCover 2020 S2 FCC", right_layer="ESA WorldCover 2020" 23 | ) 24 | m.add_legend(title="ESA Land Cover", builtin_legend="ESA_WorldCover") 25 | 26 | m.to_streamlit(height=700) 27 | -------------------------------------------------------------------------------- /pages/3_📍_Marker_Cluster.py: -------------------------------------------------------------------------------- 1 | import streamlit as st 2 | import leafmap.foliumap as leafmap 3 | 4 | st.set_page_config(layout="wide") 5 | 6 | markdown = """ 7 | A Streamlit map template 8 | 9 | """ 10 | 11 | st.sidebar.title("About") 12 | st.sidebar.info(markdown) 13 | logo = "https://i.imgur.com/UbOXYAU.png" 14 | st.sidebar.image(logo) 15 | 16 | st.title("Marker Cluster") 17 | 18 | with st.expander("See source code"): 19 | with st.echo(): 20 | 21 | m = leafmap.Map(center=[40, -100], zoom=4) 22 | cities = "https://raw.githubusercontent.com/giswqs/leafmap/master/examples/data/us_cities.csv" 23 | regions = "https://raw.githubusercontent.com/giswqs/leafmap/master/examples/data/us_regions.geojson" 24 | 25 | m.add_geojson(regions, layer_name="US Regions") 26 | m.add_points_from_xy( 27 | cities, 28 | x="longitude", 29 | y="latitude", 30 | color_column="region", 31 | icon_names=["gear", "map", "leaf", "globe"], 32 | spin=True, 33 | add_legend=True, 34 | ) 35 | 36 | m.to_streamlit(height=700) 37 | -------------------------------------------------------------------------------- /pages/4_🔥_Heatmap.py: -------------------------------------------------------------------------------- 1 | import streamlit as st 2 | import leafmap.foliumap as leafmap 3 | 4 | st.set_page_config(layout="wide") 5 | 6 | markdown = """ 7 | A Streamlit map template 8 | 9 | """ 10 | 11 | st.sidebar.title("About") 12 | st.sidebar.info(markdown) 13 | logo = "https://i.imgur.com/UbOXYAU.png" 14 | st.sidebar.image(logo) 15 | 16 | st.title("Heatmap") 17 | 18 | with st.expander("See source code"): 19 | with st.echo(): 20 | filepath = "https://raw.githubusercontent.com/giswqs/leafmap/master/examples/data/us_cities.csv" 21 | m = leafmap.Map(center=[40, -100], zoom=4) 22 | m.add_heatmap( 23 | filepath, 24 | latitude="latitude", 25 | longitude="longitude", 26 | value="pop_max", 27 | name="Heat map", 28 | radius=20, 29 | ) 30 | m.to_streamlit(height=700) 31 | -------------------------------------------------------------------------------- /pages/5_🔍_Basemaps.py: -------------------------------------------------------------------------------- 1 | import streamlit as st 2 | import leafmap.foliumap as leafmap 3 | 4 | st.set_page_config(layout="wide") 5 | 6 | markdown = """ 7 | A Streamlit map template 8 | 9 | """ 10 | 11 | st.sidebar.title("About") 12 | st.sidebar.info(markdown) 13 | logo = "https://i.imgur.com/UbOXYAU.png" 14 | st.sidebar.image(logo) 15 | 16 | 17 | st.title("Searching Basemaps") 18 | st.markdown( 19 | """ 20 | This app is a demonstration of searching and loading basemaps from [xyzservices](https://github.com/geopandas/xyzservices) and [Quick Map Services (QMS)](https://github.com/nextgis/quickmapservices). Selecting from 1000+ basemaps with a few clicks. 21 | """ 22 | ) 23 | 24 | with st.expander("See demo"): 25 | st.image("https://i.imgur.com/0SkUhZh.gif") 26 | 27 | row1_col1, row1_col2 = st.columns([3, 1]) 28 | width = None 29 | height = 800 30 | tiles = None 31 | 32 | with row1_col2: 33 | 34 | checkbox = st.checkbox("Search Quick Map Services (QMS)") 35 | keyword = st.text_input("Enter a keyword to search and press Enter:") 36 | empty = st.empty() 37 | 38 | if keyword: 39 | options = leafmap.search_xyz_services(keyword=keyword) 40 | if checkbox: 41 | options = options + leafmap.search_qms(keyword=keyword) 42 | 43 | tiles = empty.multiselect("Select XYZ tiles to add to the map:", options) 44 | 45 | with row1_col1: 46 | m = leafmap.Map() 47 | 48 | if tiles is not None: 49 | for tile in tiles: 50 | m.add_xyz_service(tile) 51 | 52 | m.to_streamlit(width, height) 53 | -------------------------------------------------------------------------------- /pages/6_📦_Web_Map_Service.py: -------------------------------------------------------------------------------- 1 | import ast 2 | import streamlit as st 3 | import leafmap.foliumap as leafmap 4 | 5 | st.set_page_config(layout="wide") 6 | 7 | markdown = """ 8 | A Streamlit map template 9 | 10 | """ 11 | 12 | st.sidebar.title("About") 13 | st.sidebar.info(markdown) 14 | logo = "https://i.imgur.com/UbOXYAU.png" 15 | st.sidebar.image(logo) 16 | 17 | 18 | @st.cache_data 19 | def get_layers(url): 20 | options = leafmap.get_wms_layers(url) 21 | return options 22 | 23 | 24 | st.title("Web Map Service (WMS)") 25 | st.markdown( 26 | """ 27 | This app is a demonstration of loading Web Map Service (WMS) layers. Simply enter the URL of the WMS service 28 | in the text box below and press Enter to retrieve the layers. Go to https://apps.nationalmap.gov/services to find 29 | some WMS URLs if needed. 30 | """ 31 | ) 32 | 33 | row1_col1, row1_col2 = st.columns([3, 1.3]) 34 | width = None 35 | height = 600 36 | layers = None 37 | 38 | with row1_col2: 39 | 40 | esa_landcover = "https://services.terrascope.be/wms/v2" 41 | url = st.text_input( 42 | "Enter a WMS URL:", value="https://services.terrascope.be/wms/v2" 43 | ) 44 | empty = st.empty() 45 | 46 | if url: 47 | options = get_layers(url) 48 | 49 | default = None 50 | if url == esa_landcover: 51 | default = "WORLDCOVER_2020_MAP" 52 | layers = empty.multiselect( 53 | "Select WMS layers to add to the map:", options, default=default 54 | ) 55 | add_legend = st.checkbox("Add a legend to the map", value=True) 56 | if default == "WORLDCOVER_2020_MAP": 57 | legend = str(leafmap.builtin_legends["ESA_WorldCover"]) 58 | else: 59 | legend = "" 60 | if add_legend: 61 | legend_text = st.text_area( 62 | "Enter a legend as a dictionary {label: color}", 63 | value=legend, 64 | height=200, 65 | ) 66 | 67 | with row1_col1: 68 | m = leafmap.Map(center=(36.3, 0), zoom=2) 69 | 70 | if layers is not None: 71 | for layer in layers: 72 | m.add_wms_layer( 73 | url, layers=layer, name=layer, attribution=" ", transparent=True 74 | ) 75 | if add_legend and legend_text: 76 | legend_dict = ast.literal_eval(legend_text) 77 | m.add_legend(legend_dict=legend_dict) 78 | 79 | m.to_streamlit(width, height) 80 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | --find-links=https://girder.github.io/large_image_wheels GDAL 2 | geopandas 3 | leafmap 4 | owslib 5 | streamlit 6 | --------------------------------------------------------------------------------