-
Notifications
You must be signed in to change notification settings - Fork 2.2k
feat(pydeck): add mapId support for Google Maps #10084
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -62,6 +62,8 @@ def __init__( | |
| Dictionary of geospatial API service providers, where the keys are ``mapbox``, ``google_maps``, or ``carto`` | ||
| and the values are the API key. Defaults to None if not set. Any of the environment variables | ||
| ``MAPBOX_API_KEY``, ``GOOGLE_MAPS_API_KEY``, and ``CARTO_API_KEY`` can be set instead of hardcoding the key here. | ||
| If using Google Maps, you can also provide a ``google_maps_map_id`` in this dictionary to enable | ||
| Vector Map features (like 3D tilt and rotation), or set the ``GOOGLE_MAPS_MAP_ID`` environment variable. | ||
| map_provider : str, default 'carto' | ||
| If multiple API keys are set (e.g., both Mapbox and Google Maps), inform pydeck which basemap provider to prefer. | ||
| Values can be ``carto``, ``mapbox``, ``google_maps``, or ``maplibre``. | ||
|
|
@@ -151,16 +153,24 @@ def selected_data(self): | |
|
|
||
| def _set_api_keys(self, api_keys: dict = None): | ||
| """Sets API key for base map provider for both HTML embedding and the Jupyter widget""" | ||
| valid_providers = [p.value for p in BaseMapProvider] | ||
| for k in api_keys: | ||
| k and BaseMapProvider(k) | ||
| if k in valid_providers: | ||
| BaseMapProvider(k) | ||
| for provider in BaseMapProvider: | ||
| attr_name = f"{provider.value}_key" | ||
| provider_env_var = f"{provider.name}_API_KEY" | ||
| attr_value = api_keys.get(provider.value) or os.getenv(provider_env_var) | ||
| attr_value = api_keys.get(provider.value) or api_keys.get(attr_name) or os.getenv(provider_env_var) | ||
| setattr(self, attr_name, attr_value) | ||
| if has_jupyter_extra(): | ||
| setattr(self.deck_widget, attr_name, attr_value) | ||
|
|
||
| # Handle google_maps_map_id specifically | ||
| gm_map_id = api_keys.get("google_maps_map_id") or os.getenv("GOOGLE_MAPS_MAP_ID") | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually, in general it is a bit weird to set the mapId in def _set_google_maps_map_id(self, map_id=None):
self.google_maps_map_id = map_id or os.getenv("GOOGLE_MAPS_MAP_ID")
if has_jupyter_extra():
self.deck_widget.google_maps_map_id = self.google_maps_map_id |
||
| self.google_maps_map_id = gm_map_id | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. use setattr like the current code? |
||
| if has_jupyter_extra(): | ||
| self.deck_widget.google_maps_map_id = gm_map_id | ||
|
|
||
| def show(self): | ||
| """Display current Deck object for a Jupyter notebook""" | ||
| # TODO: Jupyter-specific features not currently supported in pydeck v0.9. | ||
|
|
@@ -238,6 +248,7 @@ def to_html( | |
| deck_json, | ||
| mapbox_key=self.mapbox_key, | ||
| google_maps_key=self.google_maps_key, | ||
| google_maps_map_id=self.google_maps_map_id, | ||
| filename=filename, | ||
| open_browser=open_browser, | ||
| notebook_display=notebook_display, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -131,6 +131,7 @@ function createStandaloneFromProvider({ | |
| props, | ||
| mapboxApiKey, | ||
| googleMapsKey, | ||
| googleMapsMapId, | ||
| handleEvent, | ||
| getTooltip, | ||
| container, | ||
|
|
@@ -183,7 +184,8 @@ function createStandaloneFromProvider({ | |
| return createGoogleMapsDeckOverlay({ | ||
| ...sharedProps, | ||
| ...props, | ||
| googleMapsKey | ||
| googleMapsKey, | ||
| googleMapsMapId | ||
| }); | ||
| case 'maplibre': | ||
| log.info('Using MapLibre')(); | ||
|
|
@@ -202,9 +204,10 @@ function createStandaloneFromProvider({ | |
| } | ||
| } | ||
|
|
||
| function createDeck({ | ||
| export function createDeck({ | ||
| mapboxApiKey, | ||
| googleMapsKey, | ||
| googleMapsMapId, | ||
| container, | ||
| jsonInput, | ||
| tooltip, | ||
|
|
@@ -251,6 +254,7 @@ function createDeck({ | |
| props, | ||
| mapboxApiKey, | ||
| googleMapsKey, | ||
| googleMapsMapId, | ||
| handleEvent, | ||
| getTooltip, | ||
| container, | ||
|
|
@@ -284,4 +288,4 @@ function createDeck({ | |
| return deckgl; | ||
| } | ||
|
|
||
| export {createDeck, updateDeck, jsonConverter}; | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why this change? |
||
| export {updateDeck, jsonConverter}; | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The old code called BaseMapProvider(k) on every key, which would raise ValueError for unknown keys — acting as input validation. The new code silently ignores unknown keys. This is needed because google_maps_map_id isn't a provider, but it also means typos like api_keys={"mapbx": "key"} will silently be ignored instead of raising an error. A better approach would be to define an allowlist of known non-provider keys: