Cesium Widget Example

This is an example notebook to sow how to bind the Cesiumjs with the IPython interactive widget system.


In [ ]:
from CesiumWidget import CesiumWidget
from IPython import display
from czml_example import simple_czml, complex_czml

The code:

from czml_example import simple_czml, complex_czml

Simply import some CZML data for the viewer to display.

Create widget object


In [ ]:
cesiumExample = CesiumWidget(width="100%",czml=simple_czml, enable_lighting=True)

Display the widget:


In [ ]:
#cesiumExample

Add some data to the viewer

  • A simple czml

In [ ]:
#cesiumExample.czml = simple_czml
  • A more complex CZML example

In [ ]:
#cesiumExample.czml = complex_czml

Now let's make some interactive widget:


In [ ]:
from __future__ import print_function
from ipywidgets import interact, interactive, fixed
from ipywidgets import widgets
  • store the CZML objet in a dictionary and use their name as keys
  • define a function to switch between CZML
  • bind the IPython intercat class to the function

In [ ]:
myczml = {'simple_czml':simple_czml, 'complex_czml':complex_czml}

In [ ]:
myplace = {'Eboli, IT':'', 'Woods Hole, MA':'', 'Durham, NH':''}

In [ ]:
import geocoder
import time
for i in myplace.keys():
    g = geocoder.google(i)
    print(g.latlng)
    myplace[i]=g.latlng

In [ ]:
myplace

In [ ]:
def f(CZML):
    cesiumExample.czml = myczml[CZML]

In [ ]:
def z(Location,z=(0,20000000)):
    cesiumExample.zoom_to(myplace[Location][1],myplace[Location][0],z)

In [ ]:
interact(f, CZML=('simple_czml','complex_czml')), interact(z, Location=('Eboli, IT','Woods Hole, MA','Durham, NH'));

In [ ]:
cesiumExample