PointCollection.vue 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. render () {},
  7. name: 'bm-point-collection',
  8. mixins: [commonMixin('overlay')],
  9. props: {
  10. points: {
  11. type: Array,
  12. default () {
  13. return []
  14. }
  15. },
  16. shape: {
  17. type: String,
  18. default: 'BMAP_POINT_SHAPE_CIRCLE'
  19. },
  20. color: {
  21. type: String
  22. },
  23. size: {
  24. type: String,
  25. default: 'BMAP_POINT_SIZE_NORMAL'
  26. }
  27. },
  28. watch: {
  29. shape (val) {
  30. const {originInstance, color, size} = this
  31. originInstance.setStyles({
  32. shape: global[val],
  33. color,
  34. size: global[size]
  35. })
  36. },
  37. size (val) {
  38. const {originInstance, color, shape} = this
  39. originInstance.setStyles({
  40. shape: global[shape],
  41. color,
  42. size: global[val]
  43. })
  44. },
  45. color (val) {
  46. const {originInstance, shape, size} = this
  47. originInstance.setStyles({
  48. shape: global[shape],
  49. color: val,
  50. size: global[size]
  51. })
  52. },
  53. points: {
  54. deep: true,
  55. handler (val) {
  56. const {originInstance} = this
  57. originInstance.clear()
  58. originInstance.setPoints(val)
  59. }
  60. }
  61. },
  62. methods: {
  63. load () {
  64. const {BMap, map, points, shape, color, size} = this
  65. const overlay = this.originInstance = new BMap.PointCollection(points.map(p => createPoint(BMap, p)), {
  66. shape: global[shape],
  67. color,
  68. size: global[size]
  69. })
  70. bindEvents.call(this, overlay)
  71. map.addOverlay(overlay)
  72. }
  73. }
  74. }
  75. </script>