createPolygonOutlineGeometry.js 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676
  1. /* This file is automatically rebuilt by the Cesium build process. */
  2. define(['./when-e6985d2a', './Check-24cae389', './Math-392d0035', './Cartesian2-a5d6dde9', './Transforms-81680c41', './RuntimeError-61701d3e', './WebGLConstants-34c08bc0', './ComponentDatatype-cb08e294', './GeometryAttribute-6d403cd9', './GeometryAttributes-d6ea8c2b', './AttributeCompression-114c6354', './GeometryPipeline-e8a01ba6', './EncodedCartesian3-c758025f', './IndexDatatype-1be7d1f8', './IntersectionTests-f17c84f0', './Plane-ac6a1d3e', './GeometryOffsetAttribute-9c46b133', './GeometryInstance-252acf0f', './arrayRemoveDuplicates-1ded18d8', './EllipsoidTangentPlane-85280670', './ArcType-13a53523', './EllipsoidRhumbLine-5f1ab81f', './PolygonPipeline-197b7d5c', './PolygonGeometryLibrary-a0562073'], function (when, Check, _Math, Cartesian2, Transforms, RuntimeError, WebGLConstants, ComponentDatatype, GeometryAttribute, GeometryAttributes, AttributeCompression, GeometryPipeline, EncodedCartesian3, IndexDatatype, IntersectionTests, Plane, GeometryOffsetAttribute, GeometryInstance, arrayRemoveDuplicates, EllipsoidTangentPlane, ArcType, EllipsoidRhumbLine, PolygonPipeline, PolygonGeometryLibrary) { 'use strict';
  3. var createGeometryFromPositionsPositions = [];
  4. var createGeometryFromPositionsSubdivided = [];
  5. function createGeometryFromPositions(
  6. ellipsoid,
  7. positions,
  8. minDistance,
  9. perPositionHeight,
  10. arcType
  11. ) {
  12. var tangentPlane = EllipsoidTangentPlane.EllipsoidTangentPlane.fromPoints(positions, ellipsoid);
  13. var positions2D = tangentPlane.projectPointsOntoPlane(
  14. positions,
  15. createGeometryFromPositionsPositions
  16. );
  17. var originalWindingOrder = PolygonPipeline.PolygonPipeline.computeWindingOrder2D(positions2D);
  18. if (originalWindingOrder === PolygonPipeline.WindingOrder.CLOCKWISE) {
  19. positions2D.reverse();
  20. positions = positions.slice().reverse();
  21. }
  22. var subdividedPositions;
  23. var i;
  24. var length = positions.length;
  25. var index = 0;
  26. if (!perPositionHeight) {
  27. var numVertices = 0;
  28. if (arcType === ArcType.ArcType.GEODESIC) {
  29. for (i = 0; i < length; i++) {
  30. numVertices += PolygonGeometryLibrary.PolygonGeometryLibrary.subdivideLineCount(
  31. positions[i],
  32. positions[(i + 1) % length],
  33. minDistance
  34. );
  35. }
  36. } else if (arcType === ArcType.ArcType.RHUMB) {
  37. for (i = 0; i < length; i++) {
  38. numVertices += PolygonGeometryLibrary.PolygonGeometryLibrary.subdivideRhumbLineCount(
  39. ellipsoid,
  40. positions[i],
  41. positions[(i + 1) % length],
  42. minDistance
  43. );
  44. }
  45. }
  46. subdividedPositions = new Float64Array(numVertices * 3);
  47. for (i = 0; i < length; i++) {
  48. var tempPositions;
  49. if (arcType === ArcType.ArcType.GEODESIC) {
  50. tempPositions = PolygonGeometryLibrary.PolygonGeometryLibrary.subdivideLine(
  51. positions[i],
  52. positions[(i + 1) % length],
  53. minDistance,
  54. createGeometryFromPositionsSubdivided
  55. );
  56. } else if (arcType === ArcType.ArcType.RHUMB) {
  57. tempPositions = PolygonGeometryLibrary.PolygonGeometryLibrary.subdivideRhumbLine(
  58. ellipsoid,
  59. positions[i],
  60. positions[(i + 1) % length],
  61. minDistance,
  62. createGeometryFromPositionsSubdivided
  63. );
  64. }
  65. var tempPositionsLength = tempPositions.length;
  66. for (var j = 0; j < tempPositionsLength; ++j) {
  67. subdividedPositions[index++] = tempPositions[j];
  68. }
  69. }
  70. } else {
  71. subdividedPositions = new Float64Array(length * 2 * 3);
  72. for (i = 0; i < length; i++) {
  73. var p0 = positions[i];
  74. var p1 = positions[(i + 1) % length];
  75. subdividedPositions[index++] = p0.x;
  76. subdividedPositions[index++] = p0.y;
  77. subdividedPositions[index++] = p0.z;
  78. subdividedPositions[index++] = p1.x;
  79. subdividedPositions[index++] = p1.y;
  80. subdividedPositions[index++] = p1.z;
  81. }
  82. }
  83. length = subdividedPositions.length / 3;
  84. var indicesSize = length * 2;
  85. var indices = IndexDatatype.IndexDatatype.createTypedArray(length, indicesSize);
  86. index = 0;
  87. for (i = 0; i < length - 1; i++) {
  88. indices[index++] = i;
  89. indices[index++] = i + 1;
  90. }
  91. indices[index++] = length - 1;
  92. indices[index++] = 0;
  93. return new GeometryInstance.GeometryInstance({
  94. geometry: new GeometryAttribute.Geometry({
  95. attributes: new GeometryAttributes.GeometryAttributes({
  96. position: new GeometryAttribute.GeometryAttribute({
  97. componentDatatype: ComponentDatatype.ComponentDatatype.DOUBLE,
  98. componentsPerAttribute: 3,
  99. values: subdividedPositions,
  100. }),
  101. }),
  102. indices: indices,
  103. primitiveType: GeometryAttribute.PrimitiveType.LINES,
  104. }),
  105. });
  106. }
  107. function createGeometryFromPositionsExtruded(
  108. ellipsoid,
  109. positions,
  110. minDistance,
  111. perPositionHeight,
  112. arcType
  113. ) {
  114. var tangentPlane = EllipsoidTangentPlane.EllipsoidTangentPlane.fromPoints(positions, ellipsoid);
  115. var positions2D = tangentPlane.projectPointsOntoPlane(
  116. positions,
  117. createGeometryFromPositionsPositions
  118. );
  119. var originalWindingOrder = PolygonPipeline.PolygonPipeline.computeWindingOrder2D(positions2D);
  120. if (originalWindingOrder === PolygonPipeline.WindingOrder.CLOCKWISE) {
  121. positions2D.reverse();
  122. positions = positions.slice().reverse();
  123. }
  124. var subdividedPositions;
  125. var i;
  126. var length = positions.length;
  127. var corners = new Array(length);
  128. var index = 0;
  129. if (!perPositionHeight) {
  130. var numVertices = 0;
  131. if (arcType === ArcType.ArcType.GEODESIC) {
  132. for (i = 0; i < length; i++) {
  133. numVertices += PolygonGeometryLibrary.PolygonGeometryLibrary.subdivideLineCount(
  134. positions[i],
  135. positions[(i + 1) % length],
  136. minDistance
  137. );
  138. }
  139. } else if (arcType === ArcType.ArcType.RHUMB) {
  140. for (i = 0; i < length; i++) {
  141. numVertices += PolygonGeometryLibrary.PolygonGeometryLibrary.subdivideRhumbLineCount(
  142. ellipsoid,
  143. positions[i],
  144. positions[(i + 1) % length],
  145. minDistance
  146. );
  147. }
  148. }
  149. subdividedPositions = new Float64Array(numVertices * 3 * 2);
  150. for (i = 0; i < length; ++i) {
  151. corners[i] = index / 3;
  152. var tempPositions;
  153. if (arcType === ArcType.ArcType.GEODESIC) {
  154. tempPositions = PolygonGeometryLibrary.PolygonGeometryLibrary.subdivideLine(
  155. positions[i],
  156. positions[(i + 1) % length],
  157. minDistance,
  158. createGeometryFromPositionsSubdivided
  159. );
  160. } else if (arcType === ArcType.ArcType.RHUMB) {
  161. tempPositions = PolygonGeometryLibrary.PolygonGeometryLibrary.subdivideRhumbLine(
  162. ellipsoid,
  163. positions[i],
  164. positions[(i + 1) % length],
  165. minDistance,
  166. createGeometryFromPositionsSubdivided
  167. );
  168. }
  169. var tempPositionsLength = tempPositions.length;
  170. for (var j = 0; j < tempPositionsLength; ++j) {
  171. subdividedPositions[index++] = tempPositions[j];
  172. }
  173. }
  174. } else {
  175. subdividedPositions = new Float64Array(length * 2 * 3 * 2);
  176. for (i = 0; i < length; ++i) {
  177. corners[i] = index / 3;
  178. var p0 = positions[i];
  179. var p1 = positions[(i + 1) % length];
  180. subdividedPositions[index++] = p0.x;
  181. subdividedPositions[index++] = p0.y;
  182. subdividedPositions[index++] = p0.z;
  183. subdividedPositions[index++] = p1.x;
  184. subdividedPositions[index++] = p1.y;
  185. subdividedPositions[index++] = p1.z;
  186. }
  187. }
  188. length = subdividedPositions.length / (3 * 2);
  189. var cornersLength = corners.length;
  190. var indicesSize = (length * 2 + cornersLength) * 2;
  191. var indices = IndexDatatype.IndexDatatype.createTypedArray(
  192. length + cornersLength,
  193. indicesSize
  194. );
  195. index = 0;
  196. for (i = 0; i < length; ++i) {
  197. indices[index++] = i;
  198. indices[index++] = (i + 1) % length;
  199. indices[index++] = i + length;
  200. indices[index++] = ((i + 1) % length) + length;
  201. }
  202. for (i = 0; i < cornersLength; i++) {
  203. var corner = corners[i];
  204. indices[index++] = corner;
  205. indices[index++] = corner + length;
  206. }
  207. return new GeometryInstance.GeometryInstance({
  208. geometry: new GeometryAttribute.Geometry({
  209. attributes: new GeometryAttributes.GeometryAttributes({
  210. position: new GeometryAttribute.GeometryAttribute({
  211. componentDatatype: ComponentDatatype.ComponentDatatype.DOUBLE,
  212. componentsPerAttribute: 3,
  213. values: subdividedPositions,
  214. }),
  215. }),
  216. indices: indices,
  217. primitiveType: GeometryAttribute.PrimitiveType.LINES,
  218. }),
  219. });
  220. }
  221. /**
  222. * A description of the outline of a polygon on the ellipsoid. The polygon is defined by a polygon hierarchy.
  223. *
  224. * @alias PolygonOutlineGeometry
  225. * @constructor
  226. *
  227. * @param {Object} options Object with the following properties:
  228. * @param {PolygonHierarchy} options.polygonHierarchy A polygon hierarchy that can include holes.
  229. * @param {Number} [options.height=0.0] The distance in meters between the polygon and the ellipsoid surface.
  230. * @param {Number} [options.extrudedHeight] The distance in meters between the polygon's extruded face and the ellipsoid surface.
  231. * @param {VertexFormat} [options.vertexFormat=VertexFormat.DEFAULT] The vertex attributes to be computed.
  232. * @param {Ellipsoid} [options.ellipsoid=Ellipsoid.WGS84] The ellipsoid to be used as a reference.
  233. * @param {Number} [options.granularity=CesiumMath.RADIANS_PER_DEGREE] The distance, in radians, between each latitude and longitude. Determines the number of positions in the buffer.
  234. * @param {Boolean} [options.perPositionHeight=false] Use the height of options.positions for each position instead of using options.height to determine the height.
  235. * @param {ArcType} [options.arcType=ArcType.GEODESIC] The type of path the outline must follow. Valid options are {@link ArcType.GEODESIC} and {@link ArcType.RHUMB}.
  236. *
  237. * @see PolygonOutlineGeometry#createGeometry
  238. * @see PolygonOutlineGeometry#fromPositions
  239. *
  240. * @example
  241. * // 1. create a polygon outline from points
  242. * var polygon = new Cesium.PolygonOutlineGeometry({
  243. * polygonHierarchy : new Cesium.PolygonHierarchy(
  244. * Cesium.Cartesian3.fromDegreesArray([
  245. * -72.0, 40.0,
  246. * -70.0, 35.0,
  247. * -75.0, 30.0,
  248. * -70.0, 30.0,
  249. * -68.0, 40.0
  250. * ])
  251. * )
  252. * });
  253. * var geometry = Cesium.PolygonOutlineGeometry.createGeometry(polygon);
  254. *
  255. * // 2. create a nested polygon with holes outline
  256. * var polygonWithHole = new Cesium.PolygonOutlineGeometry({
  257. * polygonHierarchy : new Cesium.PolygonHierarchy(
  258. * Cesium.Cartesian3.fromDegreesArray([
  259. * -109.0, 30.0,
  260. * -95.0, 30.0,
  261. * -95.0, 40.0,
  262. * -109.0, 40.0
  263. * ]),
  264. * [new Cesium.PolygonHierarchy(
  265. * Cesium.Cartesian3.fromDegreesArray([
  266. * -107.0, 31.0,
  267. * -107.0, 39.0,
  268. * -97.0, 39.0,
  269. * -97.0, 31.0
  270. * ]),
  271. * [new Cesium.PolygonHierarchy(
  272. * Cesium.Cartesian3.fromDegreesArray([
  273. * -105.0, 33.0,
  274. * -99.0, 33.0,
  275. * -99.0, 37.0,
  276. * -105.0, 37.0
  277. * ]),
  278. * [new Cesium.PolygonHierarchy(
  279. * Cesium.Cartesian3.fromDegreesArray([
  280. * -103.0, 34.0,
  281. * -101.0, 34.0,
  282. * -101.0, 36.0,
  283. * -103.0, 36.0
  284. * ])
  285. * )]
  286. * )]
  287. * )]
  288. * )
  289. * });
  290. * var geometry = Cesium.PolygonOutlineGeometry.createGeometry(polygonWithHole);
  291. *
  292. * // 3. create extruded polygon outline
  293. * var extrudedPolygon = new Cesium.PolygonOutlineGeometry({
  294. * polygonHierarchy : new Cesium.PolygonHierarchy(
  295. * Cesium.Cartesian3.fromDegreesArray([
  296. * -72.0, 40.0,
  297. * -70.0, 35.0,
  298. * -75.0, 30.0,
  299. * -70.0, 30.0,
  300. * -68.0, 40.0
  301. * ])
  302. * ),
  303. * extrudedHeight: 300000
  304. * });
  305. * var geometry = Cesium.PolygonOutlineGeometry.createGeometry(extrudedPolygon);
  306. */
  307. function PolygonOutlineGeometry(options) {
  308. //>>includeStart('debug', pragmas.debug);
  309. Check.Check.typeOf.object("options", options);
  310. Check.Check.typeOf.object("options.polygonHierarchy", options.polygonHierarchy);
  311. if (options.perPositionHeight && when.defined(options.height)) {
  312. throw new Check.DeveloperError(
  313. "Cannot use both options.perPositionHeight and options.height"
  314. );
  315. }
  316. if (
  317. when.defined(options.arcType) &&
  318. options.arcType !== ArcType.ArcType.GEODESIC &&
  319. options.arcType !== ArcType.ArcType.RHUMB
  320. ) {
  321. throw new Check.DeveloperError(
  322. "Invalid arcType. Valid options are ArcType.GEODESIC and ArcType.RHUMB."
  323. );
  324. }
  325. //>>includeEnd('debug');
  326. var polygonHierarchy = options.polygonHierarchy;
  327. var ellipsoid = when.defaultValue(options.ellipsoid, Cartesian2.Ellipsoid.WGS84);
  328. var granularity = when.defaultValue(
  329. options.granularity,
  330. _Math.CesiumMath.RADIANS_PER_DEGREE
  331. );
  332. var perPositionHeight = when.defaultValue(options.perPositionHeight, false);
  333. var perPositionHeightExtrude =
  334. perPositionHeight && when.defined(options.extrudedHeight);
  335. var arcType = when.defaultValue(options.arcType, ArcType.ArcType.GEODESIC);
  336. var height = when.defaultValue(options.height, 0.0);
  337. var extrudedHeight = when.defaultValue(options.extrudedHeight, height);
  338. if (!perPositionHeightExtrude) {
  339. var h = Math.max(height, extrudedHeight);
  340. extrudedHeight = Math.min(height, extrudedHeight);
  341. height = h;
  342. }
  343. this._ellipsoid = Cartesian2.Ellipsoid.clone(ellipsoid);
  344. this._granularity = granularity;
  345. this._height = height;
  346. this._extrudedHeight = extrudedHeight;
  347. this._arcType = arcType;
  348. this._polygonHierarchy = polygonHierarchy;
  349. this._perPositionHeight = perPositionHeight;
  350. this._perPositionHeightExtrude = perPositionHeightExtrude;
  351. this._offsetAttribute = options.offsetAttribute;
  352. this._workerName = "createPolygonOutlineGeometry";
  353. /**
  354. * The number of elements used to pack the object into an array.
  355. * @type {Number}
  356. */
  357. this.packedLength =
  358. PolygonGeometryLibrary.PolygonGeometryLibrary.computeHierarchyPackedLength(polygonHierarchy) +
  359. Cartesian2.Ellipsoid.packedLength +
  360. 8;
  361. }
  362. /**
  363. * Stores the provided instance into the provided array.
  364. *
  365. * @param {PolygonOutlineGeometry} value The value to pack.
  366. * @param {Number[]} array The array to pack into.
  367. * @param {Number} [startingIndex=0] The index into the array at which to start packing the elements.
  368. *
  369. * @returns {Number[]} The array that was packed into
  370. */
  371. PolygonOutlineGeometry.pack = function (value, array, startingIndex) {
  372. //>>includeStart('debug', pragmas.debug);
  373. Check.Check.typeOf.object("value", value);
  374. Check.Check.defined("array", array);
  375. //>>includeEnd('debug');
  376. startingIndex = when.defaultValue(startingIndex, 0);
  377. startingIndex = PolygonGeometryLibrary.PolygonGeometryLibrary.packPolygonHierarchy(
  378. value._polygonHierarchy,
  379. array,
  380. startingIndex
  381. );
  382. Cartesian2.Ellipsoid.pack(value._ellipsoid, array, startingIndex);
  383. startingIndex += Cartesian2.Ellipsoid.packedLength;
  384. array[startingIndex++] = value._height;
  385. array[startingIndex++] = value._extrudedHeight;
  386. array[startingIndex++] = value._granularity;
  387. array[startingIndex++] = value._perPositionHeightExtrude ? 1.0 : 0.0;
  388. array[startingIndex++] = value._perPositionHeight ? 1.0 : 0.0;
  389. array[startingIndex++] = value._arcType;
  390. array[startingIndex++] = when.defaultValue(value._offsetAttribute, -1);
  391. array[startingIndex] = value.packedLength;
  392. return array;
  393. };
  394. var scratchEllipsoid = Cartesian2.Ellipsoid.clone(Cartesian2.Ellipsoid.UNIT_SPHERE);
  395. var dummyOptions = {
  396. polygonHierarchy: {},
  397. };
  398. /**
  399. * Retrieves an instance from a packed array.
  400. *
  401. * @param {Number[]} array The packed array.
  402. * @param {Number} [startingIndex=0] The starting index of the element to be unpacked.
  403. * @param {PolygonOutlineGeometry} [result] The object into which to store the result.
  404. * @returns {PolygonOutlineGeometry} The modified result parameter or a new PolygonOutlineGeometry instance if one was not provided.
  405. */
  406. PolygonOutlineGeometry.unpack = function (array, startingIndex, result) {
  407. //>>includeStart('debug', pragmas.debug);
  408. Check.Check.defined("array", array);
  409. //>>includeEnd('debug');
  410. startingIndex = when.defaultValue(startingIndex, 0);
  411. var polygonHierarchy = PolygonGeometryLibrary.PolygonGeometryLibrary.unpackPolygonHierarchy(
  412. array,
  413. startingIndex
  414. );
  415. startingIndex = polygonHierarchy.startingIndex;
  416. delete polygonHierarchy.startingIndex;
  417. var ellipsoid = Cartesian2.Ellipsoid.unpack(array, startingIndex, scratchEllipsoid);
  418. startingIndex += Cartesian2.Ellipsoid.packedLength;
  419. var height = array[startingIndex++];
  420. var extrudedHeight = array[startingIndex++];
  421. var granularity = array[startingIndex++];
  422. var perPositionHeightExtrude = array[startingIndex++] === 1.0;
  423. var perPositionHeight = array[startingIndex++] === 1.0;
  424. var arcType = array[startingIndex++];
  425. var offsetAttribute = array[startingIndex++];
  426. var packedLength = array[startingIndex];
  427. if (!when.defined(result)) {
  428. result = new PolygonOutlineGeometry(dummyOptions);
  429. }
  430. result._polygonHierarchy = polygonHierarchy;
  431. result._ellipsoid = Cartesian2.Ellipsoid.clone(ellipsoid, result._ellipsoid);
  432. result._height = height;
  433. result._extrudedHeight = extrudedHeight;
  434. result._granularity = granularity;
  435. result._perPositionHeight = perPositionHeight;
  436. result._perPositionHeightExtrude = perPositionHeightExtrude;
  437. result._arcType = arcType;
  438. result._offsetAttribute =
  439. offsetAttribute === -1 ? undefined : offsetAttribute;
  440. result.packedLength = packedLength;
  441. return result;
  442. };
  443. /**
  444. * A description of a polygon outline from an array of positions.
  445. *
  446. * @param {Object} options Object with the following properties:
  447. * @param {Cartesian3[]} options.positions An array of positions that defined the corner points of the polygon.
  448. * @param {Number} [options.height=0.0] The height of the polygon.
  449. * @param {Number} [options.extrudedHeight] The height of the polygon extrusion.
  450. * @param {Ellipsoid} [options.ellipsoid=Ellipsoid.WGS84] The ellipsoid to be used as a reference.
  451. * @param {Number} [options.granularity=CesiumMath.RADIANS_PER_DEGREE] The distance, in radians, between each latitude and longitude. Determines the number of positions in the buffer.
  452. * @param {Boolean} [options.perPositionHeight=false] Use the height of options.positions for each position instead of using options.height to determine the height.
  453. * @param {ArcType} [options.arcType=ArcType.GEODESIC] The type of path the outline must follow. Valid options are {@link LinkType.GEODESIC} and {@link ArcType.RHUMB}.
  454. * @returns {PolygonOutlineGeometry}
  455. *
  456. *
  457. * @example
  458. * // create a polygon from points
  459. * var polygon = Cesium.PolygonOutlineGeometry.fromPositions({
  460. * positions : Cesium.Cartesian3.fromDegreesArray([
  461. * -72.0, 40.0,
  462. * -70.0, 35.0,
  463. * -75.0, 30.0,
  464. * -70.0, 30.0,
  465. * -68.0, 40.0
  466. * ])
  467. * });
  468. * var geometry = Cesium.PolygonOutlineGeometry.createGeometry(polygon);
  469. *
  470. * @see PolygonOutlineGeometry#createGeometry
  471. */
  472. PolygonOutlineGeometry.fromPositions = function (options) {
  473. options = when.defaultValue(options, when.defaultValue.EMPTY_OBJECT);
  474. //>>includeStart('debug', pragmas.debug);
  475. Check.Check.defined("options.positions", options.positions);
  476. //>>includeEnd('debug');
  477. var newOptions = {
  478. polygonHierarchy: {
  479. positions: options.positions,
  480. },
  481. height: options.height,
  482. extrudedHeight: options.extrudedHeight,
  483. ellipsoid: options.ellipsoid,
  484. granularity: options.granularity,
  485. perPositionHeight: options.perPositionHeight,
  486. arcType: options.arcType,
  487. offsetAttribute: options.offsetAttribute,
  488. };
  489. return new PolygonOutlineGeometry(newOptions);
  490. };
  491. /**
  492. * Computes the geometric representation of a polygon outline, including its vertices, indices, and a bounding sphere.
  493. *
  494. * @param {PolygonOutlineGeometry} polygonGeometry A description of the polygon outline.
  495. * @returns {Geometry|undefined} The computed vertices and indices.
  496. */
  497. PolygonOutlineGeometry.createGeometry = function (polygonGeometry) {
  498. var ellipsoid = polygonGeometry._ellipsoid;
  499. var granularity = polygonGeometry._granularity;
  500. var polygonHierarchy = polygonGeometry._polygonHierarchy;
  501. var perPositionHeight = polygonGeometry._perPositionHeight;
  502. var arcType = polygonGeometry._arcType;
  503. var polygons = PolygonGeometryLibrary.PolygonGeometryLibrary.polygonOutlinesFromHierarchy(
  504. polygonHierarchy,
  505. !perPositionHeight,
  506. ellipsoid
  507. );
  508. if (polygons.length === 0) {
  509. return undefined;
  510. }
  511. var geometryInstance;
  512. var geometries = [];
  513. var minDistance = _Math.CesiumMath.chordLength(
  514. granularity,
  515. ellipsoid.maximumRadius
  516. );
  517. var height = polygonGeometry._height;
  518. var extrudedHeight = polygonGeometry._extrudedHeight;
  519. var extrude =
  520. polygonGeometry._perPositionHeightExtrude ||
  521. !_Math.CesiumMath.equalsEpsilon(height, extrudedHeight, 0, _Math.CesiumMath.EPSILON2);
  522. var offsetValue;
  523. var i;
  524. if (extrude) {
  525. for (i = 0; i < polygons.length; i++) {
  526. geometryInstance = createGeometryFromPositionsExtruded(
  527. ellipsoid,
  528. polygons[i],
  529. minDistance,
  530. perPositionHeight,
  531. arcType
  532. );
  533. geometryInstance.geometry = PolygonGeometryLibrary.PolygonGeometryLibrary.scaleToGeodeticHeightExtruded(
  534. geometryInstance.geometry,
  535. height,
  536. extrudedHeight,
  537. ellipsoid,
  538. perPositionHeight
  539. );
  540. if (when.defined(polygonGeometry._offsetAttribute)) {
  541. var size =
  542. geometryInstance.geometry.attributes.position.values.length / 3;
  543. var offsetAttribute = new Uint8Array(size);
  544. if (polygonGeometry._offsetAttribute === GeometryOffsetAttribute.GeometryOffsetAttribute.TOP) {
  545. offsetAttribute = GeometryOffsetAttribute.arrayFill(offsetAttribute, 1, 0, size / 2);
  546. } else {
  547. offsetValue =
  548. polygonGeometry._offsetAttribute === GeometryOffsetAttribute.GeometryOffsetAttribute.NONE
  549. ? 0
  550. : 1;
  551. offsetAttribute = GeometryOffsetAttribute.arrayFill(offsetAttribute, offsetValue);
  552. }
  553. geometryInstance.geometry.attributes.applyOffset = new GeometryAttribute.GeometryAttribute(
  554. {
  555. componentDatatype: ComponentDatatype.ComponentDatatype.UNSIGNED_BYTE,
  556. componentsPerAttribute: 1,
  557. values: offsetAttribute,
  558. }
  559. );
  560. }
  561. geometries.push(geometryInstance);
  562. }
  563. } else {
  564. for (i = 0; i < polygons.length; i++) {
  565. geometryInstance = createGeometryFromPositions(
  566. ellipsoid,
  567. polygons[i],
  568. minDistance,
  569. perPositionHeight,
  570. arcType
  571. );
  572. geometryInstance.geometry.attributes.position.values = PolygonPipeline.PolygonPipeline.scaleToGeodeticHeight(
  573. geometryInstance.geometry.attributes.position.values,
  574. height,
  575. ellipsoid,
  576. !perPositionHeight
  577. );
  578. if (when.defined(polygonGeometry._offsetAttribute)) {
  579. var length =
  580. geometryInstance.geometry.attributes.position.values.length;
  581. var applyOffset = new Uint8Array(length / 3);
  582. offsetValue =
  583. polygonGeometry._offsetAttribute === GeometryOffsetAttribute.GeometryOffsetAttribute.NONE
  584. ? 0
  585. : 1;
  586. GeometryOffsetAttribute.arrayFill(applyOffset, offsetValue);
  587. geometryInstance.geometry.attributes.applyOffset = new GeometryAttribute.GeometryAttribute(
  588. {
  589. componentDatatype: ComponentDatatype.ComponentDatatype.UNSIGNED_BYTE,
  590. componentsPerAttribute: 1,
  591. values: applyOffset,
  592. }
  593. );
  594. }
  595. geometries.push(geometryInstance);
  596. }
  597. }
  598. var geometry = GeometryPipeline.GeometryPipeline.combineInstances(geometries)[0];
  599. var boundingSphere = Transforms.BoundingSphere.fromVertices(
  600. geometry.attributes.position.values
  601. );
  602. return new GeometryAttribute.Geometry({
  603. attributes: geometry.attributes,
  604. indices: geometry.indices,
  605. primitiveType: geometry.primitiveType,
  606. boundingSphere: boundingSphere,
  607. offsetAttribute: polygonGeometry._offsetAttribute,
  608. });
  609. };
  610. function createPolygonOutlineGeometry(polygonGeometry, offset) {
  611. if (when.defined(offset)) {
  612. polygonGeometry = PolygonOutlineGeometry.unpack(polygonGeometry, offset);
  613. }
  614. polygonGeometry._ellipsoid = Cartesian2.Ellipsoid.clone(polygonGeometry._ellipsoid);
  615. return PolygonOutlineGeometry.createGeometry(polygonGeometry);
  616. }
  617. return createPolygonOutlineGeometry;
  618. });