PolygonGraphics.js 16 KB

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