interface makersInf {
userIdentity: string,
marker: any
}
class MapUtl {
static makerList: makersInf[] = [];
static amap: any = null;
static loadMap: any = null;
static wecherInfo: any = null;
static addMaker(data: any) {
const { lng, lat, title, users } = data;
// if (MapUtl.loadMap === null) return;
const marker = new MapUtl.loadMap.Marker({
position: new MapUtl.loadMap.LngLat(lng, lat),
title: title,
});
var content = [
"
姓名 :" + users?.user_name + "",
"职位 : " + users.pos_held,
"电话 : " + users.tel,
"
",
];
var infoWindow = new MapUtl.loadMap.InfoWindow({
offset: new MapUtl.loadMap.Pixel(0, -30),
autoMove: true,
content: content.join("
"),
});
marker.on("click", (e) => {
infoWindow.open(MapUtl.amap, e.target.getPosition());
});
MapUtl.amap?.add(marker);
// 将maker添加到数组
MapUtl.makerList.push({
userIdentity: users.identity,
marker: marker
})
}
static addMakerDis(data: any) {
const { lng, lat, title } = data;
const marker = new MapUtl.loadMap.Marker({
position: new MapUtl.loadMap.LngLat(lng, lat),
icon: new MapUtl.loadMap.Icon({
image:
"https://img20.360buyimg.com/n1/jfs/t1/98676/8/28819/96905/62e1e96eE69561497/0e201e39d6d1c1e3.png",
imageSize: [30, 30],
}),
title: title,
});
var content = [
"站点名称 :" + title + "",
// "职位 : " + users.pos_held,
// "电话 : " + users.tel,
"
",
];
var infoWindow = new MapUtl.loadMap.InfoWindow({
offset: new MapUtl.loadMap.Pixel(0, -30),
autoMove: true,
content: content.join("
"),
});
marker.on("click", (e) => {
infoWindow.open(MapUtl.amap, e.target.getPosition());
});
MapUtl.amap?.add(marker);
}
static setMakericon = (maker) => {
maker.setPosition([103.55, 30.342]);
var m = MapUtl.amap;
var newIcon = new m.Icon({
image: "//a.amap.com/jsapi_demos/static/demo-center/icons/dir-marker.png", //Icon 的图像
size: new m.Size(25, 34), // 图标大小
anchor: new m.Pixel(12, 32), // 图标锚点
});
maker.setIcon(newIcon);
}
static polyline = (lineArr) => {
var marker = new MapUtl.loadMap.Marker({
map: MapUtl.amap,
position: [116.478935, 39.997761],
icon: "https://a.amap.com/jsapi_demos/static/demo-center-v2/car.png",
offset: new MapUtl.loadMap.Pixel(-13, -26),
});
new MapUtl.loadMap.Polyline({
map: MapUtl.amap,
path: lineArr,
showDir: true,
strokeColor: "#28F", //线颜色
strokeWeight: 6, //线宽
});
var passedPolyline = new MapUtl.loadMap.Polyline({
map: MapUtl.amap,
strokeColor: "#AF5", //线颜色
strokeWeight: 6, //线宽
});
marker.on('moving', function (e) {
passedPolyline.setPath(e.passedPath);
MapUtl.amap.setCenter(e.target.getPosition(), true)
});
MapUtl.amap.setFitView();
marker.moveAlong(lineArr, {
duration: 500,//可根据实际采集时间间隔设置
autoRotation: true,
});
}
static getWecher() {
}
// 百度转高德
static bdConvertGd(coordinate) {
var bd_lng = coordinate[0];
var bd_lat = coordinate[1];
var pi = 3.14159265358979324 * 3000.0 / 180.0;
var x = bd_lng - 0.0065;
var y = bd_lat - 0.006;
var z = Math.sqrt(x * x + y * y) - 0.00002 * Math.sin(y * pi);
var theta = Math.atan2(y, x) - 0.000003 * Math.cos(x * pi);
var gd_lng = z * Math.cos(theta);
var gd_lat = z * Math.sin(theta);
return [gd_lng, gd_lat];
}
}
export default MapUtl;