设备序号: ' + item.devSn + "
"); - info.push('车辆/人员名称: ' + item.numberPlate + "
"); - info.push('最后更新时间: ' + item.updateTime + "
"); - info.push('位置: ' + address + "
"); - var infoWindow = new AMap.InfoWindow({ - offset: new AMap.Pixel(10, -30), - content: info.join("") //使用默认信息窗体框样式,显示信息内容 - }); - infoWindow.open(map, e.target.getPosition()); - } - // 绘制轨迹 let polyline = new AMap.Polyline({ map: map, @@ -929,11 +880,57 @@ function trackMapInit(path: any, item: any) { // strokeStyle: "solid" //线样式 }); - marker.on("moving", function (e) { - console.log("播放",e) - passedPolyline.setPath(e.passedPath); + function createMarkerAndInfoWindow() { + marker = new AMap.Marker({ + map: map, + position: path[0], + icon: "https://webapi.amap.com/images/car.png", + offset: new AMap.Pixel(-26, -13), + autoRotation: true, + angle: -90 + }); + marker.on("click", markerClick); + marker.emit("click", { target: marker }); + marker.on("moving", function (e) { + passedPolyline.setPath(e.passedPath); + }); + } + + // 使用逆地理编码获取地址信息 + let address = "未知"; + AMap.plugin("AMap.Geocoder", function () { + let geocoder = new AMap.Geocoder(); + + geocoder.getAddress(path[0], function (status, result) { + if (status === "complete" && result.info === "OK") { + address = result.regeocode.formattedAddress; // 获取中文地址名称 + console.log("位置", address); + createMarkerAndInfoWindow(); + } else { + console.log("获取地址信息失败"); + createMarkerAndInfoWindow(); + } + }); }); + function markerClick(e) { + let lnglat = e.target.getPosition(); + + //构建信息窗体中显示的内容 + console.log(e); + let info = []; + + info.push('设备序号: ' + item.devSn + "
"); + info.push('车辆/人员名称: ' + item.numberPlate + "
"); + info.push('最后更新时间: ' + item.updateTime + "
"); + info.push('位置: ' + address + "
"); + var infoWindow = new AMap.InfoWindow({ + offset: new AMap.Pixel(10, -30), + content: info.join("") //使用默认信息窗体框样式,显示信息内容 + }); + infoWindow.open(map, e.target.getPosition()); + } + map.setFitView(); } function startAnimation() { diff --git a/src/views/sevenLargeScreen/headNoise/leftCenter.vue b/src/views/sevenLargeScreen/headNoise/leftCenter.vue index 45b536b..5c87be4 100644 --- a/src/views/sevenLargeScreen/headNoise/leftCenter.vue +++ b/src/views/sevenLargeScreen/headNoise/leftCenter.vue @@ -11,13 +11,13 @@