Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add TopoJSON support to GeoJsonDataSource #906

Merged
merged 6 commits into from
Jun 28, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 30 additions & 22 deletions Apps/CesiumViewer/CesiumViewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,34 +84,42 @@ define([

if (typeof endUserOptions.source !== 'undefined') {
var source;
if (endsWith(endUserOptions.source.toUpperCase(), ".GEOJSON")) {
var sourceUrl = endUserOptions.source.toUpperCase();
if (endsWith(sourceUrl, ".GEOJSON") || //
endsWith(sourceUrl, ".JSON") || //
endsWith(sourceUrl, ".TOPOJSON")) {
source = new GeoJsonDataSource();
} else {
} else if (endsWith(sourceUrl, ".CZML")) {
source = new CzmlDataSource();
} else {
loadingIndicator.style.display = 'none';
window.alert("Unknown format: " + endUserOptions.source);
}
source.loadUrl(endUserOptions.source).then(function() {
viewer.dataSources.add(source);
if (typeof source !== 'undefined') {
source.loadUrl(endUserOptions.source).then(function() {
viewer.dataSources.add(source);

var dataClock = source.getClock();
if (typeof dataClock !== 'undefined') {
dataClock.clone(viewer.clock);
viewer.timeline.updateFromClock();
viewer.timeline.zoomTo(dataClock.startTime, dataClock.stopTime);
}
var dataClock = source.getClock();
if (typeof dataClock !== 'undefined') {
dataClock.clone(viewer.clock);
viewer.timeline.updateFromClock();
viewer.timeline.zoomTo(dataClock.startTime, dataClock.stopTime);
}

if (typeof endUserOptions.lookAt !== 'undefined') {
var dynamicObject = source.getDynamicObjectCollection().getObject(endUserOptions.lookAt);
if (typeof dynamicObject !== 'undefined') {
viewer.trackedObject = dynamicObject;
} else {
window.alert('No object with id ' + endUserOptions.lookAt + ' exists in the provided source.');
if (typeof endUserOptions.lookAt !== 'undefined') {
var dynamicObject = source.getDynamicObjectCollection().getObject(endUserOptions.lookAt);
if (typeof dynamicObject !== 'undefined') {
viewer.trackedObject = dynamicObject;
} else {
window.alert('No object with id ' + endUserOptions.lookAt + ' exists in the provided source.');
}
}
}
}, function(e) {
window.alert(e);
}).always(function() {
loadingIndicator.style.display = 'none';
});
}, function(e) {
window.alert(e);
}).always(function() {
loadingIndicator.style.display = 'none';
});
}
} else {
loadingIndicator.style.display = 'none';
}
Expand Down
2 changes: 1 addition & 1 deletion CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Beta Releases
* Removed `CesiumViewerWidget` and replaced it with a new `Viewer` widget with mixin architecture. This new widget does not depend on Dojo and is part of the combined Cesium.js file. It is intended to be a flexible base widget for easily building robust applications. See [#838](https://github.com/AnalyticalGraphicsInc/cesium/pull/838) for the full details.
* Removed the Dojo-based `checkForChromeFrame` function, and replaced it with a new standalone version that returns a promise to signal when the asynchronous check has completed.
* Fix resizing issues in `CesiumWidget` ([#608](https://github.com/AnalyticalGraphicsInc/cesium/issues/608), [#834](https://github.com/AnalyticalGraphicsInc/cesium/issues/834)).
* Added initial support for [GeoJSON](http://www.geojson.org/) see [#890](https://github.com/AnalyticalGraphicsInc/cesium/pull/890) for details.
* Added initial support for [GeoJSON](http://www.geojson.org/) and [TopoJSON](https://github.com/mbostock/topojson). See [#890](https://github.com/AnalyticalGraphicsInc/cesium/pull/890) and [#906](https://github.com/AnalyticalGraphicsInc/cesium/pull/906) for details.
* Added `Context.getAntialias`.
* Added rotation, aligned axis, width, and height properties to `Billboard`s.
* Improved the performance of "missing tile" checking, especially for Bing imagery.
Expand Down
17 changes: 17 additions & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,23 @@ https://github.com/SteveSanderson/knockout-es5
>
> THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

### topojson

https://github.com/mbostock/topojson

> Copyright (c) 2012, Michael Bostock
> All rights reserved.
>
> Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
>
> * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
>
> * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
>
> * The name Michael Bostock may not be used to endorse or promote products derived from this software without specific prior written permission.
>
> THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL MICHAEL BOSTOCK BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Tests
=====

Expand Down
32 changes: 21 additions & 11 deletions Source/DynamicScene/GeoJsonDataSource.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ define(['../Core/createGuid',
'./DynamicPolygon',
'./DynamicMaterialProperty',
'./DynamicObjectCollection',
'../ThirdParty/when'], function(
'../ThirdParty/when',
'../ThirdParty/topojson'], function(
createGuid,
Cartographic,
Color,
Expand All @@ -32,7 +33,8 @@ define(['../Core/createGuid',
DynamicPolygon,
DynamicMaterialProperty,
DynamicObjectCollection,
when) {
when,
topojson) {
"use strict";

//DynamicPositionProperty is pretty hard to use with non-CZML based data
Expand All @@ -50,10 +52,6 @@ define(['../Core/createGuid',
return value;
};

ConstantPositionProperty.prototype.setValue = function(value) {
this._value = value;
};

//GeoJSON specifies only the Feature object has a usable id property
//But since "multi" geometries create multiple dynamicObject,
//we can't use it for them either.
Expand Down Expand Up @@ -159,6 +157,16 @@ define(['../Core/createGuid',
dynamicObject.vertexPositions = new ConstantPositionProperty(coordinatesArrayToCartesianArray(geometry.coordinates[0], crsFunction));
}

function processTopology(dataSource, geoJson, geometry, crsFunction, source) {
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, source);
}
}
}

function processMultiPolygon(dataSource, geoJson, geometry, crsFunction, source) {
//TODO holes
var polygons = geometry.coordinates;
Expand All @@ -179,7 +187,8 @@ define(['../Core/createGuid',
MultiPoint : processMultiPoint,
MultiPolygon : processMultiPolygon,
Point : processPoint,
Polygon : processPolygon
Polygon : processPolygon,
Topology : processTopology
};

var geometryTypes = {
Expand All @@ -189,13 +198,14 @@ define(['../Core/createGuid',
MultiPoint : processMultiPoint,
MultiPolygon : processMultiPolygon,
Point : processPoint,
Polygon : processPolygon
Polygon : processPolygon,
Topology : processTopology
};

/**
* A {@link DataSource} which processes GeoJSON. Since GeoJSON has no standard for styling content,
* we provide default graphics via the defaultPoint, defaultLine, and defaultPolygon properties.
* Any changes to these objects will affect the resulting {@link DynamicObject} collection.
* A {@link DataSource} which processes both GeoJSON and TopoJSON data. Since GeoJSON has no standard for styling
* content, we provide default graphics via the defaultPoint, defaultLine, and defaultPolygon properties. Any
* changes to these objects will affect the resulting {@link DynamicObject} collection.
* @alias GeoJsonDataSource
* @constructor
*
Expand Down
Loading