提交 4bbbbce0 编写于 作者: Q qiang

fix: 修复 App 端 map 组件 markers 无 id 时无法移除的问题

上级 6dcf012a
...@@ -194,7 +194,8 @@ export default { ...@@ -194,7 +194,8 @@ export default {
mapStyle.center = new plus.maps.Point(this.longitude, this.latitude) mapStyle.center = new plus.maps.Point(this.longitude, this.latitude)
} }
const map = this.map = plus.maps.create(this.$page.id + '-map-' + (this.id || Date.now()), mapStyle) const map = this.map = plus.maps.create(this.$page.id + '-map-' + (this.id || Date.now()), mapStyle)
map.__markers__ = {} map.__markers__ = []
map.__markers_map__ = {}
map.__lines__ = [] map.__lines__ = []
map.__circles__ = [] map.__circles__ = []
map.setZoom(parseInt(this.scale)) map.setZoom(parseInt(this.scale))
...@@ -317,16 +318,18 @@ export default { ...@@ -317,16 +318,18 @@ export default {
} }
} }
nativeMap.addOverlay(nativeMarker) nativeMap.addOverlay(nativeMarker)
nativeMap.__markers__[id + ''] = nativeMarker nativeMap.__markers__.push(nativeMarker)
nativeMap.__markers_map__[id + ''] = nativeMarker
}) })
}, },
_clearMarkers () { _clearMarkers () {
const map = this.map const map = this.map
const data = map.__markers__ const markers = map.__markers__
for (const key in data) { markers.forEach(marker => {
map.removeOverlay(data[key]) map.removeOverlay(marker)
} })
map.__markers__ = {} map.__markers__ = []
map.__markers_map__ = {}
}, },
_addMarkers (markers, clear) { _addMarkers (markers, clear) {
if (this.map) { if (this.map) {
...@@ -352,7 +355,7 @@ export default { ...@@ -352,7 +355,7 @@ export default {
markerId markerId
}) { }) {
if (this.map) { if (this.map) {
const nativeMarker = this.map.__markers__[markerId + ''] const nativeMarker = this.map.__markers_map__[markerId + '']
if (nativeMarker) { if (nativeMarker) {
nativeMarker.setPoint(new plus.maps.Point(destination.longitude, destination.latitude)) nativeMarker.setPoint(new plus.maps.Point(destination.longitude, destination.latitude))
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册