I happened across an interesting Github repository from Samapriya Roy the other day for creating custom basemaps to add to your Google Earth Engine map. Traditionally when using or sharing your work in GEE you have the option between a standard Google cartographic basemap or the ‘satellite’ view ( in quotations here since it’s my understanding that they’re typically aerial imagery… but who’s splitting hairs).  Adding a custom basemap really doesn’t have much appeal other than it is interesting, but maybe you want to show off some cool analysis you did and the regular colors just don’t highlight your finding in an interesting way.

Boring base map

You’re favourite boring basemap.

For this tutorial, we’ll cover how to install eebasemaps, convert a Snazzy map into something useable by EE, and how to build a custom module to hold multiple basemaps to add to any script you’re working on.

The main requirements to follow this tutorial successfully are:

  • A GEE account
  • Git
  • A python3 environment

Firstly head over to Samapriya Roy’s eebasemap repository and clone it – make sure you have a python3 environment setup.

git clone https://github.com/samapriya/earthengine-standalone-tools.git
cd earthengine-standalone-tools/eebasemaps

Next, go to snazzymaps. You can either find a map style you like or follow along with the base style in this tutorial. We’ll use the “Ultra Light with Labels” map. Copy the URL which we’ll need to generate the EE style.

Snazzy maps base map

Generate the EE style using snazzy_maps.py and pipe the output to a text file.

python3 snazzy_maps.py --url "https://snazzymaps.com/style/151/ultra-light-with-labels" > ultra-light.txt

Text file output from snazzy_maps.py

The output text file can be directly copy/pasted into the GEE code editor to add the custom basemap. NeatO!

Cumston base map in GEE.

These nice styles come with a price, and that price is line space. Let’s modify this into something a little more useable – we will make a EE module that we can then call from other scripts to load our custom basemap.

First, create a dictionary to hold your new basemap variable there is only one there but this will let you add more custom basemaps if you want to at a later time. Then make a new function to load the basemap rather than calling it in your script.

var baseDict = {
function addCustomBasemap (base){
base = baseDict[base]
Map.setOptions(undefined, {'Custom': base})

Also, let’s add a help function so we don’t have to memorize each custom basemap name. All this does is get the keys from our dictionary and print them out to the console with a short help text.

var avalible = Object.keys(baseDict);
function help(){
print("addCustomBasemap (base) \n Add a custom basemap to map. \n args: \n -base(string) \
\n A string name of an available basemap theme.\nreturns: \n basemap\n\nAvailable themes are :", avalible)

Lastly, to make our script into a module we need to assign which variables or functions will be accessible when we import the script.

exports = {
addCustomBasemap : addCustomBasemap,
help :help

With the module all set up, we can now call it in any other scripts to add a custom basemap.  Make sure to update the username, repository, and module to your information!

var basemap = require('users/USERNAME/REPOSITY:MODULE')

Try adding some other snazzy maps or feel free to use the few I have already put together.

Screenshot of loading custom base map module.

Example of calling module with multiple basemaps to choose from.

Adding a custom basemap to the script: https://code.earthengine.google.com/1d564e6f4157b0745a5dd403939ca6b6

Custom basemap module : https://code.earthengine.google.com/0b9a9be1330c2916517e3754695e10c1