diff --git a/Apps/CesiumViewer/CesiumViewer.js b/Apps/CesiumViewer/CesiumViewer.js index 82aa19e2a2b5..9d716b8b057c 100644 --- a/Apps/CesiumViewer/CesiumViewer.js +++ b/Apps/CesiumViewer/CesiumViewer.js @@ -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'; } diff --git a/CHANGES.md b/CHANGES.md index 2cd5e993bbb2..81db49e05bc5 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -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. diff --git a/LICENSE.md b/LICENSE.md index 53a9f18c12cd..f6df88649498 100644 --- a/LICENSE.md +++ b/LICENSE.md @@ -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 ===== diff --git a/Source/DynamicScene/GeoJsonDataSource.js b/Source/DynamicScene/GeoJsonDataSource.js index 9335b5dea669..7a20d2999ea9 100644 --- a/Source/DynamicScene/GeoJsonDataSource.js +++ b/Source/DynamicScene/GeoJsonDataSource.js @@ -15,7 +15,8 @@ define(['../Core/createGuid', './DynamicPolygon', './DynamicMaterialProperty', './DynamicObjectCollection', - '../ThirdParty/when'], function( + '../ThirdParty/when', + '../ThirdParty/topojson'], function( createGuid, Cartographic, Color, @@ -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 @@ -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. @@ -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; @@ -179,7 +187,8 @@ define(['../Core/createGuid', MultiPoint : processMultiPoint, MultiPolygon : processMultiPolygon, Point : processPoint, - Polygon : processPolygon + Polygon : processPolygon, + Topology : processTopology }; var geometryTypes = { @@ -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 * diff --git a/Source/ThirdParty/topojson.js b/Source/ThirdParty/topojson.js new file mode 100644 index 000000000000..9ec40cf33a81 --- /dev/null +++ b/Source/ThirdParty/topojson.js @@ -0,0 +1,335 @@ +/** +@license +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. +*/ + +/** + * @author sole / http://soledadpenades.com + * @author mrdoob / http://mrdoob.com + * @author Robert Eisele / http://www.xarg.org + * @author Philippe / http://philippe.elsass.me + * @author Robert Penner / http://www.robertpenner.com/easing_terms_of_use.html + * @author Paul Lewis / http://www.aerotwist.com/ + * @author lechecacharro + * @author Josh Faul / http://jocafa.com/ + * @author egraether / http://egraether.com/ + */ + +/*global define*/ +define(function() { + +var topojson = (function() { + + function merge(topology, arcs) { + var arcsByEnd = {}, + fragmentByStart = {}, + fragmentByEnd = {}; + + arcs.forEach(function(i) { + var e = ends(i); + (arcsByEnd[e[0]] || (arcsByEnd[e[0]] = [])).push(i); + (arcsByEnd[e[1]] || (arcsByEnd[e[1]] = [])).push(~i); + }); + + arcs.forEach(function(i) { + var e = ends(i), + start = e[0], + end = e[1], + f, g; + + if (f = fragmentByEnd[start]) { + delete fragmentByEnd[f.end]; + f.push(i); + f.end = end; + if (g = fragmentByStart[end]) { + delete fragmentByStart[g.start]; + var fg = g === f ? f : f.concat(g); + fragmentByStart[fg.start = f.start] = fragmentByEnd[fg.end = g.end] = fg; + } else if (g = fragmentByEnd[end]) { + delete fragmentByStart[g.start]; + delete fragmentByEnd[g.end]; + var fg = f.concat(g.map(function(i) { return ~i; }).reverse()); + fragmentByStart[fg.start = f.start] = fragmentByEnd[fg.end = g.start] = fg; + } else { + fragmentByStart[f.start] = fragmentByEnd[f.end] = f; + } + } else if (f = fragmentByStart[end]) { + delete fragmentByStart[f.start]; + f.unshift(i); + f.start = start; + if (g = fragmentByEnd[start]) { + delete fragmentByEnd[g.end]; + var gf = g === f ? f : g.concat(f); + fragmentByStart[gf.start = g.start] = fragmentByEnd[gf.end = f.end] = gf; + } else if (g = fragmentByStart[start]) { + delete fragmentByStart[g.start]; + delete fragmentByEnd[g.end]; + var gf = g.map(function(i) { return ~i; }).reverse().concat(f); + fragmentByStart[gf.start = g.end] = fragmentByEnd[gf.end = f.end] = gf; + } else { + fragmentByStart[f.start] = fragmentByEnd[f.end] = f; + } + } else if (f = fragmentByStart[start]) { + delete fragmentByStart[f.start]; + f.unshift(~i); + f.start = end; + if (g = fragmentByEnd[end]) { + delete fragmentByEnd[g.end]; + var gf = g === f ? f : g.concat(f); + fragmentByStart[gf.start = g.start] = fragmentByEnd[gf.end = f.end] = gf; + } else if (g = fragmentByStart[end]) { + delete fragmentByStart[g.start]; + delete fragmentByEnd[g.end]; + var gf = g.map(function(i) { return ~i; }).reverse().concat(f); + fragmentByStart[gf.start = g.end] = fragmentByEnd[gf.end = f.end] = gf; + } else { + fragmentByStart[f.start] = fragmentByEnd[f.end] = f; + } + } else if (f = fragmentByEnd[end]) { + delete fragmentByEnd[f.end]; + f.push(~i); + f.end = start; + if (g = fragmentByEnd[start]) { + delete fragmentByStart[g.start]; + var fg = g === f ? f : f.concat(g); + fragmentByStart[fg.start = f.start] = fragmentByEnd[fg.end = g.end] = fg; + } else if (g = fragmentByStart[start]) { + delete fragmentByStart[g.start]; + delete fragmentByEnd[g.end]; + var fg = f.concat(g.map(function(i) { return ~i; }).reverse()); + fragmentByStart[fg.start = f.start] = fragmentByEnd[fg.end = g.start] = fg; + } else { + fragmentByStart[f.start] = fragmentByEnd[f.end] = f; + } + } else { + f = [i]; + fragmentByStart[f.start = start] = fragmentByEnd[f.end = end] = f; + } + }); + + function ends(i) { + var arc = topology.arcs[i], p0 = arc[0], p1 = [0, 0]; + arc.forEach(function(dp) { p1[0] += dp[0], p1[1] += dp[1]; }); + return [p0, p1]; + } + + var fragments = []; + for (var k in fragmentByEnd) fragments.push(fragmentByEnd[k]); + return fragments; + } + + function mesh(topology, o, filter) { + var arcs = []; + + if (arguments.length > 1) { + var geomsByArc = [], + geom; + + function arc(i) { + if (i < 0) i = ~i; + (geomsByArc[i] || (geomsByArc[i] = [])).push(geom); + } + + function line(arcs) { + arcs.forEach(arc); + } + + function polygon(arcs) { + arcs.forEach(line); + } + + function geometry(o) { + if (o.type === "GeometryCollection") o.geometries.forEach(geometry); + else if (o.type in geometryType) { + geom = o; + geometryType[o.type](o.arcs); + } + } + + var geometryType = { + LineString: line, + MultiLineString: polygon, + Polygon: polygon, + MultiPolygon: function(arcs) { arcs.forEach(polygon); } + }; + + geometry(o); + + geomsByArc.forEach(arguments.length < 3 + ? function(geoms, i) { arcs.push(i); } + : function(geoms, i) { if (filter(geoms[0], geoms[geoms.length - 1])) arcs.push(i); }); + } else { + for (var i = 0, n = topology.arcs.length; i < n; ++i) arcs.push(i); + } + + return object(topology, {type: "MultiLineString", arcs: merge(topology, arcs)}); + } + + function featureOrCollection(topology, o) { + return o.type === "GeometryCollection" ? { + type: "FeatureCollection", + features: o.geometries.map(function(o) { return feature(topology, o); }) + } : feature(topology, o); + } + + function feature(topology, o) { + var f = { + type: "Feature", + id: o.id, + properties: o.properties || {}, + geometry: object(topology, o) + }; + if (o.id == null) delete f.id; + return f; + } + + function object(topology, o) { + var tf = topology.transform, + kx = tf.scale[0], + ky = tf.scale[1], + dx = tf.translate[0], + dy = tf.translate[1], + arcs = topology.arcs; + + function arc(i, points) { + if (points.length) points.pop(); + for (var a = arcs[i < 0 ? ~i : i], k = 0, n = a.length, x = 0, y = 0, p; k < n; ++k) points.push([ + (x += (p = a[k])[0]) * kx + dx, + (y += p[1]) * ky + dy + ]); + if (i < 0) reverse(points, n); + } + + function point(coordinates) { + return [coordinates[0] * kx + dx, coordinates[1] * ky + dy]; + } + + function line(arcs) { + var points = []; + for (var i = 0, n = arcs.length; i < n; ++i) arc(arcs[i], points); + if (points.length < 2) points.push(points[0]); + return points; + } + + function ring(arcs) { + var points = line(arcs); + while (points.length < 4) points.push(points[0]); + return points; + } + + function polygon(arcs) { + return arcs.map(ring); + } + + function geometry(o) { + var t = o.type; + return t === "GeometryCollection" ? {type: t, geometries: o.geometries.map(geometry)} + : t in geometryType ? {type: t, coordinates: geometryType[t](o)} + : null; + } + + var geometryType = { + Point: function(o) { return point(o.coordinates); }, + MultiPoint: function(o) { return o.coordinates.map(point); }, + LineString: function(o) { return line(o.arcs); }, + MultiLineString: function(o) { return o.arcs.map(line); }, + Polygon: function(o) { return polygon(o.arcs); }, + MultiPolygon: function(o) { return o.arcs.map(polygon); } + }; + + return geometry(o); + } + + function reverse(array, n) { + var t, j = array.length, i = j - n; while (i < --j) t = array[i], array[i++] = array[j], array[j] = t; + } + + function bisect(a, x) { + var lo = 0, hi = a.length; + while (lo < hi) { + var mid = lo + hi >>> 1; + if (a[mid] < x) lo = mid + 1; + else hi = mid; + } + return lo; + } + + function neighbors(objects) { + var indexesByArc = {}, // arc index -> array of object indexes + neighbors = objects.map(function() { return []; }); + + function line(arcs, i) { + arcs.forEach(function(a) { + if (a < 0) a = ~a; + var o = indexesByArc[a]; + if (o) o.push(i); + else indexesByArc[a] = [i]; + }); + } + + function polygon(arcs, i) { + arcs.forEach(function(arc) { line(arc, i); }); + } + + function geometry(o, i) { + if (o.type === "GeometryCollection") o.geometries.forEach(function(o) { geometry(o, i); }); + else if (o.type in geometryType) geometryType[o.type](o.arcs, i); + } + + var geometryType = { + LineString: line, + MultiLineString: polygon, + Polygon: polygon, + MultiPolygon: function(arcs, i) { arcs.forEach(function(arc) { polygon(arc, i); }); } + }; + + objects.forEach(geometry); + + for (var i in indexesByArc) { + for (var indexes = indexesByArc[i], m = indexes.length, j = 0; j < m; ++j) { + for (var k = j + 1; k < m; ++k) { + var ij = indexes[j], ik = indexes[k], n; + if ((n = neighbors[ij])[i = bisect(n, ik)] !== ik) n.splice(i, 0, ik); + if ((n = neighbors[ik])[i = bisect(n, ij)] !== ij) n.splice(i, 0, ij); + } + } + } + + return neighbors; + } + + return { + version: "1.1.4", + mesh: mesh, + feature: featureOrCollection, + neighbors: neighbors + }; +})(); + +return topojson; +}); \ No newline at end of file diff --git a/Source/Widgets/Viewer/viewerDragDropMixin.js b/Source/Widgets/Viewer/viewerDragDropMixin.js index 1739284b3ec4..84fffd141a63 100644 --- a/Source/Widgets/Viewer/viewerDragDropMixin.js +++ b/Source/Widgets/Viewer/viewerDragDropMixin.js @@ -204,9 +204,12 @@ define([ function createOnLoadCallback(viewer, source, firstTime) { var DataSource; - if (endsWith(source.toUpperCase(), ".CZML")) { + var sourceUpperCase = source.toUpperCase(); + if (endsWith(sourceUpperCase, ".CZML")) { DataSource = CzmlDataSource; - } else if (endsWith(source.toUpperCase(), '.GEOJSON')) { + } else if (endsWith(sourceUpperCase, ".GEOJSON") || // + endsWith(sourceUpperCase, ".JSON") || // + endsWith(sourceUpperCase, ".TOPOJSON")) { DataSource = GeoJsonDataSource; } else { viewer.onDropError.raiseEvent(viewer, source, 'Unrecognized file extension: ' + source); diff --git a/Specs/Data/test.geojson b/Specs/Data/test.geojson index 71609fe2143a..21898279a425 100644 --- a/Specs/Data/test.geojson +++ b/Specs/Data/test.geojson @@ -1,40 +1,51 @@ { "type" : "FeatureCollection", - "features" : [ - { - "type" : "Feature", - "geometry" : { - "type" : "Point", - "coordinates" : [ 102.0, 0.5 ] - }, - "properties" : { - "prop0" : "value0" - } - }, - { - "type" : "Feature", - "geometry" : { - "type" : "LineString", - "coordinates" : [ [ 102.0, 0.0 ], [ 103.0, 1.0 ], - [ 104.0, 0.0 ], [ 105.0, 1.0 ] ] - }, - "properties" : { - "prop0" : "value0", - "prop1" : 0.0 - } - }, - { - "type" : "Feature", - "geometry" : { - "type" : "Polygon", - "coordinates" : [ [ [ 100.0, 0.0 ], [ 101.0, 0.0 ], - [ 101.0, 1.0 ], [ 100.0, 1.0 ], [ 100.0, 0.0 ] ] ] - }, - "properties" : { - "prop0" : "value0", - "prop1" : { - "this" : "that" - } - } - } ] -} \ No newline at end of file + "features" : [{ + "type" : "Feature", + "geometry" : { + "type" : "Point", + "coordinates" : [102.0, 0.5] + }, + "properties" : { + "prop0" : "value0" + } + }, { + "type" : "Feature", + "geometry" : { + "type" : "LineString", + "coordinates" : [[102.0, 0.0], [103.0, 1.0], [104.0, 0.0], [105.0, 1.0]] + }, + "properties" : { + "prop0" : "value0", + "prop1" : 0.0 + } + }, { + "type" : "Feature", + "geometry" : { + "type" : "Polygon", + "coordinates" : [[[100.0, 0.0], [101.0, 0.0], [101.0, 1.0], [100.0, 1.0], [100.0, 0.0]]] + }, + "properties" : { + "prop0" : "value0", + "prop1" : { + "this" : "that" + } + } + }, { + "type" : "Feature", + "geometry" : { + "type" : "Topology", + "transform" : { + "scale" : [1, 1], + "translate" : [0, 0] + }, + "objects" : { + "polygon" : { + "type" : "Polygon", + "arcs" : [[0, 1, 2, 3]] + } + }, + "arcs" : [[[0, 0], [1, 0], [0, 1], [-1, 0], [0, -1]], [[0, 0], [1, 0], [0, 1]], [[1, 1], [-1, 0], [0, -1]], [[1, 1]], [[0, 0]]] + } + }] +} diff --git a/Specs/DynamicScene/GeoJsonDataSourceSpec.js b/Specs/DynamicScene/GeoJsonDataSourceSpec.js index e1682fc32542..b85a1fcc0e58 100644 --- a/Specs/DynamicScene/GeoJsonDataSourceSpec.js +++ b/Specs/DynamicScene/GeoJsonDataSourceSpec.js @@ -155,6 +155,31 @@ defineSuite(['DynamicScene/GeoJsonDataSource', 'geometries' : [unknownGeometry] }; + var topoJson = { + type : "Topology", + transform : { + scale : [1, 1], + translate : [0, 0] + }, + objects : { + polygon : { + type : "Polygon", + arcs : [[0, 1, 2, 3]], + properties : { + myProps : 0 + } + }, + lineString : { + type : "LineString", + arcs : [4], + properties : { + myProps : 1 + } + } + }, + "arcs" : [[[0, 0], [1, 0], [0, 1], [-1, 0], [0, -1]], [[0, 0], [1, 0], [0, 1]], [[1, 1], [-1, 0], [0, -1]], [[1, 1]], [[0, 0]]] + }; + it('default constructor has expected values', function() { var dataSource = new GeoJsonDataSource(); expect(dataSource.getChangedEvent()).toBeInstanceOf(Event); @@ -339,6 +364,29 @@ defineSuite(['DynamicScene/GeoJsonDataSource', }); }); + it('Works with topojson geometry', function() { + var dataSource = new GeoJsonDataSource(); + dataSource.load(topoJson); + + var dynamicObjectCollection = dataSource.getDynamicObjectCollection(); + waitsFor(function() { + return dynamicObjectCollection.getObjects().length === 2; + }); + runs(function() { + var objects = dynamicObjectCollection.getObjects(); + + var polygon = objects[0]; + expect(polygon.geoJson.properties).toBe(topoJson.objects.polygon.properties); + expect(polygon.vertexPositions).toBeDefined(); + expect(polygon.polygon).toBeDefined(); + expect(polygon.polyline).toBeDefined(); + + var lineString = objects[1]; + expect(lineString.geoJson.properties).toBe(topoJson.objects.lineString.properties); + expect(lineString.polyline).toBeDefined(); + }); + }); + it('Works with geometrycollection', function() { var dataSource = new GeoJsonDataSource(); dataSource.load(geometryCollection); @@ -404,7 +452,7 @@ defineSuite(['DynamicScene/GeoJsonDataSource', dataSource.loadUrl('Data/test.geojson'); waitsFor(function() { - return dataSource.getDynamicObjectCollection().getObjects().length === 3; + return dataSource.getDynamicObjectCollection().getObjects().length === 4; }); });