includePoints在页面中使用正常,在组件中使用无效,success和fail也没有触发(页面里面有触发)
wxml:<map id="map" style="width:100%;height:100%;position:fixed;top: 0;left: 0;right: 0;bottom: 0;" longitude="{{longitude}}" latitude="{{latitude}}"></map>
js:let mapC = wx.createMapContext('map');
console.log('======', mapC)
mapC.includePoints({
points: [{
"latitude": 30.259433598978386,
"longitude": 120.0117004409193
}, {
"latitude": 30.257973471323258,
"longitude": 120.0117003182772
}
padding: [10, 10, 10, 10], // 设置视野边距
success: (res) => {
console.log('res', res)
},
fail: (err) => {
console.log('err', err)
}
组件中创建需要加一个this,
let mapC = wx.createMapContext('map', this);
在组件的
ready
生命周期函数中调用includePoints
方法,确保组件已经渲染完成。代码片段:https://developers.weixin.qq.com/s/eW2OENmi7WXQ