123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201 |
- define([
- '../Core/defaultValue',
- '../Core/defined',
- '../Core/defineProperties',
- '../Core/destroyObject',
- '../Core/DeveloperError',
- '../Core/Event'
- ], function(
- defaultValue,
- defined,
- defineProperties,
- destroyObject,
- DeveloperError,
- Event) {
- "use strict";
-
- var DataSourceCollection = function() {
- this._dataSources = [];
- this._dataSourceAdded = new Event();
- this._dataSourceRemoved = new Event();
- };
- defineProperties(DataSourceCollection.prototype, {
-
- length : {
- get : function() {
- return this._dataSources.length;
- }
- },
-
- dataSourceAdded : {
- get : function() {
- return this._dataSourceAdded;
- }
- },
-
- dataSourceRemoved : {
- get : function() {
- return this._dataSourceRemoved;
- }
- }
- });
-
- DataSourceCollection.prototype.add = function(dataSource) {
-
- if (!defined(dataSource)) {
- throw new DeveloperError('dataSource is required.');
- }
-
- this._dataSources.push(dataSource);
- this._dataSourceAdded.raiseEvent(this, dataSource);
- };
-
- DataSourceCollection.prototype.remove = function(dataSource, destroy) {
- destroy = defaultValue(destroy, false);
- var index = this._dataSources.indexOf(dataSource);
- if (index !== -1) {
- this._dataSources.splice(index, 1);
- this._dataSourceRemoved.raiseEvent(this, dataSource);
- if (destroy && typeof dataSource.destroy === 'function') {
- dataSource.destroy();
- }
- return true;
- }
- return false;
- };
-
- DataSourceCollection.prototype.removeAll = function(destroy) {
- destroy = defaultValue(destroy, false);
- var dataSources = this._dataSources;
- for (var i = 0, len = dataSources.length; i < len; ++i) {
- var dataSource = dataSources[i];
- this._dataSourceRemoved.raiseEvent(this, dataSource);
- if (destroy && typeof dataSource.destroy === 'function') {
- dataSource.destroy();
- }
- }
- dataSources.length = 0;
- };
-
- DataSourceCollection.prototype.contains = function(dataSource) {
- return this.indexOf(dataSource) !== -1;
- };
-
- DataSourceCollection.prototype.indexOf = function(dataSource) {
- return this._dataSources.indexOf(dataSource);
- };
-
- DataSourceCollection.prototype.get = function(index) {
-
- if (!defined(index)) {
- throw new DeveloperError('index is required.');
- }
-
- return this._dataSources[index];
- };
-
- DataSourceCollection.prototype.isDestroyed = function() {
- return false;
- };
-
- DataSourceCollection.prototype.destroy = function() {
- this.removeAll(true);
- return destroyObject(this);
- };
- return DataSourceCollection;
- });
|