Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

DrawCircle.js 2.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /*
  2. * @Author: Caven
  3. * @Date: 2020-01-31 19:44:41
  4. * @Last Modified by: Caven
  5. * @Last Modified time: 2020-05-12 09:34:37
  6. */
  7. import Draw from './Draw'
  8. const { OverlayType, Transform } = DC
  9. const { Cesium } = DC.Namespace
  10. const DEF_STYLE = {
  11. width: 3,
  12. material: Cesium.Color.BLUE.withAlpha(0.6)
  13. }
  14. class DrawClicle extends Draw {
  15. constructor(plotInfo, style) {
  16. super(plotInfo)
  17. this._center = Cesium.Cartesian3.ZERO
  18. this._radius = 0
  19. this._style = {
  20. ...DEF_STYLE,
  21. ...style
  22. }
  23. }
  24. _mouseClickHandler(e) {
  25. let position = e.target ? e.position : e.surfacePosition
  26. if (position && this._center === Cesium.Cartesian3.ZERO) {
  27. this._center = position
  28. } else {
  29. this._computeRadius(this._center, position)
  30. this._unbindEnvet()
  31. this._plotEvent.raiseEvent({
  32. type: OverlayType.CIRCLE,
  33. points: [Transform.transformCartesianToWGS84(this._center)],
  34. radius: this._radius
  35. })
  36. }
  37. }
  38. _mouseMoveHandler(e) {
  39. let position = e.target ? e.position : e.surfacePosition
  40. this._viewer.tooltip.showAt(e.windowPosition, '左击选择点位')
  41. if (position && this._center !== Cesium.Cartesian3.ZERO) {
  42. this._computeRadius(this._center, position)
  43. }
  44. }
  45. _computeRadius(src, dest) {
  46. let srcCartographic = Cesium.Cartographic.fromCartesian(src)
  47. let destCartographic = Cesium.Cartographic.fromCartesian(dest)
  48. let geodesic = new Cesium.EllipsoidGeodesic()
  49. geodesic.setEndPoints(srcCartographic, destCartographic)
  50. let s = geodesic.surfaceDistance
  51. this._radius = Math.sqrt(
  52. Math.pow(s, 2) +
  53. Math.pow(destCartographic.height - srcCartographic.height, 2)
  54. )
  55. }
  56. _prepareDelegate() {
  57. this._delegate.position = new Cesium.CallbackProperty(time => {
  58. return this._center
  59. })
  60. this._delegate.ellipse = {
  61. semiMajorAxis: new Cesium.CallbackProperty(time => {
  62. return this._radius
  63. }),
  64. semiMinorAxis: new Cesium.CallbackProperty(time => {
  65. return this._radius
  66. }),
  67. ...this._style
  68. }
  69. this._delegate.point = {
  70. pixelSize: 10,
  71. outlineColor: Cesium.Color.RED,
  72. outlineWidth: 3
  73. }
  74. this._layer.entities.add(this._delegate)
  75. }
  76. }
  77. export default DrawClicle