1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
| <template>
| <div>
| <slot></slot>
| </div>
| </template>
|
| <script>
| import commonMixin from '../base/mixins/common.js'
| import bindEvents from '../base/bindEvent.js'
| import {createLabel, createIcon, createPoint} from '../base/factory.js'
|
| export default {
| name: 'bm-marker',
| mixins: [commonMixin('overlay')],
| props: {
| position: {},
| offset: {},
| icon: {},
| massClear: {
| type: Boolean,
| default: true
| },
| dragging: {
| type: Boolean,
| default: false
| },
| clicking: {
| type: Boolean,
| default: true
| },
| raiseOnDrag: {
| type: Boolean,
| default: false
| },
| draggingCursor: {
| type: String
| },
| rotation: {
| type: Number
| },
| shadow: {
| type: Object
| },
| title: {
| type: String
| },
| label: {
| type: Object
| },
| animation: {
| type: String
| },
| top: {
| type: Boolean,
| default: false
| },
| zIndex: {
| type: Number,
| default: 0
| }
| },
| watch: {
| 'position.lng' (val, oldVal) {
| const {BMap, originInstance, position, renderByParent, $parent} = this
| if (val !== oldVal && val >= -180 && val <= 180) {
| originInstance.setPosition(createPoint(BMap, {lng: val, lat: position.lat}))
| }
| renderByParent && $parent.reload()
| },
| 'position.lat' (val, oldVal) {
| const {BMap, originInstance, position, renderByParent, $parent} = this
| if (val !== oldVal && val >= -74 && val <= 74) {
| originInstance.setPosition(createPoint(BMap, {lng: position.lng, lat: val}))
| }
| renderByParent && $parent.reload()
| },
| 'offset.width' (val, oldVal) {
| const {BMap, originInstance} = this
| if (val !== oldVal) {
| originInstance.setOffset(new BMap.Size(val, this.offset.height))
| }
| },
| 'offset.height' (val, oldVal) {
| const {BMap, originInstance} = this
| if (val !== oldVal) {
| originInstance.setOffset(new BMap.Size(this.offset.width, val))
| }
| },
| icon: {
| deep: true,
| handler (val) {
| const {BMap, originInstance, rotation} = this
| originInstance && originInstance.setIcon(createIcon(BMap, val))
| rotation && originInstance && originInstance.setRotation(rotation)
| }
| },
| massClear (val) {
| val ? this.originInstance.enableMassClear() : this.originInstance.disableMassClear()
| },
| dragging (val) {
| val ? this.originInstance.enableDragging() : this.originInstance.disableDragging()
| },
| clicking () {
| this.reload()
| },
| raiseOnDrag () {
| this.reload()
| },
| draggingCursor (val) {
| this.originInstance.setDraggingCursor(val)
| },
| rotation (val) {
| this.originInstance.setRotation(val)
| },
| shadow (val) {
| this.originInstance.setShadow(val)
| },
| title (val) {
| this.originInstance.setTitle(val)
| },
| label (val) {
| this.reload()
| },
| animation (val) {
| this.originInstance.setAnimation(global[val])
| },
| top (val) {
| this.originInstance.setTop(val)
| },
| zIndex (val) {
| this.originInstance.setZIndex(val)
| }
| },
| methods: {
| load () {
| const {BMap, map, position, offset, icon, massClear, dragging, clicking, raiseOnDrag, draggingCursor, rotation, shadow, title, label, animation, top, renderByParent, $parent, zIndex} = this
| const overlay = new BMap.Marker(new BMap.Point(position.lng, position.lat), {
| offset,
| icon: icon && createIcon(BMap, icon),
| enableMassClear: massClear,
| enableDragging: dragging,
| enableClicking: clicking,
| raiseOnDrag,
| draggingCursor,
| rotation,
| shadow,
| title
| })
| this.originInstance = overlay
| label && overlay && overlay.setLabel(createLabel(BMap, label))
| overlay.setTop(top)
| overlay.setZIndex(zIndex)
| bindEvents.call(this, overlay)
| if (renderByParent) {
| $parent.reload()
| } else {
| map.addOverlay(overlay)
| }
| overlay.setAnimation(global[animation])
| }
| }
| }
| </script>
|
|