createPolygonOutlineGeometry.js 26 KB

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