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

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

上级 1e02476b
import { import {
invokeMethod, invokeMethod,
getCurrentPageVm getCurrentPageVm
} from '../../platform' } from '../../platform'
import {
callback
} from 'uni-shared'
function operateMapPlayer (mapId, pageVm, type, data) { function operateMapPlayer (mapId, pageVm, type, data) {
invokeMethod('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 { export class MapContext {
constructor (id, pageVm) { constructor (id, pageVm) {
this.id = id this.id = id
this.pageVm = pageVm this.pageVm = pageVm
} }
getCenterLocation (args) {
operateMapPlayer(this.id, this.pageVm, 'getCenterLocation', args)
}
moveToLocation () { moveToLocation () {
operateMapPlayer(this.id, this.pageVm, 'moveToLocation') operateMapPlayer(this.id, this.pageVm, 'moveToLocation')
} }
translateMarker (args) {
operateMapPlayer(this.id, this.pageVm, 'translateMarker', args)
}
includePoints (args) { includePoints (args) {
operateMapPlayer(this.id, this.pageVm, 'includePoints', args) operateMapPlayer(this.id, this.pageVm, 'includePoints', args)
} }
}
getRegion (args) { methods.forEach(function (method) {
operateMapPlayer(this.id, this.pageVm, 'getRegion', args) MapContext.prototype[method] = callback.warp(function (options, callbackId) {
} operateMapPlayer(this.id, this.pageVm, method, {
options,
getScale (args) { callbackId
operateMapPlayer(this.id, this.pageVm, 'getScale', args) })
} })
} })
export function createMapContext (id, context) { export function createMapContext (id, context) {
if (context) { if (context) {
......
...@@ -146,7 +146,9 @@ export default { ...@@ -146,7 +146,9 @@ export default {
const list = this.controls.map((control) => { const list = this.controls.map((control) => {
let position = { position: 'absolute' }; let position = { position: 'absolute' };
['top', 'left', 'width', 'height'].forEach(key => { ['top', 'left', 'width', 'height'].forEach(key => {
position[key] = control.position[key] + 'px' if (control.position[key]) {
position[key] = control.position[key] + 'px'
}
}) })
return { return {
id: control.id, id: control.id,
...@@ -160,6 +162,25 @@ export default { ...@@ -160,6 +162,25 @@ export default {
watch: { watch: {
hidden (val) { hidden (val) {
this.map && this.map[val ? 'hide' : 'show']() 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 () { mounted () {
...@@ -175,17 +196,6 @@ export default { ...@@ -175,17 +196,6 @@ export default {
if (this.hidden) { if (this.hidden) {
map.hide() 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.$watch('position', () => {
this.map && this.map.setStyles(this.position) this.map && this.map.setStyles(this.position)
}, { }, {
...@@ -214,13 +224,40 @@ export default { ...@@ -214,13 +224,40 @@ export default {
} }
this.map && this[type](data) 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) { controlclick (e) {
this.$trigger('controltap', {}, { id: e.id }) this.$trigger('controltap', {}, { id: e.id })
}, },
_publishHandler (callbackId, data) {
UniViewJSBridge.publishHandler('onMapMethodCallback', {
callbackId,
data
}, this.$page.id)
},
_addMarker (nativeMap, marker) { _addMarker (nativeMap, marker) {
const { const {
id, id,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册