jiazx0107@163.com
2023-05-17 620eab6cca2bc9ef9ea6d3067a0a5ba1deadbd1c
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
var map = new BMapGL.Map("container");
//默认经纬度 - 风正致远股份坐标
var lon = 113.548794,lat = 34.797358;
var pl;
//生成坐标点的数组
var point = [];
$(function() {
    layui.use([ 'layer', 'laydate', 'form' ], function() {
        layer = layui.layer;
    });
 
    setPoint();
});
 
//设置点
function setPoint() {
    if(listPatrol.length == 0){
        layer.msg("暂未查到巡更记录信息!");
        firstSetCenter();
        return;
    }
 
    map.centerAndZoom(new BMapGL.Point(listPatrol[0].longitude,listPatrol[0].latitude), 17);
    map.enableScrollWheelZoom(true);     // 开启鼠标滚轮缩放
    var scaleCtrl = new BMapGL.ScaleControl();  // 添加比例尺控件
    map.addControl(scaleCtrl);
    var zoomCtrl = new BMapGL.ZoomControl();  // 添加比例尺控件
    map.addControl(zoomCtrl);
 
    for (var i = 0; i < listPatrol.length; i++) {
        point.push(new BMapGL.Point(listPatrol[i].longitude, listPatrol[i].latitude));
    }
 
    pl = new BMapGL.Polyline(point, {
        strokeColor: "#e31411",
        strokeWeight: 4,
        strokeOpacity: 1
    });
 
    //画轨迹线
    toLine();
}
 
//画轨迹线
function toLine () {
    var second = (point.length-1)*2000; //设置时间
    trackAni = new BMapGLLib.TrackAnimation(map, pl, {
        overallView: true,
        tilt: 30,
        duration: second,  //设置轨迹线的时间段
        delay: 300
    });
    trackAni.start();
 
    //显示点图标及标注
    showLabel();
}
 
//默认定位
function firstSetCenter() {
    if(curDept && curDept.lon && curDept.lat){
        lon = curDept.lon;
        lat = curDept.lat;
    }
 
    //适应地图大小,设置地图中心点坐标及地图级别
    var defaultPoint = {longitude:lon,latitude:lat};
 
    map.centerAndZoom(new BMapGL.Point(defaultPoint.longitude, defaultPoint.latitude), 12);
    map.enableScrollWheelZoom(true); //开启鼠标滚轮缩放
    var scaleCtrl = new BMapGL.ScaleControl();  // 添加比例尺控件
    map.addControl(scaleCtrl);
    var zoomCtrl = new BMapGL.ZoomControl();  // 添加比例尺控件
    map.addControl(zoomCtrl);
}
//显示坐标标注信息
function showLabel() {
    //设置标注偏移量
    var offset = new BMapGL.Size(10, -30);
 
    //配置图标
    var icon = new BMapGL.Icon("../../static/images/icon_gcoding.png", new BMapGL.Size(25, 45));
 
    //显示点图标及标注时间
    for (var i = 0; i < point.length; i++) {
        //添加点的并显示
        var marker = new BMapGL.Marker(point[i], {
            icon: icon
        });
        map.addOverlay(marker);
 
        //添加对应点id
        marker.patrol = {id: listPatrol[i].id, dayTime:dateFormatStr(listPatrol[i].createTime)};
        marker.addEventListener("click", showImg);
 
        //添加文本标注,并显示
        var opts = {
            position : point[i],
            offset : offset
        };
 
        var label = new BMapGL.Label(dateFormatStr(listPatrol[i].createTime), opts);
        label.setStyle({
            color : "black",
            "border" : "5px solid #e2e2e4",
            "border-radius" : "10px",
            "background" : "white",
            fontSize : "18px",
            lineHeight : "25px",
            fontFamily : "微软雅黑"
        });
        map.addOverlay(label);
    }
 
    setZoom(listPatrol);
}
 
//展示图片
function showImg(e) {
 
    var id= e.target.patrol.id;
    var dayTime= e.target.patrol.dayTime;
    // console.log(id);
 
    layer.msg("开始打开图片……");
 
    $.ajax({
        type: "GET",
        cache: false,
        url: "../../basic/security/patrol-img?id=" +id,
        dataType: "json",
        contentType: "application/json;charset=UTF-8",
        success: function (result) {
            if(result){
                $("#imgPath").attr("src", result.base64Img);
                layer.open({
                    type : 1,
                    title :  dayTime + "打卡记录照片",
                    area : [ '500px', '700px' ],
                    content : $('#imgRecord'),
                    closeBtn: 2
                });
            }else {
                layer.msg("无照片记录");
            }
        },
        error: function (result) {
            layer.msg("无照片记录")
        }
    });
}
 
//根据经纬极值计算绽放级别
function setZoom(points) {
    if (points.length > 0) {
        var maxLng = points[0].longitude;
        var minLng = points[0].longitude;
        var maxLat = points[0].latitude;
        var minLat = points[0].latitude;
        var res;
        for (var i = points.length - 1; i >= 0; i--) {
            res = points[i];
            if (res.longitude > maxLng) maxLng = res.longitude;
            if (res.longitude < minLng) minLng = res.longitude;
            if (res.latitude > maxLat) maxLat = res.latitude;
            if (res.latitude < minLat) minLat = res.latitude;
        }
        var cenLng = (parseFloat(maxLng) + parseFloat(minLng)) / 2;
        var cenLat = (parseFloat(maxLat) + parseFloat(minLat)) / 2;
        var zoom = getZoom(maxLng, minLng, maxLat, minLat);
        map.centerAndZoom(new BMapGL.Point(cenLng, cenLat), zoom);
    } else {
        //没有坐标,显示全中国
        map.centerAndZoom(new BMapGL.Point(103.388611, 35.563611), 5);
    }
}
 
//根据经纬极值计算绽放级别
function getZoom(maxLng, minLng, maxLat, minLat) {
    var zoom = ["50", "100", "200", "500", "1000", "2000", "5000", "10000", "20000", "25000", "50000", "100000", "200000", "500000", "1000000", "2000000"]; // 级别18到3。
    var pointA = new BMapGL.Point(maxLng, maxLat); // 创建点坐标A
    var pointB = new BMapGL.Point(minLng, minLat); // 创建点坐标B
    var distance = map.getDistance(pointA, pointB).toFixed(1); //获取两点距离,保留小数点后两位
    for (var i = 0, zoomLen = zoom.length; i < zoomLen; i++) {
        if (zoom[i] - distance > 0) {
            return 18 - i + 3; //之所以会多3,是因为地图范围常常是比例尺距离的10倍以上。所以级别会增加3。
        }
    }
}
//格式化时间
function dateFormatStr(time) {
    if(time){
        var d = new Date(time);
        return dateFtt("hh:mm:ss",d);
    }
    return "";
}
 
//单机放大图片
function newWindow() {
    var img = new Image();
    img.src = $("#imgPath")[0].src;
 
    var newWin = window.open("", '_blank');
    newWin.document.write(img.outerHTML);
    newWin.document.title = "照片记录";
    newWin.document.close();
}