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