You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

distance.js 683B

2 years ago
2 years ago
2 years ago
2 years ago
1234567891011121314151617181920212223
  1. /**
  2. * @Author : Caven Chen
  3. */
  4. import { Cesium } from '../../namespace'
  5. import { Transform } from '../transform'
  6. export default function distance(positions) {
  7. let distance = 0
  8. if (positions && Array.isArray(positions)) {
  9. for (let i = 0; i < positions.length - 1; i++) {
  10. let c1 = Transform.transformWGS84ToCartographic(positions[i])
  11. let c2 = Transform.transformWGS84ToCartographic(positions[i + 1])
  12. let geodesic = new Cesium.EllipsoidGeodesic()
  13. geodesic.setEndPoints(c1, c2)
  14. let s = geodesic.surfaceDistance
  15. s = Math.sqrt(Math.pow(s, 2) + Math.pow(c2.height - c1.height, 2))
  16. distance += s
  17. }
  18. }
  19. return distance.toFixed(3)
  20. }