PolygonGraphics.js 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353
  1. import defaultValue from '../Core/defaultValue.js';
  2. import defined from '../Core/defined.js';
  3. import defineProperties from '../Core/defineProperties.js';
  4. import DeveloperError from '../Core/DeveloperError.js';
  5. import Event from '../Core/Event.js';
  6. import isArray from '../Core/isArray.js';
  7. import PolygonHierarchy from '../Core/PolygonHierarchy.js';
  8. import ConstantProperty from './ConstantProperty.js';
  9. import createMaterialPropertyDescriptor from './createMaterialPropertyDescriptor.js';
  10. import createPropertyDescriptor from './createPropertyDescriptor.js';
  11. function createPolygonHierarchyProperty(value) {
  12. if (isArray(value)) {
  13. // convert array of positions to PolygonHierarchy object
  14. value = new PolygonHierarchy(value);
  15. }
  16. return new ConstantProperty(value);
  17. }
  18. /**
  19. * Describes a polygon defined by an hierarchy of linear rings which make up the outer shape and any nested holes.
  20. * The polygon conforms to the curvature of the globe and can be placed on the surface or
  21. * at altitude and can optionally be extruded into a volume.
  22. *
  23. * @alias PolygonGraphics
  24. * @constructor
  25. *
  26. * @param {Object} [options] Object with the following properties:
  27. * @param {Property} [options.show=true] A boolean Property specifying the visibility of the polygon.
  28. * @param {Property} [options.hierarchy] A Property specifying the {@link PolygonHierarchy}.
  29. * @param {Property} [options.height=0] A numeric Property specifying the altitude of the polygon relative to the ellipsoid surface.
  30. * @param {Property} [options.heightReference=HeightReference.NONE] A Property specifying what the height is relative to.
  31. * @param {Property} [options.extrudedHeight] A numeric Property specifying the altitude of the polygon's extruded face relative to the ellipsoid surface.
  32. * @param {Property} [options.extrudedHeightReference=HeightReference.NONE] A Property specifying what the extrudedHeight is relative to.
  33. * @param {Property} [options.stRotation=0.0] A numeric property specifying the rotation of the polygon texture counter-clockwise from north.
  34. * @param {Property} [options.granularity=Cesium.Math.RADIANS_PER_DEGREE] A numeric Property specifying the angular distance between each latitude and longitude point.
  35. * @param {Property} [options.fill=true] A boolean Property specifying whether the polygon is filled with the provided material.
  36. * @param {MaterialProperty} [options.material=Color.WHITE] A Property specifying the material used to fill the polygon.
  37. * @param {Property} [options.outline=false] A boolean Property specifying whether the polygon is outlined.
  38. * @param {Property} [options.outlineColor=Color.BLACK] A Property specifying the {@link Color} of the outline.
  39. * @param {Property} [options.outlineWidth=1.0] A numeric Property specifying the width of the outline.
  40. * @param {Property} [options.perPositionHeight=false] A boolean specifying whether or not the the height of each position is used.
  41. * @param {Boolean} [options.closeTop=true] When false, leaves off the top of an extruded polygon open.
  42. * @param {Boolean} [options.closeBottom=true] When false, leaves off the bottom of an extruded polygon open.
  43. * @param {Property} [options.arcType=ArcType.GEODESIC] The type of line the polygon edges must follow.
  44. * @param {Property} [options.shadows=ShadowMode.DISABLED] An enum Property specifying whether the polygon casts or receives shadows from each light source.
  45. * @param {Property} [options.distanceDisplayCondition] A Property specifying at what distance from the camera that this polygon will be displayed.
  46. * @param {Property} [options.classificationType=ClassificationType.BOTH] An enum Property specifying whether this polygon will classify terrain, 3D Tiles, or both when on the ground.
  47. * @param {ConstantProperty} [options.zIndex=0] A property specifying the zIndex used for ordering ground geometry. Only has an effect if the polygon is constant and neither height or extrudedHeight are specified.
  48. *
  49. * @see Entity
  50. * @demo {@link https://sandcastle.cesium.com/index.html?src=Polygon.html|Cesium Sandcastle Polygon Demo}
  51. */
  52. function PolygonGraphics(options) {
  53. this._definitionChanged = new Event();
  54. this._show = undefined;
  55. this._showSubscription = undefined;
  56. this._hierarchy = undefined;
  57. this._hierarchySubscription = undefined;
  58. this._height = undefined;
  59. this._heightSubscription = undefined;
  60. this._heightReference = undefined;
  61. this._heightReferenceSubscription = undefined;
  62. this._extrudedHeight = undefined;
  63. this._extrudedHeightSubscription = undefined;
  64. this._extrudedHeightReference = undefined;
  65. this._extrudedHeightReferenceSubscription = undefined;
  66. this._stRotation = undefined;
  67. this._stRotationSubscription = undefined;
  68. this._granularity = undefined;
  69. this._granularitySubscription = undefined;
  70. this._fill = undefined;
  71. this._fillSubscription = undefined;
  72. this._material = undefined;
  73. this._materialSubscription = undefined;
  74. this._outline = undefined;
  75. this._outlineSubscription = undefined;
  76. this._outlineColor = undefined;
  77. this._outlineColorSubscription = undefined;
  78. this._outlineWidth = undefined;
  79. this._outlineWidthSubscription = undefined;
  80. this._perPositionHeight = undefined;
  81. this._perPositionHeightSubscription = undefined;
  82. this._closeTop = undefined;
  83. this._closeTopSubscription = undefined;
  84. this._closeBottom = undefined;
  85. this._closeBottomSubscription = undefined;
  86. this._arcType = undefined;
  87. this._arcTypeSubscription = undefined;
  88. this._shadows = undefined;
  89. this._shadowsSubscription = undefined;
  90. this._distanceDisplayCondition = undefined;
  91. this._distanceDisplayConditionSubscription = undefined;
  92. this._classificationType = undefined;
  93. this._classificationTypeSubscription = undefined;
  94. this._zIndex = undefined;
  95. this._zIndexSubscription = undefined;
  96. this.merge(defaultValue(options, defaultValue.EMPTY_OBJECT));
  97. }
  98. defineProperties(PolygonGraphics.prototype, {
  99. /**
  100. * Gets the event that is raised whenever a property or sub-property is changed or modified.
  101. * @memberof PolygonGraphics.prototype
  102. *
  103. * @type {Event}
  104. * @readonly
  105. */
  106. definitionChanged : {
  107. get : function() {
  108. return this._definitionChanged;
  109. }
  110. },
  111. /**
  112. * Gets or sets the boolean Property specifying the visibility of the polygon.
  113. * @memberof PolygonGraphics.prototype
  114. * @type {Property}
  115. * @default true
  116. */
  117. show : createPropertyDescriptor('show'),
  118. /**
  119. * Gets or sets the Property specifying the {@link PolygonHierarchy}.
  120. * @memberof PolygonGraphics.prototype
  121. * @type {Property}
  122. */
  123. hierarchy : createPropertyDescriptor('hierarchy', undefined, createPolygonHierarchyProperty),
  124. /**
  125. * Gets or sets the numeric Property specifying the constant altitude of the polygon.
  126. * @memberof PolygonGraphics.prototype
  127. * @type {Property}
  128. * @default 0.0
  129. */
  130. height : createPropertyDescriptor('height'),
  131. /**
  132. * Gets or sets the Property specifying the {@link HeightReference}.
  133. * @memberof PolygonGraphics.prototype
  134. * @type {Property}
  135. * @default HeightReference.NONE
  136. */
  137. heightReference : createPropertyDescriptor('heightReference'),
  138. /**
  139. * Gets or sets the numeric Property specifying the altitude of the polygon extrusion.
  140. * If {@link PolygonGraphics#perPositionHeight} is false, the volume starts at {@link PolygonGraphics#height} and ends at this altitude.
  141. * If {@link PolygonGraphics#perPositionHeight} is true, the volume starts at the height of each {@link PolygonGraphics#hierarchy} position and ends at this altitude.
  142. * @memberof PolygonGraphics.prototype
  143. * @type {Property}
  144. */
  145. extrudedHeight : createPropertyDescriptor('extrudedHeight'),
  146. /**
  147. * Gets or sets the Property specifying the extruded {@link HeightReference}.
  148. * @memberof PolygonGraphics.prototype
  149. * @type {Property}
  150. * @default HeightReference.NONE
  151. */
  152. extrudedHeightReference : createPropertyDescriptor('extrudedHeightReference'),
  153. /**
  154. * Gets or sets the numeric property specifying the rotation of the polygon texture counter-clockwise from north.
  155. * @memberof PolygonGraphics.prototype
  156. * @type {Property}
  157. * @default 0
  158. */
  159. stRotation : createPropertyDescriptor('stRotation'),
  160. /**
  161. * Gets or sets the numeric Property specifying the angular distance between points on the polygon.
  162. * @memberof PolygonGraphics.prototype
  163. * @type {Property}
  164. * @default {CesiumMath.RADIANS_PER_DEGREE}
  165. */
  166. granularity : createPropertyDescriptor('granularity'),
  167. /**
  168. * Gets or sets the boolean Property specifying whether the polygon is filled with the provided material.
  169. * @memberof PolygonGraphics.prototype
  170. * @type {Property}
  171. * @default true
  172. */
  173. fill : createPropertyDescriptor('fill'),
  174. /**
  175. * Gets or sets the Property specifying the material used to fill the polygon.
  176. * @memberof PolygonGraphics.prototype
  177. * @type {MaterialProperty}
  178. * @default Color.WHITE
  179. */
  180. material : createMaterialPropertyDescriptor('material'),
  181. /**
  182. * Gets or sets the Property specifying whether the polygon is outlined.
  183. * @memberof PolygonGraphics.prototype
  184. * @type {Property}
  185. * @default false
  186. */
  187. outline : createPropertyDescriptor('outline'),
  188. /**
  189. * Gets or sets the Property specifying the {@link Color} of the outline.
  190. * @memberof PolygonGraphics.prototype
  191. * @type {Property}
  192. * @default Color.BLACK
  193. */
  194. outlineColor : createPropertyDescriptor('outlineColor'),
  195. /**
  196. * Gets or sets the numeric Property specifying the width of the outline.
  197. * @memberof PolygonGraphics.prototype
  198. * @type {Property}
  199. * @default 1.0
  200. */
  201. outlineWidth : createPropertyDescriptor('outlineWidth'),
  202. /**
  203. * Gets or sets the boolean specifying whether or not the the height of each position is used.
  204. * If true, the shape will have non-uniform altitude defined by the height of each {@link PolygonGraphics#hierarchy} position.
  205. * If false, the shape will have a constant altitude as specified by {@link PolygonGraphics#height}.
  206. * @memberof PolygonGraphics.prototype
  207. * @type {Property}
  208. */
  209. perPositionHeight : createPropertyDescriptor('perPositionHeight'),
  210. /**
  211. * Gets or sets a boolean specifying whether or not the top of an extruded polygon is included.
  212. * @memberof PolygonGraphics.prototype
  213. * @type {Property}
  214. */
  215. closeTop : createPropertyDescriptor('closeTop'),
  216. /**
  217. * Gets or sets a boolean specifying whether or not the bottom of an extruded polygon is included.
  218. * @memberof PolygonGraphics.prototype
  219. * @type {Property}
  220. */
  221. closeBottom : createPropertyDescriptor('closeBottom'),
  222. /**
  223. * Gets or sets the {@link ArcType} Property specifying the type of lines the polygon edges use.
  224. * @memberof PolygonGraphics.prototype
  225. * @type {Property}
  226. * @default ArcType.GEODESIC
  227. */
  228. arcType : createPropertyDescriptor('arcType'),
  229. /**
  230. * Get or sets the enum Property specifying whether the polygon
  231. * casts or receives shadows from each light source.
  232. * @memberof PolygonGraphics.prototype
  233. * @type {Property}
  234. * @default ShadowMode.DISABLED
  235. */
  236. shadows : createPropertyDescriptor('shadows'),
  237. /**
  238. * Gets or sets the {@link DistanceDisplayCondition} Property specifying at what distance from the camera that this polygon will be displayed.
  239. * @memberof PolygonGraphics.prototype
  240. * @type {Property}
  241. */
  242. distanceDisplayCondition : createPropertyDescriptor('distanceDisplayCondition'),
  243. /**
  244. * Gets or sets the {@link ClassificationType} Property specifying whether this polygon will classify terrain, 3D Tiles, or both when on the ground.
  245. * @memberof PolygonGraphics.prototype
  246. * @type {Property}
  247. * @default ClassificationType.BOTH
  248. */
  249. classificationType : createPropertyDescriptor('classificationType'),
  250. /**
  251. * Gets or sets the zIndex Prperty specifying the ordering of ground geometry. Only has an effect if the polygon is constant and neither height or extrudedHeight are specified.
  252. * @memberof PolygonGraphics.prototype
  253. * @type {ConstantProperty}
  254. * @default 0
  255. */
  256. zIndex : createPropertyDescriptor('zIndex')
  257. });
  258. /**
  259. * Duplicates this instance.
  260. *
  261. * @param {PolygonGraphics} [result] The object onto which to store the result.
  262. * @returns {PolygonGraphics} The modified result parameter or a new instance if one was not provided.
  263. */
  264. PolygonGraphics.prototype.clone = function(result) {
  265. if (!defined(result)) {
  266. return new PolygonGraphics(this);
  267. }
  268. result.show = this.show;
  269. result.hierarchy = this.hierarchy;
  270. result.height = this.height;
  271. result.heightReference = this.heightReference;
  272. result.extrudedHeight = this.extrudedHeight;
  273. result.extrudedHeightReference = this.extrudedHeightReference;
  274. result.stRotation = this.stRotation;
  275. result.granularity = this.granularity;
  276. result.fill = this.fill;
  277. result.material = this.material;
  278. result.outline = this.outline;
  279. result.outlineColor = this.outlineColor;
  280. result.outlineWidth = this.outlineWidth;
  281. result.perPositionHeight = this.perPositionHeight;
  282. result.closeTop = this.closeTop;
  283. result.closeBottom = this.closeBottom;
  284. result.arcType = this.arcType;
  285. result.shadows = this.shadows;
  286. result.distanceDisplayCondition = this.distanceDisplayCondition;
  287. result.classificationType = this.classificationType;
  288. result.zIndex = this.zIndex;
  289. return result;
  290. };
  291. /**
  292. * Assigns each unassigned property on this object to the value
  293. * of the same property on the provided source object.
  294. *
  295. * @param {PolygonGraphics} source The object to be merged into this object.
  296. */
  297. PolygonGraphics.prototype.merge = function(source) {
  298. //>>includeStart('debug', pragmas.debug);
  299. if (!defined(source)) {
  300. throw new DeveloperError('source is required.');
  301. }
  302. //>>includeEnd('debug');
  303. this.show = defaultValue(this.show, source.show);
  304. this.hierarchy = defaultValue(this.hierarchy, source.hierarchy);
  305. this.height = defaultValue(this.height, source.height);
  306. this.heightReference = defaultValue(this.heightReference, source.heightReference);
  307. this.extrudedHeight = defaultValue(this.extrudedHeight, source.extrudedHeight);
  308. this.extrudedHeightReference = defaultValue(this.extrudedHeightReference, source.extrudedHeightReference);
  309. this.stRotation = defaultValue(this.stRotation, source.stRotation);
  310. this.granularity = defaultValue(this.granularity, source.granularity);
  311. this.fill = defaultValue(this.fill, source.fill);
  312. this.material = defaultValue(this.material, source.material);
  313. this.outline = defaultValue(this.outline, source.outline);
  314. this.outlineColor = defaultValue(this.outlineColor, source.outlineColor);
  315. this.outlineWidth = defaultValue(this.outlineWidth, source.outlineWidth);
  316. this.perPositionHeight = defaultValue(this.perPositionHeight, source.perPositionHeight);
  317. this.closeTop = defaultValue(this.closeTop, source.closeTop);
  318. this.closeBottom = defaultValue(this.closeBottom, source.closeBottom);
  319. this.arcType = defaultValue(this.arcType, source.arcType);
  320. this.shadows = defaultValue(this.shadows, source.shadows);
  321. this.distanceDisplayCondition = defaultValue(this.distanceDisplayCondition, source.distanceDisplayCondition);
  322. this.classificationType = defaultValue(this.classificationType, source.classificationType);
  323. this.zIndex = defaultValue(this.zIndex, source.zIndex);
  324. };
  325. export default PolygonGraphics;