小程序自定义气泡

            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
                }
    },

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值