Lushu.vue 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. <script>
  2. /*eslint-disable*/
  3. import commonMixin from '../base/mixins/common.js'
  4. import { createIcon } from '../base/factory.js'
  5. import Lushu from 'bmaplib.lushu'
  6. export default {
  7. name: 'bm-lushu',
  8. render(h) { },
  9. emits: ['start', 'stop', 'pause'],
  10. mixins: [commonMixin('lushu')],
  11. props: {
  12. path: {
  13. type: Array,
  14. default: []
  15. },
  16. landmarkPois: {
  17. type: Array,
  18. default() {
  19. return []
  20. }
  21. },
  22. icon: {
  23. type: Object
  24. },
  25. speed: {
  26. type: Number,
  27. default: 4000
  28. },
  29. content: {
  30. type: String,
  31. default: ''
  32. },
  33. autoView: {
  34. type: Boolean,
  35. default: false
  36. },
  37. rotation: {
  38. type: Boolean,
  39. default: false
  40. },
  41. infoWindow: {
  42. type: Boolean,
  43. default: true
  44. },
  45. play: {
  46. type: Boolean,
  47. default: true
  48. }
  49. },
  50. watch: {
  51. path: {
  52. handler(val) {
  53. this.reload()
  54. },
  55. deep: true
  56. },
  57. landmarkPois: {
  58. handler(val) {
  59. this.reload()
  60. },
  61. deep: true
  62. },
  63. icon: {
  64. handler(val) {
  65. const { originInstance, content } = this
  66. const newMarker = createIcon(BMap, val)
  67. originInstance._opts.icon = newMarker
  68. originInstance._marker = newMarker
  69. },
  70. deep: true
  71. },
  72. speed(val) {
  73. const { originInstance, content } = this
  74. originInstance._opts.speed = val
  75. },
  76. content(val) {
  77. const { originInstance, infoWindow } = this
  78. val && infoWindow ? originInstance.showInfoWindow() : originInstance.hideInfoWindow()
  79. originInstance._opts.defaultContent = val
  80. originInstance._overlay && originInstance._overlay.setHtml(val)
  81. },
  82. autoView(val) {
  83. const { originInstance, content } = this
  84. originInstance._opts.autoView = val
  85. },
  86. rotation(val) {
  87. const { originInstance, content } = this
  88. originInstance._opts.enableRotation = val
  89. },
  90. infoWindow(val) {
  91. const { originInstance, content } = this
  92. originInstance && val && content ? originInstance.showInfoWindow() : originInstance.hideInfoWindow()
  93. },
  94. play(val) {
  95. const { originInstance } = this
  96. val && originInstance ? originInstance.start() : !this._isEnd && originInstance.pause()
  97. }
  98. },
  99. methods: {
  100. load() {
  101. const { BMap, map, path, landmarkPois, icon, speed, content, autoView, rotation, infoWindow, play } = this
  102. const lushu = this.originInstance = new Lushu(map, path, {
  103. enableRotation: rotation,
  104. landmarkPois,
  105. showInfoWindow: infoWindow,
  106. defaultContent: content,
  107. icon: icon && createIcon(BMap, icon),
  108. speed,
  109. autoView,
  110. onstart: e => {
  111. this._isEnd = false
  112. this.$emit('start')
  113. },
  114. onstop: e => {
  115. this._isEnd = true
  116. this.$emit('stop')
  117. },
  118. onpause: e => this.$emit('pause')
  119. })
  120. play && path.length && lushu.start(this)
  121. path.length && (content && infoWindow ? lushu.showInfoWindow() : lushu.hideInfoWindow())
  122. }
  123. }
  124. }
  125. </script>