jiazx0107
2025-11-21 2d34de3edb86c16cfadf4ec09ff22d1eb128bccb
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
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
var colors = {};
var map;
var disProvince;//行政区颜色渲染
var deptAreasMap = {};
var allDeptMap = {};
var markers = [];//点标记
var type = "0";
var county = "all";
 
//var switch2AreaNode2;
 
$(function () {
    if (deptAreas) {
        for (var i = 0; i < deptAreas.length; i++) {
            deptAreasMap[deptAreas[i].id] = deptAreas[i];
        }
    }
    if (allDept) {
        for (var i = 0; i < allDept.length; i++) {
            allDeptMap[allDept[i].id] = allDept[i];
        }
    }
    //初始化时间
    //initTime();
 
    //初始化地图
    initMap();
 
    //左侧图表
/*    pieChartLoad(
        [
            {value: "0.000", name: '稻谷'},
            {value: "0.000", name: '玉米'},
            {value: "0.000", name: '小麦'}
        ],
        'breedChart'
    );*/
 
    //渲染部门
    //renderDepts();
 
    //大屏标语
    //initDicSlogan();
 
    //renderAreas(610000);
    setTimeout(function () {
         renderAreas(610000);
    }, 2000);
 
});
 
// 刷新时间
function initTime() {
    setInterval(function () {
        $("#navBarDate").html(formatDate('mm月dd日', new Date()));
        $("#navBarTime").html(formatDate('HH:MM:SS', new Date()));
        $("#navBarWeek").html(getWeekDate());
    }, 1000);
}
 
function initMap() {
    map = new AMap.Map('map_container', {
        center: [108.953544, 34.265892],
        zoom: 6.6,
        mapStyle: 'amap://styles/41f8248740d3659ddc65dc363078592c',
        // rotateEnable:true,
        // pitchEnable:true,
        // pitch: 0,
        // rotation: 0,
        resizeEnable: true
        //viewMode:'3D', //开启3D视图,默认为关闭
    });
 
    new AMap.DistrictSearch({
        extensions: 'all',
        subdistrict: 0
    }).search('陕西省', function (status, result) {
        // 外多边形坐标数组和内多边形坐标数组
        var outer = [
            new AMap.LngLat(-360, 90, true),
            new AMap.LngLat(-360, -90, true),
            new AMap.LngLat(360, -90, true),
            new AMap.LngLat(360, 90, true),
        ];
        var holes = result.districtList[0].boundaries
 
        var pathArray = [
            outer
        ];
        pathArray.push.apply(pathArray, holes)
        var polygon = new AMap.Polygon({
            pathL: pathArray,
            strokeColor: '#71B3ff',//#00eeff
            strokeWeight: 1,
            fillColor: '#000000',//#71B3ff
            fillOpacity: 0.4
        });
        polygon.setPath(pathArray);
        map.add(polygon);
    })
 
    //console.log(colors);
 
    //-------------------------------------------------------------------------------------------------------------------------
 
 
    //默认行政区域编码
    //renderColor(defaultAreaCode);
}
 
//socket信息返回處理
function socketOnMessage(pocket) {
 
    if (pocket.userId == "slogan") {
        var data = pocket.data;
        dicSlogan = data;
        initDicSlogan();
    }
}
 
/**
 * 初始标语数据
 */
function initDicSlogan() {
    if (dicSlogan) {
        if (dicSlogan.color == "red") {
            $("#sloganText").css({
                color: "#DE2910"
            });
        } else {
            $("#sloganText").css({
                color: "#7ddfff"
            });
        }
        $("#sloganText").text(dicSlogan.content);
    }
}
 
/**
 * 根据区县获取库区
 */
function getDeptArea(city, county) {
    var list = [];
    if (deptAreas) {
        for (var i = 0; i < deptAreas.length; i++) {
            if (city == deptAreas[i].deptCity) {
                list.push(deptAreas[i]);
            }
            if (county == deptAreas[i].deptCounty) {
                list.push(deptAreas[i]);
            }
        }
    }
    return list;
}
 
/**
 * 用户点击城市或者县级区级渲染库区点位
 */
function renderAreas(deptId) {
    var d = allDeptMap[deptId];
    if (d) {
        closeInfoWindow();
        removeColor();
        delMarker();
        //map.setCity(deptId);
        renderColor(deptId);
        var a = [];
        if ("10" == d.type) {
            a = getDeptArea(deptId, "")
        }
        if ("11" == d.type) {
            a = getDeptArea("", deptId)
        }
        if (a && a.length > 0) {
            for (var i = 0; i < a.length; i++) {
                addMarker(a[i], false);
            }
        }
        //刷新数据
        county = deptId;
        ajaxFoodNum();
    } else {
        console.log("没有获取到该行政区划:" + deptId);
    }
    //陕西
 
}
 
/**
 * 渲染库区信息弹窗
 * @param deptAreaId
 */
function showAreaInfo(deptAreaId) {
    var d = deptAreasMap[deptAreaId];
    if (d) {
        closeInfoWindow();
        removeColor();
        delMarker();
        //map.setCity(d.deptCounty);
        // map.setZoom(10);
        renderColor(d.deptCounty);
        addMarker(d, true);
    } else {
        console.log("没有获取到该库区:" + deptAreaId);
    }
}
 
/**
 * 渲染库区列表
 */
function renderDepts() {
    if (depts) {
        var html = "";
        var childs = [];
        var areas = [];
        for (var i = 0; i < depts.length; i++) {
            html += "<div style=\"width: 305px; overflow: hidden\">" +
                "<div class=\"sup-menu-group menu-group\">" +
                "<div class=\"sup-menu-title\">" +
                "<i class=\"i-icon fl\"><img src=\"/static/images/visual/icon-sj.png\"/></i>" +
                "<a href=\"###\" onclick=\"renderAreas('" + depts[i].id + "')\">" +
                "<span class=\"i-icon32 fl\"><img src=\"/static/images/visual/c-i2.png\"/></span>" +
                (depts[i].name ? depts[i].name : "") +
                "</a>" +
                "</div>";
            if (depts[i].children && depts[i].children.length > 0) {
                childs = depts[i].children;
                for (var j = 0; j < childs.length; j++) {
                    html += "<ul class=\"sup-menu-ul  menu-h\">" +
                        "<li>" +
                        "<div class=\"sup-menu-h\">" +
                        "<i class=\"i-icon fl\"><img src=\"/static/images/visual/icon-sj.png\"/></i>" +
                        "<a href=\"###\" onclick=\"renderAreas('" + childs[j].id + "')\">" +
                        "<span class=\"i-icon32 fl\"><img src=\"/static/images/visual/c-i2.png\"/></span>" +
                        (childs[j].name ? childs[j].name : "") +
                        "</a>" +
                        "</div>";
                    areas = getDeptArea("", childs[j].id);
                    if (areas && areas.length > 0) {
                        for (var k = 0; k < areas.length; k++) {
                            html += "<div class=\"sup-menu-box\">" +
                                "<p>" +
                                "<span class=\"i-icon32 fl\"><img src=\"/static/images/visual/icon-kuqu.png\"/></span>" +
                                "<a href=\"#\" onclick=\"showAreaInfo('" + areas[k].id + "')\">" + areas[k].name + "</a>" +
                                "</p>" +
                                "</div>";
                        }
                    }
                    html += "</li>" +
                        "</ul>";
                }
            } else {
                //没有子节点,直接就是区级别
                areas = getDeptArea("", depts[i].id);
                if (areas && areas.length > 0) {
                    for (var k = 0; k < areas.length; k++) {
                        html += "<ul class=\"sup-menu-ul\">" +
                            "<li>" +
                            "<div class=\"sup-menu-h\">" +
                            "<i class=\"i-icon fl\"><img src=\"/static/images/visual/icon-sj.png\"/></i>" +
                            "<a href=\"###\" onclick=\"renderAreas('" + areas[k].id + "')\">" +
                            "<span class=\"i-icon32 fl\"><img src=\"/static/images/visual/icon-kuqu.png\"/></span>" +
                            (areas[k].name ? areas[k].name : "") +
                            "</a>" +
                            "</div>";
                        html += "<div class=\"sup-menu-box\">" +
                            "</div>";
                        html += "</li>" +
                            "</ul>";
 
                    }
                }
            }
 
            html += "</div>" +
                "</div>";
        }
 
        $("#menuDiv").html(html);
    }
}
 
/**
 * 获取地图行政区域颜色
 * @param adcode
 * @returns {*}
 */
function getColorByAdcode(adcode) {
    if (!colors[adcode]) {
        var gb = Math.random() * 155 + 50;
        colors[adcode] = 'rgb(' + gb + ',' + gb + ',255)';
    }
    return colors[adcode];
};
 
/**
 *
 *增加库区点位
 * tag 是否直接显示信息弹窗
 */
function addMarker(deptArea, tag) {
    if (deptArea) {
        var markerContent = " <div class=\"right-map-item right-map-item2\"style=' left: 0px !important; top: 0px !important;'>" +
            // "                        <p>天府新区</p>" +
            "                        <span class=\"map-round\"></span>" +
            "                    </div>";
        var position = [deptArea.lon, deptArea.lat];
        var marker = new AMap.Marker({
            position: position,
            // 将 html 传给 content
            content: markerContent,
            // 以 icon 的 [center bottom] 为原点
            // achor:'center',
            offset: new AMap.Pixel(-25, -25)
 
        });
        markers.push(marker);
        // 将 markers 添加到地图
        map.add(marker);
 
        var infoWinodw = new AMap.InfoWindow({
            isCustom: true,  //使用自定义窗体
            content: createInfoWindow(deptArea),
            achor: 'bottom-center',
            offset: new AMap.Pixel(0, 0)
        });
        //鼠标点击marker弹出自定义的信息窗体
        marker.on('click', function () {
            infoWinodw.open(map, marker.getPosition());
        });
        if (tag) {
            infoWinodw.open(map, marker.getPosition());
        }
    } else {
        console.log("库区为空");
    }
}
 
/**
 *
 *删除库区点位
 */
function delMarker() {
    if (map) {
        map.remove(markers);
    }
}
 
//关闭信息窗体
function closeInfoWindow() {
    if (map) {
        map.clearInfoWindow();
    }
}
 
/**
 * 创建信息窗口
 */
function createInfoWindow(deptArea) {
    var deptAreaId = deptArea.id;
    var content = "<div class=\"BMap_bubble_pop\" style=\"padding: 0px 8px; position: relative; top:0px !important;left:0px !important;cursor: default; border: 1px solid rgb(221, 221, 221); background-color: rgb(255, 255, 255); border-radius: 10px; left: 837px; top: -46px; width: 376px;\">" +
        "<div class=\"BMap_bubble_top\" style=\"height:31px\">" +
        "<div class=\"BMap_bubble_title\" style=\"line-height: 30px; overflow: hidden; height: 30px; white-space: nowrap; color: rgb(51, 51, 51); width: 376px;\">" +
        "</div>" +
        "<div class=\"BMap_bubble_buttons\" style=\"float:right;position:absolute;top:-2px;right:0px;height:30px;\">" +
        "<div style=\"cursor: pointer; display: none;\">" +
        "<div style=\"position:absolute;top:9px;width:10px;height:10px;-moz-user-select:none;cursor:pointer;z-index:10000;display:none\">×</div>" +
        "</div>" +
        "<div style=\"cursor:pointer;width:32px;height:30px;color:#ccc\">" +
        "<div style=\"position:absolute;top:2px;right:12px;text-align:center;line-height:30px;-moz-user-select:none;cursor:pointer;z-index:10000;font-size:20px\">×</div>" +
        "</div>" +
        "</div>" +
        "</div>" +
        "<div class=\"BMap_bubble_center\" style=\"z-index: 3; position: relative; height: 324px; width: 376px;\">" +
        "<div class=\"BMap_bubble_content\" style=\"font-size: 14px; line-height: 24px; position: absolute; top: 2px; color: rgb(85, 85, 85); width: 364px; height: 324px; overflow: auto;\">" +
        '<div style=\"height:100%;box-sizing:border-box;\">' +
        '<div style="height: 34px;">'+
        '<div style="width: 320px;float: left;">';
    if (deptArea.name.length>17) {
        content += '<h3 style="margin:0 0 10px 0;line-height:24px;font-size:14px;color:#fff;">' + (deptArea.name ? deptArea.name : "没有获取到库区信息") + '</h3>' ;
    }else{
        content +=  '<h3 style="margin:0 0 10px 0;line-height:24px;font-size:18px;color:#fff;">' + (deptArea.name ? deptArea.name : "没有获取到库区信息") + '</h3>' ;
    }
    content += '</div>'+
        '<div style="width: 40px;float: left;">' +
        '<img style="height: 20px;" src="../../static/images/visual/icon_close.png" onclick="closeInfoWindow()"></img>' +
        '</div>'+
        '</div>'+
 
        '<p style="line-height:24px;font-size:12px;color:#fff;margin-right: 15px;"><img src="../../static/images/visual/icon-address.png" alt="" style="float:left;width: 16px;height: 16px;margin-right:3px;margin-top: 5px;"/>' + (deptArea.address ? deptArea.address + "(" + deptArea.lon + "," + deptArea.lat + ")" : "没有获取到库区信息") + '</P>' +
        '<div class="right-topInfo-kd " style="height: 80px;width: 270px;margin: 5px auto 10px auto;">' +
        '<div class="right-topInfo-kd-item">' +
        '<h3>粮仓个数(个)</h3>' +
        '<p>' + (deptArea.depotNum ? deptArea.depotNum : 0) + '</p>' +
        '</div>' +
        '<div class="right-topInfo-kd-item">' +
        '<h3>油罐个数(个)</h3>' +
        '<p>' + (deptArea.depotOilNum ? deptArea.depotOilNum : 0) + '</p>' +
        '</div>' +
        '</div>' +
        '<ul class="right-topInfo-kd-list right-topInfo-jg sup-topInfo-list">' +
        '<li>';
    if (deptArea.storage && (deptArea.storage + "").length > 4) {
        content += '<p style="font-size: 22px">' + (deptArea.storage ? deptArea.storage.toFixed(3) : 0) + '</p>';
    } else {
        content += '<p style="font-size: 22px">' + (deptArea.storage ? deptArea.storage.toFixed(3) : 0) + '</p>';
 
    }
    content += '<h3>粮食储量(吨)</h3>'+
        '</li>' +
        '<li>';
    if (deptArea.storage && (deptArea.oilStorage + "").length > 4) {
        content += '<p style="font-size: 22px">' + (deptArea.oilStorage ? deptArea.oilStorage.toFixed(3) : 0) + '</p>';
    } else {
        content += '<p style="font-size: 22px">' + (deptArea.oilStorage ? deptArea.oilStorage.toFixed(3) : 0) + '</p>';
    }
    content += '<h3>植物油储量(吨)</h3>' +
        '</li>' +
        '<li>' +
        '<p style="font-size: 22px" >' + (deptArea.area ? deptArea.area : 0) + '</p>' +
        '<h3>占地面积(㎡)</h3>' +
        '</li>' +
        '</ul>' +
        '<a href="javaScript:;" onclick="toHomeDetail(\'' + deptAreaId + '\')"  class="sup-deatil-link"><img src="../../static/images/visual/spu-detail-btn.png" alt="" style="width:100%;height:100%;"/></a>' +
        '</div>' +
        "</div></div><div class=\"BMap_bubble_bottom\" style=\"display: block; z-index: 2; position: absolute; width: 376px;\">" +
        "</div><img style=\"z-index: 1; position: absolute; width: 58px; height: 31px; left: 159px; bottom: -30px; top: 356px;\" src=\"http://webmap0.bdimg.com/image/api/iw_tail.png\"></div>";
 
    return content;
}
 
/**
 * 调用父节点方法执行,默认退出全屏并进入后台
 * @param id
 */
function toHomeDetail(id) {
    var url = "../home?t=grain&deptAreaId=" + id;
    window.parent.open(url, "_self");
};
 
/**
 * 根据行政编码渲染颜色,市级会将下面所有区渲染,区级只渲染当前区
 * @param adcode
 */
function renderColor(adcode) {
    // disProvince = new AMap.DistrictLayer.Province({
    //     zIndex: 12,
    //     adcode: adcode,
    //     depth: 2,
    //     opacity: 0.6,
    //     styles: {
    //         'fill': function (properties) {
    //             var adcode = properties.adcode;
    //             return getColorByAdcode(adcode);
    //         },
    //         'province-stroke': 'cornflowerblue',
    //         'city-stroke': 'white',//中国地级市边界
    //         'county-stroke': 'rgba(255,255,255,0.5)'//中国区县边界
    //     }
    // });
    // disProvince.setMap(map);
    //window.switch2AreaNode2(adcode);
    switch2AreaNode(adcode);
}
 
function removeColor() {
    // if (disProvince) {
    //     disProvince.setMap(null);
    // }
}
 
/**
 * 格式化日期
 * @param fmt
 * @param date
 * @return {*}
 */
function formatDate(fmt, date) {
    var ret;
    const opt = {
        "Y+": date.getFullYear().toString(),        // 年
        "m+": (date.getMonth() + 1).toString(),     // 月
        "d+": date.getDate().toString(),            // 日
        "H+": date.getHours().toString(),           // 时
        "M+": date.getMinutes().toString(),         // 分
        "S+": date.getSeconds().toString()          // 秒
        // 有其他格式化字符需求可以继续添加,必须转化成字符串
    };
    for (var k in opt) {
        ret = new RegExp("(" + k + ")").exec(fmt);
        if (ret) {
            fmt = fmt.replace(ret[1], (ret[1].length == 1) ? (opt[k]) : (opt[k].padStart(ret[1].length, "0")))
        }
    }
    return fmt;
}
 
/**
 *获取当前星期几
 */
function getWeekDate() {
    var now = new Date();
    var day = now.getDay();
    var weeks = new Array("星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六");
    var week = weeks[day];
    return week;
}
 
/**
 * 格式化日期
 * @param fmt
 * @param date
 * @return {*}
 */
function formatDate(fmt, date) {
    var ret;
    const opt = {
        "Y+": date.getFullYear().toString(), // 年
        "m+": (date.getMonth() + 1).toString(), // 月
        "d+": date.getDate().toString(), // 日
        "H+": date.getHours().toString(), // 时
        "M+": date.getMinutes().toString(), // 分
        "S+": date.getSeconds().toString() // 秒
        // 有其他格式化字符需求可以继续添加,必须转化成字符串
    };
    for (let k in opt) {
        ret = new RegExp("(" + k + ")").exec(fmt);
        if (ret) {
            fmt = fmt.replace(ret[1], (ret[1].length == 1) ? (opt[k]) : (opt[k].padStart(ret[1].length, "0")))
        }
    }
    return fmt;
}
 
/**
 *获取当前星期几
 */
function getWeekDate() {
    var now = new Date();
    var day = now.getDay();
    var weeks = new Array("星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六");
    var week = weeks[day];
    return week;
}
 
var navBarDateDom = document.getElementById('navBarDate');
var navBarTimeDom = document.getElementById('navBarTime');
var navBarWeekDom = document.getElementById('navBarWeek');
 
/*刷新时间*/
setInterval(function () {
    navBarDateDom.innerHTML = formatDate('mm月dd日', new Date());
    navBarTimeDom.innerHTML = formatDate('HH:MM:SS', new Date());
    navBarWeekDom.innerHTML = getWeekDate();
}, 1000)
 
$(function () {
    $('.m-nav .tit').click(function () {
        $(this).siblings('.sub').stop().slideToggle();
 
    });
    $('.c-left .close').on('click', function () {
        $('.c-left').addClass('hidden')
    });
    $('.c-left .o-btn').on('click', function () {
        $('.c-left').removeClass('hidden')
    });
    $('.c-right .close').on('click', function () {
        $('.c-right').addClass('hidden')
    });
    $('.c-right .o-btn').on('click', function () {
        $('.c-right').removeClass('hidden')
    });
 
});