123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158 |
- define([
- '../Core/defined',
- '../Core/defineProperties',
- '../Core/DeveloperError',
- '../Core/Event',
- '../Core/EventHelper',
- '../Core/TimeIntervalCollection',
- './Property'
- ], function(
- defined,
- defineProperties,
- DeveloperError,
- Event,
- EventHelper,
- TimeIntervalCollection,
- Property) {
- "use strict";
- function subscribeAll(property, eventHelper, definitionChanged, intervals) {
- var callback = function() {
- definitionChanged.raiseEvent(property);
- };
- var items = [];
- eventHelper.removeAll();
- var length = intervals.length;
- for (var i = 0; i < length; i++) {
- var interval = intervals.get(i);
- if (defined(interval.data) && items.indexOf(interval.data) === -1) {
- eventHelper.add(interval.data.definitionChanged, callback);
- }
- }
- }
-
- var CompositeProperty = function() {
- this._eventHelper = new EventHelper();
- this._definitionChanged = new Event();
- this._intervals = new TimeIntervalCollection();
- this._intervals.changedEvent.addEventListener(CompositeProperty.prototype._intervalsChanged, this);
- };
- defineProperties(CompositeProperty.prototype, {
-
- isConstant : {
- get : function() {
- return this._intervals.isEmpty;
- }
- },
-
- definitionChanged : {
- get : function() {
- return this._definitionChanged;
- }
- },
-
- intervals : {
- get : function() {
- return this._intervals;
- }
- }
- });
-
- CompositeProperty.prototype.getValue = function(time, result) {
-
- if (!defined(time)) {
- throw new DeveloperError('time is required');
- }
-
- var innerProperty = this._intervals.findDataForIntervalContainingDate(time);
- if (defined(innerProperty)) {
- return innerProperty.getValue(time, result);
- }
- return undefined;
- };
-
- CompositeProperty.prototype.equals = function(other) {
- return this === other ||
- (other instanceof CompositeProperty &&
- this._intervals.equals(other._intervals, Property.equals));
- };
-
- CompositeProperty.prototype._intervalsChanged = function() {
- subscribeAll(this, this._eventHelper, this._definitionChanged, this._intervals);
- this._definitionChanged.raiseEvent(this);
- };
- return CompositeProperty;
- });
|