PointCollection.vue 1.9 KB

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