-
I am trying to visualize two PMTiles layers using leafmap, and for some reason, the below code is not working without any error messages. Any hints? import leafmap.foliumap as leafmap
parcel_url = 'https://lidar.digitalforestry.org/vt/in/2022/IN2022-Parcels.pmtiles'
parcel_metadata = leafmap.pmtiles_metadata(parcel_url)
print(f"layer names: {parcel_metadata['layer_names']}")
print(f"bounds: {parcel_metadata['bounds']}")
ap_url = 'https://lidar.digitalforestry.org/vt/in/2022/IN2022-Address_Points.pmtiles'
ap_metadata = leafmap.pmtiles_metadata(ap_url)
print(f"layer names: {ap_metadata['layer_names']}")
print(f"bounds: {ap_metadata['bounds']}")
m = leafmap.Map(center=[37, -88], zoom=6, height='800px')
m.add_basemap('CartoDB.DarkMatter')
m.add_basemap('Esri.WorldImagery', show=False)
parcel_style = {
"version": 8,
"sources": {
"parcel_source": {
"type": "vector",
"url": "pmtiles://" + parcel_url,
"attribution": 'PMTiles',
}
},
"layers": [
{
"id": "parcel",
"source": "parcel_source",
"source-layer": "in2022_parcels",
"type": "fill",
"paint": {"fill-color": "#3388ff", "fill-opacity": 0.5},
},
],
}
ap_style = {
"version": 8,
"sources": {
"ap_source": {
"type": "vector",
"url": "pmtiles://" + ap_url,
"attribution": 'PMTiles',
}
},
"layers": [
{
"id": "in2022_address_points",
"source": "ap_source",
"source-layer": "in2022_address_points",
"type": "circle",
"paint": {
"circle-radius": 3,
"circle-color": "#0000ff"
},
},
],
}
m.add_pmtiles(
parcel_url, name='Parcels', style=parcel_style, overlay=True, show=True, zoom_to_layer=False
)
m.add_pmtiles(
ap_url, style=ap_style, name='Address Points', overlay=True, show=True, zoom_to_layer=False
)
m |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 10 replies
-
It appears that the folium backend has some issues with multiple layers. I don't have a solution yet. If you install the pmtiles branch from my ipyleaflet repo, it can support multiple layers. I am not sure when ipyleaflet will accept my PR jupyter-widgets/ipyleaflet#1138 pip install git+https://github.com/giswqs/ipyleaflet.git@pmtiles import leafmap
m = leafmap.Map()
parcel_url = 'https://lidar.digitalforestry.org/vt/in/2022/IN2022-Parcels.pmtiles'
ap_url = 'https://lidar.digitalforestry.org/vt/in/2022/IN2022-Address_Points.pmtiles'
parcel_style = {
"version": 8,
"sources": {
"example_source": {
"type": "vector",
"url": "pmtiles://" + parcel_url,
"attribution": 'PMTiles',
}
},
"layers": [
{
"id": "in2022_parcels",
"source": "example_source",
"source-layer": "in2022_parcels",
"type": "fill",
"paint": {"fill-color": "#3388ff", "fill-opacity": 0.5},
},
],
}
ap_style = {
"version": 8,
"sources": {
"ap_source": {
"type": "vector",
"url": "pmtiles://" + ap_url,
"attribution": 'PMTiles',
}
},
"layers": [
{
"id": "in2022_address_points",
"source": "ap_source",
"source-layer": "in2022_address_points",
"type": "circle",
"paint": {
"circle-radius": 3,
"circle-color": "#0000ff"
},
},
],
}
m.add_pmtiles(
parcel_url, name='PMTiles', style=parcel_style, overlay=True, show=True, zoom_to_layer=True
)
m.add_pmtiles(
ap_url, style=ap_style, name='Address Points', overlay=True, show=True, zoom_to_layer=True
)
m |
Beta Was this translation helpful? Give feedback.
-
The installation sequence probably cause this issue. Here is how I installed it. Install the pmtiles branch first, then install leafmap. Otherwise, the git installation might not overwrite the the existing ipyleaflet that comes with leafmap. I will see if I can publish the pmtiles branch as a PyPI package so that the installation is eaiser. conda create -n pm python=3.11
conda activate pm
pip install git+https://github.com/giswqs/ipyleaflet.git@pmtiles
pip install leafmap pmtiles jupyterlab
jupyter lab |
Beta Was this translation helpful? Give feedback.
-
I have published the ipyleaflet wheel here. It should now be easier to install it without having to complie the source code. It should work out of the box. conda create -n pm python=3.11
conda activate pm
pip install https://github.com/opengeos/data/releases/download/v1.0.0/ipyleaflet-0.17.4-py3-none-any.whl
pip install leafmap pmtiles jupyterlab
jupyter lab |
Beta Was this translation helpful? Give feedback.
-
@jinha v0.29.8 now supports rendering multiple layers with the folium backend. ipyleaflet also support visualizing PMTiles now. |
Beta Was this translation helpful? Give feedback.
The installation sequence probably cause this issue. Here is how I installed it. Install the pmtiles branch first, then install leafmap. Otherwise, the git installation might not overwrite the the existing ipyleaflet that comes with leafmap. I will see if I can publish the pmtiles branch as a PyPI package so that the installation is eaiser.