maplibre module¶
Map
¶
Bases: AnyWidget
Create a MapLibre map widget.
Source code in mapwidget/maplibre.py
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 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 |
|
layer_names
property
¶
Get the names of the layers in the map.
layers
property
¶
Get the current style of the map.
__init__(center=[0, 20], zoom=2, bearing=0, pitch=0, style='https://tiles.openfreemap.org/styles/liberty', controls=None, **kwargs)
¶
Initialize the Map widget.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
center
|
Initial center [lng, lat]. Defaults to [0, 20] |
[0, 20]
|
|
zoom
|
Initial zoom level. Defaults to 2 |
2
|
|
controls
|
List of controls to add by default. Defaults to ["navigation", "fullscreen", "globe"] |
None
|
|
**kwargs
|
Additional widget parameters |
{}
|
Source code in mapwidget/maplibre.py
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
|
add_call(method, args=None, kwargs=None)
¶
Invoke a JS map method with arguments.
Source code in mapwidget/maplibre.py
131 132 133 134 135 136 137 |
|
add_control(control_type, position='top-right', options=None)
¶
Add a control to the map.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
control_type
|
str
|
Type of control to add. Options include: - 'navigation' or 'NavigationControl' - 'geolocate' or 'GeolocateControl' - 'scale' or 'ScaleControl' - 'fullscreen' or 'FullscreenControl' - 'attribution' or 'AttributionControl' - 'globe' or 'GlobeControl' - 'logo' or 'LogoControl' - 'terrain' or 'TerrainControl' |
required |
position
|
str
|
Position on the map. Options: 'top-left', 'top-right', 'bottom-left', 'bottom-right' |
'top-right'
|
options
|
dict
|
Optional configuration for the control |
None
|
Source code in mapwidget/maplibre.py
222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 |
|
add_draw_control(options=None, controls=None, position='top-right', geojson=None, **kwargs)
¶
Adds a drawing control to the map.
This method enables users to add interactive drawing controls to the map, allowing for the creation, editing, and deletion of geometric shapes on the map. The options, position, and initial GeoJSON can be customized.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
options
|
Optional[Dict[str, Any]]
|
Configuration options for the drawing control. Defaults to None. |
None
|
controls
|
Optional[Dict[str, Any]]
|
The drawing controls to enable. Can be one or more of the following: 'polygon', 'line_string', 'point', 'trash', 'combine_features', 'uncombine_features'. Defaults to None. |
None
|
position
|
str
|
The position of the control on the map. Defaults to "top-right". |
'top-right'
|
geojson
|
Optional[Dict[str, Any]]
|
Initial GeoJSON data to load into the drawing control. Defaults to None. |
None
|
**kwargs
|
Any
|
Additional keyword arguments to be passed to the drawing control. |
{}
|
Returns:
Type | Description |
---|---|
None
|
None |
Source code in mapwidget/maplibre.py
258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 |
|
add_layer(layer, before_id=None)
¶
Add a new layer to the map.
Source code in mapwidget/maplibre.py
191 192 193 194 195 196 |
|
add_legend(targets, options=None, position='top-right')
¶
Adds a legend control to the map using mapbox-gl-legend plugin.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
targets
|
Dict[str, str]
|
A dictionary mapping layer IDs to display names |
required |
options
|
Optional[Dict[str, Any]]
|
Configuration options for the legend control. Available options: - showDefault (bool): Whether to show default legend. Defaults to False. - showCheckbox (bool): Whether to show checkboxes. Defaults to False. - onlyRendered (bool): Whether to show only rendered layers. Defaults to True. - reverseOrder (bool): Whether to reverse the order. Defaults to True. |
None
|
position
|
str
|
The position of the control on the map. Defaults to "top-right". |
'top-right'
|
Returns:
Type | Description |
---|---|
None
|
None |
Source code in mapwidget/maplibre.py
327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 |
|
add_opacity_control(base_layers=None, over_layers=None, options=None, position='top-right', default_visibility=None, collapsible=False)
¶
Adds an opacity control to the map using maplibre-gl-opacity plugin.
This control allows users to adjust the opacity of multiple tile layers and switch between base layers and overlays.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
base_layers
|
Optional[Dict[str, str]]
|
A dictionary mapping base layer IDs to display names. Only one base layer can be visible at a time. |
None
|
over_layers
|
Optional[Dict[str, str]]
|
A dictionary mapping overlay layer IDs to display names. Multiple overlays can be visible simultaneously. |
None
|
options
|
Optional[Dict[str, Any]]
|
Configuration options for the opacity control. Available options: - opacityControl (bool): Whether to show opacity sliders. Defaults to True. |
None
|
position
|
str
|
The position of the control on the map. Defaults to "top-right". |
'top-right'
|
default_visibility
|
Optional[Dict[str, bool]]
|
A dictionary mapping layer IDs to their default visibility state. If not specified, overlay layers will be visible by default and base layers will follow the first-wins rule. |
None
|
collapsible
|
bool
|
Whether to add a toggle button to show/hide the control. Defaults to False. |
False
|
Returns:
Type | Description |
---|---|
None
|
None |
Example
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 |
|
Source code in mapwidget/maplibre.py
373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 |
|
add_source(source_id, source)
¶
Add a new source to the map.
Source code in mapwidget/maplibre.py
183 184 185 |
|
draw_features_delete_all()
¶
Deletes all features from the drawing control.
This method removes all drawn features from the map and updates the model accordingly.
Returns:
Type | Description |
---|---|
None
|
None |
Source code in mapwidget/maplibre.py
315 316 317 318 319 320 321 322 323 324 325 |
|
fit_bounds(bounds, options=None)
¶
Fit the map to given bounds [[west, south], [east, north]].
Source code in mapwidget/maplibre.py
164 165 166 167 168 169 |
|
fly_to(center=None, zoom=None, bearing=None, pitch=None)
¶
Fly to a given location with optional zoom, bearing, and pitch.
Source code in mapwidget/maplibre.py
151 152 153 154 155 156 157 158 159 160 161 162 |
|
pan_to(lng, lat)
¶
Pan the map to a given location.
Source code in mapwidget/maplibre.py
147 148 149 |
|
remove_control(control_type)
¶
Remove a control from the map.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
control_type
|
str
|
The type of control to remove (e.g., 'navigation', 'fullscreen') |
required |
Source code in mapwidget/maplibre.py
247 248 249 250 251 252 253 254 255 256 |
|
remove_draw_control()
¶
Removes the drawing control from the map.
This method removes the drawing control and clears all associated draw features from the map and model.
Returns:
Type | Description |
---|---|
None
|
None |
Source code in mapwidget/maplibre.py
303 304 305 306 307 308 309 310 311 312 313 |
|
remove_layer(layer_id)
¶
Remove a layer from the map.
Source code in mapwidget/maplibre.py
198 199 200 |
|
remove_source(source_id)
¶
Remove a source from the map.
Source code in mapwidget/maplibre.py
187 188 189 |
|
resize()
¶
Trigger map resize.
Source code in mapwidget/maplibre.py
179 180 181 |
|
set_bearing(bearing)
¶
Set the bearing of the map.
Source code in mapwidget/maplibre.py
175 176 177 |
|
set_center(lng, lat)
¶
Set the center of the map.
Source code in mapwidget/maplibre.py
139 140 141 |
|
set_draw_mode(mode)
¶
Set the drawing mode, even if the map is not yet loaded.
Source code in mapwidget/maplibre.py
364 365 366 367 368 369 370 371 |
|
set_filter(layer_id, filter_expr)
¶
Set a filter expression on a layer.
Source code in mapwidget/maplibre.py
210 211 212 |
|
set_layer_visibility(layer_id, visibility)
¶
Set visibility of a layer ('visible' or 'none').
Source code in mapwidget/maplibre.py
218 219 220 |
|
set_layout_property(layer_id, prop, value)
¶
Set a layout property on a layer.
Source code in mapwidget/maplibre.py
206 207 208 |
|
set_paint_property(layer_id, prop, value)
¶
Set a paint property on a layer.
Source code in mapwidget/maplibre.py
202 203 204 |
|
set_pitch(pitch)
¶
Set the pitch of the map.
Source code in mapwidget/maplibre.py
171 172 173 |
|
set_style(style_url)
¶
Set the map style.
Source code in mapwidget/maplibre.py
214 215 216 |
|
set_zoom(zoom)
¶
Set the zoom level.
Source code in mapwidget/maplibre.py
143 144 145 |
|