【紧急】小程序地图组件Markers的label属性不展示
发布于 4 年前 作者 leiyuan 2809 次浏览 来自 问答

功能如图:

问题:

使用小程序map组件中的markers

markers有label属性用来处理Marker旁边的白框

但是!同一数据白框的展示在开发者工具是正常的,在真机就有时候展示有时候不展示

代码:

initMarkerData(){
   let _this = this;
   let markerList = [];
   for (let i in _this.data.listData){
       let poiInfo = _this.data.listData[i];
       let singleMarker = {};
       let labelInfo = {};
       singleMarker['iconPath'] = "../../image/oilCallout.png";
       singleMarker['width'] = 40;
       singleMarker['height'] = 40;
       singleMarker['id'] = poiInfo.id;
       singleMarker['latitude'] = poiInfo.placeLatitude;
       singleMarker['longitude'] = poiInfo.placeLongitude;
       singleMarker['label'] = {};
       singleMarker['label']['content'] = poiInfo.placeName + '\n' + poiInfo.placeAddress;
       singleMarker['label']['x'] = 20;
       singleMarker['label']['y'] = -40;
       singleMarker['label']['padding'] = 3;
       singleMarker['label']['bgColor'] = '#ffffff';
       singleMarker['label']['borderRadius'] = 5;
       markerList.push(singleMarker);
       
   }
   return markerList;
},
onLoad() {//页面加载时
   let _this = this;
   //初次进入页面获取到我的位置,方便设置map
   wx.getLocation({//获取当前的地理位置、速度
       type: 'wgs84', //返回可以用于wx.openLocation的经纬度
       success: res => {
           _this.setData({
               markers: _this.initMarkerData(),//请求后端获取所有markers
               longitude: res.longitude,
               latitude: res.latitude,
               scale: 8 //首次地图比例改这里
           })
       }
   });
},

bug:

回到顶部