<map
id="map"
style="flex: 1"
:latitude="latitude"
:longitude="longitude"
:scale="zoom"
show-location
@markertap="onClickMarker">
</map>
onClickMarker(e) {
console.log("onClickMarker"+e)
},
createMapContext() {
// 创建地图对象
this.map = uni.createMapContext("map", this);
let _this = this
// 仅调用初始化,才会触发 on.("markerClusterCreate", (e) => {})
this.map.initMarkerCluster({ // 初始化点聚合的配置
enableDefaultStyle: false, // 是否使用默认样式
zoomOnClick: true,
gridSize: 60,
complete(res) {
console.log('initMarkerCluster', res)
}
})
this.map.on("markerClusterCreate", (e) => {
console.log("markerClusterCreate", e);
})
this.getVehiclesPosition()
},
getVehiclesPosition(i) {
postReq("getVehiclesPosition", {vehicleName: this.vehicleName}).then(res=> {
console.log(res)
if(res.result){
let data = res.data
if(data.length>0){
data.forEach((item,index)=>{
if(item.lat&&item.lng){
let lnglat = transformFromWGSToGCJ(item.lat-0, item.lng-0)
if(item.onlineStatus == 1) {
this.covers.push({
id: index+1,
latitude: lnglat.latitude,
longitude: lnglat.longitude,
iconPath: '../../static/img/index/cc.png',
width: 30,
height: 26,
joinCluster: true,
callout: {
content: item.vehicleName,
color: "rgba(255,255,255,1)",
fontSize: 10,
borderRadius: 10,
bgColor: "rgba(2,167,240,1)",
padding: 5,
display: "ALWAYS"
}
})
}else{
// 'code_'+item.code
this.covers.push({
id: index+1,
latitude: lnglat.latitude,
longitude: lnglat.longitude,
iconPath: '../../static/img/index/cc1.png',
width: 30,
height: 26,
joinCluster: true,
callout: {
content: item.vehicleName,
color: "rgba(0,0,0,1)",
fontSize: 10,
borderRadius: 10,
bgColor: "rgba(204,204,204,1)",
padding: 5,
display: "ALWAYS"
}
})
}
}
})
let markers = JSON.parse(JSON.stringify(this.covers))
this.map.addMarkers({
markers,
clear: false, // 是否先清空地图上所有marker
})
}
}else{
uni.hideLoading()
uni.showToast({
title: res.msg,
icon: 'none'
})
}
}).catch(err=>{
uni.hideLoading()
uni.showToast({
title: err.msg,
icon: 'none'
})
})
}
1 个回复
9***@qq.com (作者) - hello worid
已找到问题,记录一下:
1、markerId IOS上需是数字
2、ios上 e.detail.markerId取不到, JSON.stringify(e.detail.markerId)能取到