Skip to content

MGRS

image image image

Visualize the Military Grid Reference System (MGRS)

Uncomment the following line to install leafmap if needed.

1
# %pip install "leafmap[maplibre]"
1
import leafmap.maplibregl as leafmap
1
2
3
4
5
6
7
m = leafmap.Map(style="positron", projection="globe")
m.add_basemap("Satellite")

geojson = "https://github.com/opengeos/datasets/releases/download/world/mgrs_grid_zone.geojson"
m.add_geojson(geojson)
m.add_labels(geojson, "GZD", text_color="white", min_zoom=2, max_zoom=10)
m
 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
43
44
45
46
m = leafmap.Map(style="positron", projection="globe")
m.add_basemap("Satellite")

geojson = "https://github.com/opengeos/datasets/releases/download/world/mgrs_grid_zone.geojson"
paint = {"line-color": "red"}

pmtiles = (
    "https://huggingface.co/datasets/giswqs/geospatial/resolve/main/MGRS_100km.pmtiles"
)
fill_style = {
    "layers": [
        {
            "id": "MGRS_100km_fill",
            "source": "MGRS_100km",
            "source-layer": "MGRS_100km",
            "type": "fill",
            "paint": {
                "fill-opacity": 0,
                "fill-color": "white",
                "fill-outline-color": "#ffffff",
            },
            "min-zoom": 3,
        },
    ]
}

line_style = {
    "layers": [
        {
            "id": "MGRS_100km_line",
            "source": "MGRS_100km_line",
            "source-layer": "MGRS_100km",
            "type": "line",
            "paint": {
                "line-color": "white",
            },
            "min-zoom": 3,
        },
    ]
}

m.add_pmtiles(pmtiles, style=fill_style, tooltip=True, fit_bounds=False)
m.add_pmtiles(pmtiles, style=line_style, tooltip=False, fit_bounds=False)
m.add_geojson(geojson, layer_type="line", paint=paint)
m.add_labels(geojson, "GZD", text_color="white", min_zoom=2)
m

image