index.vue
6.86 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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
<template>
<div>
<div id="mapContainer" class="map-container"></div>
</div>
</template>
<script>
// import mapService from "@/amap/mapService";
import "@/assets/spritesmith-generated/sprite.css";
import "@/assets/styles/monitor.scss";
import GLMapSdk from "@/utils/glsk-mapapi-sdk";
/**
* address: gps地址
* bsAddress:基站地址
* bsLat,bsLng:基站经纬度
* gpsLat,gpsLng:gps经纬度
* name:车主姓名
* standNo:车架号
* time:定位时间
*/
export default {
name: "MapLocation",
props: {
info: {
type: Object,
default: function () {
return {
};
},
},
},
data() {
return {
mapObj: "",
zoom: 12,
};
},
mounted() {
this.initMap();
console.log('地图');
},
methods: {
async initMap() {
// console.log(GLMapSdk);
try {
// new GLMapSdk(async (mapapi) => {
console.log(this.mapapi, 'mapapi');
const mapapi = this.mapapi
const map = await mapapi.invoke("Map", "mapContainer");
const { lng, lat } = this.info;
mapapi.invoke("centerAndZoom", mapapi.invoke("Point", lng, lat), this.zoom);
mapapi.invoke('NavigationControl')
// mapapi.invoke('enableScrollWheelZoom')
this.drawMaker(mapapi, map);
// })
} catch (error) {
console.log(error);
}
},
// 激活位置
drawMaker(mapapi, map) {
let data = this.info;
const lng = parseFloat(data.lng || data.bsLng);
const lat = parseFloat(data.lat || data.bsLat);
var marker = mapapi.invoke("Marker", mapapi.invoke("Point", lng, lat), {
icon: mapapi.invoke(
"Icon",
require("@/assets/images/icon_car.png"),
mapapi.invoke("Size", 60, 60),
{
anchor: mapapi.invoke("Size", 10, 15),
infoWindowAnchor: mapapi.invoke("Size", 10, 0),
}
),
});
this.bindActiveLocationInfoWindow(marker, map, data);
mapapi.invoke("addOverlay", marker);
},
// 创建位置点弹框
createActiveInfo(info) {
let msg = "报警";
// 激活
if (info.type == 1) {
msg = "激活";
}
// 定位
if (info.type == 2) {
msg = "定位";
}
let _html = `<h3 class="map-infowindow-title">${info.name}/${info.standNo}</h3>
<div class="map-infowindow-ct">
<p><i class="icon icon-info_device"></i> 设备号: <span class="des">${
info.sn
} (${info.source == 1 ? "有线" : "无线"})</span></p>`;
// 是否包含断电、光感报警
if (info.alarmTypeSet && info.alarmTypeSet.length > 0) {
let tg = "";
let cHmtl = "";
let typeList = {
1: "断电",
99: "光感",
};
info.alarmTypeSet.forEach((alarmType) => {
tg += `<a class="btn_danger">${typeList[alarmType]}</a>`;
});
cHmtl =
'<p><i class="icon icon-info_device_alarm"></i><span>报警状态:</span>' +
tg +
"</p>";
_html += cHmtl;
}
_html += `<p><i class="icon icon-info_time"></i>${msg}时间: <span class="des"data-time>${
info.time
}</span></p>
<p style="display:${
info.bsLng ? "flex" : "none"
}"><i class="icon icon-info_type"></i>定位类型: <a class="locate-btn active" id="locateTypeGps">GPS</a><a class="locate-btn" id="locateTypeBase">基站</a></p>
<p class="long_p"><i class="icon icon-info_location"></i><span>${msg}地址:</span><span class="des" data-transferAddress>${
info.address
}</span></p>
</div>`;
return _html;
},
// 位置点弹框
bindActiveLocationInfoWindow(marker, map, info) {
var self = this;
var infoDiv = document.createElement("div");
infoDiv.innerHTML = self.createActiveInfo(info);
// gps位置信息
function fillGPS() {
infoDiv.querySelector("[data-time]").textContent = info.time;
infoDiv.querySelector("[data-transferAddress]").textContent = info.address;
infoDiv.querySelector("#locateTypeGps").classList.add("active");
infoDiv.querySelector("#locateTypeBase").classList.remove("active");
marker.setPosition(self.mapapi.invoke("Point", info.lng, info.lat));
// map.openInfoWindow(marker.infoWindow, marker.getPosition());
self.mapapi.invoke("mapOpenInfoWindow", marker.infoWindow, self.mapapi.invoke('markerGetPosition'));
}
// 基站位置信息
function fillBase() {
infoDiv.querySelector("[data-time]").textContent = info.bsTime;
infoDiv.querySelector("[data-transferAddress]").textContent = info.bsAddress;
infoDiv.querySelector("#locateTypeGps").classList.remove("active");
infoDiv.querySelector("#locateTypeBase").classList.add("active");
console.log(self.mapapi.invoke("Point", info.bsLng, info.bsLat), "基站点位置", map);
marker.setPosition(self.mapapi.invoke("Point", info.bsLng, info.bsLat));
// map.openInfoWindow(marker.infoWindow, marker.getPosition());
self.mapapi.invoke("mapOpenInfoWindow", marker.infoWindow, self.mapapi.invoke('markerGetPosition'));
}
infoDiv.querySelector("#locateTypeGps").onclick = function (e) {
fillGPS();
};
infoDiv.querySelector("#locateTypeBase").onclick = function (e) {
fillBase();
};
if (info.lng) {
fillGPS();
}
if (!info.lng && info.bsLng) {
fillBase();
}
return this.createActiveInfoWindow(marker, map, infoDiv);
},
// 创建位置点弹框
createActiveInfoWindow(marker, map, div, isInfoOpen, isInfoAutoMove) {
const { mapapi } = this;
let opts = {
width: 150, // 信息窗口宽度
// height: 170, // 信息窗口高度
};
let infoWindow = mapapi.invoke("InfoWindow", div, opts);
marker.infoWindow = infoWindow;
// map.openInfoWindow(infoWindow, marker.getPosition());
mapapi.invoke("mapOpenInfoWindow", infoWindow, mapapi.invoke('markerGetPosition'));
//给Marker绑定单击事件
// marker.addEventListener("click", markerClick);
mapapi.invoke("markerAddEventListener", 'click', markerClick)
function markerClick(e) {
// map.openInfoWindow(infoWindow, marker.getPosition());
mapapi.invoke("mapOpenInfoWindow", infoWindow, mapapi.invoke('markerGetPosition'));
}
return infoWindow;
},
// 打开激活位置点弹框
openActiveInfoWindow(map, makers, infoWindow) {
const MAP = map;
const lnglat = makers.getPosition();
infoWindow.open(MAP, lnglat);
MAP.setZoomAndCenter(MAP.getZoom(), lnglat);
},
},
};
</script>
<style lang="scss" scoped>
p {
margin: 0;
padding: 0;
}
.map-container {
width: 100%;
min-width: 600px;
height: 400px;
font-size: 13px;
}
</style>