Skip to content

Globe control

image image image

Add a globe control to the map

Uncomment the following line to install leafmap if needed.

1
# %pip install "leafmap[maplibre]"

Import library

1
import leafmap.maplibregl as leafmap

To run this notebook, you will need an API key from MapTiler. Once you have the API key, you can uncomment the following code block and replace YOUR_API_KEY with your actual API key. Then, run the code block code to set the API key as an environment variable.

1
2
# import os
# os.environ["MAPTILER_KEY"] = "YOUR_API_KEY"

Add globe control

1
2
3
m = leafmap.Map(center=[-100, 40], zoom=3, style="liberty")
m.add_globe_control()
m

image

Use globe projection

1
2
3
m = leafmap.Map(center=[-100, 40], zoom=3, style="basic", projection="globe")
m.add_overture_3d_buildings()
m
1
2
m = leafmap.Map(center=[-100, 40], zoom=3, style="3d-hybrid", projection="globe")
m

image

Create 3D choropleth maps

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
m = leafmap.Map(
    center=[19.43, 49.49], zoom=3, pitch=60, style="basic", projection="globe"
)
source = {
    "type": "geojson",
    "data": "https://docs.maptiler.com/sdk-js/assets/Mean_age_of_women_at_first_marriage_in_2019.geojson",
}
m.add_source("countries", source)
layer = {
    "id": "eu-countries",
    "source": "countries",
    "type": "fill-extrusion",
    "paint": {
        "fill-extrusion-color": [
            "interpolate",
            ["linear"],
            ["get", "age"],
            23.0,
            "#fff5eb",
            24.0,
            "#fee6ce",
            25.0,
            "#fdd0a2",
            26.0,
            "#fdae6b",
            27.0,
            "#fd8d3c",
            28.0,
            "#f16913",
            29.0,
            "#d94801",
            30.0,
            "#8c2d04",
        ],
        "fill-extrusion-opacity": 1,
        "fill-extrusion-height": ["*", ["get", "age"], 5000],
    },
}
first_symbol_layer_id = m.find_first_symbol_layer()["id"]
m.add_layer(layer, first_symbol_layer_id)
m.add_layer_control()
m
1
data = "https://github.com/opengeos/datasets/releases/download/vector/countries.geojson"
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
m = leafmap.Map(style="liberty", projection="globe")
first_symbol_id = m.find_first_symbol_layer()["id"]
m.add_data(
    data,
    column="POP_EST",
    scheme="Quantiles",
    cmap="Blues",
    legend_title="Population",
    name="Population",
    before_id=first_symbol_id,
    extrude=True,
    scale_factor=1000,
)
m.add_layer_control()
m

image

Google Earth Engine

1
2
3
4
5
6
m = leafmap.Map(style="3d-terrain", projection="globe")
m.add_ee_layer(asset_id="ESA/WorldCover/v200", opacity=0.5)
m.add_legend(builtin_legend="ESA_WorldCover", title="ESA Landcover")
m.add_overture_3d_buildings()
m.add_layer_control()
m