Spaces:
Sleeping
Sleeping
# -*- coding: utf-8 -*- | |
# Licensed under the Apache License, Version 2.0 (the "License"); | |
# you may not use this file except in compliance with the License. | |
# You may obtain a copy of the License at | |
# | |
# http://www.apache.org/licenses/LICENSE-2.0 | |
# | |
# Unless required by applicable law or agreed to in writing, software | |
# distributed under the License is distributed on an "AS IS" BASIS, | |
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
# See the License for the specific language governing permissions and | |
# limitations under the License. | |
import leafmap.foliumap as leafmap | |
import streamlit as st | |
st.set_page_config(layout="wide", page_title="Protected Areas Explorer", page_icon=":globe:") | |
# + | |
public = "https://minio.carlboettiger.info/shared-data/pad/public.pmtiles" | |
tribal = "https://minio.carlboettiger.info/shared-data/pad/tribal.pmtiles" | |
private = "https://minio.carlboettiger.info/shared-data/pad/private.pmtiles" | |
mixed = "https://minio.carlboettiger.info/shared-data/pad/mixed.pmtiles" | |
red = "#850101" | |
purple = "#BF40BF" | |
green = "#005a00" | |
blue = "#3388ff" | |
public_style = { | |
"version": 8, | |
"sources": { | |
"public": { | |
"type": "vector", | |
"url": "pmtiles://" + public, | |
"attribution": "US PAD v3"}}, | |
"layers": [{ | |
"id": "public", | |
"source": "public", | |
"source-layer": "public_protected", | |
"type": "fill", | |
"paint": {"fill-color": blue, "fill-opacity": 0.5}}]} | |
private_style = { | |
"version": 8, | |
"sources": { | |
"private": { | |
"type": "vector", | |
"url": "pmtiles://" + private, | |
"attribution": "US PAD v3",}}, | |
"layers": [ | |
{ | |
"id": "private", | |
"source": "private", | |
"source-layer": "private_protected", | |
"type": "fill", | |
"paint": {"fill-color": red, "fill-opacity": 0.5}}]} | |
tribal_style = { | |
"version": 8, | |
"sources": { | |
"tribal": { | |
"type": "vector", | |
"url": "pmtiles://" + tribal, | |
"attribution": "US PAD v3"}}, | |
"layers": [{ | |
"id": "tribal", | |
"source": "tribal", | |
"source-layer": "tribal_protected", | |
"type": "fill", | |
"paint": {"fill-color": purple, "fill-opacity": 0.6}}]} | |
mixed_style = { | |
"version": 8, | |
"sources": { | |
"mixed": { | |
"type": "vector", | |
"url": "pmtiles://" + mixed, | |
"attribution": "US PAD v3"}}, | |
"layers": [{ | |
"id": "mixed", | |
"source": "mixed", | |
"source-layer": "mixed_protected", | |
"type": "fill", | |
"paint": {"fill-color": green, "fill-opacity": 0.6}}]} | |
# - | |
## Tooltip layer -- hack | |
combined_style = { | |
"version": 8, | |
"sources": { | |
"public": { | |
"type": "vector", | |
"url": "pmtiles://" + public, | |
"attribution": "PMTiles"}, | |
"tribal": { | |
"type": "vector", | |
"url": "pmtiles://" + tribal, | |
"attribution": "PMTiles"}, | |
"private": { | |
"type": "vector", | |
"url": "pmtiles://" + private, | |
"attribution": "PMTiles"}, | |
"mixed": { | |
"type": "vector", | |
"url": "pmtiles://" + mixed, | |
"attribution": "PMTiles"}}, | |
"layers": [{ | |
"id": "mixed", | |
"source": "mixed", | |
"source-layer": "mixed_protected", | |
"type": "fill", | |
"paint": {"fill-color": green, "fill-opacity": 0.}}, | |
{ | |
"id": "tribal", | |
"source": "tribal", | |
"source-layer": "tribal_protected", | |
"type": "fill", | |
"paint": {"fill-color": purple, "fill-opacity": 0.} | |
}, | |
{ | |
"id": "public", | |
"source": "public", | |
"source-layer": "public_protected", | |
"type": "fill", | |
"paint": {"fill-color": blue, "fill-opacity": 0.} | |
}, | |
{ | |
"id": "private", | |
"source": "private", | |
"source-layer": "private_protected", | |
"type": "fill", | |
"paint": {"fill-color": red, "fill-opacity": 0.}}]} | |
# + | |
m = leafmap.Map(center=[35, -100], zoom=3) | |
m.add_basemap("CartoDB.DarkMatter") | |
m.add_tile_layer( | |
url="https://minio.carlboettiger.info/shared-data/mobi-tiles/grey/{z}/{x}/{y}.png", | |
name="Imperiled Species Richness (Greyscale)", | |
attribution="NatureServe", | |
opacity=0.99 | |
) | |
m.add_pmtiles( public, name="Public", style=public_style, overlay=True, show=True, zoom_to_layer=False) | |
m.add_pmtiles(private, name="Private", style=private_style, overlay=True, show=True, zoom_to_layer=False) | |
m.add_pmtiles(tribal, name="Tribal", style=tribal_style, overlay=True, show=True, zoom_to_layer=False) | |
m.add_pmtiles(mixed, name="Mixed", style=mixed_style, overlay=True, show=True, zoom_to_layer=False) | |
m.add_pmtiles(tribal, name="tooltip", style=combined_style, overlay=True, show=True, zoom_to_layer=False) | |
m.to_streamlit(height=900) | |
# - | |
## Tooltip layer -- hack | |
style = { | |
"version": 8, | |
"sources": { | |
"public": { | |
"type": "vector", | |
"url": "pmtiles://" + public, | |
"attribution": "PMTiles"}, | |
"tribal": { | |
"type": "vector", | |
"url": "pmtiles://" + tribal, | |
"attribution": "PMTiles"}, | |
"private": { | |
"type": "vector", | |
"url": "pmtiles://" + private, | |
"attribution": "PMTiles"}, | |
"mixed": { | |
"type": "vector", | |
"url": "pmtiles://" + mixed, | |
"attribution": "PMTiles"}}, | |
"layers": [{ | |
"id": "mixed", | |
"source": "mixed", | |
"source-layer": "mixed_protected", | |
"type": "fill", | |
"paint": {"fill-color": green, "fill-opacity": 0.5}}, | |
{ | |
"id": "tribal", | |
"source": "tribal", | |
"source-layer": "tribal_protected", | |
"type": "fill", | |
"paint": {"fill-color": purple, "fill-opacity": 0.5} | |
}, | |
{ | |
"id": "public", | |
"source": "public", | |
"source-layer": "public_protected", | |
"type": "fill", | |
"paint": {"fill-color": blue, "fill-opacity": 0.5} | |
}, | |
{ | |
"id": "private", | |
"source": "private", | |
"source-layer": "private_protected", | |
"type": "fill", | |
"paint": {"fill-color": red, "fill-opacity": 0.5}}]} | |
# + | |
st.write("# MOBI Species Richness (Light theme)") | |
# style = leafmap.pmtiles_style(url) # Use default style | |
m = leafmap.Map(center=[35, -100], zoom=4) | |
m.add_basemap("Esri.WorldGrayCanvas") | |
m.add_tile_layer( | |
url="https://minio.carlboettiger.info/shared-data/mobi-tiles/red/{z}/{x}/{y}.png", | |
name="MOBI", | |
attribution="NatureServe", | |
opacity=0.9 | |
) | |
m.add_pmtiles( | |
tribal, name="PMTiles", style=style, overlay=True, show=True, zoom_to_layer=False | |
) | |
m.to_streamlit(height=900) | |