Polyline.vue 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. <script>
  2. import commonMixin from '../base/mixins/common.js'
  3. import bindEvents from '../base/bindEvent.js'
  4. import {createPoint} from '../base/factory.js'
  5. export default {
  6. name: 'bm-polyline',
  7. render () {},
  8. mixins: [commonMixin('overlay')],
  9. props: {
  10. path: {
  11. type: Array
  12. },
  13. strokeColor: {
  14. type: String
  15. },
  16. strokeWeight: {
  17. type: Number
  18. },
  19. strokeOpacity: {
  20. type: Number
  21. },
  22. strokeStyle: {
  23. type: String
  24. },
  25. massClear: {
  26. type: Boolean,
  27. default: true
  28. },
  29. clicking: {
  30. type: Boolean,
  31. default: true
  32. },
  33. editing: {
  34. type: Boolean,
  35. default: false
  36. }
  37. },
  38. watch: {
  39. path: {
  40. handler (val, oldVal) {
  41. this.reload()
  42. },
  43. deep: true
  44. },
  45. strokeColor (val) {
  46. this.originInstance.setStrokeColor(val)
  47. },
  48. strokeOpacity (val) {
  49. this.originInstance.setStrokeOpacity(val)
  50. },
  51. strokeWeight (val) {
  52. this.originInstance.setStrokeWeight(val)
  53. },
  54. strokeStyle (val) {
  55. this.originInstance.setStrokeStyle(val)
  56. },
  57. editing (val) {
  58. val ? this.originInstance.enableEditing() : this.originInstance.disableEditing()
  59. },
  60. massClear (val) {
  61. val ? this.originInstance.enableMassClear() : this.originInstance.disableMassClear()
  62. },
  63. clicking (val) {
  64. this.reload()
  65. }
  66. },
  67. methods: {
  68. load () {
  69. const {BMap, map, path, strokeColor, strokeWeight, strokeOpacity, strokeStyle, editing, massClear, clicking} = this
  70. const overlay = new BMap.Polyline(path.map(item => createPoint(BMap, {lng: item.lng, lat: item.lat})), {
  71. strokeColor,
  72. strokeWeight,
  73. strokeOpacity,
  74. strokeStyle,
  75. enableEditing: editing,
  76. enableMassClear: massClear,
  77. enableClicking: clicking
  78. })
  79. this.originInstance = overlay
  80. map.addOverlay(overlay)
  81. bindEvents.call(this, overlay)
  82. }
  83. }
  84. }
  85. </script>