Skip to content

Commit

Permalink
Merge pull request #1 from mramato/mramato-kmlSpecs
Browse files Browse the repository at this point in the history
Improve unit tests for Point geometry.
  • Loading branch information
andr3nun3s committed Jul 21, 2013
2 parents 6a3ac8d + 6af3b13 commit 441b9b6
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 17 deletions.
2 changes: 0 additions & 2 deletions Source/DynamicScene/KmlDataSource.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,6 @@ define(['../Core/createGuid',
if(styleUrl.length > 0){
var styleObj = styleCollection.getObject(styleUrl[0].textContent);
dynamicObject.merge(styleObj);
} else {
throw new RuntimeError('Undefined style');
}
}
dynamicObject.position = new ConstantPositionProperty(cartesian3);
Expand Down
64 changes: 49 additions & 15 deletions Specs/DynamicScene/KmlDataSourceSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,20 @@ defineSuite(['DynamicScene/KmlDataSource',
'DynamicScene/DynamicBillboard',
'DynamicScene/DynamicPolyline',
'Core/loadXML',
'Core/Event'
'Core/Cartographic',
'Core/Ellipsoid',
'Core/Event',
'Core/Math'
], function(
KmlDataSource,
DynamicObjectCollection,
DynamicBillboard,
DynamicPolyline,
loadXML,
Event) {
Cartographic,
Ellipsoid,
Event,
CesiumMath) {
"use strict";
/*global jasmine,describe,xdescribe,it,xit,expect,beforeEach,afterEach,beforeAll,afterAll,spyOn,runs,waits,waitsFor*/

Expand All @@ -25,22 +31,50 @@ defineSuite(['DynamicScene/KmlDataSource',
expect(dataSource.getIsTimeVarying()).toEqual(true);
});

it('handlesPointGeometry', function() {
var txt = '<?xml version="1.0" encoding="UTF-8"?><kml xmlns="http://www.opengis.net/kml/2.2"><Document>';
txt = txt + '<Style id="randomColorIcon"> <IconStyle> <color>ffffff00</color> <scale>2</scale>';
txt = txt + '<Icon> <href>http://maps.google.com/mapfiles/kml/pal3/icon23.png</href> </Icon> </IconStyle> </Style>';
txt = txt + '<Placemark> <name>IconStyle.kml</name> <styleUrl>#randomColorIcon</styleUrl>';
txt = txt + '<Point> <coordinates>-9.171441666666666,38.67883055555556,0</coordinates> </Point> </Placemark></Document></kml>';
it('handles Point Geometry', function() {
var position = new Cartographic(CesiumMath.toRadians(1), CesiumMath.toRadians(2), 3);
var cartesianPosition = Ellipsoid.WGS84.cartographicToCartesian(position);
var pointKml = '<?xml version="1.0" encoding="UTF-8"?>\
<kml xmlns="http://www.opengis.net/kml/2.2">\
<Document>\
<Placemark>\
<Point>\
<coordinates>1,2,3</coordinates>\
</Point>\
</Placemark>\
</Document>\
</kml>';

var parser = new DOMParser();
var xmlDoc = parser.parseFromString(pointKml, "text/xml");

var dataSource = new KmlDataSource();
dataSource.load(xmlDoc);
expect(dataSource.getDynamicObjectCollection().getObjects().length).toEqual(1);
expect(dataSource.getDynamicObjectCollection().getObjects()[0].position.getValueCartesian()).toEqual(cartesianPosition);
});

var parser=new DOMParser();
var xmlDoc=parser.parseFromString(txt,"text/xml");
it('handles Point Geometry without altitude', function() {
var position = new Cartographic(CesiumMath.toRadians(1), CesiumMath.toRadians(2), 0);
var cartesianPosition = Ellipsoid.WGS84.cartographicToCartesian(position);
var pointKml = '<?xml version="1.0" encoding="UTF-8"?>\
<kml xmlns="http://www.opengis.net/kml/2.2">\
<Document>\
<Placemark>\
<Point>\
<coordinates>1,2</coordinates>\
</Point>\
</Placemark>\
</Document>\
</kml>';

var parser = new DOMParser();
var xmlDoc = parser.parseFromString(pointKml, "text/xml");

var dataSource = new KmlDataSource();
dataSource.load(xmlDoc);
expect(dataSource.getDynamicObjectCollection()).toBeInstanceOf(DynamicObjectCollection);
expect(dataSource.getDynamicObjectCollection().getObjects().length).toEqual(1);
expect(dataSource.getDynamicObjectCollection().getObjects()[0].billboard).toBeInstanceOf(DynamicBillboard);
expect(dataSource.getDynamicObjectCollection().getObjects()[0].position).toBeDefined();
expect(dataSource.getDynamicObjectCollection().getObjects()[0].position.getValueCartesian()).toEqual(cartesianPosition);
});

it('handlesLineGeometry', function() {
Expand All @@ -53,8 +87,8 @@ defineSuite(['DynamicScene/KmlDataSource',
txt = txt + '<coordinates>-122.364167,37.824787,50 -122.363917,37.824423,50</coordinates></LineString></Placemark></Document></kml>';
var dataSource = new KmlDataSource();

var parser=new DOMParser();
var xmlDoc=parser.parseFromString(txt,"text/xml");
var parser = new DOMParser();
var xmlDoc = parser.parseFromString(txt, "text/xml");

dataSource.load(xmlDoc);
expect(dataSource.getDynamicObjectCollection()).toBeInstanceOf(DynamicObjectCollection);
Expand Down

0 comments on commit 441b9b6

Please sign in to comment.