123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500 |
- define([
- '../Core/Color',
- '../Core/ColorGeometryInstanceAttribute',
- '../Core/defaultValue',
- '../Core/defined',
- '../Core/defineProperties',
- '../Core/destroyObject',
- '../Core/DeveloperError',
- '../Core/Ellipsoid',
- '../Core/Event',
- '../Core/GeometryInstance',
- '../Core/Iso8601',
- '../Core/PolylineGeometry',
- '../Core/PolylinePipeline',
- '../Core/ShowGeometryInstanceAttribute',
- '../Scene/PolylineCollection',
- '../Scene/PolylineColorAppearance',
- '../Scene/PolylineMaterialAppearance',
- './ColorMaterialProperty',
- './ConstantProperty',
- './MaterialProperty',
- './Property'
- ], function(
- Color,
- ColorGeometryInstanceAttribute,
- defaultValue,
- defined,
- defineProperties,
- destroyObject,
- DeveloperError,
- Ellipsoid,
- Event,
- GeometryInstance,
- Iso8601,
- PolylineGeometry,
- PolylinePipeline,
- ShowGeometryInstanceAttribute,
- PolylineCollection,
- PolylineColorAppearance,
- PolylineMaterialAppearance,
- ColorMaterialProperty,
- ConstantProperty,
- MaterialProperty,
- Property) {
- "use strict";
-
- var polylineCollections = {};
- var defaultMaterial = ColorMaterialProperty.fromColor(Color.WHITE);
- var defaultShow = new ConstantProperty(true);
- var GeometryOptions = function(entity) {
- this.id = entity;
- this.vertexFormat = undefined;
- this.positions = undefined;
- this.width = undefined;
- this.followSurface = undefined;
- this.granularity = undefined;
- };
-
- var PolylineGeometryUpdater = function(entity, scene) {
-
- if (!defined(entity)) {
- throw new DeveloperError('entity is required');
- }
- if (!defined(scene)) {
- throw new DeveloperError('scene is required');
- }
-
- this._entity = entity;
- this._scene = scene;
- this._entitySubscription = entity.definitionChanged.addEventListener(PolylineGeometryUpdater.prototype._onEntityPropertyChanged, this);
- this._fillEnabled = false;
- this._dynamic = false;
- this._geometryChanged = new Event();
- this._showProperty = undefined;
- this._materialProperty = undefined;
- this._options = new GeometryOptions(entity);
- this._onEntityPropertyChanged(entity, 'polyline', entity.polyline, undefined);
- };
- defineProperties(PolylineGeometryUpdater, {
-
- perInstanceColorAppearanceType : {
- value : PolylineColorAppearance
- },
-
- materialAppearanceType : {
- value : PolylineMaterialAppearance
- }
- });
- defineProperties(PolylineGeometryUpdater.prototype, {
-
- entity : {
- get : function() {
- return this._entity;
- }
- },
-
- fillEnabled : {
- get : function() {
- return this._fillEnabled;
- }
- },
-
- hasConstantFill : {
- get : function() {
- return !this._fillEnabled || (!defined(this._entity.availability) && Property.isConstant(this._showProperty));
- }
- },
-
- fillMaterialProperty : {
- get : function() {
- return this._materialProperty;
- }
- },
-
- outlineEnabled : {
- value : false
- },
-
- hasConstantOutline : {
- value : true
- },
-
- outlineColorProperty : {
- value : undefined
- },
-
- isDynamic : {
- get : function() {
- return this._dynamic;
- }
- },
-
- isClosed : {
- value : false
- },
-
- geometryChanged : {
- get : function() {
- return this._geometryChanged;
- }
- }
- });
-
- PolylineGeometryUpdater.prototype.isOutlineVisible = function(time) {
- return false;
- };
-
- PolylineGeometryUpdater.prototype.isFilled = function(time) {
- var entity = this._entity;
- return this._fillEnabled && entity.isAvailable(time) && this._showProperty.getValue(time);
- };
-
- PolylineGeometryUpdater.prototype.createFillGeometryInstance = function(time) {
-
- if (!defined(time)) {
- throw new DeveloperError('time is required.');
- }
- if (!this._fillEnabled) {
- throw new DeveloperError('This instance does not represent a filled geometry.');
- }
-
- var color;
- var attributes;
- var entity = this._entity;
- var isAvailable = entity.isAvailable(time);
- var show = new ShowGeometryInstanceAttribute(isAvailable && this._showProperty.getValue(time));
- if (this._materialProperty instanceof ColorMaterialProperty) {
- var currentColor = Color.WHITE;
- if (defined(this._materialProperty.color) && (this._materialProperty.color.isConstant || isAvailable)) {
- currentColor = this._materialProperty.color.getValue(time);
- }
- color = ColorGeometryInstanceAttribute.fromColor(currentColor);
- attributes = {
- show : show,
- color : color
- };
- } else {
- attributes = {
- show : show
- };
- }
- return new GeometryInstance({
- id : entity,
- geometry : new PolylineGeometry(this._options),
- attributes : attributes
- });
- };
-
- PolylineGeometryUpdater.prototype.createOutlineGeometryInstance = function(time) {
-
- throw new DeveloperError('This instance does not represent an outlined geometry.');
-
- };
-
- PolylineGeometryUpdater.prototype.isDestroyed = function() {
- return false;
- };
-
- PolylineGeometryUpdater.prototype.destroy = function() {
- this._entitySubscription();
- destroyObject(this);
- };
- PolylineGeometryUpdater.prototype._onEntityPropertyChanged = function(entity, propertyName, newValue, oldValue) {
- if (!(propertyName === 'availability' || propertyName === 'polyline')) {
- return;
- }
- var polyline = this._entity.polyline;
- if (!defined(polyline)) {
- if (this._fillEnabled) {
- this._fillEnabled = false;
- this._geometryChanged.raiseEvent(this);
- }
- return;
- }
- var positionsProperty = polyline.positions;
- var show = polyline.show;
- if ((defined(show) && show.isConstant && !show.getValue(Iso8601.MINIMUM_VALUE)) ||
- (!defined(positionsProperty))) {
- if (this._fillEnabled) {
- this._fillEnabled = false;
- this._geometryChanged.raiseEvent(this);
- }
- return;
- }
- var material = defaultValue(polyline.material, defaultMaterial);
- var isColorMaterial = material instanceof ColorMaterialProperty;
- this._materialProperty = material;
- this._showProperty = defaultValue(show, defaultShow);
- this._fillEnabled = true;
- var width = polyline.width;
- var followSurface = polyline.followSurface;
- var granularity = polyline.granularity;
- if (!positionsProperty.isConstant || !Property.isConstant(width) ||
- !Property.isConstant(followSurface) || !Property.isConstant(granularity)) {
- if (!this._dynamic) {
- this._dynamic = true;
- this._geometryChanged.raiseEvent(this);
- }
- } else {
- var options = this._options;
- var positions = positionsProperty.getValue(Iso8601.MINIMUM_VALUE, options.positions);
-
-
- if (!defined(positions) || positions.length < 2) {
- if (this._fillEnabled) {
- this._fillEnabled = false;
- this._geometryChanged.raiseEvent(this);
- }
- return;
- }
- options.vertexFormat = isColorMaterial ? PolylineColorAppearance.VERTEX_FORMAT : PolylineMaterialAppearance.VERTEX_FORMAT;
- options.positions = positions;
- options.width = defined(width) ? width.getValue(Iso8601.MINIMUM_VALUE) : undefined;
- options.followSurface = defined(followSurface) ? followSurface.getValue(Iso8601.MINIMUM_VALUE) : undefined;
- options.granularity = defined(granularity) ? granularity.getValue(Iso8601.MINIMUM_VALUE) : undefined;
- this._dynamic = false;
- this._geometryChanged.raiseEvent(this);
- }
- };
-
- PolylineGeometryUpdater.prototype.createDynamicUpdater = function(primitives) {
-
- if (!this._dynamic) {
- throw new DeveloperError('This instance does not represent dynamic geometry.');
- }
- if (!defined(primitives)) {
- throw new DeveloperError('primitives is required.');
- }
-
- return new DynamicGeometryUpdater(primitives, this);
- };
-
- var DynamicGeometryUpdater = function(primitives, geometryUpdater) {
- var sceneId = geometryUpdater._scene.id;
- var polylineCollection = polylineCollections[sceneId];
- if (!defined(polylineCollection)) {
- polylineCollection = new PolylineCollection();
- polylineCollections[sceneId] = polylineCollection;
- primitives.add(polylineCollection);
- }
- var line = polylineCollection.add();
- line.id = geometryUpdater._entity;
- this._line = line;
- this._primitives = primitives;
- this._geometryUpdater = geometryUpdater;
- this._positions = [];
- };
- var generateCartesianArcOptions = {
- positions : undefined,
- granularity : undefined,
- height : undefined
- };
- DynamicGeometryUpdater.prototype.update = function(time) {
- var geometryUpdater = this._geometryUpdater;
- var entity = geometryUpdater._entity;
- var polyline = entity.polyline;
- var line = this._line;
- if (!entity.isAvailable(time) || !Property.getValueOrDefault(polyline._show, time, true)) {
- line.show = false;
- return;
- }
- var positionsProperty = polyline.positions;
- var positions = Property.getValueOrUndefined(positionsProperty, time, this._positions);
- if (!defined(positions)) {
- line.show = false;
- return;
- }
- var followSurface = Property.getValueOrDefault(polyline._followSurface, time, true);
- if (followSurface) {
- generateCartesianArcOptions.positions = positions;
- generateCartesianArcOptions.granularity = Property.getValueOrUndefined(polyline._granularity, time);
- generateCartesianArcOptions.height = PolylinePipeline.extractHeights(positions, Ellipsoid.WGS84);
- positions = PolylinePipeline.generateCartesianArc(generateCartesianArcOptions);
- }
- line.show = true;
- line.positions = positions;
- line.material = MaterialProperty.getValue(time, geometryUpdater.fillMaterialProperty, line.material);
- line.width = Property.getValueOrDefault(polyline._width, time, 1);
- };
- DynamicGeometryUpdater.prototype.isDestroyed = function() {
- return false;
- };
- DynamicGeometryUpdater.prototype.destroy = function() {
- var geometryUpdater = this._geometryUpdater;
- var sceneId = geometryUpdater._scene.id;
- var polylineCollection = polylineCollections[sceneId];
- polylineCollection.remove(this._line);
- if (polylineCollection.length === 0) {
- this._primitives.removeAndDestroy(polylineCollection);
- delete polylineCollections[sceneId];
- }
- destroyObject(this);
- };
- return PolylineGeometryUpdater;
- });
|