Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

MeasureBase.js 2.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. /**
  2. * @Author: Caven
  3. * @Date: 2021-07-11 09:56:33
  4. */
  5. import { Cesium } from '@dc-modules/namespace'
  6. class MeasureBase {
  7. constructor() {
  8. this._viewer = undefined
  9. this._layer = undefined
  10. this._startLabel = new Cesium.Entity({
  11. label: {
  12. text: '开始',
  13. font: '12px',
  14. pixelOffset: { x: 0, y: -15 },
  15. disableDepthTestDistance: Number.POSITIVE_INFINITY,
  16. showBackground: true
  17. }
  18. })
  19. this._resultLabel = new Cesium.Entity({
  20. label: {
  21. font: '12px',
  22. pixelOffset: { x: 0, y: -15 },
  23. disableDepthTestDistance: Number.POSITIVE_INFINITY,
  24. showBackground: true
  25. }
  26. })
  27. this._options = {}
  28. }
  29. /**
  30. *
  31. * @param positions
  32. * @param includeModel
  33. * @returns {*}
  34. */
  35. _getSampledHeight(positions, includeModel = false) {
  36. let terrainPromise =
  37. this._viewer.terrainProvider &&
  38. !(this._viewer.terrainProvider instanceof Cesium.EllipsoidTerrainProvider)
  39. ? Cesium.sampleTerrainMostDetailed(
  40. this._viewer.terrainProvider,
  41. positions.map(item => Cesium.Cartographic.fromCartesian(item))
  42. )
  43. : Promise.resolve(
  44. positions.map(item => Cesium.Cartographic.fromCartesian(item))
  45. )
  46. let modelPromise =
  47. this._viewer.scene.clampToHeightSupported && includeModel
  48. ? this._viewer.scene.clampToHeightMostDetailed(
  49. positions,
  50. this._layer.entities.values
  51. )
  52. : Promise.resolve(positions)
  53. return Promise.all([terrainPromise, modelPromise])
  54. }
  55. /**
  56. *
  57. * @private
  58. */
  59. _onDrawStop(delegate) {}
  60. /**
  61. *
  62. * @param positions
  63. * @private
  64. */
  65. _onCalc(positions) {}
  66. /**
  67. *
  68. * @param measure
  69. * @param options
  70. */
  71. _startHook(measure, options) {
  72. this._viewer = measure.viewer
  73. this._layer = measure.layer
  74. this._options = options
  75. this._options.onDrawStop = this._onDrawStop.bind(this)
  76. this._options.onCalc = this._onCalc.bind(this)
  77. this._layer.entities.add(this._startLabel)
  78. this._layer.entities.add(this._resultLabel)
  79. }
  80. /**
  81. *
  82. * @param measure
  83. * @param options
  84. * @returns {MeasureBase}
  85. */
  86. start(measure, options) {
  87. return this
  88. }
  89. }
  90. export default MeasureBase