123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237 |
- define([
- '../Core/defaultValue',
- '../Core/defined',
- '../Core/destroyObject',
- '../Core/DeveloperError',
- '../Core/EventHelper',
- './BillboardVisualizer',
- './BoxGeometryUpdater',
- './CorridorGeometryUpdater',
- './CylinderGeometryUpdater',
- './EllipseGeometryUpdater',
- './EllipsoidGeometryUpdater',
- './GeometryVisualizer',
- './LabelVisualizer',
- './ModelVisualizer',
- './PathVisualizer',
- './PointVisualizer',
- './PolygonGeometryUpdater',
- './PolylineGeometryUpdater',
- './RectangleGeometryUpdater',
- './WallGeometryUpdater'
- ], function(
- defaultValue,
- defined,
- destroyObject,
- DeveloperError,
- EventHelper,
- BillboardVisualizer,
- BoxGeometryUpdater,
- CorridorGeometryUpdater,
- CylinderGeometryUpdater,
- EllipseGeometryUpdater,
- EllipsoidGeometryUpdater,
- GeometryVisualizer,
- LabelVisualizer,
- ModelVisualizer,
- PathVisualizer,
- PointVisualizer,
- PolygonGeometryUpdater,
- PolylineGeometryUpdater,
- RectangleGeometryUpdater,
- WallGeometryUpdater) {
- "use strict";
-
- var DataSourceDisplay = function(options) {
- var scene = options.scene;
- var dataSourceCollection = options.dataSourceCollection;
-
- if (!defined(options)) {
- throw new DeveloperError('options is required.');
- }
- if (!defined(options.scene)) {
- throw new DeveloperError('scene is required.');
- }
- if (!defined(options.dataSourceCollection)) {
- throw new DeveloperError('dataSourceCollection is required.');
- }
-
- this._eventHelper = new EventHelper();
- this._eventHelper.add(dataSourceCollection.dataSourceAdded, this._onDataSourceAdded, this);
- this._eventHelper.add(dataSourceCollection.dataSourceRemoved, this._onDataSourceRemoved, this);
- this._dataSourceCollection = dataSourceCollection;
- this._scene = scene;
- this._visualizersCallback = defaultValue(options.visualizersCallback, DataSourceDisplay.defaultVisualizersCallback);
- for (var i = 0, len = dataSourceCollection.length; i < len; i++) {
- this._onDataSourceAdded(dataSourceCollection, dataSourceCollection.get(i));
- }
- };
-
- DataSourceDisplay.defaultVisualizersCallback = function(scene, dataSource) {
- var entities = dataSource.entities;
- return [new BillboardVisualizer(scene, entities),
- new GeometryVisualizer(BoxGeometryUpdater, scene, entities),
- new GeometryVisualizer(CylinderGeometryUpdater, scene, entities),
- new GeometryVisualizer(CorridorGeometryUpdater, scene, entities),
- new GeometryVisualizer(EllipseGeometryUpdater, scene, entities),
- new GeometryVisualizer(EllipsoidGeometryUpdater, scene, entities),
- new GeometryVisualizer(PolygonGeometryUpdater, scene, entities),
- new GeometryVisualizer(PolylineGeometryUpdater, scene, entities),
- new GeometryVisualizer(RectangleGeometryUpdater, scene, entities),
- new GeometryVisualizer(WallGeometryUpdater, scene, entities),
- new LabelVisualizer(scene, entities),
- new ModelVisualizer(scene, entities),
- new PointVisualizer(scene, entities),
- new PathVisualizer(scene, entities)];
- };
-
- DataSourceDisplay.prototype.getScene = function() {
- return this._scene;
- };
-
- DataSourceDisplay.prototype.getDataSources = function() {
- return this._dataSourceCollection;
- };
-
- DataSourceDisplay.prototype.isDestroyed = function() {
- return false;
- };
-
- DataSourceDisplay.prototype.destroy = function() {
- this._eventHelper.removeAll();
- var dataSourceCollection = this._dataSourceCollection;
- for (var i = 0, length = dataSourceCollection.length; i < length; ++i) {
- this._onDataSourceRemoved(this._dataSourceCollection, dataSourceCollection.get(i));
- }
- return destroyObject(this);
- };
-
- DataSourceDisplay.prototype.update = function(time) {
-
- if (!defined(time)) {
- throw new DeveloperError('time is required.');
- }
-
- var result = true;
- var i;
- var x;
- var visualizers;
- var vLength;
- var dataSources = this._dataSourceCollection;
- var length = dataSources.length;
- for (i = 0; i < length; i++) {
- var dataSource = dataSources.get(i);
- if (defined(dataSource.update)) {
- result = dataSource.update(time) && result;
- }
- visualizers = dataSource._visualizers;
- vLength = visualizers.length;
- for (x = 0; x < vLength; x++) {
- result = visualizers[x].update(time) && result;
- }
- }
- return result;
- };
- DataSourceDisplay.prototype._onDataSourceAdded = function(dataSourceCollection, dataSource) {
- var visualizers = this._visualizersCallback(this._scene, dataSource);
- dataSource._visualizers = visualizers;
- };
- DataSourceDisplay.prototype._onDataSourceRemoved = function(dataSourceCollection, dataSource) {
- var visualizers = dataSource._visualizers;
- var length = visualizers.length;
- for (var i = 0; i < length; i++) {
- visualizers[i].destroy();
- dataSource._visualizers = undefined;
- }
- };
-
- return DataSourceDisplay;
- });
|