map组件中心点重设失效
我有个map组件,通过移动地图产生变化后,重新获取中心点,可是show-location并不会产生变化,而我新增的markers标记点是有变化的,是什么情况?希望官方给个回应
测试代码如下:
<map id="map" latitude="{{lat}}" longitude="{{lng}}" markers='{{markers}}' bindregionchange="moveMap" show-location> <cover-view class="text">{{lat}}***{{lng}}</cover-view></map> |
let mapCtx=null;Page({ data: { lat: 0, lng: 0, markers:[] }, onLoad: function (options) { let that = this; wx.getLocation({ success: function (res) { that.setData({ lat: res.latitude, lng: res.longitude, markers: [{ id: 0, title: '000', latitude: res.latitude, longitude: res.longitude }] }); }, }); }, onReady: function () { mapCtx=wx.createMapContext('map', this); }, moveMap(e){ console.log(e) let that=this; if(e.type==='end'){ let markers=that.data.markers; mapCtx.getCenterLocation({ success(res) { console.log(res) markers.push({ id: 1, title: '111', latitude: res.latitude, longitude: res.longitude }) that.setData({ lat: res.latitude, lng: res.longitude, markers: markers }); console.log(that.data.markers) } }) } }}) |
以上逻辑代码中,我将用户中心点作为markers标记点,移动地图后重新获取用户中心点并赋值中心点坐标和markers标记点,但是show-location坐标点并没有跟着产生变化
效果如下:
