index.vue
4.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
<template>
<div id="mapContainer" class="map-container"></div>
</template>
<script>
import { CONSTANT } from "@/amap/map";
import mapService from "@/amap/mapService";
import AMapLoader from "@amap/amap-jsapi-loader";
import "@/assets/spritesmith-generated/sprite.css";
import "@/assets/styles/monitor.scss";
/**
* address: gps地址
* bsAddress:基站地址
* bsLat,bsLng:基站经纬度
* gpsLat,gpsLng:gps经纬度
* name:车主姓名
* standNo:车架号
* time:定位时间
*/
export default {
name: "MapLocation",
props: {
info: {
type: Object,
default: function () {
return {
// activeDate: "2022-02-22 17:57:23",
// address: "广东省深圳市南山区科技园",
// bsAddress: "广东省深圳市南山区科技园",
// bsLat: "22.551794",
// bsLng: "113.941085",
// bsTime: null,
// deviceType: null,
// deviceTypeStr: null,
// elat: "22.550615",
// elng: "113.938668",
// finalBsTime: null,
// finalGpsTime: null,
// gpsLat: "22.550615",
// gpsLng: "113.938668",
// lastBsAddress: "",
// lastGpsAddress: "广东省深圳市南山区科技园",
// lastPoiAddress: "广东省深圳市南山区科技园",
// lastPoiTime: "2018-10-15 16:14:11",
// lat: "22.550615",
// lng: "113.938668",
// name: "仲利测试1",
// ownerName: "仲利测试1",
// poiType: "GPS",
// shopName: "仲利国际租赁有限公司",
// sn: "7140626339",
// source: null,
// sourceStr: null,
// standNo: "LGBF5AE08FR305952",
// time: '2022-02-22 17:57:23',
// type: 2,
// vin: "LGBF5AE08FR305952",
// workOrderNo: "481985751282679808",
};
},
},
},
data() {
return {
mapObj: "",
};
},
mounted() {
console.log(mapService);
this.initMap();
},
methods: {
// 初始化地图
initMap() {
let _this = this;
if (window.AMap) {
_this.init(window.AMap);
return false;
}
AMapLoader.reset();
AMapLoader.load({
key: CONSTANT.MAP_KEY, // 申请好的Web端开发者Key,首次调用 load 时必填
version: "1.4.2", // 指定要加载的 JSAPI 的版本,缺省时默认为 1.4.15
plugins: CONSTANT.MAP_PLUGINS, // 需要使用的的插件列表,如比例尺'AMap.Scale'等
}).then((AMap) => {
_this.init(AMap);
// let _amap = new AMap.Map("mapContainer", {
// //设置地图容器id
// viewMode: "3D", //是否为3D地图模式
// });
// _amap.on("complete", function () {
// console.log(_this.info);
// if (_this.info && (_this.info.bsLng || _this.info.gpsLng)) {
// _this.drawMaker();
// }
// });
// _this.mapObj = _amap;
});
},
// 初始化方法
init(AMap) {
let _this = this;
let _amap = new AMap.Map("mapContainer", {
//设置地图容器id
viewMode: "3D", //是否为3D地图模式
});
_amap.on("complete", function () {
console.log(_this.info);
if (_this.info && (_this.info.bsLng || _this.info.gpsLng)) {
_this.drawMaker();
}
});
_this.mapObj = _amap;
},
// 激活位置
drawMaker() {
let data = this.info;
const MAP = this.mapObj;
const marker = mapService.createCarMarker(
[
parseFloat(data.lng || data.bsLng),
parseFloat(data.lat || data.bsLat),
],
MAP
);
const infoWindow = mapService.bindActiveLocationInfoWindow(
marker,
MAP,
data,
true
);
// 设置图标
mapService.setDefaultIcon(marker, data.vehicleIcon);
//if (autoOpenLastInfoWindow) {
// /EventBus.$emit("uiMap.monitor.openInfoWindow");
mapService.openActiveInfoWindow(MAP, marker, infoWindow);
//}
//EventBus.$emit("uiMap.monitor.drawDone");
},
},
};
</script>
<style lang="scss" scoped>
p {
margin: 0;
padding: 0;
}
.map-container {
width: 100%;
min-width: 600px;
height: 400px;
font-size: 13px;
}
</style>