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.

CoordinateSystem.js 2.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. /**
  2. * @Author: Caven
  3. * @Date: 2020-02-02 16:21:35
  4. */
  5. import { Cesium } from '@dc-modules/namespace'
  6. class CoordinateSystem {
  7. constructor(viewer, api) {
  8. this._viewer = viewer
  9. this._dimensions = ['lng', 'lat']
  10. this._mapOffset = [0, 0]
  11. this._api = api
  12. }
  13. setMapOffset(mapOffset) {
  14. this._mapOffset = mapOffset
  15. return this
  16. }
  17. getViewer() {
  18. return this._viewer
  19. }
  20. dataToPoint(data) {
  21. let scene = this._viewer.scene
  22. let result = [0, 0]
  23. let cartesian3 = Cesium.Cartesian3.fromDegrees(data[0], data[1])
  24. if (!cartesian3) {
  25. return result
  26. }
  27. if (
  28. scene.mode === Cesium.SceneMode.SCENE3D &&
  29. Cesium.Cartesian3.angleBetween(scene.camera.position, cartesian3) >
  30. Cesium.Math.toRadians(80)
  31. ) {
  32. return false
  33. }
  34. let coords = scene.cartesianToCanvasCoordinates(cartesian3)
  35. if (!coords) {
  36. return result
  37. }
  38. return [coords.x - this._mapOffset[0], coords.y - this._mapOffset[1]]
  39. }
  40. pointToData(point) {
  41. let ellipsoid = this._viewer.scene.globe.ellipsoid
  42. let cartesian3 = new Cesium.Cartesian3(
  43. point[0] + this._mapOffset[0],
  44. point[1] + this._mapOffset[1],
  45. 0
  46. )
  47. let cartographic = ellipsoid.cartesianToCartographic(cartesian3)
  48. return [
  49. Cesium.Math.toDegrees(cartographic.longitude),
  50. Cesium.Math.toDegrees(cartographic.latitude)
  51. ]
  52. }
  53. getViewRect() {
  54. let api = this._api
  55. return new echarts.graphic.BoundingRect(
  56. 0,
  57. 0,
  58. api.getWidth(),
  59. api.getHeight()
  60. )
  61. }
  62. getRoamTransform() {
  63. return echarts.matrix.create()
  64. }
  65. get dimensions() {
  66. return this._dimensions
  67. }
  68. static get dimensions() {
  69. return ['lng', 'lat']
  70. }
  71. static create(ecModel, api) {
  72. let coordinateSys = undefined
  73. ecModel.eachComponent('GLMap', function(model) {
  74. coordinateSys = new CoordinateSystem(echarts.viewer.delegate, api)
  75. coordinateSys.setMapOffset(model.__mapOffset || [0, 0])
  76. model.coordinateSystem = coordinateSys
  77. })
  78. ecModel.eachSeries(function(model) {
  79. 'GLMap' === model.get('coordinateSystem') &&
  80. (model.coordinateSystem = coordinateSys)
  81. })
  82. }
  83. }
  84. export default CoordinateSystem