createVectorTilePoints.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /**
  2. * Cesium - https://github.com/AnalyticalGraphicsInc/cesium
  3. *
  4. * Copyright 2011-2017 Cesium Contributors
  5. *
  6. * Licensed under the Apache License, Version 2.0 (the "License");
  7. * you may not use this file except in compliance with the License.
  8. * You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing, software
  13. * distributed under the License is distributed on an "AS IS" BASIS,
  14. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. * See the License for the specific language governing permissions and
  16. * limitations under the License.
  17. *
  18. * Columbus View (Pat. Pend.)
  19. *
  20. * Portions licensed separately.
  21. * See https://github.com/AnalyticalGraphicsInc/cesium/blob/master/LICENSE.md for full licensing details.
  22. */
  23. define(['./when-8d13db60', './Check-70bec281', './Math-61ede240', './Cartographic-fe4be337', './Cartesian2-85064f09', './AttributeCompression-84a90a13', './createTaskProcessorWorker'], function (when, Check, _Math, Cartographic, Cartesian2, AttributeCompression, createTaskProcessorWorker) { 'use strict';
  24. var maxShort = 32767;
  25. var scratchBVCartographic = new Cartographic.Cartographic();
  26. var scratchEncodedPosition = new Cartographic.Cartesian3();
  27. var scratchRectangle = new Cartesian2.Rectangle();
  28. var scratchEllipsoid = new Cartesian2.Ellipsoid();
  29. var scratchMinMaxHeights = {
  30. min : undefined,
  31. max : undefined
  32. };
  33. function unpackBuffer(packedBuffer) {
  34. packedBuffer = new Float64Array(packedBuffer);
  35. var offset = 0;
  36. scratchMinMaxHeights.min = packedBuffer[offset++];
  37. scratchMinMaxHeights.max = packedBuffer[offset++];
  38. Cartesian2.Rectangle.unpack(packedBuffer, offset, scratchRectangle);
  39. offset += Cartesian2.Rectangle.packedLength;
  40. Cartesian2.Ellipsoid.unpack(packedBuffer, offset, scratchEllipsoid);
  41. }
  42. function createVectorTilePoints(parameters, transferableObjects) {
  43. var positions = new Uint16Array(parameters.positions);
  44. unpackBuffer(parameters.packedBuffer);
  45. var rectangle = scratchRectangle;
  46. var ellipsoid = scratchEllipsoid;
  47. var minimumHeight = scratchMinMaxHeights.min;
  48. var maximumHeight = scratchMinMaxHeights.max;
  49. var positionsLength = positions.length / 3;
  50. var uBuffer = positions.subarray(0, positionsLength);
  51. var vBuffer = positions.subarray(positionsLength, 2 * positionsLength);
  52. var heightBuffer = positions.subarray(2 * positionsLength, 3 * positionsLength);
  53. AttributeCompression.AttributeCompression.zigZagDeltaDecode(uBuffer, vBuffer, heightBuffer);
  54. var decoded = new Float64Array(positions.length);
  55. for (var i = 0; i < positionsLength; ++i) {
  56. var u = uBuffer[i];
  57. var v = vBuffer[i];
  58. var h = heightBuffer[i];
  59. var lon = _Math.CesiumMath.lerp(rectangle.west, rectangle.east, u / maxShort);
  60. var lat = _Math.CesiumMath.lerp(rectangle.south, rectangle.north, v / maxShort);
  61. var alt = _Math.CesiumMath.lerp(minimumHeight, maximumHeight, h / maxShort);
  62. var cartographic = Cartographic.Cartographic.fromRadians(lon, lat, alt, scratchBVCartographic);
  63. var decodedPosition = ellipsoid.cartographicToCartesian(cartographic, scratchEncodedPosition);
  64. Cartographic.Cartesian3.pack(decodedPosition, decoded, i * 3);
  65. }
  66. transferableObjects.push(decoded.buffer);
  67. return {
  68. positions : decoded.buffer
  69. };
  70. }
  71. var createVectorTilePoints$1 = createTaskProcessorWorker(createVectorTilePoints);
  72. return createVectorTilePoints$1;
  73. });