Repository navigation
Add api_key option to TileLayer for providers that need a key - #2361
Open
nilay-v3rma wants to merge 1 commit into
Open
nilay-v3rma wants to merge 1 commit into
nilay-v3rma wants to merge 1 commit into
Conversation
CARTO now only serves its basemaps to requests that carry an API key,
and xyzservices strips the key placeholder and warns when none is given.
Folium had no way to pass a key through for built-in tile names, so
`TileLayer("CartoDB Positron")` always rendered watermarked tiles, and
an `apikey=` kwarg silently ended up as an unused Leaflet option.
`TileLayer` now takes `api_key`, which fills the provider's token
placeholder whatever the provider calls it (`apikey`, `accessToken`,
`subscriptionKey`, ...). It raises a ValueError when used with a custom
URL or a provider that has no placeholder, instead of being ignored.
Also note the key requirement in the Map and TileLayer docstrings and
stop using CartoDB tiles in the Map and DualMap docstring examples
without a key.
Refs python-visualization#2321
This branch has not been deployed
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Addresses part of #2321 (item 3, plus the docstrings from item 2).
Since CARTO started requiring an API key,
folium.TileLayer("CartoDB Positron")always renders "API KEY REQUIRED" tiles. You can't pass a key with a built-in name: xyzservices removes the?key={apikey}placeholder before folium gets the URL. Passingapikey="..."doesn't help either. It lands in the Leaflet options and is ignored without any error.Change
TileLayergets anapi_keyargument:apikey,apiKey,key,accessTokenorsubscriptionKey, so the same argument also works for Thunderforest, MapBox, Stadia and others. The placeholder is found with the ruleTileProvider.requires_token()uses: a field containing"<insert your"that appears in the URL. No provider has more than one such field.ValueErrorwhen given with a custom URL, or with a provider that has nothing to fill (no key needed, or a key is already set). Before this change the key was dropped without any error.provider(**{field: key}).Docstrings:
TileLayernow says CartoDB needs a key and documentsapi_key. TheMapdocstring explains how to pass a key, and its example uses one. TheDualMapexample now uses OpenStreetMap.Not in this PR
Mapitself doesn't get anapi_keyargument.Mapforwards only a few tile options, andtiles=TileLayer(...)is already how you pass anything more. I can addMap(..., api_key=...)if you'd like.Tests
New tests in
tests/test_raster_layers.pycheck that:TileProviderapikeyplaceholder (MapBox'saccessToken) is filledpre-commitandmypypass on the changed files.