Skip to content

Commit

Permalink
Merge pull request #2148 from AnalyticalGraphicsInc/geojson-heights
Browse files Browse the repository at this point in the history
GeoJson fixes and cleanup
  • Loading branch information
emackey committed Sep 30, 2014
2 parents d178445 + c686950 commit 65abef5
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 26 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Change Log
* Fixed model orientations to follow the same Z-up convention used throughout Cesium. There was also an orientation issue fixed in the [online model converter](http://cesiumjs.org/convertmodel.html). If you are having orientation issues after updating, try reconverting your models.
* Fixed a bug in `Model` where the wrong animations could be used when the model was created from glTF JSON instead of
a url to a glTF file. [#2078](https://github.com/AnalyticalGraphicsInc/cesium/issues/2078)
* Fixed a bug in `GeoJsonDataSource` which was causing polygons with height values to be drawn onto the surface.
* Eliminated imagery artifacts at some zoom levels due to Mercator reprojection.
* Added a constructor option to `Scene`, `CesiumWidget`, and `Viewer` to disable order independent translucency.
* Added support for WKID 102113 (equivalent to 102100) to `ArcGisMapServerImageryProvider`.
Expand Down
55 changes: 30 additions & 25 deletions Source/DataSources/GeoJsonDataSource.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ define([
}

// GeoJSON processing functions
function processFeature(dataSource, feature, notUsed, crsFunction, sourceUri) {
function processFeature(dataSource, feature, notUsed, crsFunction) {
if (!defined(feature.geometry)) {
throw new RuntimeError('feature.geometry is required.');
}
Expand All @@ -153,18 +153,18 @@ define([
if (!defined(geometryHandler)) {
throw new RuntimeError('Unknown geometry type: ' + geometryType);
}
geometryHandler(dataSource, feature, feature.geometry, crsFunction, sourceUri);
geometryHandler(dataSource, feature, feature.geometry, crsFunction);
}
}

function processFeatureCollection(dataSource, featureCollection, notUsed, crsFunction, sourceUri) {
function processFeatureCollection(dataSource, featureCollection, notUsed, crsFunction) {
var features = featureCollection.features;
for (var i = 0, len = features.length; i < len; i++) {
processFeature(dataSource, features[i], undefined, crsFunction, sourceUri);
processFeature(dataSource, features[i], undefined, crsFunction);
}
}

function processGeometryCollection(dataSource, geoJson, geometryCollection, crsFunction, sourceUri) {
function processGeometryCollection(dataSource, geoJson, geometryCollection, crsFunction) {
var geometries = geometryCollection.geometries;
for (var i = 0, len = geometries.length; i < len; i++) {
var geometry = geometries[i];
Expand All @@ -173,17 +173,17 @@ define([
if (!defined(geometryHandler)) {
throw new RuntimeError('Unknown geometry type: ' + geometryType);
}
geometryHandler(dataSource, geoJson, geometry, crsFunction, sourceUri);
geometryHandler(dataSource, geoJson, geometry, crsFunction);
}
}

function processPoint(dataSource, geoJson, geometry, crsFunction, sourceUri) {
function processPoint(dataSource, geoJson, geometry, crsFunction) {
var entity = createObject(geoJson, dataSource._entityCollection);
entity.point = pointGraphics.clone();
entity.position = new ConstantPositionProperty(crsFunction(geometry.coordinates));
}

function processMultiPoint(dataSource, geoJson, geometry, crsFunction, sourceUri) {
function processMultiPoint(dataSource, geoJson, geometry, crsFunction) {
var coordinates = geometry.coordinates;
for (var i = 0; i < coordinates.length; i++) {
var entity = createObject(geoJson, dataSource._entityCollection);
Expand All @@ -192,13 +192,13 @@ define([
}
}

function processLineString(dataSource, geoJson, geometry, crsFunction, sourceUri) {
function processLineString(dataSource, geoJson, geometry, crsFunction) {
var entity = createObject(geoJson, dataSource._entityCollection);
entity.polyline = polylineGraphics.clone();
entity.polyline.positions = new ConstantProperty(coordinatesArrayToCartesianArray(geometry.coordinates, crsFunction));
}

function processMultiLineString(dataSource, geoJson, geometry, crsFunction, sourceUri) {
function processMultiLineString(dataSource, geoJson, geometry, crsFunction) {
var lineStrings = geometry.coordinates;
for (var i = 0; i < lineStrings.length; i++) {
var entity = createObject(geoJson, dataSource._entityCollection);
Expand All @@ -207,32 +207,37 @@ define([
}
}

function processPolygon(dataSource, geoJson, geometry, crsFunction, sourceUri) {
function createPolygon(dataSource, geoJson, crsFunction, coordinateArray) {
var entity = createObject(geoJson, dataSource._entityCollection);
entity.polygon = polygonGraphics.clone();
entity.polygon.positions = new ConstantProperty(coordinatesArrayToCartesianArray(geometry.coordinates[0], crsFunction));
entity.polygon.positions = new ConstantProperty(coordinatesArrayToCartesianArray(coordinateArray, crsFunction));
if (coordinateArray.length > 0 && coordinateArray[0].length > 2) {
entity.polygon.perPositionHeight = new ConstantProperty(true);
}
}

function processPolygon(dataSource, geoJson, geometry, crsFunction) {
var coordinateArray = geometry.coordinates[0];
createPolygon(dataSource, geoJson, crsFunction, coordinateArray);
}

function processMultiPolygon(dataSource, geoJson, geometry, crsFunction) {
var polygons = geometry.coordinates;
for (var i = 0; i < polygons.length; i++) {
createPolygon(dataSource, geoJson, crsFunction, polygons[i][0]);
}
}

function processTopology(dataSource, geoJson, geometry, crsFunction, sourceUri) {
function processTopology(dataSource, geoJson, geometry, crsFunction) {
for ( var property in geometry.objects) {
if (geometry.objects.hasOwnProperty(property)) {
var feature = topojson.feature(geometry, geometry.objects[property]);
var typeHandler = geoJsonObjectTypes[feature.type];
typeHandler(dataSource, feature, feature, crsFunction, sourceUri);
typeHandler(dataSource, feature, feature, crsFunction);
}
}
}

function processMultiPolygon(dataSource, geoJson, geometry, crsFunction, sourceUri) {
var polygons = geometry.coordinates;
for (var i = 0; i < polygons.length; i++) {
var polygon = polygons[i];
var entity = createObject(geoJson, dataSource._entityCollection);
entity.polygon = polygonGraphics.clone();
entity.polygon.positions = new ConstantProperty(coordinatesArrayToCartesianArray(polygon[0], crsFunction));
}
}

var geoJsonObjectTypes = {
Feature : processFeature,
FeatureCollection : processFeatureCollection,
Expand Down Expand Up @@ -472,7 +477,7 @@ define([
var dataSource = this;
return when(crsFunction, function(crsFunction) {
dataSource._entityCollection.removeAll();
typeHandler(dataSource, geoJson, geoJson, crsFunction, sourceUri);
typeHandler(dataSource, geoJson, geoJson, crsFunction);
setLoading(dataSource, false);
dataSource._changed.raiseEvent(dataSource);
}).otherwise(function(error) {
Expand Down
24 changes: 23 additions & 1 deletion Specs/DataSources/GeoJsonDataSourceSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ defineSuite([
var time = new JulianDate();

function coordinatesToCartesian(coordinates) {
return Cartesian3.fromDegrees(coordinates[0], coordinates[1]);
return Cartesian3.fromDegrees(coordinates[0], coordinates[1], coordinates[2]);
}

function coordinatesArrayToCartesian(coordinates) {
Expand Down Expand Up @@ -104,6 +104,11 @@ defineSuite([
coordinates : [[[100.0, 0.0], [101.0, 0.0], [101.0, 1.0], [100.0, 1.0], [100.0, 0.0]], [[100.2, 0.2], [100.8, 0.2], [100.8, 0.8], [100.2, 0.8], [100.2, 0.2]]]
};

var polygonWithHeights = {
type : 'Polygon',
coordinates : [[[100.0, 0.0, 1.0], [101.0, 0.0, 2.0], [101.0, 1.0, 1.0], [100.0, 1.0, 2.0], [100.0, 0.0, 3.0]]]
};

var multiPoint = {
type : 'MultiPoint',
coordinates : [[100.0, 0.0], [101.0, 1.0], [101.0, 3.0]]
Expand Down Expand Up @@ -356,6 +361,23 @@ defineSuite([
var object = entityCollection.entities[0];
expect(object.properties).toBe(polygon.properties);
expect(object.polygon.positions.getValue(time)).toEqual(polygonCoordinatesToCartesian(polygon.coordinates));
expect(object.polygon.perPositionHeight).toBeUndefined();
});
});

it('Works with polygon geometry with Heights', function() {
var dataSource = new GeoJsonDataSource();
dataSource.load(polygonWithHeights);

var entityCollection = dataSource.entities;
waitsFor(function() {
return entityCollection.entities.length === 1;
});
runs(function() {
var object = entityCollection.entities[0];
expect(object.properties).toBe(polygonWithHeights.properties);
expect(object.polygon.positions.getValue(time)).toEqual(polygonCoordinatesToCartesian(polygonWithHeights.coordinates));
expect(object.polygon.perPositionHeight.getValue(time)).toBe(true);
});
});

Expand Down

0 comments on commit 65abef5

Please sign in to comment.