Skip to content
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

Add Google map tiles #1963

Open
wants to merge 21 commits into
base: master
Choose a base branch
from
Open

Add Google map tiles #1963

wants to merge 21 commits into from

Conversation

giswqs
Copy link
Member

@giswqs giswqs commented Apr 6, 2024

The PR adds a google_map_tiles() function for for generating Google Map tiles. To get an API key and enable Map Tiles API, visit https://developers.google.com/maps/get-started#create-project. The API key can be set as an environment variable MAPS_API_KEY or as a Colab secret.

@jdbcode @naschmitz For now, I only add the fucntion to generate the xyzservices.TileProvider. Two more things to discuss:

  • Whether to add googlemaps as a core dependency
  • Whether to add Google Map tiles by default if the environment variable MAPS_API_KEY is detected
import os
os.environ["MAPS_API_KEY"] = "YOUR-API-KEY"
import geemap
m = geemap.Map()
# The map type can be 'roadmap', 'satellite', 'terrain', 'hybrid', 'traffic', 'streetview'
basemap = geemap.google_map_tiles(map_type='hybrid')  
m.add_basemap(basemap)
m

image

style = [
    {
      "stylers": [
        { "hue": "#00ffe6" },
        { "saturation": -20 }
      ]
    },{
      "featureType": "road",
      "elementType": "geometry",
      "stylers": [
        { "lightness": 100 },
        { "visibility": "simplified" }
      ]
    }
  ]

m = geemap.Map()
basemap = geemap.google_map_tiles(map_type="roadmap",region="CN", language="zh-Cn", scale='scaleFactor2x', highDpi=True, style=style)
m.add_basemap(basemap)
m

image

@giswqs giswqs requested review from jdbcode and naschmitz April 6, 2024 03:42
Copy link

github-actions bot commented Apr 6, 2024

@github-actions github-actions bot temporarily deployed to pull request April 6, 2024 03:50 Inactive
@github-actions github-actions bot temporarily deployed to pull request April 6, 2024 13:55 Inactive
@github-actions github-actions bot temporarily deployed to pull request April 8, 2024 19:39 Inactive
Copy link
Collaborator

@jdbcode jdbcode left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! Thanks, Qiusheng. I've left some minor comments for discussion. Also...

  • Whether to add googlemaps as a core dependency
  • Whether to add Google Map tiles by default if the environment variable MAPS_API_KEY is detected

These two seem connected. I think we should try to make adding these tiles as easy as possible, which would requires the package be available and fetching stored Maps API key.

The googlemaps package looks a little stale (not much activity on the repo), we should find out what its status is and if the maps team is supporting it. If they are, we should try to get installed in Colab and make sure it is available on Conda-Forge. If maps team is not supporting it, we should discuss what that means.

geemap/common.py Outdated Show resolved Hide resolved
geemap/common.py Outdated Show resolved Hide resolved
geemap/common.py Outdated Show resolved Hide resolved
@jdbcode
Copy link
Collaborator

jdbcode commented Apr 10, 2024

Looking again, I don't think googlemaps is needed. The client that was created in the demo is never actually used 🤦. I tested the workflow without the googlemaps parts and it's fine. So, we can just move forward - no additional dependencies to worry about. Can you please remove the googlemaps parts.

@giswqs
Copy link
Member Author

giswqs commented Apr 10, 2024

@jdbcode That's great. I was wondering the same thing when implementing it. I have removed it. Will address other comments later today.

@github-actions github-actions bot temporarily deployed to pull request April 10, 2024 19:21 Inactive
@jdbcode
Copy link
Collaborator

jdbcode commented Apr 10, 2024

Thanks for removing googlemaps! No rush on the other changes, we could wait until @naschmitz has a chance to comment too.

@github-actions github-actions bot temporarily deployed to pull request April 10, 2024 22:55 Inactive
@github-actions github-actions bot temporarily deployed to pull request April 10, 2024 23:10 Inactive
@github-actions github-actions bot temporarily deployed to pull request April 11, 2024 01:37 Inactive
@giswqs
Copy link
Member Author

giswqs commented Apr 11, 2024

The map_type parameter accepts one of the three case insensitive variatioins, such as Roadmap, Google Roadmap, and Google.Roadmap

@giswqs
Copy link
Member Author

giswqs commented Apr 11, 2024

The next step is to add Google Map tiles by default if the environment variable MAPS_API_KEY is detected. The will require making changes to core.py

@jdbcode
Copy link
Collaborator

jdbcode commented Apr 12, 2024

Sounds good, thanks for the progress. I'll be at EGU next week, so may not respond right away if you post something.

@github-actions github-actions bot temporarily deployed to pull request April 16, 2024 23:43 Inactive
@giswqs
Copy link
Member Author

giswqs commented Apr 17, 2024

I have improved the function. It now supports returning all gmap providers when map_type=None.

# returns all gmap providers as a dict when map_type is None, which can be accessed via providers['roadmap'], providers['hybrid']
providers = geemap.google_map_tiles(map_type=None) 

# returns a specific gmap provider
geemap.google_map_tiles(map_type='roadmap', language="en-Us", region="US", scale="scaleFactor2x", highDpi=True)

@github-actions github-actions bot temporarily deployed to pull request April 17, 2024 01:06 Inactive
@github-actions github-actions bot temporarily deployed to pull request April 17, 2024 01:43 Inactive
@giswqs
Copy link
Member Author

giswqs commented Apr 17, 2024

The Google.Roadmap will be used as the default map if the MAPS_API_KEY is detected.

import geemap.core as geemap
m = geemap.Map()
m

image

m = geemap.Map(basemap="Google.Hybrid")
m

image

@github-actions github-actions bot temporarily deployed to pull request April 17, 2024 03:16 Inactive
Copy link
Collaborator

@naschmitz naschmitz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I left quite a few comments, sorry for the churn! I'm happy to help implement these changes if you run out of time.

I'll also bug you for integration tests too :), but I'll wait until some of the other comments have been addressed.

geemap/core.py Outdated Show resolved Hide resolved
geemap/core.py Outdated Show resolved Hide resolved
geemap/common.py Show resolved Hide resolved
geemap/common.py Outdated Show resolved Hide resolved
geemap/common.py Outdated Show resolved Hide resolved
geemap/common.py Outdated Show resolved Hide resolved
geemap/common.py Show resolved Hide resolved
geemap/common.py Outdated Show resolved Hide resolved
geemap/common.py Outdated Show resolved Hide resolved
geemap/basemaps.py Outdated Show resolved Hide resolved
@giswqs
Copy link
Member Author

giswqs commented Apr 24, 2024

@naschmitz Good suggestions. I will resolve them this Friday after I return from the conference.

@github-actions github-actions bot temporarily deployed to pull request April 29, 2024 00:33 Inactive
@github-actions github-actions bot temporarily deployed to pull request April 29, 2024 01:00 Inactive
@github-actions github-actions bot temporarily deployed to pull request April 29, 2024 02:01 Inactive
@github-actions github-actions bot temporarily deployed to pull request April 29, 2024 04:05 Inactive
@giswqs
Copy link
Member Author

giswqs commented May 2, 2024

Sorry for the delay. I have been traveling the past few days. Will resume working on this tomorrow.

@github-actions github-actions bot temporarily deployed to pull request May 7, 2024 01:56 Inactive
@github-actions github-actions bot temporarily deployed to pull request May 7, 2024 04:33 Inactive
@github-actions github-actions bot temporarily deployed to pull request May 7, 2024 16:05 Inactive
@github-actions github-actions bot temporarily deployed to pull request May 7, 2024 17:03 Inactive
@giswqs
Copy link
Member Author

giswqs commented May 7, 2024

@naschmitz @jdbcode I have implemented all suggested changes. If the MAPS_API_KEY environment variable is detected, Google map tiles can will be used. Otherwise, the alternative Esri basemaps will be used.

Set environment variable

import os
os.environ["MAPS_API_KEY"] = "YOUR_API_KEY"

Get a single Google tile provider

from geemap.basemaps import GoogleMapsTileProvider
GoogleMapsTileProvider(map_type='hybrid')

image

Get all Google tiles as a dictionary

from geemap.basemaps import google_map_tiles
google_map_tiles()

image

Use geemap.core

import geemap.core as geemap
m = geemap.Map()
m

image

import geemap.core as geemap
m = geemap.Map(basemap="Hybrid")
m

image

Use geemap

import geemap
m = geemap.Map()
m.add_basemap("Google.Satellite")
m

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants