提交 5623740d 编写于 作者: d-u-a's avatar d-u-a

fix: V3版本 vue <map> 部分 API 无效及部分属性不能动态更新的 Bug

上级 1e02476b
import {
invokeMethod,
getCurrentPageVm
} from '../../platform'
} from '../../platform'
import {
callback
} from 'uni-shared'
function operateMapPlayer (mapId, pageVm, type, data) {
invokeMethod('operateMapPlayer', mapId, pageVm, type, data)
}
UniServiceJSBridge.subscribe('onMapMethodCallback', ({
callbackId,
data
}) => {
callback.invoke(callbackId, data)
})
const methods = ['getCenterLocation', 'translateMarker', 'getScale', 'getRegion']
export class MapContext {
constructor (id, pageVm) {
this.id = id
this.pageVm = pageVm
}
getCenterLocation (args) {
operateMapPlayer(this.id, this.pageVm, 'getCenterLocation', args)
}
moveToLocation () {
operateMapPlayer(this.id, this.pageVm, 'moveToLocation')
}
translateMarker (args) {
operateMapPlayer(this.id, this.pageVm, 'translateMarker', args)
}
includePoints (args) {
operateMapPlayer(this.id, this.pageVm, 'includePoints', args)
}
}
getRegion (args) {
operateMapPlayer(this.id, this.pageVm, 'getRegion', args)
}
getScale (args) {
operateMapPlayer(this.id, this.pageVm, 'getScale', args)
}
}
methods.forEach(function (method) {
MapContext.prototype[method] = callback.warp(function (options, callbackId) {
operateMapPlayer(this.id, this.pageVm, method, {
options,
callbackId
})
})
})
export function createMapContext (id, context) {
if (context) {
......
......@@ -146,7 +146,9 @@ export default {
const list = this.controls.map((control) => {
let position = { position: 'absolute' };
['top', 'left', 'width', 'height'].forEach(key => {
position[key] = control.position[key] + 'px'
if (control.position[key]) {
position[key] = control.position[key] + 'px'
}
})
return {
id: control.id,
......@@ -160,6 +162,25 @@ export default {
watch: {
hidden (val) {
this.map && this.map[val ? 'hide' : 'show']()
},
latitude (val) {
this.map && this.map.setStyles({
center: new plus.maps.Point(this.longitude, this.latitude)
})
},
longitude (val) {
this.map && this.map.setStyles({
center: new plus.maps.Point(this.longitude, this.latitude)
})
},
markers (val) {
this.map && this._addMarkers(val)
},
polyline (val) {
this.map && this._addMapLines(val)
},
circles (val) {
this.map && this._addMapCircles(val)
}
},
mounted () {
......@@ -175,17 +196,6 @@ export default {
if (this.hidden) {
map.hide()
}
this.$watch('attrs', () => {
if (this.map) {
this.map.setStyles(this.attrs)
// TODO 临时处理更新 longitude, latitude 无效问题
this.map.setStyles({
center: new plus.maps.Point(this.longitude, this.latitude)
})
}
}, {
deep: true
})
this.$watch('position', () => {
this.map && this.map.setStyles(this.position)
}, {
......@@ -214,13 +224,40 @@ export default {
}
this.map && this[type](data)
},
getRegion () {
moveToLocation (data) {
this.map.setCenter(new plus.maps.Point(this.longitude, this.latitude))
},
getCenterLocation ({ callbackId }) {
const center = this.map.getCenter()
this._publishHandler(callbackId, {
longitude: center.longitude,
latitude: center.latitude,
errMsg: 'getCenterLocation:ok'
})
},
getScale () {
getRegion ({ callbackId }) {
const rect = this.map.getBounds()
this._publishHandler(callbackId, {
southwest: rect.southwest,
northeast: rect.northeast || rect.northease, // 5plus API 名字写错了
errMsg: 'getRegion:ok'
})
},
getScale ({ callbackId }) {
this._publishHandler(callbackId, {
scale: this.map.getZoom(),
errMsg: 'getScale:ok'
})
},
controlclick (e) {
this.$trigger('controltap', {}, { id: e.id })
},
_publishHandler (callbackId, data) {
UniViewJSBridge.publishHandler('onMapMethodCallback', {
callbackId,
data
}, this.$page.id)
},
_addMarker (nativeMap, marker) {
const {
id,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册