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 707B

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