Skip to content

Instantly share code, notes, and snippets.

@diehl
Created April 18, 2023 04:05
Show Gist options
  • Save diehl/c28319ce709ec7ad543c82d2167878cc to your computer and use it in GitHub Desktop.
Save diehl/c28319ce709ec7ad543c82d2167878cc to your computer and use it in GitHub Desktop.
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "markdown",
"id": "db9ad12b",
"metadata": {},
"source": [
"# Prerequisites"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "c7d97c39",
"metadata": {},
"outputs": [],
"source": [
"!pip install pydeck==0.8.0\n",
"!pip install panel==0.14.3"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "d882a739",
"metadata": {},
"outputs": [],
"source": [
"import pydeck as pdk\n",
"import panel as pn\n",
"pn.extension('deckgl')"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "ffbe55b8",
"metadata": {},
"outputs": [],
"source": [
"ACCESS_TOKEN = \"pk.eyJ1IjoicGFuZWxvcmciLCJhIjoiY2s1enA3ejhyMWhmZjNobjM1NXhtbWRrMyJ9.B_frQsAVepGIe-HiOJeqvQ\""
]
},
{
"cell_type": "markdown",
"id": "b6db8443",
"metadata": {},
"source": [
"# Load the PyDeck Visualization with the Initial Basemap\n",
"## Question: Toggling between _light_ and _satellite_ updates _map_style_ but does not trigger a reload of the PyDeck pane. What else is required to trigger the update?"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "60567d6a",
"metadata": {},
"outputs": [],
"source": [
"INITIAL_VIEW_STATE = pdk.ViewState(\n",
" latitude=38,\n",
" longitude=-97,\n",
" zoom=3,\n",
" min_zoom=3,\n",
" max_zoom=16,\n",
" pitch=0,\n",
" bearing=0\n",
")\n",
"\n",
"mvt_layer = pdk.Layer(\n",
" \"MVTLayer\",\n",
" 'https://api.mapbox.com/v4/diehl.6baso3o2/{z}/{x}/{y}.mvt?access_token='+ACCESS_TOKEN,\n",
" get_line_color = [0, 255, 0],\n",
" get_fill_color = [0, 0, 0, 0], # Transparent fill\n",
" line_width_min_pixels = 1,\n",
" pickable=True\n",
")\n",
"\n",
"TOOLTIP_HTML = ('<b>{properties.ALLOT_NAME}</b><br />'\n",
" '<b>Allotment #</b>: {properties.ST_ALLOT}<br />'\n",
" '<b>Acres</b>: {properties.GIS_ACRES}<br />')\n",
"\n",
"r = pdk.Deck(\n",
" layers=[mvt_layer],\n",
" initial_view_state=INITIAL_VIEW_STATE,\n",
" map_provider='mapbox',\n",
" map_style='light',\n",
" tooltip={'html': TOOLTIP_HTML},\n",
" api_keys={'mapbox': ACCESS_TOKEN}\n",
")\n",
"\n",
"map = pn.pane.DeckGL(r,sizing_mode='stretch_both') \n",
"basemap = pn.widgets.Select(name='Basemap', options=['light','satellite'])\n",
"basemap.link(map.object, value='map_style')\n",
"row = pn.Row(basemap,map,sizing_mode='stretch_both')\n",
"row.show()"
]
}
],
"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.9.16"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment