前言
最近公司有个项目需要用到小程序的map组件,要实现一个类似摩拜红包车的信息弹框,简单说就是在map组件上添加自定义view。
摩拜红包车
代码实现
.wxml
<map id="map" longitude="{{point.longitude}}" latitude="{{point.latitude}}"
markers="{{markers}}" scale="{{mapScale}}" show-location bindregionchange="regionchange"
bindmarkertap="markertap" controls="{{controls}}" bindcontroltap="controltap"
style="width: {{mapWidth}}; height: {{mapHeight}};top: {{mapTop}}">
<cover-view class="place_info">
<cover-view class="place_info_parking">cover-view</cover-view>
<cover-view class="place_info_surplus">可覆盖在原生组件的组件</cover-view>
<cover-view class="place_info_order">66666</cover-view>
</cover-view>
</map>
.wxss
.place_info {
position: relative;
width: 90%;
margin-left: 20rpx;
margin-top: 10rpx;
border-radius: 5rpx;
background: white;
padding: 10rpx;
}
.place_info_parking{
font-size: 50rpx
}
.place_info_surplus{
color: #999999
}
.place_info_order{
margin-top: 10rpx;
margin-bottom: 10rpx;
margin-left: 20rpx;
background-color: #ff5722;
color: #FFFFFF;
padding: 10rpx;
width: 90%;
border-radius: 5rpx;
text-align: center;
}
效果图