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
//默认公司位置置--113.550545,34.798932
var locations = [{longitude:"113.550545",latitude:"34.798932",name:"某演示粮库"}];
var tsn = locationArray;
//定义标记点数组
var markers = Array();
//定义点数组
var points = Array();
//定义下标数组
var indexs = Array();
//创建标记文本标注数组
var labels = Array();
var map = new BMapGL.Map("container");
var timer;
var layer;
 
$(function() {
    layui.use([ 'layer', 'laydate', 'form' ], function() {
        layer = layui.layer;
    });
 
    //旋转动画
    rotate();
 
    //初次定位到库区位置
    setTimeout('firstSetCenter(locations)', 6000);
 
    //再定位到设备位置
    setTimeout('setCenterAndLocation(tsn)', 13000);
 
    //定时请求位置信息并实时定位
    timing();
});
 
//定位库区位置
function firstSetCenter(data) {
    //适应地图大小,设置地图中心点坐标及地图级别
    var defaultPoint = data[0];
    map.centerAndZoom(new BMapGL.Point(defaultPoint.longitude, defaultPoint.latitude), 18);
 
    //标记位置
    markPosition(data);
    //位置信息显示
    showInfo(data);
}
 
//定位设备位置
function setCenterAndLocation(data) {
    if(data.length==0){
        layer.alert("暂无设备位置信息!");
        return;
    }
    //适应地图大小,设置地图中心点坐标及地图级别
    var defaultPoint = data[0];
    map.centerAndZoom(new BMapGL.Point(defaultPoint.longitude, defaultPoint.latitude), 14);
    markPosition(data);
    showInfo(data);
}
 
//定时每5分钟定时请求位置
function timing() {
    timer = setInterval(function() {
        changeMarkerPosition();
    }, 300000);
}
 
//请求后台获取最新位置信息
function getCurrentLocation() {
    $.ajax({
        type : "POST",
        url : "../../basic/oa/quaryLocation",
        contentType : "application/json;charset=UTF-8",
        success : function(data) {
            tsn = null;
            tsn = data;
        },
        error : function(error) {
            console.log("获取位置失败!");
        }
    });
}
 
//获取最新位置后进行定位
function changeMarkerPosition () {
 
    //到后台请求最新的位置信息
    getCurrentLocation();
 
    //清除所有的覆盖物标识
    map.clearOverlays();
 
    if(tsn.length==0){
        layer.alert("暂无设备位置信息,定位到粮库位置!");
        firstSetCenter(locations);
        return;
    }
    //适应地图大小,设置地图中心点坐标及地图级别
    var defaultPoint = tsn[0];
    map.centerAndZoom(new BMapGL.Point(defaultPoint.longitude, defaultPoint.latitude), 14);
    markPosition(tsn);
    showInfo(tsn);
}
 
//根据坐标标记位置
function markPosition(data) {
    var sContent;
    for (var i = 0; i < data.length; i++) {
        // 根据数据设定点
        points[i] = new BMapGL.Point(data[i].longitude, data[i].latitude);
        // 自定义标注图片
        var myIcon = new BMapGL.Icon( '../../static/images/icon_gcoding.png', new BMapGL.Size(25, 35));
        // 创建标注
        markers[i] = new BMapGL.Marker(points[i], {icon : myIcon});
        // 将标注添加到地图中
        map.addOverlay(markers[i]);
        indexs[i] = i
    }
}
 
function showInfo(data) {
    // 对标记数组添加事件
    markers.map(function(value, index) {
        // 设定点以定位文本标注位置
        var point = new BMapGL.Point(data[index].longitude,
            data[index].latitude);
 
        var opts = {
            position : point, // 指定文本标注所在的地理位置
            offset : new BMapGL.Size(10, -20)
            //设置文本偏移量
        };
 
        // 创建文本标注对象为文字
        labels[index] = new BMapGL.Label(data[index].name +"\r\n"+ dateFormatStr(data[index].updateTime), opts);
        // 设置label样式
        labels[index].setStyle({
            color : "black",
            // border:"none",
            "border" : "5px solid #e2e2e4",
            "border-radius" : "10px",
            "background" : "white",
            fontSize : "18px",
            // height : "50px",
            lineHeight : "25px",
            fontFamily : "微软雅黑"
        });
        // 将文本标注添加到地图上
        map.addOverlay(labels[index]);
    });
}
 
function rotate() {
    //开启鼠标滚轮缩放
    map.enableScrollWheelZoom(true);
 
    //开启地球模式
    map.setMapType(BMAP_EARTH_MAP);
 
    // 初始化地图,设置动画起始点坐标和地图级别
    map.centerAndZoom(new BMapGL.Point(214.406, 40.000), 5);
 
    //旋转动画开始
    setTimeout(function() {
        map.panTo(new BMapGL.Point(204.406, 40.000));
    }, 2000);
    setTimeout(function() {
        map.panTo(new BMapGL.Point(194.406, 40.000)); //旋转动画
    }, 2250);
    setTimeout(function() {
        map.panTo(new BMapGL.Point(184.406, 40.000)); //旋转动画
    }, 2500);
    setTimeout(function() {
        map.panTo(new BMapGL.Point(174.406, 40.000)); //旋转动画
    }, 2775);
    setTimeout(function() {
        map.panTo(new BMapGL.Point(164.406, 40.000)); //旋转动画
    }, 3000);
    setTimeout(function() {
        map.panTo(new BMapGL.Point(154.406, 40.000)); //旋转动画
    }, 3250);
    setTimeout(function() {
        map.panTo(new BMapGL.Point(144.406, 40.000)); //旋转动画
    }, 3500);
    setTimeout(function() {
        map.panTo(new BMapGL.Point(134.406, 40.000)); //旋转动画
    }, 3750);
    setTimeout(function() {
        map.panTo(new BMapGL.Point(124.406, 40.000)); //旋转动画
    }, 4000);
    //旋转动画结束
    setTimeout(function() {
        map.panTo(new BMapGL.Point(114.403, 40.000));
    }, 4250);
}
 
//格式化时间
function dateFormatStr(time) {
    if(time){
        var d = new Date(time);
        return dateFtt("yyyy-MM-dd hh:mm:ss",d);
    }
    return "";
}