示例#1
0
    def test_add_entities_with_properties(self):
        viewer = cesiumpy.Viewer(divid="viewertest")
        box = cesiumpy.Box(dimensions=(40e4, 30e4, 50e4),
                           position=[-120, 40, 0])
        viewer.entities.add(box, material=cesiumpy.color.RED)
        result = viewer.to_html()
        exp = """<script src="https://cesiumjs.org/Cesium/Build/Cesium/Cesium.js"></script>
<link rel="stylesheet" href="https://cesiumjs.org/Cesium/Build/Cesium/Widgets/widgets.css" type="text/css">
<div id="viewertest" style="width:100%; height:100%;"><div>
<script type="text/javascript">
  var widget = new Cesium.Viewer("viewertest");
  widget.entities.add({position : Cesium.Cartesian3.fromDegrees(-120.0, 40.0, 0.0), box : {dimensions : new Cesium.Cartesian3(400000.0, 300000.0, 500000.0), material : Cesium.Color.RED}});
  widget.zoomTo(widget.entities);
</script>"""
        self.assertEqual(result, exp)

        viewer = cesiumpy.Viewer(divid="viewertest")
        box1 = cesiumpy.Box(dimensions=(40e4, 30e4, 50e4),
                            position=[-120, 40, 0])
        box2 = cesiumpy.Box(dimensions=(50e4, 60e4, 70e4),
                            position=[-100, 80, 0])
        viewer.entities.add([box1, box2], material=cesiumpy.color.RED)
        result = viewer.to_html()
        exp = """<script src="https://cesiumjs.org/Cesium/Build/Cesium/Cesium.js"></script>
<link rel="stylesheet" href="https://cesiumjs.org/Cesium/Build/Cesium/Widgets/widgets.css" type="text/css">
<div id="viewertest" style="width:100%; height:100%;"><div>
<script type="text/javascript">
  var widget = new Cesium.Viewer("viewertest");
  widget.entities.add({position : Cesium.Cartesian3.fromDegrees(-120.0, 40.0, 0.0), box : {dimensions : new Cesium.Cartesian3(400000.0, 300000.0, 500000.0), material : Cesium.Color.RED}});
  widget.entities.add({position : Cesium.Cartesian3.fromDegrees(-100.0, 80.0, 0.0), box : {dimensions : new Cesium.Cartesian3(500000.0, 600000.0, 700000.0), material : Cesium.Color.RED}});
  widget.zoomTo(widget.entities);
</script>"""
        self.assertEqual(result, exp)
示例#2
0
    def test_box(self):
        e = cesiumpy.Box(dimensions=(40e4, 30e4, 50e4),
                         material=cesiumpy.color.RED,
                         position=[-120, 40, 0])
        exp = "{position : Cesium.Cartesian3.fromDegrees(-120.0, 40.0, 0.0), box : {dimensions : new Cesium.Cartesian3(400000.0, 300000.0, 500000.0), material : Cesium.Color.RED}}"
        self.assertEqual(e.script, exp)

        e = e.copy()
        self.assertEqual(e.script, exp)

        msg = "The 'dimensions' trait of a Box instance must be a Cartesian3"
        with nose.tools.assert_raises_regexp(traitlets.TraitError, msg):
            cesiumpy.Box(dimensions=(40e4, 30e4),
                         material=cesiumpy.color.RED,
                         position=[-120, 40, 0])
示例#3
0
    def test_entities_geocode(self):
        try:
            e = cesiumpy.Point(position='Los Angeles')
            exp = """{position : Cesium.Cartesian3.fromDegrees(-118.2436849, 34.0522342, 0.0), point : {pixelSize : 10.0, color : Cesium.Color.WHITE}}"""
            self.assertEqual(e.script, exp)

            e = cesiumpy.Label(position='Los Angeles', text='xxx')
            exp = """{position : Cesium.Cartesian3.fromDegrees(-118.2436849, 34.0522342, 0.0), label : {text : "xxx"}}"""
            self.assertEqual(e.script, exp)

            p = cesiumpy.Pin()
            e = cesiumpy.Billboard(position='Los Angeles', image=p)
            exp = """{position : Cesium.Cartesian3.fromDegrees(-118.2436849, 34.0522342, 0.0), billboard : {image : new Cesium.PinBuilder().fromColor(Cesium.Color.ROYALBLUE, 48.0)}}"""
            self.assertEqual(e.script, exp)

            e = cesiumpy.Box(position='Los Angeles', dimensions=(40e4, 30e4, 50e4))
            exp = """{position : Cesium.Cartesian3.fromDegrees(-118.2436849, 34.0522342, 0.0), box : {dimensions : new Cesium.Cartesian3(400000.0, 300000.0, 500000.0)}}"""
            self.assertEqual(e.script, exp)

            e = cesiumpy.Ellipse(position='Los Angeles', semiMinorAxis=25e4,
                                 semiMajorAxis=40e4)
            exp = """{position : Cesium.Cartesian3.fromDegrees(-118.2436849, 34.0522342, 0.0), ellipse : {semiMinorAxis : 250000.0, semiMajorAxis : 400000.0}}"""
            self.assertEqual(e.script, exp)

            e = cesiumpy.Cylinder(position='Los Angeles', length=100e4,
                                  topRadius=10e4, bottomRadius=10e4)
            exp = """{position : Cesium.Cartesian3.fromDegrees(-118.2436849, 34.0522342, 0.0), cylinder : {length : 1000000.0, topRadius : 100000.0, bottomRadius : 100000.0}}"""
            self.assertEqual(e.script, exp)

            e = cesiumpy.Polygon(hierarchy=['Los Angeles', 'Las Vegas', 'San Francisco'])
            exp = """{polygon : {hierarchy : Cesium.Cartesian3.fromDegreesArray([-118.2436849, 34.0522342, -115.1398296, 36.1699412, -122.4194155, 37.7749295])}}"""
            self.assertEqual(e.script, exp)

            # not supported, Unabel to create rectangle from single geolocation
            e = cesiumpy.Rectangle(coordinates=(-85, 40, -80, 45))

            e = cesiumpy.Ellipsoid(position='Los Angeles', radii=(20e4, 20e4, 30e4))
            exp = """{position : Cesium.Cartesian3.fromDegrees(-118.2436849, 34.0522342, 0.0), ellipsoid : {radii : new Cesium.Cartesian3(200000.0, 200000.0, 300000.0)}}"""
            self.assertEqual(e.script, exp)

            e = cesiumpy.Wall(positions=['Los Angeles', 'Las Vegas', 'San Francisco'],
                              maximumHeights=10e4, minimumHeights=0)
            exp = "{wall : {positions : Cesium.Cartesian3.fromDegreesArray([-118.2436849, 34.0522342, -115.1398296, 36.1699412, -122.4194155, 37.7749295]), maximumHeights : [100000.0, 100000.0, 100000.0], minimumHeights : [0, 0, 0]}}"
            self.assertEqual(e.script, exp)

            e = cesiumpy.Corridor(positions=['Los Angeles', 'Las Vegas', 'San Francisco'], width=2e5)
            exp = """{corridor : {positions : Cesium.Cartesian3.fromDegreesArray([-118.2436849, 34.0522342, -115.1398296, 36.1699412, -122.4194155, 37.7749295]), width : 200000.0}}"""
            self.assertEqual(e.script, exp)

            e = cesiumpy.Polyline(positions=['Los Angeles', 'Las Vegas', 'San Francisco'], width=0.5)
            exp = """{polyline : {positions : Cesium.Cartesian3.fromDegreesArray([-118.2436849, 34.0522342, -115.1398296, 36.1699412, -122.4194155, 37.7749295]), width : 0.5}}"""
            self.assertEqual(e.script, exp)

            e = cesiumpy.PolylineVolume(positions=['Los Angeles', 'Las Vegas', 'San Francisco'],
                                        shape=[-5e4, -5e4, 5e4, -5e4, 5e4, 5e4, -5e4, 5e4])
            exp = """{polylineVolume : {positions : Cesium.Cartesian3.fromDegreesArray([-118.2436849, 34.0522342, -115.1398296, 36.1699412, -122.4194155, 37.7749295]), shape : [new Cesium.Cartesian2(-50000.0, -50000.0), new Cesium.Cartesian2(50000.0, -50000.0), new Cesium.Cartesian2(50000.0, 50000.0), new Cesium.Cartesian2(-50000.0, 50000.0)]}}"""
            self.assertEqual(e.script, exp)
        except geopy.exc.GeocoderQuotaExceeded:
            raise nose.SkipTest("exceeded geocoder quota")
示例#4
0
    def test_outlineColor_property(self):
        msg = "The 'outlineColor' trait of a Box instance must be a Color or None"
        with nose.tools.assert_raises_regexp(traitlets.TraitError, msg):
            cesiumpy.Box(position=[-120, 40, 0],
                         dimensions=(10, 20, 30),
                         outlineColor=1)

        b = cesiumpy.Box(position=[-120, 40, 0],
                         dimensions=(10, 20, 30),
                         outlineColor='red')
        exp = """{position : Cesium.Cartesian3.fromDegrees(-120.0, 40.0, 0.0), box : {dimensions : new Cesium.Cartesian3(10.0, 20.0, 30.0), outlineColor : Cesium.Color.RED}}"""
        self.assertEqual(b.script, exp)

        msg = "The 'outlineColor' trait of a Box instance must be a Color or None"
        with nose.tools.assert_raises_regexp(traitlets.TraitError, msg):
            b.outlineColor = 1

        b.outlineColor = 'blue'
        exp = """{position : Cesium.Cartesian3.fromDegrees(-120.0, 40.0, 0.0), box : {dimensions : new Cesium.Cartesian3(10.0, 20.0, 30.0), outlineColor : Cesium.Color.BLUE}}"""
        self.assertEqual(b.script, exp)
示例#5
0
import cesiumpy

v = cesiumpy.CesiumWidget()

v = cesiumpy.Viewer()
b = cesiumpy.Box(dimensions=(40e4, 30e4, 50e4), material=cesiumpy.color.RED, position=[-120, 40, 0])
v.entities.add(b)#print
示例#6
0
    def test_add_entities(self):
        viewer = cesiumpy.Viewer(divid="viewertest", **self.options)

        box = cesiumpy.Box(dimensions=(40e4, 30e4, 50e4),
                           material=cesiumpy.color.RED,
                           position=[-120, 40, 0])
        viewer.entities.add(box)

        ellipse = cesiumpy.Ellipse(semiMinorAxis=25e4,
                                   semiMajorAxis=40e4,
                                   material=cesiumpy.color.BLUE,
                                   position=[-110, 40, 0])
        viewer.entities.add(ellipse)

        cyl = cesiumpy.Cylinder(position=[-100, 40, 50e4],
                                length=100e4,
                                topRadius=10e4,
                                bottomRadius=10e4,
                                material=cesiumpy.color.AQUA)
        viewer.entities.add(cyl)

        pol = cesiumpy.Polygon([-90, 40, -95, 40, -95, 45, -90, 40],
                               material=cesiumpy.color.ORANGE)
        viewer.entities.add(pol)

        rect = cesiumpy.Rectangle(coordinates=(-85, 40, -80, 45),
                                  material=cesiumpy.color.GREEN)
        viewer.entities.add(rect)

        ellipsoid = cesiumpy.Ellipsoid(position=(-70, 40, 0),
                                       radii=(20e4, 20e4, 30e4),
                                       material=cesiumpy.color.GREEN)
        viewer.entities.add(ellipsoid)

        wall = cesiumpy.Wall(positions=[-60, 40, -65, 40, -65, 45, -60, 45],
                             maximumHeights=[10e4] * 4,
                             minimumHeights=[0] * 4,
                             material=cesiumpy.color.RED)
        viewer.entities.add(wall)

        corridor = cesiumpy.Corridor(positions=[-120, 30, -90, 35, -60, 30],
                                     width=2e5,
                                     material=cesiumpy.color.RED)
        viewer.entities.add(corridor)

        polyline = cesiumpy.Polyline(positions=[-120, 25, -90, 30, -60, 25],
                                     width=0.5,
                                     material=cesiumpy.color.BLUE)
        viewer.entities.add(polyline)
        polylinevolume = cesiumpy.PolylineVolume(
            positions=[-120, 20, -90, 25, -60, 20],
            shape=[
                cesiumpy.Cartesian2(-50000, -50000),
                cesiumpy.Cartesian2(50000, -50000),
                cesiumpy.Cartesian2(50000, 50000),
                cesiumpy.Cartesian2(-50000, 50000)
            ],
            material=cesiumpy.color.GREEN)
        viewer.entities.add(polylinevolume)
        result = viewer.to_html()

        exp = """<script src="https://cesiumjs.org/Cesium/Build/Cesium/Cesium.js"></script>
<link rel="stylesheet" href="https://cesiumjs.org/Cesium/Build/Cesium/Widgets/widgets.css" type="text/css">
<div id="viewertest" style="width:100%; height:100%;"><div>
<script type="text/javascript">
  var widget = new Cesium.Viewer("viewertest", {animation : true, baseLayerPicker : false, fullscreenButton : false, geocoder : false, homeButton : false, infoBox : false, sceneModePicker : true, selectionIndicator : false, timeline : false, navigationHelpButton : false, navigationInstructionsInitiallyVisible : false});
  widget.entities.add({position : Cesium.Cartesian3.fromDegrees(-120.0, 40.0, 0.0), box : {dimensions : new Cesium.Cartesian3(400000.0, 300000.0, 500000.0), material : Cesium.Color.RED}});
  widget.entities.add({position : Cesium.Cartesian3.fromDegrees(-110.0, 40.0, 0.0), ellipse : {semiMinorAxis : 250000.0, semiMajorAxis : 400000.0, material : Cesium.Color.BLUE}});
  widget.entities.add({position : Cesium.Cartesian3.fromDegrees(-100.0, 40.0, 500000.0), cylinder : {length : 1000000.0, topRadius : 100000.0, bottomRadius : 100000.0, material : Cesium.Color.AQUA}});
  widget.entities.add({polygon : {hierarchy : Cesium.Cartesian3.fromDegreesArray([-90, 40, -95, 40, -95, 45, -90, 40]), material : Cesium.Color.ORANGE}});
  widget.entities.add({rectangle : {coordinates : Cesium.Rectangle.fromDegrees(-85.0, 40.0, -80.0, 45.0), material : Cesium.Color.GREEN}});
  widget.entities.add({position : Cesium.Cartesian3.fromDegrees(-70.0, 40.0, 0.0), ellipsoid : {radii : new Cesium.Cartesian3(200000.0, 200000.0, 300000.0), material : Cesium.Color.GREEN}});
  widget.entities.add({wall : {positions : Cesium.Cartesian3.fromDegreesArray([-60, 40, -65, 40, -65, 45, -60, 45]), maximumHeights : [100000.0, 100000.0, 100000.0, 100000.0], minimumHeights : [0, 0, 0, 0], material : Cesium.Color.RED}});
  widget.entities.add({corridor : {positions : Cesium.Cartesian3.fromDegreesArray([-120, 30, -90, 35, -60, 30]), width : 200000.0, material : Cesium.Color.RED}});
  widget.entities.add({polyline : {positions : Cesium.Cartesian3.fromDegreesArray([-120, 25, -90, 30, -60, 25]), width : 0.5, material : Cesium.Color.BLUE}});
  widget.entities.add({polylineVolume : {positions : Cesium.Cartesian3.fromDegreesArray([-120, 20, -90, 25, -60, 20]), shape : [new Cesium.Cartesian2(-50000.0, -50000.0), new Cesium.Cartesian2(50000.0, -50000.0), new Cesium.Cartesian2(50000.0, 50000.0), new Cesium.Cartesian2(-50000.0, 50000.0)], material : Cesium.Color.GREEN}});
  widget.zoomTo(widget.entities);
</script>"""
        self.assertEqual(result, exp)

        # clear entities
        viewer.entities.clear()
        result = viewer.to_html()
        exp_clear = """<script src="https://cesiumjs.org/Cesium/Build/Cesium/Cesium.js"></script>
<link rel="stylesheet" href="https://cesiumjs.org/Cesium/Build/Cesium/Widgets/widgets.css" type="text/css">
<div id="viewertest" style="width:100%; height:100%;"><div>
<script type="text/javascript">
  var widget = new Cesium.Viewer("viewertest", {animation : true, baseLayerPicker : false, fullscreenButton : false, geocoder : false, homeButton : false, infoBox : false, sceneModePicker : true, selectionIndicator : false, timeline : false, navigationHelpButton : false, navigationInstructionsInitiallyVisible : false});
</script>"""
        self.assertEqual(result, exp_clear)

        # add multiple objects at once
        viewer = cesiumpy.Viewer(divid="viewertest", **self.options)
        objs = [
            box, ellipse, cyl, pol, rect, ellipsoid, wall, corridor, polyline,
            polylinevolume
        ]
        viewer.entities.add(objs)
        result = viewer.to_html()
        self.assertEqual(result, exp)

        viewer.entities.clear()
        result = viewer.to_html()
        self.assertEqual(result, exp_clear)
示例#7
0
    def test_entities_repr(self):
        e = cesiumpy.Point(position=[-110, 40, 0])
        exp = "Point(-110.0, 40.0, 0.0)"
        self.assertEqual(repr(e), exp)

        e = cesiumpy.Label(position=[-110, 40, 0], text='xxx')
        exp = "Label(-110.0, 40.0, 0.0)"
        self.assertEqual(repr(e), exp)

        p = cesiumpy.Pin()
        e = cesiumpy.Billboard(position=(-110, 40, 0), image=p)
        exp = "Billboard(-110.0, 40.0, 0.0)"
        self.assertEqual(repr(e), exp)

        e = cesiumpy.Box(position=[-110, 40, 0], dimensions=(40e4, 30e4, 50e4))
        exp = "Box(-110.0, 40.0, 0.0)"
        self.assertEqual(repr(e), exp)

        e = cesiumpy.Ellipse(position=[-110, 40, 0],
                             semiMinorAxis=25e4,
                             semiMajorAxis=40e4)
        exp = "Ellipse(-110.0, 40.0, 0.0)"
        self.assertEqual(repr(e), exp)

        e = cesiumpy.Cylinder(position=[-110, 40, 100],
                              length=100e4,
                              topRadius=10e4,
                              bottomRadius=10e4)
        exp = "Cylinder(-110.0, 40.0, 100.0)"
        self.assertEqual(repr(e), exp)

        e = cesiumpy.Polygon(hierarchy=[-90, 40, -95, 40, -95, 45, -90, 40])
        exp = "Polygon([-90, 40, -95, 40, -95, 45, -90, 40])"
        self.assertEqual(repr(e), exp)

        e = cesiumpy.Rectangle(coordinates=(-85, 40, -80, 45))
        exp = "Rectangle(west=-85.0, south=40.0, east=-80.0, north=45.0)"
        self.assertEqual(repr(e), exp)

        e = cesiumpy.Ellipsoid(position=(-70, 40, 0), radii=(20e4, 20e4, 30e4))
        exp = "Ellipsoid(-70.0, 40.0, 0.0)"
        self.assertEqual(repr(e), exp)

        e = cesiumpy.Wall(positions=[-60, 40, -65, 40, -65, 45, -60, 45],
                          maximumHeights=[10e4] * 4,
                          minimumHeights=[0] * 4)
        exp = "Wall([-60, 40, -65, 40, -65, 45, -60, 45])"
        self.assertEqual(repr(e), exp)

        e = cesiumpy.Corridor(positions=[-120, 30, -90, 35, -60, 30],
                              width=2e5)
        exp = "Corridor([-120, 30, -90, 35, -60, 30])"
        self.assertEqual(repr(e), exp)

        e = cesiumpy.Polyline(positions=[-120, 25, -90, 30, -60, 25],
                              width=0.5)
        exp = "Polyline([-120, 25, -90, 30, -60, 25])"
        self.assertEqual(repr(e), exp)

        e = cesiumpy.PolylineVolume(
            positions=[-120, 20, -90, 25, -60, 20],
            shape=[-5e4, -5e4, 5e4, -5e4, 5e4, 5e4, -5e4, 5e4])
        exp = "PolylineVolume([-120, 20, -90, 25, -60, 20])"
        self.assertEqual(repr(e), exp)