-
Notifications
You must be signed in to change notification settings - Fork 2.2k
pydeck: support Maplibre including Globe projection #9896
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 2 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
125774f
pydeck: Update to [email protected]
felixpalmer de09c20
pydeck: support Maplibre including Globe projection
felixpalmer 2f04dea
Merge branch 'master' into felix/pydeck9.2-maplibre
felixpalmer d5e55f0
Simplify integration
felixpalmer 64505db
tidy
felixpalmer 20b14a0
Register styles properly
felixpalmer cf04406
Explicitly list mapbox for MapboxOverlay
felixpalmer fbec4e2
lint fixes
felixpalmer eb49eef
Lint
felixpalmer 7b518a4
Merge branch 'master' into felix/pydeck9.2-maplibre
felixpalmer File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| """ | ||
| A5Layer | ||
| ======= | ||
|
|
||
| Plot of bike parking density in San Francisco using the A5 geospatial indexing system. | ||
|
|
||
| A5 is a pentagonal discrete global grid system that provides equal-area cells worldwide. | ||
| Learn more at https://a5geo.org | ||
|
|
||
| This example is adapted from the deck.gl documentation. | ||
| """ | ||
|
|
||
| import pydeck as pdk | ||
| import pandas as pd | ||
|
|
||
| A5_DATA = "https://raw.githubusercontent.com/visgl/deck.gl-data/master/website/sf.bike.parking.a5.json" | ||
|
|
||
| df = pd.read_json(A5_DATA) | ||
|
|
||
| # Define a layer to display on a map | ||
| layer = pdk.Layer( | ||
| "A5Layer", | ||
| df, | ||
| pickable=True, | ||
| extruded=True, | ||
| get_pentagon="pentagon", | ||
| get_fill_color="[(1 - count / 211) * 235, 255 - 85 * count / 211, 255 - 170 * count / 211]", | ||
| get_elevation="count", | ||
| elevation_scale=10, | ||
| ) | ||
|
|
||
| # Set the viewport location - centered on San Francisco | ||
| view_state = pdk.ViewState( | ||
| latitude=37.74, | ||
| longitude=-122.4, | ||
| zoom=11, | ||
| bearing=0, | ||
| pitch=40 | ||
| ) | ||
|
|
||
| # Render | ||
| r = pdk.Deck( | ||
| layers=[layer], | ||
| initial_view_state=view_state, | ||
| tooltip={"text": "{pentagon} count: {count}"} | ||
| ) | ||
| r.to_html("a5_layer.html") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| """ | ||
| GlobeView | ||
| ========= | ||
|
|
||
| Over 33,000 power plants of the world plotted by their production capacity (given by height) | ||
| and fuel type (green if renewable) on a MapLibre globe view. | ||
|
|
||
| This example demonstrates using MapLibre's globe projection with deck.gl layers by setting | ||
| map_provider='maplibre' and map_projection='globe'. The globe view uses MapLibre's | ||
| MapboxOverlay with interleaved rendering for optimal performance. | ||
| """ | ||
| import pydeck as pdk | ||
| import pandas as pd | ||
|
|
||
| POWER_PLANTS = "https://raw.githubusercontent.com/ajduberstein/geo_datasets/master/global_power_plant_database.csv" | ||
|
|
||
| df = pd.read_csv(POWER_PLANTS) | ||
|
|
||
|
|
||
| def is_green(fuel_type): | ||
| """Return a green RGB value if a facility uses a renewable fuel type""" | ||
| if fuel_type.lower() in ("nuclear", "water", "wind", "hydro", "biomass", "solar", "geothermal"): | ||
| return [10, 230, 120] | ||
| return [230, 158, 10] | ||
|
|
||
|
|
||
| df["color"] = df["primary_fuel"].apply(is_green) | ||
|
|
||
| # Use MapView with a globe projection | ||
| view_state = pdk.ViewState(latitude=51.47, longitude=0.45, zoom=0) | ||
|
|
||
| layers = [ | ||
| pdk.Layer( | ||
| "ColumnLayer", | ||
| id="power-plant", | ||
| data=df, | ||
| get_elevation="capacity_mw", | ||
| get_position=["longitude", "latitude"], | ||
| elevation_scale=100, | ||
| pickable=True, | ||
| auto_highlight=True, | ||
| radius=20000, | ||
| get_fill_color="color", | ||
| ), | ||
| ] | ||
|
|
||
| deck = pdk.Deck( | ||
| initial_view_state=view_state, | ||
| tooltip={"text": "{name}, {primary_fuel} plant, {country}"}, | ||
| layers=layers, | ||
| # Use MapLibre with globe projection | ||
| map_provider="maplibre", | ||
| map_style="https://basemaps.cartocdn.com/gl/dark-matter-gl-style/style.json", | ||
| map_projection="globe", | ||
| ) | ||
|
|
||
| deck.to_html("maplibre_globe.html", css_background_color="black", offline=True) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,126 @@ | ||
| """ | ||
| Multi-View Widgets Example | ||
| =========================== | ||
|
|
||
| Demonstrates deck.gl widgets with multiple synchronized views using SplitterWidget. | ||
|
|
||
| This example shows: | ||
| - Two side-by-side MapView instances | ||
| - SplitterWidget to adjust the split between views | ||
| - Widgets assigned to specific views using view_id | ||
| - Synchronized navigation between views | ||
| """ | ||
| import pydeck as pdk | ||
|
|
||
| # Data sources | ||
| COUNTRIES = 'https://d2ad6b4ur7yvpq.cloudfront.net/naturalearth-3.3.0/ne_50m_admin_0_scale_rank.geojson' | ||
| AIR_PORTS = 'https://d2ad6b4ur7yvpq.cloudfront.net/naturalearth-3.3.0/ne_10m_airports.geojson' | ||
|
|
||
| # Initial view centered on London | ||
| INITIAL_VIEW_STATE = pdk.ViewState( | ||
| latitude=51.47, | ||
| longitude=0.45, | ||
| zoom=4, | ||
| bearing=0, | ||
| pitch=30 | ||
| ) | ||
|
|
||
| # Create two map views side-by-side | ||
| left_view = pdk.View( | ||
| type='MapView', | ||
| id='left-map', | ||
| x='0%', | ||
| width='50%', | ||
| controller=True | ||
| ) | ||
|
|
||
| right_view = pdk.View( | ||
| type='MapView', | ||
| id='right-map', | ||
| x='50%', | ||
| width='50%', | ||
| controller=True | ||
| ) | ||
|
|
||
| # Layers | ||
| countries_layer = pdk.Layer( | ||
| 'GeoJsonLayer', | ||
| id='base-map', | ||
| data=COUNTRIES, | ||
| stroked=True, | ||
| filled=True, | ||
| line_width_min_pixels=2, | ||
| opacity=0.4, | ||
| get_line_color=[60, 60, 60], | ||
| get_fill_color=[200, 200, 200] | ||
| ) | ||
|
|
||
| airports_layer = pdk.Layer( | ||
| 'GeoJsonLayer', | ||
| id='airports', | ||
| data=AIR_PORTS, | ||
| filled=True, | ||
| point_radius_min_pixels=2, | ||
| point_radius_scale=2000, | ||
| get_point_radius='11 - properties.scalerank', | ||
| get_fill_color=[200, 0, 80, 180], | ||
| pickable=True, | ||
| auto_highlight=True | ||
| ) | ||
|
|
||
| # Create widgets - some are assigned to specific views | ||
| widgets = [ | ||
| # Left map widgets | ||
| pdk.Widget('ZoomWidget', view_id='left-map'), | ||
| pdk.Widget('CompassWidget', view_id='left-map'), | ||
| pdk.Widget('FullscreenWidget', view_id='left-map'), | ||
| pdk.Widget('ScreenshotWidget', view_id='left-map'), | ||
| pdk.Widget('ResetViewWidget', view_id='left-map'), | ||
| pdk.Widget('FpsWidget', view_id='left-map'), | ||
| pdk.Widget('LoadingWidget', view_id='left-map'), | ||
| pdk.Widget('ThemeWidget', view_id='left-map'), | ||
| pdk.Widget('StatsWidget', statsType='luma', view_id='left-map'), | ||
|
|
||
| # Right map widgets | ||
| pdk.Widget('GeocoderWidget', view_id='right-map'), | ||
|
|
||
| # Global widgets (not tied to a specific view) | ||
| pdk.Widget('ScaleWidget', placement='bottom-right'), | ||
| pdk.Widget('InfoWidget', mode='hover'), | ||
| pdk.Widget('InfoWidget', mode='click'), | ||
| pdk.Widget('ContextMenuWidget'), | ||
| pdk.Widget('TimelineWidget', | ||
| placement='bottom-left', | ||
| time_range=[0, 24], | ||
| step=1, | ||
| initial_time=0, | ||
| play_interval=1000 | ||
| ), | ||
|
|
||
| # Splitter widget to adjust view sizes | ||
| pdk.Widget('SplitterWidget', | ||
| view_id1='left-map', | ||
| view_id2='right-map', | ||
| orientation='vertical' | ||
| ) | ||
| ] | ||
|
|
||
| # Create deck with multiple views | ||
| deck = pdk.Deck( | ||
| views=[left_view, right_view], | ||
| initial_view_state={ | ||
| 'left-map': INITIAL_VIEW_STATE, | ||
| 'right-map': INITIAL_VIEW_STATE | ||
| }, | ||
| layers=[countries_layer, airports_layer], | ||
| widgets=widgets, | ||
| tooltip={ | ||
| 'text': '{properties.name} ({properties.abbrev})\n{properties.type}' | ||
| }, | ||
| map_provider='carto', | ||
| map_style='https://basemaps.cartocdn.com/gl/positron-gl-style/style.json' | ||
| ) | ||
|
|
||
| # Save to HTML | ||
| deck.to_html('widgets.html', css_background_color='#f0f0f0', offline=True) | ||
| print('Saved to widgets.html') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1 @@ | ||
| DECKGL_SEMVER = "~9.1.*" | ||
| DECKGL_SEMVER = "~9.2.*" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,6 +10,7 @@ | |
| {% endif %} | ||
| <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap-theme.min.css" /> | ||
| <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.6.3/css/font-awesome.min.css" /> | ||
| <link rel="stylesheet" href="https://unpkg.com/[email protected]/dist/maplibre-gl.css" /> | ||
| {{ deckgl_jupyter_widget_bundle }} | ||
| <link rel="stylesheet" href={{ deckgl_widget_css_url }} /> | ||
| <style> | ||
|
|
@@ -26,6 +27,7 @@ | |
| const tooltip = {{tooltip}}; | ||
| const customLibraries = {{custom_libraries or 'null'}}; | ||
| const configuration = {{configuration or 'null'}}; | ||
| const mapProjection = {{map_projection}}; | ||
|
|
||
| const deckInstance = createDeck({ | ||
| {% if mapbox_key %} | ||
|
|
@@ -39,6 +41,7 @@ | |
| tooltip, | ||
| customLibraries, | ||
| configuration, | ||
| mapProjection, | ||
| {% if show_error %} | ||
| showError: true, | ||
| {% endif %} | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.