Home
nzshm_rupture_widget
Provides ipywidgets
for displaying interactive 3D GeoJSON ruptures in a Jupyter Notebook
.
Examples:
# display a geojson object in a map
geojson_3d_map([geojson_object])
# add two geojson objects to a map and provide a slider to select which one to display
geojson_3d_map([geojson_a, geojson_b])
# create a cesium map and display two geojson objects at once
cesium = CesiumWidget(data = [geojson_a, geojson_b], selection=-1)
# add a layout with standard controls
layout = decorate(cesium)
# create an ipywidgets.HTML widget and display it in the top right corner of the map
layout.top_right(HTML("Hello World"))
# display the map
layout.build()
Classes:
CesiumWidget
- a map widgetSliderWidget
- a generic slider widget with step buttonsFullScreenWidget
- a button that displays the map in fullscreen modeHomeWidget
- a button that tells a map to navigate "home"ValueButtonWidget
- a button that can cycle through a pre-set list of valuesMapLayoutBuilder
- builds layouts for maps and map widgets
Functions:
transparency_button(map_widget, values)
- creates a button that lets users change the opacity of the map globelegend(title, values)
- creates a map legendselection_slider(map_widget)
- creates a slider that lets user switch between GeoJSON layersdecorate(cesium, home, fullscreen, transparency, slider)
- decorates a map with standard widgetsgeojson_3d_map(geojson)
- displays a map with default controls.
__version__ = importlib.metadata.version('nzshm_rupture_widget')
module-attribute
CesiumWidget
Bases: anywidget.AnyWidget
A map widget encapsulating a CesiumJS Viewer for displaying 3D GeoJSON data.
GeoJSON
CesiumWidget
accepts a number of non-standard attributes.
-
elevationToMeters
: A GeoJSONFeatureCollection
may have the attributeelevationToMeters
which will be multiplied with each elevation component of each coordinate. If not specified, this value defaults to-1000
to supportOpenSHA
geometry. Set this attribute to1
if coordinates are alreay in meters. -
Styling:
CesiumJS supports simplestyle properties in a Feature.
Additionally,
CesiumWidget
supports aLeaflet
-inspiredstyle
property with the folling sub-properties:stroke
: whether lines should be drawncolor
: line colorweight
: line thicknessopacity
: line opacityfill
: whether a polygon should have a fillfillColor
: polygon fill colorfillOpacity
: polygon fill opacityextrusion
: clamps polygons to the ground and extrudes them to this height in meters
Note that this means that a fill
value directly in the properties is polygon fill color, while a fill
in
the style
property is a boolean that switches fill on or off.
Attributes:
Name | Type | Description |
---|---|---|
data |
list
|
a list of GeoJSON dicts to be displayed on the map. Modifying this attribute after the map has been rendered will not have an effect. |
selection |
int
|
determines which entry of |
hover_style |
dict
|
a style to apply to polygons when the mouse hovers over them. Supported are |
no_info |
bool
|
suppresses Cesium's built-in GeoJSON properties pop-ups. |
globe_opacity |
float
|
allows for the adjustment of globe opacity to better inspect underground geometry. Note that a value of 1 causes all GeoJSON to be rendered on top of the globe. |
Source code in src\nzshm_rupture_widget\__init__.py
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 |
|
data = traitlets.List().tag(sync=True)
class-attribute
instance-attribute
globe_opacity = traitlets.Float(1).tag(sync=True)
class-attribute
instance-attribute
hover_style = traitlets.Dict().tag(sync=True)
class-attribute
instance-attribute
no_info = traitlets.Bool(False).tag(sync=True)
class-attribute
instance-attribute
selection = traitlets.Int(0).tag(sync=True)
class-attribute
instance-attribute
go_home()
Causes the map to navigate "home", which is the extent of the currently selected GeoJSON.
Source code in src\nzshm_rupture_widget\__init__.py
131 132 133 134 135 |
|
on_hover(callback)
Registers a callback
that is invoked when the mouse hovers over a new GeoJSON entity.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
callback |
function
|
will be called with events of the structure:
|
required |
Source code in src\nzshm_rupture_widget\__init__.py
116 117 118 119 120 121 122 123 124 125 126 127 128 129 |
|
FullScreenWidget
Bases: anywidget.AnyWidget
A button widget that sets the nearest ancestor with the fullScreenTarget
class to fullscreen.
Source code in src\nzshm_rupture_widget\__init__.py
161 162 163 164 165 166 167 |
|
HomeWidget
Bases: anywidget.AnyWidget
A button widget that calls the go_home()
method on a CesiumWidget
.
Source code in src\nzshm_rupture_widget\__init__.py
170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 |
|
__init__(map: CesiumWidget)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
map |
CesiumWidget
|
|
required |
Source code in src\nzshm_rupture_widget\__init__.py
179 180 181 182 183 184 185 |
|
MapLayoutBuilder
Creates a layout for adding widgets to a map.
This class is not a widget itself. Call build()
to create the widget.
Source code in src\nzshm_rupture_widget\__init__.py
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 |
|
cesium: None = cesium
instance-attribute
grid_box: None = None
instance-attribute
widgets = {'top-left': [], 'bottom-left': [], 'top-right': [], 'bottom-right': []}
instance-attribute
__init__(cesium: CesiumWidget)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
cesium |
CesiumWidget
|
the map widget. All other widgets will be overlayed on top of this widget. |
required |
Source code in src\nzshm_rupture_widget\__init__.py
284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 |
|
bottom_left(*widgets)
Adds DOMWidget
widgets to the bottom_left
area of the map.
Returns:
Name | Type | Description |
---|---|---|
MapLayoutBuilder |
this instance |
Source code in src\nzshm_rupture_widget\__init__.py
326 327 328 329 330 331 332 333 334 335 |
|
bottom_right(*widgets)
Adds DOMWidget
widgets to the bottom_right
area of the map.
Returns:
Name | Type | Description |
---|---|---|
MapLayoutBuilder |
this instance |
Source code in src\nzshm_rupture_widget\__init__.py
304 305 306 307 308 309 310 311 312 313 |
|
build()
Creates a widget that contains all added widgets.
Returns:
Name | Type | Description |
---|---|---|
GridBox |
The widget. |
Source code in src\nzshm_rupture_widget\__init__.py
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 |
|
top_left(*widgets)
Adds DOMWidget
widgets to the top_left
area of the map.
Returns:
Name | Type | Description |
---|---|---|
MapLayoutBuilder |
this instance |
Source code in src\nzshm_rupture_widget\__init__.py
337 338 339 340 341 342 343 344 345 346 |
|
top_right(*widgets)
Adds DOMWidget
widgets to the top_right
area of the map.
Returns:
Name | Type | Description |
---|---|---|
MapLayoutBuilder |
this instance |
Source code in src\nzshm_rupture_widget\__init__.py
315 316 317 318 319 320 321 322 323 324 |
|
SliderWidget
Bases: anywidget.AnyWidget
A slider widget with step buttons.
Attributes:
Name | Type | Description |
---|---|---|
min |
int
|
The minimum value |
max |
int
|
The maximum value |
value |
int
|
The value |
title |
string
|
Tooltip text |
Source code in src\nzshm_rupture_widget\__init__.py
138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 |
|
max = traitlets.Int(10).tag(sync=True)
class-attribute
instance-attribute
min = traitlets.Int(0).tag(sync=True)
class-attribute
instance-attribute
title = traitlets.Unicode('').tag(sync=True)
class-attribute
instance-attribute
value = traitlets.Int(0).tag(sync=True)
class-attribute
instance-attribute
ValueButtonWidget
Bases: anywidget.AnyWidget
A button widget that cycles through a list of preset values.
Attributes:
Name | Type | Description |
---|---|---|
values |
list
|
a list of values to cycle through |
value |
any
|
the current value |
icon |
string
|
a CSS class. Classes already assigned to the HTML element are |
title |
string
|
tooltip text |
Source code in src\nzshm_rupture_widget\__init__.py
188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 |
|
icon = traitlets.Unicode('fa-exclamation').tag(sync=True)
class-attribute
instance-attribute
title = traitlets.Unicode('').tag(sync=True)
class-attribute
instance-attribute
value = traitlets.Any(0).tag(sync=True)
class-attribute
instance-attribute
values = traitlets.List([0, 1]).tag(sync=True)
class-attribute
instance-attribute
decorate(cesium: CesiumWidget, home=True, fullscreen=True, transparency=True, slider=True)
Creates a MapLayoutBuilder with default widgets.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
cesium |
CesiumWidget
|
the CesiumWidget |
required |
home |
bool
|
whether to add a home button. Defaults to True. |
True
|
fullscreen |
bool
|
whether to add a full screen button. Defaults to True. |
True
|
transparency |
bool
|
whether to add a transparency button. Defaults to True. |
True
|
slider |
bool
|
whether to add a slider. Defaults to True. |
True
|
Returns:
Name | Type | Description |
---|---|---|
MapLayoutBuilder |
a |
Source code in src\nzshm_rupture_widget\__init__.py
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 |
|
geojson_3d_map(data: list)
Creates a map with default controls. No further widgets may be added.
The CesiumWidget
can be obtained with
map = geojson_3d_map(geojson_data)
cesium = map.children[0]
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data |
list
|
a list of GeoJSON objects |
required |
Returns:
Name | Type | Description |
---|---|---|
GridBox |
a widget containing the map and control widgets. |
Source code in src\nzshm_rupture_widget\__init__.py
427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 |
|
legend(title: str, values: dict)
Creates a legend widget.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
title |
str
|
The title of the legend |
required |
values |
dict
|
A mapping from |
required |
Returns:
Name | Type | Description |
---|---|---|
HTML |
A static widget displaying the legend. |
Source code in src\nzshm_rupture_widget\__init__.py
233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 |
|
selection_slider(map_widget: CesiumWidget)
A slider that can be used to switch between different GeoJSON objects of map_widget
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
map_widget |
CesiumWidget
|
a map with more than one GeoJSON object |
required |
Returns:
Name | Type | Description |
---|---|---|
SliderWidget |
A slider widget that is linked to the |
Source code in src\nzshm_rupture_widget\__init__.py
256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 |
|
transparency_button(map_widget: CesiumWidget, values: list)
Creates a button widget that switches the globe-opacity
of a CesiumWidget
between
the specified values
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
map_widget |
CesiumWidget
|
the map |
required |
values |
list
|
a list of possible opacity values between 0 and 1 |
required |
Returns:
Name | Type | Description |
---|---|---|
ValueButtonWidget |
the button widget |
Source code in src\nzshm_rupture_widget\__init__.py
211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 |
|