Bus.vue 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. <template>
  2. <div v-show="panel">
  3. </div>
  4. </template>
  5. <script>
  6. import { createPoint } from '../base/factory.js'
  7. import { isPoint } from '../base/util.js'
  8. import commonMixin from '../base/mixins/common.js'
  9. export default {
  10. name: 'bm-bus',
  11. emits: ['getbuslistcomplete', 'getbuslinecomplete', 'buslisthtmlset', 'buslinehtmlset', 'markersset', 'polylinesset'],
  12. mixins: [commonMixin('search')],
  13. props: {
  14. location: {
  15. type: [Object, String]
  16. },
  17. keyword: {
  18. type: String
  19. },
  20. panel: {
  21. type: Boolean,
  22. default: true
  23. },
  24. pageCapacity: {
  25. type: Number
  26. },
  27. autoViewport: {
  28. type: Boolean
  29. },
  30. selectFirstResult: {
  31. type: Boolean
  32. }
  33. },
  34. watch: {
  35. location: {
  36. handler(val) {
  37. const { originInstance, map } = this
  38. originInstance.setLocation(val || map)
  39. },
  40. deep: true
  41. },
  42. keyword(val) {
  43. this.search(val)
  44. },
  45. panel() {
  46. this.reload()
  47. },
  48. autoViewport(val) {
  49. this.reload()
  50. },
  51. selectFirstResult(val) {
  52. this.reload()
  53. }
  54. },
  55. methods: {
  56. search(keyword) {
  57. const { originInstance } = this
  58. originInstance.getBusList(keyword)
  59. },
  60. load() {
  61. const instance = this
  62. const { location, selectFirstResult, autoViewport, highlightMode, keyword, search, BMap, map, originInstance } = this
  63. const _location = location ? isPoint(location) ? createPoint(BMap, location) : location : map
  64. const route = this.originInstance = new BMap.BusLineSearch(_location, {
  65. renderOptions: {
  66. map,
  67. panel: this.$el,
  68. selectFirstResult,
  69. autoViewport,
  70. highlightMode
  71. },
  72. onGetBusListComplete(e) {
  73. if (originInstance && originInstance !== route) {
  74. originInstance.clearResults()
  75. }
  76. instance.$emit('getbuslistcomplete', e)
  77. },
  78. onGetBusLineComplete(e) {
  79. if (originInstance && originInstance !== route) {
  80. originInstance.clearResults()
  81. }
  82. instance.$emit('getbuslinecomplete', e)
  83. },
  84. onBusListHtmlSet(e) {
  85. instance.$emit('buslisthtmlset', e)
  86. },
  87. onBusLineHtmlSet(e) {
  88. instance.$emit('buslinehtmlset', e)
  89. },
  90. onMarkersSet(e) {
  91. instance.$emit('markersset', e)
  92. },
  93. onPolylinesSet(e) {
  94. instance.$emit('polylinesset', e)
  95. }
  96. })
  97. search(keyword)
  98. }
  99. }
  100. }
  101. </script>