def test_fillColor_property(self): msg = "The 'fillColor' trait of a Label instance must be a Color or None" with nose.tools.assert_raises_regexp(traitlets.TraitError, msg): cesiumpy.Label(position=[-120, 40, 0], text="xxx", fillColor=1) b = cesiumpy.Label(position=[-120, 40, 0], text="xxx", fillColor="red") exp = """{position : Cesium.Cartesian3.fromDegrees(-120.0, 40.0, 0.0), label : {text : "xxx", fillColor : Cesium.Color.RED}}""" self.assertEqual(b.script, exp) msg = "The 'fillColor' trait of a Label instance must be a Color or None" with nose.tools.assert_raises_regexp(traitlets.TraitError, msg): b.fillColor = 1 b.fillColor = 'blue' exp = """{position : Cesium.Cartesian3.fromDegrees(-120.0, 40.0, 0.0), label : {text : "xxx", fillColor : Cesium.Color.BLUE}}""" self.assertEqual(b.script, exp)
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")
def test_label(self): e = cesiumpy.Label(position=(-110, 40, 0), text='label_text') exp = """{position : Cesium.Cartesian3.fromDegrees(-110.0, 40.0, 0.0), label : {text : "label_text"}}""" self.assertEqual(e.script, exp) e = e.copy() self.assertEqual(e.script, exp) e = cesiumpy.Label(position=(-110, 40, 0), text='label_text', fillColor='blue', scale=0.1) exp = """{position : Cesium.Cartesian3.fromDegrees(-110.0, 40.0, 0.0), label : {text : "label_text", fillColor : Cesium.Color.BLUE, scale : 0.1}}""" self.assertEqual(e.script, exp) e = e.copy() self.assertEqual(e.script, exp)
def label(self, text, x, y, z=None, size=None, color=None): """ Plot cesiumpy.Label Parameters ---------- text : list List of labels x : list List of longitudes y : list List of latitudes z : list or float Heights size : list or float Text size color : list or Color Text color """ x = com.validate_listlike(x, key='x') # for list validation (not allow scalar) text = com.validate_listlike(text, key='text') text = self._fill_by(text, len(x), key='text') y = com.validate_listlike(y, key='y') y = self._fill_by(y, len(x), key='y') z = self._fill_by(z, len(x), key='z', default=0) size = self._fill_by(size, len(x), key='size') color = self._fill_by(color, len(x), key='color') for i, (_text, _x, _y, _z, _size, _color) in enumerate(zip(text, x, y, z, size, color)): p = cesiumpy.Label(position=(_x, _y, _z), text=_text, scale=_size, fillColor=_color) self.widget.entities.add(p) return self.widget
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)