PolygonOutlineGeometry.js 25 KB

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