zhitong.yu
2025-02-14 c4cce49f5e6fd1f74b9962cd86dd201694c3765e
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
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
<%--
  Created by IntelliJ IDEA.
  User: Lenovo
  Date: 2024/6/11
  Time: 11:32
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
    <style>
        *{
            margin: 0;
            padding: 0;
        }
        #titles{
            background: url("/hxzkuwb/Home/HomeImg/title.png")no-repeat;
            background-position: center;
        }
    </style>
</head>
<body>
<div class="layui-container" style="width: 100%;">
    <div class="layui-row">
    <div class="layui-col-xs12 layui-col-md12" style="width: 100%;height: 10%;position: fixed;z-index: 9">
       <h1 style="text-align: center;color: white" id="titles">定位管理系统</h1>
    </div>
    </div>
    <div class="layui-row">
        <div class="layui-col-xs12 layui-col-md12" style="width: 100%;height: 100%;"  id="container">
        </div>
    </div>
</div>
</body>
<script src="../HouTai/Js/jquery-3.5.1.js"></script>
<script src="//api.map.baidu.com/api?type=webgl&v=1.0&ak=zoVtgLNWuaZBjMAa32RZRFIagXxST0fm"></script>
<script>
    var bm = new BMapGL.Map("container");
    bm.centerAndZoom(new BMapGL.Point(116.404, 39.915), 12); // 初始化地图,设置中心点坐标和地图级别
    bm.setMapType(BMAP_EARTH_MAP);
    bm.enableScrollWheelZoom(true); // 开启鼠标滚轮缩放
    bm.setHeading(64.5);
    bm.setTilt(73);
    bm.setDisplayOptions({
        skyColors: ['rgba(186, 0, 255, 0)','rgba(186, 0, 255, 0.2)']
    })
 
 
    var zuobiaoxi = "";
    //从数据库查询当前选择的什么系坐标
    $.ajax({
        url: "/hxzkuwb/findbaidumapList",
        type: "GET",
        async: false,
        success: function(data) {
            zuobiaoxi = data[0].zhuanhuan
        }
    });
    var markers = {};
    var markers1 = {};
    var timer = setInterval(function() {
        markers = {};
        bm.clearOverlays();
            //只显示在线
            var gps_node_list1 = getGPS();
            for (var i = 0; i < gps_node_list1.length; i++) {
                var gpsInfo = gps_node_list1[i];
                var c = new Convertor();
                if(gpsInfo.baoliu2>10){
                    var rr = c.WGS2BD09({ lng: parseFloat(gpsInfo.baoliu2), lat: parseFloat(gpsInfo.baoliu3)});
                    if (zuobiaoxi == "百度"){
                        var lng = parseFloat(rr.lng);
                        var lat = parseFloat(rr.lat);
 
                    }else{
                        var lng = parseFloat(gpsInfo.baoliu2);
                        var lat = parseFloat(gpsInfo.baoliu3);
                    }
                    var userId = gpsInfo.ptagid;
                    // 判断在线状态
                    localStorage.setItem("username","超级管理员")
                    if(gpsInfo.psos == "1") {
                        if (markers1.hasOwnProperty(userId)) {
                            // 如果已经存在该标记,则移除原来的标记
                            bm.removeOverlay(markers1[userId]);
                            // 更新标记位置
                            const customOverlay = new BMapGL.CustomOverlay(createDOM, {
                                point: new BMapGL.Point(lng, lat),
                                opacity: 1,
                                bm: bm,
                                offsetY: 26,
                                zIndex: -1
                            });
                            bm.addOverlay(customOverlay);
                            markers1[userId] = customOverlay;
                        } else {
                            // 如果不存在该标记,则添加新标记
                            const customOverlay = new BMapGL.CustomOverlay(createDOM, {
                                point: new BMapGL.Point(lng, lat),
                                opacity: 1,
                                bm: bm,
                                offsetY: 26,
                                zIndex: -1
                            });
                            bm.addOverlay(customOverlay);
                            markers1[userId] = customOverlay;
                        }
                    }else{
                        if (markers1.hasOwnProperty(userId)) {
                            // 如果已经存在该标记,则移除原来的标记
                            bm.removeOverlay(markers1[userId]);
                        }
                    }
                    // 创建坐标点
                    var point = new BMapGL.Point(lng, lat);
                    // 创建标记
                    var myIcon = new BMapGL.Icon("../Icon/"+gpsInfo.pimage, new BMapGL.Size(40, 40), {
 
                    });
                    var marker = new BMapGL.Marker(point, { icon: myIcon });
 
                    // 将标记添加到地图上
                    bm.addOverlay(marker);
                    var label = new BMapGL.Label(gpsInfo.pname+" "+userId,{offset: new BMapGL.Size(0, -50)});
                    label.setStyle({
                        color: "#fff",
                        fontSize: "14px",
                        borderRadius: "5px",
                        padding: "5px 5px",
                        border: "0",
                        backgroundColor: gpsInfo.bumencolor,
                        transform: 'translateX(-50%)',
                    });
                    marker.setLabel(label);
                    // 存储标记到 markers 对象中
                    markers[userId] = marker;
                    marker.setTitle(gpsInfo.ptagid);
                }
            }
 
    }, 2000);
 
 
    function getGPS() {
        var gpslist = [];
        $.ajax({
            async: false,
            type: 'POST',
            traditional: true,
            url: "/hxzkuwb/getGPS",
            dataType: 'json',
            data: {},
            success: function (data) {
                //经纬度从度分秒转成度
                gpslist = data
            },
        });
        return gpslist;
    };
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
    function Convertor(ak) {
        this.stepCount = 100;
        this.pointCount = [];
        this.Result = [];
        this.NoisIndex = [];
        this.Time = new Date();
        this.AK = ak;
        this.M_PI = 3.14159265358979324;
        this.A = 6378245.0;
        this.EE = 0.00669342162296594323;
        this.X_PI = this.M_PI * 3000.0 / 180.0;
    }
    Convertor.prototype.outofChine = function (p) {
        if (p.lng < 72.004 || p.lng > 137.8347) {
            return true;
        }
        if (p.lat < 0.8293 || p.lat > 55.8271) {
            return true;
        }
        return false;
    }
    ;
    Convertor.prototype.WGS2GCJ_lat = function (x, y) {
        var ret1 = -100.0 + 2.0 * x + 3.0 * y + 0.2 * y * y + 0.1 * x * y + 0.2 * Math.sqrt(Math.abs(x));
        ret1 += (20.0 * Math.sin(6.0 * x * this.M_PI) + 20.0 * Math.sin(2.0 * x * this.M_PI)) * 2.0 / 3.0;
        ret1 += (20.0 * Math.sin(y * this.M_PI) + 40.0 * Math.sin(y / 3.0 * this.M_PI)) * 2.0 / 3.0;
        ret1 += (160.0 * Math.sin(y / 12.0 * this.M_PI) + 320 * Math.sin(y * this.M_PI / 30.0)) * 2.0 / 3.0;
        return ret1;
    }
    ;
    Convertor.prototype.WGS2GCJ_lng = function (x, y) {
        var ret2 = 300.0 + x + 2.0 * y + 0.1 * x * x + 0.1 * x * y + 0.1 * Math.sqrt(Math.abs(x));
        ret2 += (20.0 * Math.sin(6.0 * x * this.M_PI) + 20.0 * Math.sin(2.0 * x * this.M_PI)) * 2.0 / 3.0;
        ret2 += (20.0 * Math.sin(x * this.M_PI) + 40.0 * Math.sin(x / 3.0 * this.M_PI)) * 2.0 / 3.0;
        ret2 += (150.0 * Math.sin(x / 12.0 * this.M_PI) + 300.0 * Math.sin(x / 30.0 * this.M_PI)) * 2.0 / 3.0;
        return ret2;
    }
    ;
    Convertor.prototype.WGS2GCJ = function (poi) {
        if (this.outofChine(poi)) {
            return;
        }
        var poi2 = {};
        var dLat = this.WGS2GCJ_lat(poi.lng - 105.0, poi.lat - 35.0);
        var dLon = this.WGS2GCJ_lng(poi.lng - 105.0, poi.lat - 35.0);
        var radLat = poi.lat / 180.0 * this.M_PI;
        var magic = Math.sin(radLat);
        magic = 1 - this.EE * magic * magic;
        var sqrtMagic = Math.sqrt(magic);
        dLat = (dLat * 180.0) / ((this.A * (1 - this.EE)) / (magic * sqrtMagic) * this.M_PI);
        dLon = (dLon * 180.0) / (this.A / sqrtMagic * Math.cos(radLat) * this.M_PI);
        poi2.lat = poi.lat + dLat;
        poi2.lng = poi.lng + dLon;
        return poi2;
    }
    ;
    Convertor.prototype.GCJ2BD09 = function (poi) {
        var poi2 = {};
        var x = poi.lng
            , y = poi.lat;
        var z = Math.sqrt(x * x + y * y) + 0.00002 * Math.sin(y * this.X_PI);
        var theta = Math.atan2(y, x) + 0.000003 * Math.cos(x * this.X_PI);
        poi2.lng = z * Math.cos(theta) + 0.0065;
        poi2.lat = z * Math.sin(theta) + 0.006;
        return poi2;
    }
    ;
    /**
     * WGS->百度坐标系
     */
    Convertor.prototype.WGS2BD09 = function (poi) {
        //WGS->GCJ
        var poi2 = this.WGS2GCJ(poi);
        if (typeof poi2 === "undefined") {
            return;
        }
        //GCJ->百度坐标系
        return this.GCJ2BD09(poi2);
    }
 
    function zhuanhuan(aaa) {
        var c = new Convertor();
        var bbb = [];
        for (var i = 0; i < aaa.length; i++) {
            var rr = c.WGS2BD09({ lng: aaa[i].lng, lat: aaa[i].lat });
            bbb.push(rr);
        }
        return bbb;
        c = null;
        bbb = null;
    }
 
</script>
</html>