0
# Interactive Mapping
1
2
Core mapping functionality providing interactive visualization capabilities for geospatial data with multiple backend support and comprehensive Earth Engine integration.
3
4
## Capabilities
5
6
### Map Class
7
8
Main interactive map class that supports multiple backends (ipyleaflet, folium, plotly, kepler.gl, pydeck, maplibre) with automatic backend selection based on environment configuration.
9
10
```python { .api }
11
class Map:
12
"""Interactive map class with Earth Engine integration."""
13
14
def __init__(
15
self,
16
center: List[float] = [20, 0],
17
zoom: int = 2,
18
height: str = "600px",
19
width: str = "100%",
20
basemap: str = "OpenStreetMap",
21
**kwargs
22
) -> None:
23
"""
24
Initialize interactive map.
25
26
Args:
27
center: Map center coordinates [latitude, longitude]
28
zoom: Initial zoom level
29
height: Map height in CSS format
30
width: Map width in CSS format
31
basemap: Base map to use
32
**kwargs: Additional map parameters
33
"""
34
```
35
36
### Layer Management
37
38
Add and manage map layers including Earth Engine assets, local data, and various tile services.
39
40
```python { .api }
41
def addLayer(
42
self,
43
ee_object,
44
vis_params: Dict = {},
45
name: str = None,
46
shown: bool = True,
47
opacity: float = 1.0
48
) -> None:
49
"""
50
Add layer to map.
51
52
Args:
53
ee_object: Earth Engine object (Image, ImageCollection, FeatureCollection, Geometry)
54
vis_params: Visualization parameters
55
name: Layer name for display
56
shown: Whether layer is visible
57
opacity: Layer opacity (0-1)
58
"""
59
60
def add_tile_layer(
61
self,
62
url: str,
63
name: str = "TileLayer",
64
attribution: str = "",
65
opacity: float = 1.0,
66
shown: bool = True,
67
**kwargs
68
) -> None:
69
"""
70
Add tile layer to map.
71
72
Args:
73
url: Tile layer URL template
74
name: Layer name
75
attribution: Attribution text
76
opacity: Layer opacity (0-1)
77
shown: Whether layer is visible
78
**kwargs: Additional tile layer parameters
79
"""
80
81
def add_geojson(
82
self,
83
data,
84
style: Dict = {},
85
hover_style: Dict = {},
86
style_callback: callable = None,
87
fill_colors: List[str] = None,
88
info_mode: str = "on_hover",
89
**kwargs
90
) -> None:
91
"""
92
Add GeoJSON data to map.
93
94
Args:
95
data: GeoJSON data (dict, str path, or URL)
96
style: Default style dictionary
97
hover_style: Style when hovering
98
style_callback: Function for dynamic styling
99
fill_colors: List of fill colors for features
100
info_mode: How to display feature information
101
**kwargs: Additional GeoJSON layer parameters
102
"""
103
104
def add_shp(
105
self,
106
in_shp: str,
107
style: Dict = {},
108
hover_style: Dict = {},
109
style_callback: callable = None,
110
fill_colors: List[str] = None,
111
info_mode: str = "on_hover",
112
**kwargs
113
) -> None:
114
"""
115
Add shapefile to map.
116
117
Args:
118
in_shp: Path to shapefile
119
style: Default style dictionary
120
hover_style: Style when hovering
121
style_callback: Function for dynamic styling
122
fill_colors: List of fill colors for features
123
info_mode: How to display feature information
124
**kwargs: Additional parameters
125
"""
126
```
127
128
### Map Navigation and Control
129
130
Methods for controlling map view, center, and zoom programmatically.
131
132
```python { .api }
133
def centerObject(self, ee_object, zoom: int = None) -> None:
134
"""
135
Center map on Earth Engine object.
136
137
Args:
138
ee_object: Earth Engine object to center on
139
zoom: Zoom level (optional)
140
"""
141
142
def setCenter(self, lon: float, lat: float, zoom: int = None) -> None:
143
"""
144
Set map center coordinates.
145
146
Args:
147
lon: Longitude
148
lat: Latitude
149
zoom: Zoom level (optional)
150
"""
151
152
def setOptions(self, mapTypeId: str = None, styles: Dict = None, types: List[str] = None) -> None:
153
"""
154
Set map options.
155
156
Args:
157
mapTypeId: Map type identifier
158
styles: Map styling options
159
types: Available map types
160
"""
161
162
def getCenter(self) -> Dict[str, float]:
163
"""
164
Get current map center.
165
166
Returns:
167
Dict containing 'lon' and 'lat' keys
168
"""
169
170
def getZoom(self) -> int:
171
"""
172
Get current zoom level.
173
174
Returns:
175
Current zoom level
176
"""
177
178
def getBounds(self) -> List[List[float]]:
179
"""
180
Get current map bounds.
181
182
Returns:
183
Bounds as [[south, west], [north, east]]
184
"""
185
```
186
187
### Drawing and Interaction
188
189
Interactive drawing tools and user interaction capabilities.
190
191
```python { .api }
192
@property
193
def draw_control(self) -> Any:
194
"""Get the draw control widget."""
195
196
@property
197
def draw_features(self) -> List[Any]:
198
"""Get list of drawn features."""
199
200
@property
201
def draw_last_feature(self) -> Optional[Any]:
202
"""Get the last drawn feature."""
203
204
@property
205
def user_roi(self) -> Optional[Any]:
206
"""Get user region of interest from drawing."""
207
208
def add_draw_control(self, **kwargs) -> None:
209
"""Add drawing control to map."""
210
211
def remove_draw_control(self) -> None:
212
"""Remove drawing control from map."""
213
```
214
215
### Basemap Management
216
217
Access and manage various basemap providers and tile services.
218
219
```python { .api }
220
def add_basemap(self, basemap: str = "OpenStreetMap") -> None:
221
"""
222
Add basemap to map.
223
224
Args:
225
basemap: Basemap name from available basemaps
226
"""
227
228
def get_basemap(name: str) -> Dict:
229
"""
230
Get basemap configuration.
231
232
Args:
233
name: Basemap identifier
234
235
Returns:
236
Basemap configuration dictionary
237
"""
238
```
239
240
### Map Linking
241
242
Create linked maps for comparison and synchronized viewing.
243
244
```python { .api }
245
def linked_maps(
246
rows: int = 2,
247
cols: int = 2,
248
height: str = "400px",
249
center: List[float] = [20, 0],
250
zoom: int = 2
251
) -> widgets.GridBox:
252
"""
253
Create linked maps for comparison.
254
255
Args:
256
rows: Number of rows
257
cols: Number of columns
258
height: Map height
259
center: Initial center coordinates
260
zoom: Initial zoom level
261
262
Returns:
263
Grid widget containing linked maps
264
"""
265
```
266
267
## Usage Examples
268
269
### Basic Map Creation
270
271
```python
272
import geemap
273
274
# Create basic map
275
m = geemap.Map(center=[40, -100], zoom=4)
276
277
# Add Earth Engine layer
278
import ee
279
ee.Initialize()
280
281
image = ee.Image('USGS/SRTMGL1_003')
282
vis_params = {'min': 0, 'max': 4000, 'palette': ['blue', 'green', 'red']}
283
m.addLayer(image, vis_params, 'Elevation')
284
285
# Display map
286
m
287
```
288
289
### Adding Local Data
290
291
```python
292
# Add GeoJSON
293
m.add_geojson('path/to/data.geojson', style={'color': 'red', 'weight': 2})
294
295
# Add shapefile
296
m.add_shp('path/to/data.shp', style={'fillColor': 'blue', 'weight': 1})
297
```
298
299
### Map Navigation
300
301
```python
302
# Center on specific location
303
m.setCenter(-122.4, 37.8, zoom=10) # San Francisco
304
305
# Center on Earth Engine object
306
roi = ee.Geometry.Point([-122.4, 37.8])
307
m.centerObject(roi, zoom=12)
308
```
309
310
## Types
311
312
```python { .api }
313
# Visualization parameters for Earth Engine layers
314
VisParams = Dict[str, Union[int, float, List[str], List[int], List[float]]]
315
316
# Style parameters for vector layers
317
Style = Dict[str, Union[str, int, float, bool]]
318
319
# Map bounds format
320
Bounds = List[List[float]] # [[south, west], [north, east]]
321
322
# Map center format
323
Center = Dict[str, float] # {'lon': longitude, 'lat': latitude}
324
```