hdw
2018-12-13 eb5f33c8ffdb60db5613353b8dadeb81dff7f798
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
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
<!DOCTYPE html>
<html lang="en" class="full-height">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1, user-scalable=no">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>百度地图</title>
    <link rel="stylesheet" href="css/basic.css">
    <link rel="stylesheet" href="src/css/layui.css">
    <link rel="stylesheet" href="app/css/common.css">
    <link rel="stylesheet" href="app/css/map.css">
    <link rel="stylesheet" href="font-awesome-4.7.0/css/font-awesome.css">
    <!-- 导入百度地图API -->
    <link rel="stylesheet" href="http://api.map.baidu.com/library/SearchInfoWindow/1.5/src/SearchInfoWindow_min.css" />
    <script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak=QAerSFEiGDCx1oHPB7Z5XYcBHI6R3qwx"></script>
    <script type="text/javascript" src="http://api.map.baidu.com/library/SearchInfoWindow/1.5/src/SearchInfoWindow_min.js"></script>
    <style>
        .map-panel-btn {
            /*初始化按钮*/
            font-size: 12px;
            text-decoration: none!important;
            font-family: Helvetica, Arial, sans serif;
            padding: 4px 12px;
            border-radius: 3px;
            -moz-border-radius: 3px;
            box-shadow: inset 0px 0px 2px #fff;
            -o-box-shadow: inset 0px 0px 2px #fff;
            -webkit-box-shadow: inset 0px 0px 2px #fff;
            -moz-box-shadow: inset 0px 0px 2px #fff;
            /*定义颜色和样式*/
            color: #41788c;
            border: 1px solid #6fb1c7;
            background-image: -moz-linear-gradient(#aae5f7, #73d0f1);
            background-image: -webkit-gradient(linear, 0% 0%, 0% 100%, from(#73d0f1), to(#aae5f7));
            background-image: -webkit-linear-gradient(#aae5f7, #73d0f1);
            background-image: -o-linear-gradient(#aae5f7, #73d0f1);
            text-shadow: 1px 1px 1px #bfeafb;
            background-color: #73d0f1;
            /* 定义位置 */
            margin-left: 200px;
        }
        .map-panel-btn:hover {
            border: 1px solid #4690ad;
            background-image: -moz-linear-gradient(#73d0f1, #aae5f7);
            background-image: -webkit-gradient(linear, 0% 0%, 0% 100%, from(#aae5f7), to(#73d0f1));
            background-image: -webkit-linear-gradient(#73d0f1, #aae5f7);
            background-image: -o-linear-gradient(#73d0f1, #aae5f7);
            background-color: #aae5f7;
        }
    </style>
</head>
<body class="full-height">
    <div class="abs">
        <div class="rel-full">
            <div class="page-header bg-gay3">
                <div class="layui-row h40">
                    <div class="layui-col-xs3 layui-col-md1 full-height">
                        <button class="layui-btn layui-btn-primary layui-btn-sm mrt5 mrl8"><i class="fa fa-reply mrr4"></i>返回</button>
                    </div>
                    <div class="layui-col-xs6 layui-col-md10 full-height line-height40">机房定位</div>
                    <div class="layui-col-xs3 layui-col-md1 full-height line-height40 t-align-right t-align-right">
                        <!-- <button class="layui-btn layui-btn-primary layui-btn-sm mrr8" id="homeInfo"><i class="fa fa fa-bars mrr4"></i>功能</button> -->
                    </div>
                </div>
            </div>
            <div class="page-content abs abs-top40">
                <div class="rel-full">
                    <div id="map" class="full-height"></div>
                    <div id="mapSearch" class="map-search-container">
                        <div class="layui-form layui-form-pane" action="">
                            <div class="layui-form-item">
                                <label class="layui-form-label"><i class="fa fa-search"></i></label>
                                <div class="layui-input-block">
                                    <input type="text" name="title" id="searchInput" autocomplete="off" placeholder="机房搜索" class="layui-input">
                                </div>
                            </div>
                        </div>
                    </div>
                    <div id="mapLocationLogo" class="map-location-logo">
                        <div class="map-location-logo-container default"></div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <!-- 存储机房信息列表 -->
    <div id="searchHomeIframe"></div>
    <!-- 存在机房信息 -->
    <div id="homeInfoIframe"></div>
    <script src="js/jquery-1.8.3.js"></script>
    <script src="src/layui.all.js"></script>
    <script>
        //  百度地图模块
        var map = new BMap.Map('map');
        var point = new BMap.Point(125.3192,43.8090);
        map.centerAndZoom(point, 11);    // 用城市名设置地图中心点
        map.enableScrollWheelZoom();
        map.disableDoubleClickZoom();
        // 给地图添加工具条(地图-卫星-三维)和比例尺控件
        map.addControl(new BMap.MapTypeControl({anchor: BMAP_ANCHOR_BOTTOM_RIGHT}));
 
        // 浏览器定位(前提是有网络和开启GPS权限)
        var geolocation = new BMap.Geolocation();
        
        // 点击定位按钮
        $('#mapLocationLogo .map-location-logo-container').click(function() {
            $(this).removeClass('default loading success').addClass('loading');
            var _this = $(this);
            geolocation.getCurrentPosition(function(r){
                   if(this.getStatus() == BMAP_STATUS_SUCCESS){
                       delMkByLabel('新机房');
                       _this.removeClass('default loading success').addClass('success');
                       var mk = new BMap.Marker(r.point);
                       var label = new BMap.Label("新机房",{offset:new BMap.Size(20,-10)});
                       label.setStyle({display: 'none', padding: '4px 2px'});
                       mk.enableDragging();        // 设置可拖动
                       map.addOverlay(mk);            // 将覆盖物添加到地图中
                       mk.setLabel(label);            // 给覆盖物添加label提示
                    map.panTo(r.point, 20);        // 将地图移动到添加的点位置
                    map.setZoom(20);            // 设置地图的缩放等级
                    
                    // 给maker点绑定点击事件
                    mk.addEventListener('click', function(e) {
                        var target = e.target;
                        showAddMapPanel(target);
                    });
                   }else {
                       layer.msg('定位失败,请检查GPS或网络!');
                   }
           });
        });
        
        // 删除
        function delMkByLabel(str) {
            var allOverlay = map.getOverlays();
            for (var i = 0; i < allOverlay.length -1; i++){
                if(allOverlay[i].getLabel) {
                    if(allOverlay[i].getLabel().content == str){
                        map.removeOverlay(allOverlay[i]);
                        return false;
                    }
                }
                
            }
        }
        
        // 添加增加机房的面板
        function showAddMapPanel(target) {
            var geoc = new BMap.Geocoder();
            var searchInforWin = null;
            var pt = target.point;
 
            var opts = {
                title  : '设置站点位置',      //标题
                width  : 290,             //宽度
                height : 150,              //高度
                panel  : "panel",         //检索结果面板
                enableAutoPan : true,     //自动平移
                searchTypes   :[
                    // BMAPLIB_TAB_SEARCH,   //周边检索
                    // BMAPLIB_TAB_TO_HERE,  //到这里去
                    // BMAPLIB_TAB_FROM_HERE //从这里出发
                ]
            };
            geoc.getLocation(pt, function(rs){
                var addComp = rs.addressComponents;
                $.ajax({     
                    type: "post",                 
                    url: "BattMap_informationAction!serchNotInBattMap",                
                    async:true,                
                    dataType:'text',
                    data:null,        
                    success: function(data){ 
                        //console.info(data);
                        data = eval('('+data+')');
                        var model = eval('('+data.result+')');
                        //console.info(model);
                        var options = "";
                        if(model.code == 1){
                            for(var i=0;i<model.data.length;i++){
                                options+= '<option value="'+model.data[i].StationId+'">'+model.data[i].StationName+'</option>';
                            }
                        }else{
                            options = "<option value='0'>暂无可设站点</option>";
                        }
                        
                        var content = '<div class="add-panel">'+
                            '<div style="padding: 6px 4px"><span>地址:</span>'+
                            '<span class="addr">'+addComp.province+'-'+addComp.city+'-'+addComp.district+'-'+addComp.street+'</span></div>'+
                            '<div style="padding: 6px 4px">经度:<span class="lng">'+rs.point.lng+'</span>,纬度:<span class="lat">'+rs.point.lat+'</span></div>'+
                            '<div style="padding: 6px 4px"><span>设置站点名:</span>'+'<select style="border: 1px solid #ccc; width: 180px">'+options+'</select></div>'+
                            '<div style="padding: 6px 4px; margin-top: 20px">'+
                            '<a href="javascript:showHomeInfo();" class="map-panel-btn">确定</a></div>'
                        +'</div>';
    
                        searchInforWin = new BMapLib.SearchInfoWindow(map, content, opts);
    
                        searchInforWin.open(rs.point);
                        $('.BMapLib_sendToPhone').hide();
                    }                 
                });
            });
        }
        
        
        // 显示机房详细信息
        var iframePopup;
        function showHomeInfo() {
            var lng = $('.add-panel .lng').text();                            // 获取经度
            var lat = $('.add-panel .lat').text();                            // 获取纬度
            var addr = $('.add-panel .addr').text();                        // 获取地址
            var homeId = $('.add-panel select option:selected').val();        // 机房Id
            var homeName = $('.add-panel select option:selected').text();    // 机房名称
            var temp = {
                homeId: homeId
                ,homeName: homeName
                ,addr: addr
                ,lng: lng
                ,lat: lat
            }
            // 显示暂无可设站点
            if(homeId == 0) {
                layer.msg(homeName);
                return;
            }
            // 存储值
            $('#homeInfoIframe').data('homeInfo', temp);
            
            iframePopup = layer.open({
                type: 2
                ,closeBtn: 0
                ,title: false
                ,area: ['100%', '100%']
                ,full: true
                ,anim: 4
                ,content: 'iframe/homeinfo.html'
            });
        }
        
        // 点击筛选弹出内容
        $('#homeInfo').click(function() {
            iframePopup = layer.open({
                type: 2
                ,closeBtn: 0
                ,title: false
                ,area: ['100%', '100%']
                ,full: true
                ,anim: 4
                ,content: 'iframe/homeinfo.html'
            });
        });
 
        // 搜索机房获取焦点
        $('#searchInput').on('focus', function() {
            $(this).blur();
            iframePopup = layer.open({
                type: 2
                ,closeBtn: 0
                ,title: false
                ,area: ['100%', '100%']
                ,full: true
                ,anim: 5
                ,content: 'iframe/searchHome.html'
            });
        });
        
        // 查询机房
        findHome();
        function findHome() {
            var tmp = {
                StationName1:'',
                StationName2: '',
                StationName5:''
            };
            
            // 查询将信息
            $.post("BattInfAction!serchStationName3","json="+JSON.stringify(tmp),function(result){
                var rs = JSON.parse(result.result);
                if(rs.code==1){
                    homeSource = [];
                    var data = rs.data;
                    for(var i=0; i<data.length; i++) {
                        var _data = data[i];
                        var tmp = {
                            label: _data.StationName+'('+_data.StationId+')',
                            province: _data.StationName1,
                            city: _data.StationName2,
                            county: _data.StationName5,
                            home: _data.StationName,
                            homeid: _data.StationId
                        };
                        
                        // 添加到资源
                        homeSource.push(tmp);
                    }
                    //console.log(homeSource)
                    // 设置资源内容
                    $('#searchHomeIframe').data('homeSource', homeSource);
                }
            });
            
        }
        
        
        //拦截安卓回退按钮
        history.pushState(null, null, location.href);
        window.addEventListener('popstate', function(event) {
            history.pushState(null, null, location.href );
            //此处加入回退时你要执行的代码
        });
    </script>
</body>
</html>