async getParksClone(longitude, latitude) {
let that = this
let markarr = []
const {
data: res
} = await request.http('/park/info/getParkList', 'GET')
console.log(res);
if (res.code === 200) {
let parkList = res.data;
// res.data.forEach(function(value,index,array){
// console.log(value,index);
// })
parkList.forEach(i => {
console.log(i.id);
let redIcon = 'https://mis.lmtc.zmzncs.com/file/WeChat/index-red-lucency-icon.png'
let yellowIcon = 'https://mis.lmtc.zmzncs.com/file/WeChat/index-yellow-lucency-icon.png'
let greenIcon = 'https://mis.lmtc.zmzncs.com/file/WeChat/index-green-lucency-icon.png'
let iconPath = i.emptyParkSpace <= 0 ? redIcon : i.emptyParkSpace <= 50 ? yellowIcon : greenIcon
let bjColor = i.emptyParkSpace <= 0 ? '#FE0D0D' : i.emptyParkSpace <= 50 ? '#FFCF1B' : '#3AC7A1'
let emptyParkSpace = i.emptyParkSpace <= 0 ? 0 :i.emptyParkSpace
let anchorX = emptyParkSpace < 10 ? '0rpx' : emptyParkSpace >= 10 && emptyParkSpace < 100 ? '-10rpx' : emptyParkSpace >= 100 ? '-20rpx':'-20rpx'
let markObj = {
id: Number(i.id),
latitude: i.latitude,
longitude: i.longitude,
iconPath,
width: '59rpx',
height: '69rpx',
// 这个zIndex一定要有,并且不能是一个固定值,否则会出现标记点和label,callout层级混乱
zIndex: Number(i.totalParkSpace) + 1
}
// 单独定义callout
let callout = {
// 动态数字展示
content: JSON.stringify(emptyParkSpace),
// textAlign:'center',
// 动态数字颜色
color: '#fff',
fontSize: '22rpx',
// callout在手机上显示默认有一个箭头背景,在此bgColor设置成透明色
bgColor: bjColor,
// 数字定位,放在中间
anchorX: '0rpx',
anchorY: '30rpx',
// 数字常显示
display: 'ALWAYS'
}
// 单独定义label
let label = {
// 动态数字展示
content: emptyParkSpace,
// textAlign:'center',
// 动态数字颜色
color: '#fff',
fontSize: '22rpx',
bgColor: bjColor,
borderRadius: '10',
// 数字定位,放在中间
anchorX: anchorX,
anchorY: '-40rpx'
}
// 获取当前手机型号
uni.getSystemInfo({
success(res) {
// res.platform - 客户端平台,值域为:ios、android、mac(3.1.10+)、windows(3.1.10+)、linux(3.1.10+)
// 苹果手机的数字使用callout,安卓的数字使用label
if (res.platform == 'ios') {
markObj.callout = callout
} else {
markObj.label = label
}
}
})
markarr.push(markObj)
// 车主位置marker
let myMarker = this.getMarker(0, longitude, latitude,
'https://mis.lmtc.zmzncs.com/file/WeChat/location.png', 26, 34);
markarr.unshift(myMarker); // 数组头部插入
})
that.markers = markarr
that.parkList = parkList
}
},
小程序自定义气泡
最新推荐文章于 2025-04-07 20:17:43 发布