PolylineGeometryUpdater.js 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745
  1. import ArcType from '../Core/ArcType.js';
  2. import BoundingSphere from '../Core/BoundingSphere.js';
  3. import Check from '../Core/Check.js';
  4. import Color from '../Core/Color.js';
  5. import ColorGeometryInstanceAttribute from '../Core/ColorGeometryInstanceAttribute.js';
  6. import defaultValue from '../Core/defaultValue.js';
  7. import defined from '../Core/defined.js';
  8. import defineProperties from '../Core/defineProperties.js';
  9. import destroyObject from '../Core/destroyObject.js';
  10. import DeveloperError from '../Core/DeveloperError.js';
  11. import DistanceDisplayCondition from '../Core/DistanceDisplayCondition.js';
  12. import DistanceDisplayConditionGeometryInstanceAttribute from '../Core/DistanceDisplayConditionGeometryInstanceAttribute.js';
  13. import Event from '../Core/Event.js';
  14. import GeometryInstance from '../Core/GeometryInstance.js';
  15. import GroundPolylineGeometry from '../Core/GroundPolylineGeometry.js';
  16. import Iso8601 from '../Core/Iso8601.js';
  17. import oneTimeWarning from '../Core/oneTimeWarning.js';
  18. import PolylineGeometry from '../Core/PolylineGeometry.js';
  19. import PolylinePipeline from '../Core/PolylinePipeline.js';
  20. import ShowGeometryInstanceAttribute from '../Core/ShowGeometryInstanceAttribute.js';
  21. import Entity from '../DataSources/Entity.js';
  22. import ClassificationType from '../Scene/ClassificationType.js';
  23. import GroundPolylinePrimitive from '../Scene/GroundPolylinePrimitive.js';
  24. import PolylineCollection from '../Scene/PolylineCollection.js';
  25. import PolylineColorAppearance from '../Scene/PolylineColorAppearance.js';
  26. import PolylineMaterialAppearance from '../Scene/PolylineMaterialAppearance.js';
  27. import ShadowMode from '../Scene/ShadowMode.js';
  28. import BoundingSphereState from './BoundingSphereState.js';
  29. import ColorMaterialProperty from './ColorMaterialProperty.js';
  30. import ConstantProperty from './ConstantProperty.js';
  31. import MaterialProperty from './MaterialProperty.js';
  32. import Property from './Property.js';
  33. var defaultZIndex = new ConstantProperty(0);
  34. //We use this object to create one polyline collection per-scene.
  35. var polylineCollections = {};
  36. var scratchColor = new Color();
  37. var defaultMaterial = new ColorMaterialProperty(Color.WHITE);
  38. var defaultShow = new ConstantProperty(true);
  39. var defaultShadows = new ConstantProperty(ShadowMode.DISABLED);
  40. var defaultDistanceDisplayCondition = new ConstantProperty(new DistanceDisplayCondition());
  41. var defaultClassificationType = new ConstantProperty(ClassificationType.BOTH);
  42. function GeometryOptions() {
  43. this.vertexFormat = undefined;
  44. this.positions = undefined;
  45. this.width = undefined;
  46. this.arcType = undefined;
  47. this.granularity = undefined;
  48. }
  49. function GroundGeometryOptions() {
  50. this.positions = undefined;
  51. this.width = undefined;
  52. this.arcType = undefined;
  53. this.granularity = undefined;
  54. }
  55. /**
  56. * A {@link GeometryUpdater} for polylines.
  57. * Clients do not normally create this class directly, but instead rely on {@link DataSourceDisplay}.
  58. * @alias PolylineGeometryUpdater
  59. * @constructor
  60. *
  61. * @param {Entity} entity The entity containing the geometry to be visualized.
  62. * @param {Scene} scene The scene where visualization is taking place.
  63. */
  64. function PolylineGeometryUpdater(entity, scene) {
  65. //>>includeStart('debug', pragmas.debug);
  66. if (!defined(entity)) {
  67. throw new DeveloperError('entity is required');
  68. }
  69. if (!defined(scene)) {
  70. throw new DeveloperError('scene is required');
  71. }
  72. //>>includeEnd('debug');
  73. this._entity = entity;
  74. this._scene = scene;
  75. this._entitySubscription = entity.definitionChanged.addEventListener(PolylineGeometryUpdater.prototype._onEntityPropertyChanged, this);
  76. this._fillEnabled = false;
  77. this._dynamic = false;
  78. this._geometryChanged = new Event();
  79. this._showProperty = undefined;
  80. this._materialProperty = undefined;
  81. this._shadowsProperty = undefined;
  82. this._distanceDisplayConditionProperty = undefined;
  83. this._classificationTypeProperty = undefined;
  84. this._depthFailMaterialProperty = undefined;
  85. this._geometryOptions = new GeometryOptions();
  86. this._groundGeometryOptions = new GroundGeometryOptions();
  87. this._id = 'polyline-' + entity.id;
  88. this._clampToGround = false;
  89. this._supportsPolylinesOnTerrain = Entity.supportsPolylinesOnTerrain(scene);
  90. this._zIndex = 0;
  91. this._onEntityPropertyChanged(entity, 'polyline', entity.polyline, undefined);
  92. }
  93. defineProperties(PolylineGeometryUpdater.prototype, {
  94. /**
  95. * Gets the unique ID associated with this updater
  96. * @memberof PolylineGeometryUpdater.prototype
  97. * @type {String}
  98. * @readonly
  99. */
  100. id: {
  101. get: function() {
  102. return this._id;
  103. }
  104. },
  105. /**
  106. * Gets the entity associated with this geometry.
  107. * @memberof PolylineGeometryUpdater.prototype
  108. *
  109. * @type {Entity}
  110. * @readonly
  111. */
  112. entity : {
  113. get : function() {
  114. return this._entity;
  115. }
  116. },
  117. /**
  118. * Gets a value indicating if the geometry has a fill component.
  119. * @memberof PolylineGeometryUpdater.prototype
  120. *
  121. * @type {Boolean}
  122. * @readonly
  123. */
  124. fillEnabled : {
  125. get : function() {
  126. return this._fillEnabled;
  127. }
  128. },
  129. /**
  130. * Gets a value indicating if fill visibility varies with simulation time.
  131. * @memberof PolylineGeometryUpdater.prototype
  132. *
  133. * @type {Boolean}
  134. * @readonly
  135. */
  136. hasConstantFill : {
  137. get : function() {
  138. return !this._fillEnabled || (!defined(this._entity.availability) && Property.isConstant(this._showProperty));
  139. }
  140. },
  141. /**
  142. * Gets the material property used to fill the geometry.
  143. * @memberof PolylineGeometryUpdater.prototype
  144. *
  145. * @type {MaterialProperty}
  146. * @readonly
  147. */
  148. fillMaterialProperty : {
  149. get : function() {
  150. return this._materialProperty;
  151. }
  152. },
  153. /**
  154. * Gets the material property used to fill the geometry when it fails the depth test.
  155. * @memberof PolylineGeometryUpdater.prototype
  156. *
  157. * @type {MaterialProperty}
  158. * @readonly
  159. */
  160. depthFailMaterialProperty : {
  161. get : function() {
  162. return this._depthFailMaterialProperty;
  163. }
  164. },
  165. /**
  166. * Gets a value indicating if the geometry has an outline component.
  167. * @memberof PolylineGeometryUpdater.prototype
  168. *
  169. * @type {Boolean}
  170. * @readonly
  171. */
  172. outlineEnabled : {
  173. value : false
  174. },
  175. /**
  176. * Gets a value indicating if outline visibility varies with simulation time.
  177. * @memberof PolylineGeometryUpdater.prototype
  178. *
  179. * @type {Boolean}
  180. * @readonly
  181. */
  182. hasConstantOutline : {
  183. value : true
  184. },
  185. /**
  186. * Gets the {@link Color} property for the geometry outline.
  187. * @memberof PolylineGeometryUpdater.prototype
  188. *
  189. * @type {Property}
  190. * @readonly
  191. */
  192. outlineColorProperty : {
  193. value : undefined
  194. },
  195. /**
  196. * Gets the property specifying whether the geometry
  197. * casts or receives shadows from each light source.
  198. * @memberof PolylineGeometryUpdater.prototype
  199. *
  200. * @type {Property}
  201. * @readonly
  202. */
  203. shadowsProperty : {
  204. get : function() {
  205. return this._shadowsProperty;
  206. }
  207. },
  208. /**
  209. * Gets or sets the {@link DistanceDisplayCondition} Property specifying at what distance from the camera that this geometry will be displayed.
  210. * @memberof PolylineGeometryUpdater.prototype
  211. *
  212. * @type {Property}
  213. * @readonly
  214. */
  215. distanceDisplayConditionProperty : {
  216. get : function() {
  217. return this._distanceDisplayConditionProperty;
  218. }
  219. },
  220. /**
  221. * Gets or sets the {@link ClassificationType} Property specifying if this geometry will classify terrain, 3D Tiles, or both when on the ground.
  222. * @memberof PolylineGeometryUpdater.prototype
  223. *
  224. * @type {Property}
  225. * @readonly
  226. */
  227. classificationTypeProperty : {
  228. get : function() {
  229. return this._classificationTypeProperty;
  230. }
  231. },
  232. /**
  233. * Gets a value indicating if the geometry is time-varying.
  234. * If true, all visualization is delegated to the {@link DynamicGeometryUpdater}
  235. * returned by GeometryUpdater#createDynamicUpdater.
  236. * @memberof PolylineGeometryUpdater.prototype
  237. *
  238. * @type {Boolean}
  239. * @readonly
  240. */
  241. isDynamic : {
  242. get : function() {
  243. return this._dynamic;
  244. }
  245. },
  246. /**
  247. * Gets a value indicating if the geometry is closed.
  248. * This property is only valid for static geometry.
  249. * @memberof PolylineGeometryUpdater.prototype
  250. *
  251. * @type {Boolean}
  252. * @readonly
  253. */
  254. isClosed : {
  255. value : false
  256. },
  257. /**
  258. * Gets an event that is raised whenever the public properties
  259. * of this updater change.
  260. * @memberof PolylineGeometryUpdater.prototype
  261. *
  262. * @type {Boolean}
  263. * @readonly
  264. */
  265. geometryChanged : {
  266. get : function() {
  267. return this._geometryChanged;
  268. }
  269. },
  270. /**
  271. * Gets a value indicating if the path of the line.
  272. * @memberof PolylineGeometryUpdater.prototype
  273. *
  274. * @type {ArcType}
  275. * @readonly
  276. */
  277. arcType : {
  278. get : function() {
  279. return this._arcType;
  280. }
  281. },
  282. /**
  283. * Gets a value indicating if the geometry is clamped to the ground.
  284. * Returns false if polylines on terrain is not supported.
  285. * @memberof PolylineGeometryUpdater.prototype
  286. *
  287. * @type {Boolean}
  288. * @readonly
  289. */
  290. clampToGround : {
  291. get : function() {
  292. return this._clampToGround && this._supportsPolylinesOnTerrain;
  293. }
  294. },
  295. /**
  296. * Gets the zindex
  297. * @type {Number}
  298. * @memberof PolylineGeometryUpdater.prototype
  299. * @readonly
  300. */
  301. zIndex: {
  302. get: function() {
  303. return this._zIndex;
  304. }
  305. }
  306. });
  307. /**
  308. * Checks if the geometry is outlined at the provided time.
  309. *
  310. * @param {JulianDate} time The time for which to retrieve visibility.
  311. * @returns {Boolean} true if geometry is outlined at the provided time, false otherwise.
  312. */
  313. PolylineGeometryUpdater.prototype.isOutlineVisible = function(time) {
  314. return false;
  315. };
  316. /**
  317. * Checks if the geometry is filled at the provided time.
  318. *
  319. * @param {JulianDate} time The time for which to retrieve visibility.
  320. * @returns {Boolean} true if geometry is filled at the provided time, false otherwise.
  321. */
  322. PolylineGeometryUpdater.prototype.isFilled = function(time) {
  323. var entity = this._entity;
  324. var visible = this._fillEnabled && entity.isAvailable(time) && this._showProperty.getValue(time);
  325. return defaultValue(visible, false);
  326. };
  327. /**
  328. * Creates the geometry instance which represents the fill of the geometry.
  329. *
  330. * @param {JulianDate} time The time to use when retrieving initial attribute values.
  331. * @returns {GeometryInstance} The geometry instance representing the filled portion of the geometry.
  332. *
  333. * @exception {DeveloperError} This instance does not represent a filled geometry.
  334. */
  335. PolylineGeometryUpdater.prototype.createFillGeometryInstance = function(time) {
  336. //>>includeStart('debug', pragmas.debug);
  337. if (!defined(time)) {
  338. throw new DeveloperError('time is required.');
  339. }
  340. if (!this._fillEnabled) {
  341. throw new DeveloperError('This instance does not represent a filled geometry.');
  342. }
  343. //>>includeEnd('debug');
  344. var entity = this._entity;
  345. var isAvailable = entity.isAvailable(time);
  346. var show = new ShowGeometryInstanceAttribute(isAvailable && entity.isShowing && this._showProperty.getValue(time));
  347. var distanceDisplayCondition = this._distanceDisplayConditionProperty.getValue(time);
  348. var distanceDisplayConditionAttribute = DistanceDisplayConditionGeometryInstanceAttribute.fromDistanceDisplayCondition(distanceDisplayCondition);
  349. var attributes = {
  350. show : show,
  351. distanceDisplayCondition : distanceDisplayConditionAttribute
  352. };
  353. var currentColor;
  354. if (this._materialProperty instanceof ColorMaterialProperty) {
  355. if (defined(this._materialProperty.color) && (this._materialProperty.color.isConstant || isAvailable)) {
  356. currentColor = this._materialProperty.color.getValue(time, scratchColor);
  357. }
  358. if (!defined(currentColor)) {
  359. currentColor = Color.WHITE;
  360. }
  361. attributes.color = ColorGeometryInstanceAttribute.fromColor(currentColor);
  362. }
  363. if (this.clampToGround) {
  364. return new GeometryInstance({
  365. id : entity,
  366. geometry : new GroundPolylineGeometry(this._groundGeometryOptions),
  367. attributes : attributes
  368. });
  369. }
  370. if (defined(this._depthFailMaterialProperty) && this._depthFailMaterialProperty instanceof ColorMaterialProperty) {
  371. if (defined(this._depthFailMaterialProperty.color) && (this._depthFailMaterialProperty.color.isConstant || isAvailable)) {
  372. currentColor = this._depthFailMaterialProperty.color.getValue(time, scratchColor);
  373. }
  374. if (!defined(currentColor)) {
  375. currentColor = Color.WHITE;
  376. }
  377. attributes.depthFailColor = ColorGeometryInstanceAttribute.fromColor(currentColor);
  378. }
  379. return new GeometryInstance({
  380. id : entity,
  381. geometry : new PolylineGeometry(this._geometryOptions),
  382. attributes : attributes
  383. });
  384. };
  385. /**
  386. * Creates the geometry instance which represents the outline of the geometry.
  387. *
  388. * @param {JulianDate} time The time to use when retrieving initial attribute values.
  389. * @returns {GeometryInstance} The geometry instance representing the outline portion of the geometry.
  390. *
  391. * @exception {DeveloperError} This instance does not represent an outlined geometry.
  392. */
  393. PolylineGeometryUpdater.prototype.createOutlineGeometryInstance = function(time) {
  394. //>>includeStart('debug', pragmas.debug);
  395. throw new DeveloperError('This instance does not represent an outlined geometry.');
  396. //>>includeEnd('debug');
  397. };
  398. /**
  399. * Returns true if this object was destroyed; otherwise, false.
  400. *
  401. * @returns {Boolean} True if this object was destroyed; otherwise, false.
  402. */
  403. PolylineGeometryUpdater.prototype.isDestroyed = function() {
  404. return false;
  405. };
  406. /**
  407. * Destroys and resources used by the object. Once an object is destroyed, it should not be used.
  408. *
  409. * @exception {DeveloperError} This object was destroyed, i.e., destroy() was called.
  410. */
  411. PolylineGeometryUpdater.prototype.destroy = function() {
  412. this._entitySubscription();
  413. destroyObject(this);
  414. };
  415. PolylineGeometryUpdater.prototype._onEntityPropertyChanged = function(entity, propertyName, newValue, oldValue) {
  416. if (!(propertyName === 'availability' || propertyName === 'polyline')) {
  417. return;
  418. }
  419. var polyline = this._entity.polyline;
  420. if (!defined(polyline)) {
  421. if (this._fillEnabled) {
  422. this._fillEnabled = false;
  423. this._geometryChanged.raiseEvent(this);
  424. }
  425. return;
  426. }
  427. var positionsProperty = polyline.positions;
  428. var show = polyline.show;
  429. if ((defined(show) && show.isConstant && !show.getValue(Iso8601.MINIMUM_VALUE)) || //
  430. (!defined(positionsProperty))) {
  431. if (this._fillEnabled) {
  432. this._fillEnabled = false;
  433. this._geometryChanged.raiseEvent(this);
  434. }
  435. return;
  436. }
  437. var zIndex = polyline.zIndex;
  438. var material = defaultValue(polyline.material, defaultMaterial);
  439. var isColorMaterial = material instanceof ColorMaterialProperty;
  440. this._materialProperty = material;
  441. this._depthFailMaterialProperty = polyline.depthFailMaterial;
  442. this._showProperty = defaultValue(show, defaultShow);
  443. this._shadowsProperty = defaultValue(polyline.shadows, defaultShadows);
  444. this._distanceDisplayConditionProperty = defaultValue(polyline.distanceDisplayCondition, defaultDistanceDisplayCondition);
  445. this._classificationTypeProperty = defaultValue(polyline.classificationType, defaultClassificationType);
  446. this._fillEnabled = true;
  447. this._zIndex = defaultValue(zIndex, defaultZIndex);
  448. var width = polyline.width;
  449. var arcType = polyline.arcType;
  450. var clampToGround = polyline.clampToGround;
  451. var granularity = polyline.granularity;
  452. if (!positionsProperty.isConstant || !Property.isConstant(width) ||
  453. !Property.isConstant(arcType) || !Property.isConstant(granularity) ||
  454. !Property.isConstant(clampToGround) || !Property.isConstant(zIndex)) {
  455. if (!this._dynamic) {
  456. this._dynamic = true;
  457. this._geometryChanged.raiseEvent(this);
  458. }
  459. } else {
  460. var geometryOptions = this._geometryOptions;
  461. var positions = positionsProperty.getValue(Iso8601.MINIMUM_VALUE, geometryOptions.positions);
  462. //Because of the way we currently handle reference properties,
  463. //we can't automatically assume the positions are always valid.
  464. if (!defined(positions) || positions.length < 2) {
  465. if (this._fillEnabled) {
  466. this._fillEnabled = false;
  467. this._geometryChanged.raiseEvent(this);
  468. }
  469. return;
  470. }
  471. var vertexFormat;
  472. if (isColorMaterial && (!defined(this._depthFailMaterialProperty) || this._depthFailMaterialProperty instanceof ColorMaterialProperty)) {
  473. vertexFormat = PolylineColorAppearance.VERTEX_FORMAT;
  474. } else {
  475. vertexFormat = PolylineMaterialAppearance.VERTEX_FORMAT;
  476. }
  477. geometryOptions.vertexFormat = vertexFormat;
  478. geometryOptions.positions = positions;
  479. geometryOptions.width = defined(width) ? width.getValue(Iso8601.MINIMUM_VALUE) : undefined;
  480. geometryOptions.arcType = defined(arcType) ? arcType.getValue(Iso8601.MINIMUM_VALUE) : undefined;
  481. geometryOptions.granularity = defined(granularity) ? granularity.getValue(Iso8601.MINIMUM_VALUE) : undefined;
  482. var groundGeometryOptions = this._groundGeometryOptions;
  483. groundGeometryOptions.positions = positions;
  484. groundGeometryOptions.width = geometryOptions.width;
  485. groundGeometryOptions.arcType = geometryOptions.arcType;
  486. groundGeometryOptions.granularity = geometryOptions.granularity;
  487. this._clampToGround = defined(clampToGround) ? clampToGround.getValue(Iso8601.MINIMUM_VALUE) : false;
  488. if (!this._clampToGround && defined(zIndex)) {
  489. oneTimeWarning('Entity polylines must have clampToGround: true when using zIndex. zIndex will be ignored.');
  490. }
  491. this._dynamic = false;
  492. this._geometryChanged.raiseEvent(this);
  493. }
  494. };
  495. /**
  496. * Creates the dynamic updater to be used when GeometryUpdater#isDynamic is true.
  497. *
  498. * @param {PrimitiveCollection} primitives The primitive collection to use.
  499. * @param {PrimitiveCollection|OrderedGroundPrimitiveCollection} groundPrimitives The primitive collection to use for ordered ground primitives.
  500. * @returns {DynamicGeometryUpdater} The dynamic updater used to update the geometry each frame.
  501. *
  502. * @exception {DeveloperError} This instance does not represent dynamic geometry.
  503. */
  504. PolylineGeometryUpdater.prototype.createDynamicUpdater = function(primitives, groundPrimitives) {
  505. //>>includeStart('debug', pragmas.debug);
  506. Check.defined('primitives', primitives);
  507. Check.defined('groundPrimitives', groundPrimitives);
  508. if (!this._dynamic) {
  509. throw new DeveloperError('This instance does not represent dynamic geometry.');
  510. }
  511. //>>includeEnd('debug');
  512. return new DynamicGeometryUpdater(primitives, groundPrimitives, this);
  513. };
  514. /**
  515. * @private
  516. */
  517. var generateCartesianArcOptions = {
  518. positions : undefined,
  519. granularity : undefined,
  520. height : undefined,
  521. ellipsoid : undefined
  522. };
  523. function DynamicGeometryUpdater(primitives, groundPrimitives, geometryUpdater) {
  524. this._line = undefined;
  525. this._primitives = primitives;
  526. this._groundPrimitives = groundPrimitives;
  527. this._groundPolylinePrimitive = undefined;
  528. this._material = undefined;
  529. this._geometryUpdater = geometryUpdater;
  530. this._positions = [];
  531. }
  532. function getLine(dynamicGeometryUpdater) {
  533. if (defined(dynamicGeometryUpdater._line)) {
  534. return dynamicGeometryUpdater._line;
  535. }
  536. var sceneId = dynamicGeometryUpdater._geometryUpdater._scene.id;
  537. var polylineCollection = polylineCollections[sceneId];
  538. var primitives = dynamicGeometryUpdater._primitives;
  539. if (!defined(polylineCollection) || polylineCollection.isDestroyed()) {
  540. polylineCollection = new PolylineCollection();
  541. polylineCollections[sceneId] = polylineCollection;
  542. primitives.add(polylineCollection);
  543. } else if (!primitives.contains(polylineCollection)) {
  544. primitives.add(polylineCollection);
  545. }
  546. var line = polylineCollection.add();
  547. line.id = dynamicGeometryUpdater._geometryUpdater._entity;
  548. dynamicGeometryUpdater._line = line;
  549. return line;
  550. }
  551. DynamicGeometryUpdater.prototype.update = function(time) {
  552. var geometryUpdater = this._geometryUpdater;
  553. var entity = geometryUpdater._entity;
  554. var polyline = entity.polyline;
  555. var positionsProperty = polyline.positions;
  556. var positions = Property.getValueOrUndefined(positionsProperty, time, this._positions);
  557. // Synchronize with geometryUpdater for GroundPolylinePrimitive
  558. geometryUpdater._clampToGround = Property.getValueOrDefault(polyline._clampToGround, time, false);
  559. geometryUpdater._groundGeometryOptions.positions = positions;
  560. geometryUpdater._groundGeometryOptions.width = Property.getValueOrDefault(polyline._width, time, 1);
  561. geometryUpdater._groundGeometryOptions.arcType = Property.getValueOrDefault(polyline._arcType, time, ArcType.GEODESIC);
  562. geometryUpdater._groundGeometryOptions.granularity = Property.getValueOrDefault(polyline._granularity, time, 9999);
  563. var groundPrimitives = this._groundPrimitives;
  564. if (defined(this._groundPolylinePrimitive)) {
  565. groundPrimitives.remove(this._groundPolylinePrimitive); // destroys by default
  566. this._groundPolylinePrimitive = undefined;
  567. }
  568. if (geometryUpdater.clampToGround) {
  569. if (!entity.isShowing || !entity.isAvailable(time) || !Property.getValueOrDefault(polyline._show, time, true)) {
  570. return;
  571. }
  572. if (!defined(positions) || positions.length < 2) {
  573. return;
  574. }
  575. var fillMaterialProperty = geometryUpdater.fillMaterialProperty;
  576. var appearance;
  577. if (fillMaterialProperty instanceof ColorMaterialProperty) {
  578. appearance = new PolylineColorAppearance();
  579. } else {
  580. var material = MaterialProperty.getValue(time, fillMaterialProperty, this._material);
  581. appearance = new PolylineMaterialAppearance({
  582. material : material,
  583. translucent : material.isTranslucent()
  584. });
  585. this._material = material;
  586. }
  587. this._groundPolylinePrimitive = groundPrimitives.add(new GroundPolylinePrimitive({
  588. geometryInstances : geometryUpdater.createFillGeometryInstance(time),
  589. appearance : appearance,
  590. classificationType : geometryUpdater.classificationTypeProperty.getValue(time),
  591. asynchronous : false
  592. }), Property.getValueOrUndefined(geometryUpdater.zIndex, time));
  593. // Hide the polyline in the collection, if any
  594. if (defined(this._line)) {
  595. this._line.show = false;
  596. }
  597. return;
  598. }
  599. var line = getLine(this);
  600. if (!entity.isShowing || !entity.isAvailable(time) || !Property.getValueOrDefault(polyline._show, time, true)) {
  601. line.show = false;
  602. return;
  603. }
  604. if (!defined(positions) || positions.length < 2) {
  605. line.show = false;
  606. return;
  607. }
  608. var arcType = ArcType.GEODESIC;
  609. arcType = Property.getValueOrDefault(polyline._arcType, time, arcType);
  610. var globe = geometryUpdater._scene.globe;
  611. if (arcType !== ArcType.NONE && defined(globe)) {
  612. generateCartesianArcOptions.ellipsoid = globe.ellipsoid;
  613. generateCartesianArcOptions.positions = positions;
  614. generateCartesianArcOptions.granularity = Property.getValueOrUndefined(polyline._granularity, time);
  615. generateCartesianArcOptions.height = PolylinePipeline.extractHeights(positions, globe.ellipsoid);
  616. if (arcType === ArcType.GEODESIC) {
  617. positions = PolylinePipeline.generateCartesianArc(generateCartesianArcOptions);
  618. } else {
  619. positions = PolylinePipeline.generateCartesianRhumbArc(generateCartesianArcOptions);
  620. }
  621. }
  622. line.show = true;
  623. line.positions = positions.slice();
  624. line.material = MaterialProperty.getValue(time, geometryUpdater.fillMaterialProperty, line.material);
  625. line.width = Property.getValueOrDefault(polyline._width, time, 1);
  626. line.distanceDisplayCondition = Property.getValueOrUndefined(polyline._distanceDisplayCondition, time, line.distanceDisplayCondition);
  627. };
  628. DynamicGeometryUpdater.prototype.getBoundingSphere = function(result) {
  629. //>>includeStart('debug', pragmas.debug);
  630. Check.defined('result', result);
  631. //>>includeEnd('debug');
  632. if (!this._geometryUpdater.clampToGround) {
  633. var line = getLine(this);
  634. if (line.show && line.positions.length > 0) {
  635. BoundingSphere.fromPoints(line.positions, result);
  636. return BoundingSphereState.DONE;
  637. }
  638. } else {
  639. var groundPolylinePrimitive = this._groundPolylinePrimitive;
  640. if (defined(groundPolylinePrimitive) && groundPolylinePrimitive.show && groundPolylinePrimitive.ready) {
  641. var attributes = groundPolylinePrimitive.getGeometryInstanceAttributes(this._geometryUpdater._entity);
  642. if (defined(attributes) && defined(attributes.boundingSphere)) {
  643. BoundingSphere.clone(attributes.boundingSphere, result);
  644. return BoundingSphereState.DONE;
  645. }
  646. }
  647. if ((defined(groundPolylinePrimitive) && !groundPolylinePrimitive.ready)) {
  648. return BoundingSphereState.PENDING;
  649. }
  650. return BoundingSphereState.DONE;
  651. }
  652. return BoundingSphereState.FAILED;
  653. };
  654. DynamicGeometryUpdater.prototype.isDestroyed = function() {
  655. return false;
  656. };
  657. DynamicGeometryUpdater.prototype.destroy = function() {
  658. var geometryUpdater = this._geometryUpdater;
  659. var sceneId = geometryUpdater._scene.id;
  660. var polylineCollection = polylineCollections[sceneId];
  661. if (defined(polylineCollection)) {
  662. polylineCollection.remove(this._line);
  663. if (polylineCollection.length === 0) {
  664. this._primitives.removeAndDestroy(polylineCollection);
  665. delete polylineCollections[sceneId];
  666. }
  667. }
  668. if (defined(this._groundPolylinePrimitive)) {
  669. this._groundPrimitives.remove(this._groundPolylinePrimitive);
  670. }
  671. destroyObject(this);
  672. };
  673. export default PolylineGeometryUpdater;