Skip to content

Commit 0300085

Browse files
authored
Add support for Google Maps API key (#1131)
* Add support for Google Maps API key * Remove API key from workflows * Update tests * Update tests * Remove warning
1 parent 103eb00 commit 0300085

12 files changed

Lines changed: 232 additions & 104 deletions

File tree

.github/workflows/docs-build.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ jobs:
1919
MAPBOX_TOKEN: ${{ secrets.MAPBOX_TOKEN }}
2020
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
2121
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
22-
GOOGLE_MAPS_API_KEY: ${{ secrets.GOOGLE_MAPS_API_KEY }}
2322
EARTHDATA_USERNAME: ${{ secrets.EARTHDATA_USERNAME }}
2423
EARTHDATA_PASSWORD: ${{ secrets.EARTHDATA_PASSWORD }}
2524
MAPILLARY_API_KEY: ${{ secrets.MAPILLARY_API_KEY }}

.github/workflows/docs.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ jobs:
1919
MAPBOX_TOKEN: ${{ secrets.MAPBOX_TOKEN }}
2020
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
2121
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
22-
GOOGLE_MAPS_API_KEY: ${{ secrets.GOOGLE_MAPS_API_KEY }}
2322
EARTHDATA_USERNAME: ${{ secrets.EARTHDATA_USERNAME }}
2423
EARTHDATA_PASSWORD: ${{ secrets.EARTHDATA_PASSWORD }}
2524
MAPILLARY_API_KEY: ${{ secrets.MAPILLARY_API_KEY }}

.github/workflows/py313.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ jobs:
2424
MAPBOX_TOKEN: ${{ secrets.MAPBOX_TOKEN }}
2525
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
2626
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
27-
GOOGLE_MAPS_API_KEY: ${{ secrets.GOOGLE_MAPS_API_KEY }}
27+
2828
MAPILLARY_API_KEY: ${{ secrets.MAPILLARY_API_KEY }}
2929

3030
steps:

.github/workflows/ubuntu.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ jobs:
2424
MAPBOX_TOKEN: ${{ secrets.MAPBOX_TOKEN }}
2525
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
2626
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
27-
GOOGLE_MAPS_API_KEY: ${{ secrets.GOOGLE_MAPS_API_KEY }}
2827
MAPILLARY_API_KEY: ${{ secrets.MAPILLARY_API_KEY }}
2928

3029
steps:

.github/workflows/windows.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ jobs:
2121
MAPBOX_TOKEN: ${{ secrets.MAPBOX_TOKEN }}
2222
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
2323
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
24-
GOOGLE_MAPS_API_KEY: ${{ secrets.GOOGLE_MAPS_API_KEY }}
2524
MAPILLARY_API_KEY: ${{ secrets.MAPILLARY_API_KEY }}
2625

2726
steps:

docs/notebooks/02_using_basemaps.ipynb

Lines changed: 22 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -57,44 +57,14 @@
5757
"cell_type": "markdown",
5858
"id": "5",
5959
"metadata": {},
60-
"source": [
61-
"Specify a Google basemap to use, can be one of [\"ROADMAP\", \"TERRAIN\", \"SATELLITE\", \"HYBRID\"]."
62-
]
63-
},
64-
{
65-
"cell_type": "code",
66-
"execution_count": null,
67-
"id": "6",
68-
"metadata": {},
69-
"outputs": [],
70-
"source": [
71-
"m = leafmap.Map(google_map=\"HYBRID\")\n",
72-
"m"
73-
]
74-
},
75-
{
76-
"cell_type": "code",
77-
"execution_count": null,
78-
"id": "7",
79-
"metadata": {},
80-
"outputs": [],
81-
"source": [
82-
"m = leafmap.Map(google_map=\"TERRAIN\")\n",
83-
"m"
84-
]
85-
},
86-
{
87-
"cell_type": "markdown",
88-
"id": "8",
89-
"metadata": {},
9060
"source": [
9161
"Add a basemap using the `add_basemap()` function."
9262
]
9363
},
9464
{
9565
"cell_type": "code",
9666
"execution_count": null,
97-
"id": "9",
67+
"id": "6",
9868
"metadata": {},
9969
"outputs": [],
10070
"source": [
@@ -106,7 +76,7 @@
10676
},
10777
{
10878
"cell_type": "markdown",
109-
"id": "10",
79+
"id": "7",
11080
"metadata": {},
11181
"source": [
11282
"Add an XYZ tile layer."
@@ -115,7 +85,7 @@
11585
{
11686
"cell_type": "code",
11787
"execution_count": null,
118-
"id": "11",
88+
"id": "8",
11989
"metadata": {},
12090
"outputs": [],
12191
"source": [
@@ -130,7 +100,7 @@
130100
},
131101
{
132102
"cell_type": "markdown",
133-
"id": "12",
103+
"id": "9",
134104
"metadata": {},
135105
"source": [
136106
"Add a WMS tile layer."
@@ -139,7 +109,7 @@
139109
{
140110
"cell_type": "code",
141111
"execution_count": null,
142-
"id": "13",
112+
"id": "10",
143113
"metadata": {},
144114
"outputs": [],
145115
"source": [
@@ -153,7 +123,7 @@
153123
},
154124
{
155125
"cell_type": "markdown",
156-
"id": "14",
126+
"id": "11",
157127
"metadata": {},
158128
"source": [
159129
"Add a legend to the map."
@@ -162,11 +132,12 @@
162132
{
163133
"cell_type": "code",
164134
"execution_count": null,
165-
"id": "15",
135+
"id": "12",
166136
"metadata": {},
167137
"outputs": [],
168138
"source": [
169-
"m = leafmap.Map(google_map=\"HYBRID\")\n",
139+
"m = leafmap.Map()\n",
140+
"m.add_basemap(\"Hybrid\")\n",
170141
"\n",
171142
"url1 = \"https://www.fws.gov/wetlands/arcgis/services/Wetlands/MapServer/WMSServer?\"\n",
172143
"m.add_wms_layer(\n",
@@ -185,9 +156,21 @@
185156
],
186157
"metadata": {
187158
"kernelspec": {
188-
"display_name": "Python 3",
159+
"display_name": "geo",
189160
"language": "python",
190161
"name": "python3"
162+
},
163+
"language_info": {
164+
"codemirror_mode": {
165+
"name": "ipython",
166+
"version": 3
167+
},
168+
"file_extension": ".py",
169+
"mimetype": "text/x-python",
170+
"name": "python",
171+
"nbconvert_exporter": "python",
172+
"pygments_lexer": "ipython3",
173+
"version": "3.12.2"
191174
}
192175
},
193176
"nbformat": 4,

leafmap/basemaps.py

Lines changed: 7 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@
2525
import folium
2626
import ipyleaflet
2727
import xyzservices
28-
from .common import check_package, planet_tiles
28+
from .common import check_package, planet_tiles, GoogleMapsTileProvider
2929

30-
GOOGLE_MAPS_API_KEY = os.environ.get("GOOGLE_MAPS_API_KEY", "YOUR-API-KEY")
30+
GOOGLE_MAPS_API_KEY = os.environ.get("GOOGLE_MAPS_API_KEY", None)
3131

3232
XYZ_TILES = {
3333
"OpenStreetMap": {
@@ -38,29 +38,13 @@
3838
}
3939

4040
# Add Google basemaps if API key is detected in the environment variables.
41-
if GOOGLE_MAPS_API_KEY != "":
41+
if GOOGLE_MAPS_API_KEY is not None:
4242
XYZ_TILES.update(
4343
{
44-
"ROADMAP": {
45-
"url": f"https://mt1.google.com/vt/lyrs=m&x={{x}}&y={{y}}&z={{z}}&key={GOOGLE_MAPS_API_KEY}",
46-
"attribution": "Google",
47-
"name": "Google Maps",
48-
},
49-
"SATELLITE": {
50-
"url": f"https://mt1.google.com/vt/lyrs=s&x={{x}}&y={{y}}&z={{z}}&key={GOOGLE_MAPS_API_KEY}",
51-
"attribution": "Google",
52-
"name": "Google Satellite",
53-
},
54-
"TERRAIN": {
55-
"url": f"https://mt1.google.com/vt/lyrs=p&x={{x}}&y={{y}}&z={{z}}&key={GOOGLE_MAPS_API_KEY}",
56-
"attribution": "Google",
57-
"name": "Google Terrain",
58-
},
59-
"HYBRID": {
60-
"url": f"https://mt1.google.com/vt/lyrs=y&x={{x}}&y={{y}}&z={{z}}&key={GOOGLE_MAPS_API_KEY}",
61-
"attribution": "Google",
62-
"name": "Google Hybrid",
63-
},
44+
"ROADMAP": GoogleMapsTileProvider(map_type="roadmap"),
45+
"SATELLITE": GoogleMapsTileProvider(map_type="satellite"),
46+
"TERRAIN": GoogleMapsTileProvider(map_type="terrain"),
47+
"HYBRID": GoogleMapsTileProvider(map_type="hybrid"),
6448
}
6549
)
6650
else: # If Google Maps API key is not detected, defaulting to Esri basemaps.

0 commit comments

Comments
 (0)