CesiumWidget together with CZML library

This notebook shows how to use the CesiumWidget together with the CZML library from https://github.com/cleder/czml

If the CesiumWidget is installed correctly, Cesium should be accessable at: http://localhost:8888/nbextensions/CesiumWidget/cesium/index.html


In [1]:
import collections
from CesiumWidget import CesiumWidget
import czml

In [6]:
points = collections.OrderedDict()
points['p1'] = [18.07,59.33, 20]
points['p2'] = [19.07,59.33, 20]
points['p3'] = [20.07,59.33, 20]

In [7]:
points


Out[7]:
OrderedDict([('p1', [18.07, 59.33, 20]),
             ('p2', [19.07, 59.33, 20]),
             ('p3', [20.07, 59.33, 20])])

In [8]:
doc = czml.CZML()

In [9]:
packet1 = czml.CZMLPacket(id='document',version='1.0')
doc.packets.append(packet1)

In [10]:
for i,v in enumerate(points):
    print(i,v)
    p = czml.CZMLPacket(id=i)
    p.position = czml.Position(cartographicDegrees = points[v])
    point = czml.Point(pixelSize=20, show=True)
    point.color = czml.Color(rgba=(223, 150, 47, 128))
    point.show = True
    p.point = point
    l = czml.Label(show=True, text=v)
    l.scale = 0.5
    p.label = l
    doc.packets.append(p)


0 p1
1 p2
2 p3

In [11]:
cesiumExample = CesiumWidget(width="100%", czml=doc.dumps())

In [12]:
cesiumExample

In [13]:
doc.dumps()


Out[13]:
'[{"version": "1.0", "id": "document"}, {"point": {"color": {"rgba": [223, 150, 47, 128]}, "pixelSize": 20, "show": true}, "position": {"cartographicDegrees": [18.07, 59.33, 20.0]}, "label": {"text": "p1", "scale": 0.5, "show": true}, "id": 0}, {"point": {"color": {"rgba": [223, 150, 47, 128]}, "pixelSize": 20, "show": true}, "position": {"cartographicDegrees": [19.07, 59.33, 20.0]}, "label": {"text": "p2", "scale": 0.5, "show": true}, "id": 1}, {"point": {"color": {"rgba": [223, 150, 47, 128]}, "pixelSize": 20, "show": true}, "position": {"cartographicDegrees": [20.07, 59.33, 20.0]}, "label": {"text": "p3", "scale": 0.5, "show": true}, "id": 2}]'

In [ ]: