使用小程序<map>,更改图标,点击图标实现图标变大效果,不规律出现原本图标和点击变大的图标重叠情况
发布于 7 年前 作者 ishen 1911 次浏览 来自 官方Issues

https://developers.weixin.qq.com/miniprogram/dev/component/map.html

// 地图模式获取中心点

regionchange(e) {

// 地图发生变化的时候,获取中间点,也就是用户选择的位置toFixed

if (e.type == 'end' && (e.causedBy == 'scale' || e.causedBy == 'drag')) {

var that = this;

this.mapCtx = wx.createMapContext("map4select");

this.mapCtx.getCenterLocation({

type: 'gcj02',

success: function (res) {

let { centerLon, centerLat } = that.data;

if(centerLon==res.longitude&&centerLat==res.longitude)return;

let {markers} = that.data;

markers[0] = {

id: 'center',

latitude: res.latitude - 0,

longitude: res.longitude - 0,

iconPath: "/assets/images/home/pot.png",

width: 26,

height: 32,

zIndex: 999

}

that.setData({

centerLon:res.longitude,

centerLat:res.latitude,

markers,

mapTask:{}

})

// setTimeout(()=>{

// that.setData({

// mapTask:{}

// })

// that.mapModelTaskList(res.latitude - 0,res.longitude - 0)

// },1500)

}

})

}

},

点击图标变大效果

markers.forEach((item) => {

// item.zIndex = taskIndex;

item.iconPath = "";

if (item.id == taskIndex) {

item.zIndex = 0;

item.width = 80;

item.height = 56;

item.iconPath = "/assets/images/home/pot-q.png"

//assets/images/home/pot-q.png

// item.iconPath = "/assets/images/home/select.png"

} else if (item.id != 'center') {

// item.zIndex = taskIndex;

item.width = 50;

item.height = 35;

item.iconPath = "/assets/images/home/pot-q.png"

// item.iconPath = "/assets/images/home/pot.png"

}

})

1 回复

请具体描述问题出现的流程,并提供能复现问题的简单代码片段https://developers.weixin.qq.com/miniprogram/dev/devtools/minicode.html

用出现问题的手机扫码提供下扫码结果截图

回到顶部