From d5b5c078743cd48cf8d07d19594e556077619f14 Mon Sep 17 00:00:00 2001 From: Matthew Amato Date: Tue, 9 Dec 2014 22:42:39 -0500 Subject: [PATCH] Ongoing ease of use work. Add a CustomDataSource to easily add entities programmatically. Also sort requires. --- Source/DataSources/ColorMaterialProperty.js | 8 +- Source/DataSources/CustomDataSource.js | 125 ++++++++++++++++++ Source/DataSources/EntityCollection.js | 1 + Source/DataSources/GeoJsonDataSource.js | 4 +- Source/DataSources/GridMaterialProperty.js | 8 +- Source/DataSources/ImageMaterialProperty.js | 8 +- .../PolylineGlowMaterialProperty.js | 8 +- .../PolylineOutlineMaterialProperty.js | 8 +- Source/DataSources/PropertyHelper.js | 4 +- Source/DataSources/StripeMaterialProperty.js | 4 +- 10 files changed, 152 insertions(+), 26 deletions(-) create mode 100644 Source/DataSources/CustomDataSource.js diff --git a/Source/DataSources/ColorMaterialProperty.js b/Source/DataSources/ColorMaterialProperty.js index aff3342964cb..54cf3c2344d5 100644 --- a/Source/DataSources/ColorMaterialProperty.js +++ b/Source/DataSources/ColorMaterialProperty.js @@ -7,8 +7,8 @@ define([ '../Core/DeveloperError', '../Core/Event', './ConstantProperty', - './PropertyHelper', - './Property' + './Property', + './PropertyHelper' ], function( Color, defined, @@ -17,8 +17,8 @@ define([ DeveloperError, Event, ConstantProperty, - PropertyHelper, - Property) { + Property, + PropertyHelper) { "use strict"; /** diff --git a/Source/DataSources/CustomDataSource.js b/Source/DataSources/CustomDataSource.js new file mode 100644 index 000000000000..0b9722326724 --- /dev/null +++ b/Source/DataSources/CustomDataSource.js @@ -0,0 +1,125 @@ +/*global define*/ +define([ + '../Core/defineProperties', + '../Core/Event', + './DataSource', + './EntityCollection' + ], function( + defineProperties, + Event, + DataSource, + EntityCollection) { + "use strict"; + + /** + * A {@link DataSource} which processes both + * {@link http://www.geojson.org/|GeoJSON} and {@link https://github.com/mbostock/topojson|TopoJSON} data. + * {@link https://github.com/mapbox/simplestyle-spec|Simplestyle} properties will also be used if they + * are present. + * + * @alias CustomDataSource + * @constructor + * + * @param {String} [name] The name of this data source. If undefined, a name will be taken from + * the name of the GeoJSON file. + */ + var CustomDataSource = function() { + this._name = undefined; + this._clock = undefined; + this._changed = new Event(); + this._error = new Event(); + this._isLoading = false; + this._loading = new Event(); + this._entityCollection = new EntityCollection(); + }; + + defineProperties(CustomDataSource.prototype, { + /** + * Gets a human-readable name for this instance. + * @memberof CustomDataSource.prototype + * @type {String} + */ + name : { + get : function() { + return this._name; + }, + set : function(value) { + if (this._name !== value) { + this._name = value; + this._changed.raiseEvent(this); + } + } + }, + /** + * This DataSource only defines static data, therefore this property is always undefined. + * @memberof CustomDataSource.prototype + * @type {DataSourceClock} + */ + clock : { + get : function() { + return this._clock; + }, + set : function(value) { + if (this._clock !== value) { + this._clock = value; + this._changed.raiseEvent(this); + } + } + }, + /** + * Gets the collection of {@link Entity} instances. + * @memberof CustomDataSource.prototype + * @type {EntityCollection} + */ + entities : { + get : function() { + return this._entityCollection; + } + }, + /** + * Gets a value indicating if the data source is currently loading data. + * @memberof CustomDataSource.prototype + * @type {Boolean} + */ + isLoading : { + get : function() { + return this._isLoading; + }, + set : function(value) { + DataSource.setLoading(this, value); + } + }, + /** + * Gets an event that will be raised when the underlying data changes. + * @memberof CustomDataSource.prototype + * @type {Event} + */ + changedEvent : { + get : function() { + return this._changed; + } + }, + /** + * Gets an event that will be raised if an error is encountered during processing. + * @memberof CustomDataSource.prototype + * @type {Event} + */ + errorEvent : { + get : function() { + return this._error; + } + }, + /** + * Gets an event that will be raised when the data source either starts or stops loading. + * @memberof CustomDataSource.prototype + * @type {Event} + */ + loadingEvent : { + get : function() { + return this._loading; + } + } + }); + + return CustomDataSource; +}); \ No newline at end of file diff --git a/Source/DataSources/EntityCollection.js b/Source/DataSources/EntityCollection.js index ed23de17cb65..a7b413c31419 100644 --- a/Source/DataSources/EntityCollection.js +++ b/Source/DataSources/EntityCollection.js @@ -206,6 +206,7 @@ define([ entity.definitionChanged.addEventListener(EntityCollection.prototype._onEntityDefinitionChanged, this); fireChangedEvent(this); + return entity; }; /** diff --git a/Source/DataSources/GeoJsonDataSource.js b/Source/DataSources/GeoJsonDataSource.js index fcf7ba84bf0c..1ab6a7b13809 100644 --- a/Source/DataSources/GeoJsonDataSource.js +++ b/Source/DataSources/GeoJsonDataSource.js @@ -17,12 +17,12 @@ define([ '../ThirdParty/topojson', '../ThirdParty/when', './BillboardGraphics', + './CallbackProperty', './ColorMaterialProperty', './ConstantPositionProperty', './ConstantProperty', './DataSource', './EntityCollection', - './CallbackProperty', './PolygonGraphics', './PolylineGraphics' ], function( @@ -43,12 +43,12 @@ define([ topojson, when, BillboardGraphics, + CallbackProperty, ColorMaterialProperty, ConstantPositionProperty, ConstantProperty, DataSource, EntityCollection, - CallbackProperty, PolygonGraphics, PolylineGraphics) { "use strict"; diff --git a/Source/DataSources/GridMaterialProperty.js b/Source/DataSources/GridMaterialProperty.js index d2600b1c25e2..78a9daf7abc6 100644 --- a/Source/DataSources/GridMaterialProperty.js +++ b/Source/DataSources/GridMaterialProperty.js @@ -5,16 +5,16 @@ define([ '../Core/defined', '../Core/defineProperties', '../Core/Event', - './PropertyHelper', - './Property' + './Property', + './PropertyHelper' ], function( Cartesian2, Color, defined, defineProperties, Event, - PropertyHelper, - Property) { + Property, + PropertyHelper) { "use strict"; var defaultColor = Color.WHITE; diff --git a/Source/DataSources/ImageMaterialProperty.js b/Source/DataSources/ImageMaterialProperty.js index b6ba188d3f53..93d28b14171d 100644 --- a/Source/DataSources/ImageMaterialProperty.js +++ b/Source/DataSources/ImageMaterialProperty.js @@ -4,15 +4,15 @@ define([ '../Core/defined', '../Core/defineProperties', '../Core/Event', - './PropertyHelper', - './Property' + './Property', + './PropertyHelper' ], function( Cartesian2, defined, defineProperties, Event, - PropertyHelper, - Property) { + Property, + PropertyHelper) { "use strict"; var defaultRepeat = new Cartesian2(1, 1); diff --git a/Source/DataSources/PolylineGlowMaterialProperty.js b/Source/DataSources/PolylineGlowMaterialProperty.js index e1100a2eeb24..cafd5b8f3ce0 100644 --- a/Source/DataSources/PolylineGlowMaterialProperty.js +++ b/Source/DataSources/PolylineGlowMaterialProperty.js @@ -4,15 +4,15 @@ define([ '../Core/defined', '../Core/defineProperties', '../Core/Event', - './PropertyHelper', - './Property' + './Property', + './PropertyHelper' ], function( Color, defined, defineProperties, Event, - PropertyHelper, - Property) { + Property, + PropertyHelper) { "use strict"; var defaultColor = Color.WHITE; diff --git a/Source/DataSources/PolylineOutlineMaterialProperty.js b/Source/DataSources/PolylineOutlineMaterialProperty.js index a44d930a33fb..971970ad78ff 100644 --- a/Source/DataSources/PolylineOutlineMaterialProperty.js +++ b/Source/DataSources/PolylineOutlineMaterialProperty.js @@ -4,15 +4,15 @@ define([ '../Core/defined', '../Core/defineProperties', '../Core/Event', - './PropertyHelper', - './Property' + './Property', + './PropertyHelper' ], function( Color, defined, defineProperties, Event, - PropertyHelper, - Property) { + Property, + PropertyHelper) { "use strict"; var defaultColor = Color.WHITE; diff --git a/Source/DataSources/PropertyHelper.js b/Source/DataSources/PropertyHelper.js index cc0a5da3df24..9c7ff327a302 100644 --- a/Source/DataSources/PropertyHelper.js +++ b/Source/DataSources/PropertyHelper.js @@ -4,16 +4,16 @@ define([ '../Core/defaultValue', '../Core/defined', '../Core/DeveloperError', - './ConstantProperty', './ConstantPositionProperty', + './ConstantProperty', 'require' ], function( Color, defaultValue, defined, DeveloperError, - ConstantProperty, ConstantPositionProperty, + ConstantProperty, require) { "use strict"; diff --git a/Source/DataSources/StripeMaterialProperty.js b/Source/DataSources/StripeMaterialProperty.js index 1a2583615df7..b4256926b47b 100644 --- a/Source/DataSources/StripeMaterialProperty.js +++ b/Source/DataSources/StripeMaterialProperty.js @@ -4,16 +4,16 @@ define([ '../Core/defined', '../Core/defineProperties', '../Core/Event', - './PropertyHelper', './Property', + './PropertyHelper', './StripeOrientation' ], function( Color, defined, defineProperties, Event, - PropertyHelper, Property, + PropertyHelper, StripeOrientation) { "use strict";