nvsmain.js 31.4 KB
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 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256

var g_serverList = null;
var g_userList = null;
var g_alarminfoCount = null;
var g_cameraList = null;
var g_cameraGisList = null;

$(function(){

	getServerList();
	
	getUserList();
	
	getCameraList();
	
	getCameraGisList();
	
	getAlarmInfoCount();
	
    char1();
    char2();
    char3();
    char4();
	
	setTimeout(function(){
         initMap();
    },100);
});



function getServerList(){
	var xhr = $.ajax({
		url: "/nvsthird/getservicelist",
		type: "post",
		async: false,
		dataType: "json",
		contentType: "application/json",
		data: JSON.stringify({
			token: "",
			fromindex:0,
			toindex:-1
		}),
		timeout: 5000,
		success: function(res) {
			if (res.group != null) {
				//var objToStr = JSON.stringify(res);
				//console.log('res:'+objToStr); 
				
				g_serverList = res.group;
				var online = 0;
				for (var i = 0; i < g_serverList.length; i++) {
					if(g_serverList[i].status === "1") {
						online++;
					}
				}
				
				$("#server-total").html("" + g_serverList.length);
	            $("#server-online").html("" + online);
			
			} else {
				layer.msg('获取服务列表失败',{icon: 2, title:'获取列表',time: 2000,skin: 'layer-ext-moon' });
			}
		},
		error: function(XMLHttpRequest, textStatus, errorThrown){
			layer.msg('获取服务列表超时:' + errorThrown, {icon: 2, title:'获取列表',time: 2000,skin: 'layer-ext-moon' });  
			return false;
		},
		complete : function(XMLHttpRequest,status){ //请求完成后最终执行参数
    	if(status == 'timeout'){//超时,status还有success,error等值的情况
      	 	xhr.abort();
    	} else if(status == 'error') {
				xhr.abort();
				layer.msg('获取服务列表失败', {icon: 2, time: 2000,title:'获取列表',skin: 'layer-ext-moon' });
			}
  	}
	});
}


function getUserList(){
	
	var tempData = getUserListFromCache();
	if (tempData) {
		//console.log('tempData:'+tempData); 
		g_userList = JSON.parse(""+tempData);
		var online = 0;
		for (var i = 0; i < g_userList.length; i++) {
			if(g_userList[i].status === 1) {
				online++;
			}
		}
		
		$("#user-total").html("" + g_userList.length);
	    $("#user-online").html("" + online);
		return true;
	} 
	
	
	var xhr = $.ajax({
		url: "/nvsthird/getuserlist",
		type: "post",
		async: true,
		dataType: "json",
		contentType: "application/json",
		data: JSON.stringify({
			token: "",
			fromindex:0,
			toindex:-1
		}),
		timeout: 5000,
		success: function(res) {
			if (res.group != null) {
				//var objToStr = JSON.stringify(res);
				//console.log('res:'+objToStr); 
				
				var objToStr = JSON.stringify(res.group);
				setUserListToCache(objToStr);
				
				g_userList = res.group;
				var online = 0;
				for (var i = 0; i < g_userList.length; i++) {
					if(g_userList[i].status === 1) {
						online++;
					}
				}
				
				$("#user-total").html("" + g_userList.length);
	            $("#user-online").html("" + online);
			
			} else {
				layer.msg('获取用户列表失败',{icon: 2, title:'获取列表',time: 2000,skin: 'layer-ext-moon' });
			}
		},
		error: function(XMLHttpRequest, textStatus, errorThrown){
			layer.msg('获取用户列表超时:' + errorThrown, {icon: 2, title:'获取列表',time: 2000,skin: 'layer-ext-moon' });  
			return false;
		},
		complete : function(XMLHttpRequest,status){ //请求完成后最终执行参数
    	if(status == 'timeout'){//超时,status还有success,error等值的情况
      	 	xhr.abort();
    	} else if(status == 'error') {
				xhr.abort();
				layer.msg('获取用户列表失败', {icon: 2, time: 2000,title:'获取列表',skin: 'layer-ext-moon' });
			}
  	}
	});
	
}




function getAlarmInfoCount(){
	var b = "" + getNowFormatDate() + " 00:00:00";
	var e = "" + getNowFormatDate() + " 23:59:59";
	
	var timeoutDefaultValue = getNetTimeout() * 1000;
	
	var xhr = $.ajax({
		url: "/nvsthird/getalarminfocount",
		type: "post",
		async: false,
		dataType: "json",
		contentType: "application/json",
		data: JSON.stringify({
			token: "",
			begintime: b,
			endtime: e
		}),
		timeout: timeoutDefaultValue,
		success: function(res) {
			if (res != null) {
				//var objToStr = JSON.stringify(res);
				//console.log('res:'+objToStr); 
				
				g_alarminfoCount = res;
			
			} else {
				layer.msg('获取告警信息列表失败',{icon: 2, title:'获取列表',time: 2000,skin: 'layer-ext-moon' });
			}
		},
		error: function(XMLHttpRequest, textStatus, errorThrown){
			layer.msg('获取警信息列表超时:' + errorThrown, {icon: 2, title:'获取列表',time: 2000,skin: 'layer-ext-moon' });  
			return false;
		},
		complete : function(XMLHttpRequest,status){ //请求完成后最终执行参数
    	if(status == 'timeout'){//超时,status还有success,error等值的情况
      	 	xhr.abort();
    	} else if(status == 'error') {
				xhr.abort();
				layer.msg('获取警信息列表失败', {icon: 2, time: 2000,title:'获取列表',skin: 'layer-ext-moon' });
			}
  	}
	});
}

function getCameraList(){
	var tempData = getValueFromCache("getcamlist");
	if (tempData) {
	//	console.log('tempData:'+tempData); 
		g_cameraList = JSON.parse(""+tempData);


        var online = 0;
        for (var i = 0; i < g_cameraList.length; i++) {
            if(g_cameraList[i].status == 1) {
                online++;
            }
        }

        $("#device-total").html("" + g_cameraList.length);
        $("#device-online").html("" + online);

		return true;
	} 
	
	var xhr = $.ajax({
		url: "/nvsthird/getcamlist",
		type: "post",
		async: false,
		dataType: "json",
		contentType: "application/json",
		data: JSON.stringify({
			token: "",
			fromindex:0,
			toindex:-1
		}),
		timeout: 5000,
		success: function(res) {
			if (res.group !== null) {
				var objToStr = JSON.stringify(res.group);
				
				//console.log('res:'+objToStr); 
				setKeyValueToCache("getcamlist", objToStr);
				g_cameraList = res.group;

				var online = 0;
                for (var i = 0; i < g_cameraList.length; i++) {
                    if(g_cameraList[i].status == 1) {
                        online++;
                    }
                }

                $("#device-total").html("" + g_cameraList.length);
                $("#device-online").html("" + online);
			
			} else {
				layer.msg('获取摄像机列表失败',{icon: 2, title:'获取列表',time: 2000,skin: 'layer-ext-moon' });
			}
		},
		error: function(XMLHttpRequest, textStatus, errorThrown){
			layer.msg('获取摄像机列表超时:' + errorThrown, {icon: 2, title:'获取列表',time: 2000,skin: 'layer-ext-moon' });  
			return false;
		},
		complete : function(XMLHttpRequest,status){ //请求完成后最终执行参数
    	if(status == 'timeout'){//超时,status还有success,error等值的情况
      	 	xhr.abort();
    	} else if(status == 'error') {
				xhr.abort();
				layer.msg('获取摄像机列表失败', {icon: 2, time: 2000,title:'获取列表',skin: 'layer-ext-moon' });
			}
  	}
	});
}


function getCameraGisList(){
	
	var tempData = getValueFromCache("getgislist");
	if (tempData) {
		//console.log('tempData:'+tempData); 
		g_cameraGisList = JSON.parse(""+tempData);
		return true;
	} 
		
	var xhr = $.ajax({
		url: "/nvsthird/getgislist",
		type: "post",
		async: false,
		dataType: "json",
		contentType: "application/json",
		data: JSON.stringify({
			token: "",
			fromindex:0,
			toindex:-1
		}),
		timeout: 5000,
		success: function(res) {
			if (res.group !== null) {
				var objToStr = JSON.stringify(res.group);
				//console.log('res:'+objToStr); 
				setKeyValueToCache("getgislist", objToStr);
				g_cameraGisList = res.group;
			
			} else {
				layer.msg('获取GIS列表失败',{icon: 2, title:'获取设备列表',time: 2000,skin: 'layer-ext-moon' });
			}
		},
		error: function(XMLHttpRequest, textStatus, errorThrown){
			layer.msg('获取GIS列表超时:' + errorThrown, {icon: 2, title:'获取列表',time: 2000,skin: 'layer-ext-moon' });  
			return false;
		},
		complete : function(XMLHttpRequest,status){ //请求完成后最终执行参数
    	if(status == 'timeout'){//超时,status还有success,error等值的情况
      	 	xhr.abort();
    	} else if(status == 'error') {
				xhr.abort();
				layer.msg('获取GIS列表失败', {icon: 2, time: 2000,title:'获取列表',skin: 'layer-ext-moon' });
			}
  	}
	});
}



//统计分析图
function char1() {

    var myChart = echarts.init($("#char1")[0]);
	
	var ptzIpCameraCount = 0;
	var ptzCameraCount = 0;
	var cameraCount = 0;
	var ipCameraCount = 0;
	var allCameraCount = 0;
	
	try{
		allCameraCount = g_cameraList.length;
		for(var i = 0; i < g_cameraList.length; i++) {
			var strType = g_cameraList[i].aliasId.substr(6,4);
			if(strType === "1201") {
				cameraCount++;
			} else if(strType === "1202") {
				ptzCameraCount++;
			}
			else if(strType === "1203") {
				ipCameraCount++;
			}
			else if(strType === "1204") {
				ptzIpCameraCount++;
			}
		}
		 
	}catch(e){
		
	}

    option = {
        tooltip : {
            trigger: 'item',
			formatter: "{a} <br/>{b}: {c} ({d}%)"
        },
        legend: {
            orient : 'vertical',
            x : 'right',
            textStyle : {
                color : '#ffffff'
            },
            data:['云台IP摄像机','固定IP摄像机','云台摄像机','固定摄像机']
        },
		title : {
			text: ''+allCameraCount,
			subtext: '摄像机总数',
			x:'left',
			textStyle : {
                color : 'white'
            }
		},
		color:['#00CC00', '#99CCFF','#FF9900','#FF99CC'],
        series : [
            {
                name:'摄像机类型',
				type:'pie',
				radius: ['60%', '90%'],
				avoidLabelOverlap: true,
				label: {
					normal: {
						show: false,
						position: 'center'
					},
					emphasis: {
						show: true,
						textStyle: {
							fontSize: '30',
							fontWeight: 'bold'
						}
					}
				},
				labelLine: {
					normal: {
						show: false
					}
				},
                data:[
                    {value:ptzIpCameraCount, name:'云台IP摄像机'},
                    {value:ipCameraCount, name:'固定IP摄像机'},
                    {value:ptzCameraCount, name:'云台摄像机'},
                    {value:cameraCount, name:'固定摄像机'}

                ]
            }
        ]
    };

    myChart.setOption(option);
    window.addEventListener('resize', function () {myChart.resize();})
}


function getCameraNode(id) {
	for(var i = 0; i < g_cameraList.length; i++) {
		if(g_cameraList[i].id === id) {
			return g_cameraList[i];
		}
	}
	
	return null;
}


function char2() {
	 var myChart = echarts.init($("#char2")[0]);
	 
	var nowOnlineDeviceCount = 0;
	var nowOfflineDeviceCount = 0;
	var allOnlineDeviceCount = 0;
	var allDeviceCount = 0;
	
	try{
		allDeviceCount = g_cameraList.length;
		for (var i = 0; i < g_cameraList.length; i++) {
			if(g_cameraList[i].status == 1) {
				allOnlineDeviceCount++;
			}
		}
		
		nowOnlineDeviceCount = g_alarminfoCount.encoderOnlineCount;
		nowOfflineDeviceCount = g_alarminfoCount.encoderOffCount;
		
		console.log('nowOnlineDeviceCount:'+nowOnlineDeviceCount + " nowOfflineDeviceCount:"+nowOfflineDeviceCount); 
		
		 
	}catch(e){
	}

    option = {
        grid: {show:'true',borderWidth:'0'},
        tooltip : {
            trigger: 'axis',
            axisPointer : {            // 坐标轴指示器,坐标轴触发有效
                type : 'shadow'        // 默认为直线,可选为:'line' | 'shadow'
            },

            formatter: function (params) {
                var tar = params[0];
                return tar.name + '<br/>'  + tar.value;
            }
        },

        xAxis : [
            {
                type : 'category',
                splitLine: {show:false},
                data : ['设备总数','在线设备','今日上线','今日离线'],
                axisLabel: {
                    show: true,
                    textStyle: {
                        color: '#fff'
                    }
                }

            }
        ],
        yAxis : [
            {
                type : 'value',
				minInterval: 1,
                splitLine: {show:false},
                axisLabel: {
                    show: true,
                    textStyle: {
                        color: '#fff'
                    }
                }
            }
        ],
        series : [

            {
                name:'',
                type:'bar',
                stack: '总量',
				barMinHeight:1,
                itemStyle : { 
					normal: {
						label : {show: true, position: 'inside'},
						color: function (params) {
							var colorList = ['#65d186', '#f67287', '#f29e3c', '#c05bdd']; //每根柱子的颜色
							return colorList[params.dataIndex];
						}
					},
					 //鼠标悬停时:
                    emphasis: {
						shadowBlur: 10,
						shadowOffsetX: 0,
						shadowColor: 'rgba(0, 0, 0, 0.5)'
					}
				},
                data:[allDeviceCount, allOnlineDeviceCount, nowOnlineDeviceCount, nowOfflineDeviceCount]
            }
        ]
    };

    myChart.setOption(option);
    window.addEventListener('resize', function () {myChart.resize();})
}

function char3() {

    var myChart = echarts.init($("#char3")[0]);
	
	var alarmArray = [0,0,0,0,0,0,0,0,0];
	try{
		alarmArray[0] = g_alarminfoCount.movingCount;
		alarmArray[1] = g_alarminfoCount.intrusionCount;
		alarmArray[2] = g_alarminfoCount.videoLostCount;
		alarmArray[3] = g_alarminfoCount.leftTakeCount;
		alarmArray[4] = g_alarminfoCount.videoCoverCount;
		alarmArray[5] = g_alarminfoCount.gpioInCount;
		alarmArray[6] = g_alarminfoCount.recordLostCount;
		alarmArray[7] = g_alarminfoCount.recordNoSpaceCount;
		alarmArray[8] = g_alarminfoCount.diskFaultCount;
		
		
	}catch(e){
	}


    option = {
        grid: {show:'true',borderWidth:'0'},
        tooltip : {
            trigger: 'axis',
            axisPointer : {            // 坐标轴指示器,坐标轴触发有效
                type : 'shadow'        // 默认为直线,可选为:'line' | 'shadow'
            },

            formatter: function (params) {
                var tar = params[0];
                return tar.name + '<br/>'  + tar.value;
            }
        },

        xAxis : [
            {
                type : 'category',
                splitLine: {show:false},
                data : ['移动侦测','入侵检测','视频丢失','遗留物','镜头遮挡','动环','存储丢失','空间不足','硬盘故障'],
                axisLabel: {
                    show: true,
					interval:0,//横轴信息全部显示 
					formatter: function (value) {
        	        	var str = value.split("");
        	        	return str.join("\n");
        	        },
 					
                    textStyle: {
                        color: '#fff',	
                    }
                }

            }
        ],
        yAxis : [
            {
                type : 'value',
				minInterval: 1,
                splitLine: {show:false},
                axisLabel: {
                    show: true,
                    textStyle: {
                        color: '#fff'
                    }
                }
            }
        ],
        series : [

            {
                name:'',
                type:'bar',
                stack: '总量',
				barWidth:20,
				barMinHeight:1,
				barGap:'50%',
				barCategoryGap:'50%',
                itemStyle : { 
					normal: {
						label : {show: true, position: 'inside'},
						color: function (params) {
							var colorList = ['#65d186', '#f67287', '#f29e3c', '#c05bdd','#00CC00', '#99CCFF','#FF9900', '#FF99CC','#FF99CC']; //每根柱子的颜色
							return colorList[params.dataIndex];
						}
						
					},
					 //鼠标悬停时:
                    emphasis: {
						shadowBlur: 10,
						shadowOffsetX: 0,
						shadowColor: 'rgba(0, 0, 0, 0.5)'
					}
				},
                data:alarmArray
            }
        ]
    };

    myChart.setOption(option);
    window.addEventListener('resize', function () {myChart.resize();})

}


function char4() {
	var myChart = echarts.init($("#char4")[0]);
	
	var online = [0,0,0,0];
	var offline = [0,0,0,0];
	var nowonline = [0,0,0,0];
	var nowoffline = [0,0,0,0];
	
	try{
		for (var i = 0; i < g_serverList.length; i++) {
			var strType = g_serverList[i].type;
			if(strType === "cms") {
				if(g_serverList[i].status === "1") {
					online[3]++;
				} else {
					offline[3]++;
				}
			} else if(strType === "sms") {
				if(g_serverList[i].status === "1") {
					online[2]++;
				} else {
					offline[2]++;
				}
			}
			else if(strType === "mss") {
				if(g_serverList[i].status === "1") {
					online[1]++;
				} else {
					offline[1]++;
				}
			}
			else if(strType === "frs") {
				if(g_serverList[i].status === "1") {
					online[0]++;
				} else {
					offline[0]++;
				}
			}
		}
		
		nowoffline[0] = g_alarminfoCount.cruServerOffCount;
		nowoffline[1] = g_alarminfoCount.msuServerOffCount;
		nowoffline[2] = g_alarminfoCount.mduServerOffCount;
		nowoffline[3] = g_alarminfoCount.cmuServerOffCount;
		
		nowonline[0] = g_alarminfoCount.cruServerOnlineCount;
		nowonline[1] = g_alarminfoCount.msuServerOnlineCount;
		nowonline[2] = g_alarminfoCount.mduServerOnlineCount;
		nowonline[3] = g_alarminfoCount.cmuServerOnlineCount;
		
	}catch(e){
	}

    option = {
        tooltip : {
            trigger: 'axis',
            axisPointer : {            // 坐标轴指示器,坐标轴触发有效
                type : 'shadow'        // 默认为直线,可选为:'line' | 'shadow'
            }
        },
        grid: {
			left: '3%',
			right: '4%',
			bottom: '3%',
			containLabel: true
		},
        legend: {
            data:['在线','离线','今日上线', '今日离线'],
            textStyle : {
                color : '#ffffff',

            }
        },
		color:['#00CC00', '#99CCFF','#FF9900','#FF99CC'],
        xAxis : [
            {
                type : 'value',
				minInterval: 1,
                axisLabel: {
                    show: true,
                    textStyle: {
                        color: '#fff'
                    }
                },
                splitLine:{
                    lineStyle:{
                        color:['#f2f2f2'],
                        width:0,
                        type:'solid'
                    }
                }

            }
        ],
        yAxis : [
            {
                type : 'category',
                data : ['告警存储服务','中心存储服务','媒体分发服务','中心管理服务'],
                axisLabel: {
                    show: true,
                    textStyle: {
                        color: '#fff'
                    }
                },
                splitLine:{
                    lineStyle:{
                        width:0,
                        type:'solid'
                    }
                }
            }
        ],
        series : [
            {
                name:'在线',
                type:'bar',
                stack: '总量',
				label: {
					normal: {
						show: true,
						position: 'insideRight',
						formatter: function (params) {
                            if (params.value > 0) {
                                return params.value;
                            } else {
                                return '';
                            }
                        }
						
					}
				},
                data:online
            },
            {
                name:'离线',
                type:'bar',
                stack: '总量',
                label: {
					normal: {
						show: true,
						position: 'insideRight',
						formatter: function (params) {
                            if (params.value > 0) {
                                return params.value;
                            } else {
                                return '';
                            }
                        }
					}
				},
                data:offline
            },
            {
                name:'今日上线',
                type:'bar',
                stack: '总量',
                label: {
					normal: {
						show: true,
						position: 'insideRight',
						formatter: function (params) {
                            if (params.value > 0) {
                                return params.value;
                            } else {
                                return '';
                            }
                        }
					}
				},
                data:nowonline
            },
            {
                name:'今日离线',
                type:'bar',
                stack: '总量',
                label: {
					normal: {
						show: true,
						position: 'insideRight',
						formatter: function (params) {
                            if (params.value > 0) {
                                return params.value;
                            } else {
                                return '';
                            }
                        }
					}
				},
                data:nowoffline
            }

        ]
    };

    myChart.setOption(option);
    window.addEventListener('resize', function () {myChart.resize();})
}




var map = null;                          // 地图实例
var dbColl = {};                 // 数据库集合
var db = null;                           // 数据库

var menuItemOptions = {
    width: 100,
    id: "GISMapDlg"
};

//加载地图
function initMap(){
// 百度地图API功能
    map = new BMap.Map("map_div");    // 创建Map实例
    map.centerAndZoom(new BMap.Point(116.404, 39.915), 11);  // 初始化地图,设置中心点坐标和地图级别
    //添加地图类型控件
    var size1 = new BMap.Size(10, 50);
    map.addControl(new BMap.MapTypeControl({
        offset: size1,
        mapTypes:[
            BMAP_NORMAL_MAP,
            BMAP_HYBRID_MAP,

        ]}));
		
   
    map.setCurrentCity("北京");          // 设置地图显示的城市 此项是必须设置的
    map.enableScrollWheelZoom(true);     //开启鼠标滚轮缩放
    map.enableContinuousZoom();                              // 启用连续缩放效果
	 // 地图平移缩放控件
    map.addControl(new BMap.NavigationControl({anchor: BMAP_ANCHOR_TOP_RIGHT}));
    map.addControl(new BMap.ScaleControl());              // 显示比例尺在右下角
	
    //设备地图颜色
    var mapStyle={
        style:"midnight"
    };
    map.setMapStyle(mapStyle);


//加载城市控件
    var size = new BMap.Size(10, 50);
    map.addControl(new BMap.CityListControl({
        anchor: BMAP_ANCHOR_TOP_LEFT,
        offset: size,


    }));
	
	 // 数据库
    initDatabase();
	
	 // 事件
    map.addEventListener("click", MouseClick);
	
	try{
		
		for(var i = 0; i < g_cameraGisList.length; i++) {
			var ipc = getCameraNode(g_cameraGisList[i].id);
			if(ipc == null) {
				continue;
			}
			addMarker(ipc.id, ipc.name, g_cameraGisList[i].longitude, g_cameraGisList[i].latitude, ipc.status)
		}
		 
	}catch(e){
		
	}
}


/**
 * 初始化本地数据库
 */
function initDatabase() {
    db = new loki("gis.db");
    dbColl["markers"] = db.addCollection("markers", ["id"]);
}

/**
 * 生成uuid
 * @param len
 * @param radix
 * @returns {string}
 */
function uuid(len, radix) {
    var chars = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'.split('');
    var uuid = [], i;
    radix = radix || chars.length;

    if (len) {
        // Compact form
        for (i = 0; i < len; i++) uuid[i] = chars[0 | Math.random() * radix];
    } else {
        // rfc4122, version 4 form
        var r;

        // rfc4122 requires these characters
        uuid[8] = uuid[13] = uuid[18] = uuid[23] = '-';
        uuid[14] = '4';

        // Fill in random data. At i==19 set the high bits of clock sequence as
        // per rfc4122, sec. 4.1.5
        for (i = 0; i < 36; i++) {
            if (!uuid[i]) {
                r = 0 | Math.random()*16;
                uuid[i] = chars[(i == 19) ? (r & 0x3) | 0x8 : r];
            }
        }
    }

    return uuid.join('');
}



/**
 * marker右键菜单
 * @type {[*]}
 */
var txtMarkerMenuItem = [
    {
        text: '播放实时视频',
        callback: function(e, ee, marker) {
            if (window.external.dblclick){
                window.external.dblclick(marker.camResId, marker.camResName);
            }
        }
    },
    {
        text: ''
    },
    {
        text: '删除点位',
        callback: function(e, ee, marker) {
            if (window.external.delmarker) {
                var result = window.external.delmarker(marker.camResId);
                eval("result=" + result);
                if (result.errcode == 0) {
                    dbColl["markers"].findAndRemove({
                        id: {
                            "$eq": marker.camResId
                        }
                    });
                    map.removeOverlay(marker);
                }
            }
        }
    },
    {
        text: ''
    },
    {
        text: '刷新点位',
        callback: function(e, ee, marker) {

        }
    },
    {
        text: ''
    },
    {
        text: '开始点位编辑',
        callback: function(e, ee, marker) {
            marker.isDragging = true;
            marker.enableDragging();
        }
    },
    {
        text: '结束点位编辑',
        callback: function(e, ee, marker) {
            marker.isDragging = false;
            marker.disableDragging();

            // 更新位置
            var id = marker.camResId;
            var point = marker.getPosition();
            if (window.external.updateChannelPos) {
                window.external.updateChannelPos(id, point.lng, point.lat);
            }
        }
    }
];

/**
 * 添加标注
 * @param nodeid
 * @param nodename
 * @param longitude
 * @param latitude
 */
function addMarker(nodeid, nodename, longitude, latitude, status) {
    var title = nodename + "(" + longitude + "," + latitude + ")";
    var point = new BMap.Point(longitude, latitude);      // 创建点坐标
    var imgPath = (status == "1") ? "img/camera_online.png" : "img/no-camera_online.png";
    var cabinIcon = new BMap.Icon(imgPath, new BMap.Size(32, 37));
    var cabinMarkerOptions = {
        icon: cabinIcon,
        enableDragging: false
    };
 //   map.centerAndZoom(point, 12);                      // 初始化地图,设置中心点坐标和地图级别
    var cabinMarker = new BMap.Marker(point);
    cabinMarker.setAnimation(BMAP_ANIMATION_DROP);
    cabinMarker.camResId = nodeid;
    cabinMarker.camResName = nodename;

    map.addOverlay(cabinMarker);
    //MarkMap[nodeid] = cabinMarker;

    // 插入数据库
    dbColl["markers"].insert({
        "id": nodeid,
        "name": nodename,
        "marker": cabinMarker
    });

    // 设置标注
    var label = new BMap.Label(nodename + "("+point.lng+", "+point.lat+")", {offset: BMap.Size(20, -10)});
    label.setStyle({ display : "none" });
    cabinMarker.setLabel(label);

    // 添加右键菜单
   // addMarkerCtxMenu(cabinMarker);

    cabinMarker.addEventListener("dblclick", function () {
       // window.external.dblclick(nodeid, cabinMarker.getTitle());
    });
    cabinMarker.addEventListener("mouseover", function(event) {
        cabinMarker.setTop(true);
        label.setStyle({ display : "block", left: "33px", top: "5px" });
    });
    cabinMarker.addEventListener("mouseout", function(event) {
        cabinMarker.setTop(true);
        label.setStyle({ display : "none" });
    });
    cabinMarker.addEventListener("dragging", function(event) {
        label.setStyle({ display : "block", left: "33px", top: "5px" });
        label.setContent(nodename + "(" + event.point.lng.toFixed(8) + "," + event.point.lat.toFixed(8) + ")");
    });
    cabinMarker.addEventListener("dragend", function(event) {
        label.setStyle({ display : "none" });
    });
}

/**
 * marker添加右键菜单
 *
 * @param marker
 */
function addMarkerCtxMenu(marker) {
    var markerMenu = new BMap.ContextMenu();
    for (var i = 0;  i < txtMarkerMenuItem.length; ++i) {
        var item = txtMarkerMenuItem[i];
        if (item.text != "") {
            markerMenu.addItem(new BMap.MenuItem(item.text, item.callback, menuItemOptions));
        } else {
            markerMenu.addSeparator();
        }
    }
    markerMenu.marker = marker;
    marker.addContextMenu(markerMenu);
    markerMenu.addEventListener("open", function(event) {
        var menu = event.currentTarget;
        if (marker.isDragging) {
            menu.getItem(3).disable();
            menu.getItem(4).enable();
        } else {
            menu.getItem(3).enable();
            menu.getItem(4).disable();
        }
    });
}

/**
 * 鼠标单击事件
 *
 * @param e
 * @constructor
 */
function MouseClick(e) {
    if (window.external.MouseClick) {
        window.external.MouseClick(e.point.lng, e.point.lat);
    }
}

/**
 * 设置摄像机图标
 * @param id
 * @param online
 */
function setMarkerIcon(id, online) {
    var obj = getMarkerById(id);
    if (obj) {
        var icon = obj.marker.getIcon();
        if (icon) {
            var iconPath = (online == "1") ? "img/camera_online.png" : "img/no-camera_online.png";
            icon.setImageUrl(iconPath);
        }
    }
}

/**
 * 批量设置图标
 * @param data
 */
function batchSetMarkerIcon(data) {
    if (data == null || data == "")
        return;
    var arr = JSON.parse(data);
    for (var i = 0; i < arr.length; i++) {
        var obj = getMarkerById(arr[i].id);
        if (obj) {
            var iconPath = (arr[i].status == 1) ? "img/camera_online.png" : "img/no-camera_online.png";
            obj.marker.setImageUrl(iconPath);
        }
    }
}

/**
 * 设置告警图标
 * @param id
 */
function setMarkerAlarmIcon(id) {
    var obj = getMarkerById(id);
    if (obj) {
        //obj.marker.setImageUrl("images/camera_alarm.png")
        obj.marker.setAnimation(BMAP_ANIMATION_BOUNCE);
        setTimeout(function() {
            obj.marker.setAnimation(null);
        }, 60000);
    }
}

/**
 * 查找Marker记录
 * @param markerId
 * @returns {Object|null}
 */
function getMarkerById(markerId) {
    return dbColl["markers"].findOne({
        id: {
            "$eq": markerId
        }
    });
}

/**
 * 显示所有标注
 */
function ShowAllMarker() {
    var arrayOverlays = map.getOverlays();
    for (var i = 0; i < arrayOverlays.length; i++) {
        arrayOverlays[i].show();
    }
}

/**
 * 隐藏标注
 */
function HideAllMarker() {
    var arrayOverlays = map.getOverlays();
    for (var i = 0; i < arrayOverlays.length; i++) {
        arrayOverlays[i].hide();
    }
}

/**
 * 删除标注
 */
function DeleteMarker(nodeid) {
    var obj = getMarkerById(nodeid);
    if (obj) {
        map.removeOverlay(obj.marker);
        if (window.external.delmarker) {
            window.external.delmarker(nodeid)
        }
        dbColl["markers"].remove(obj);
    }
}

/**
 * 添点到默认位置
 * @param id
 * @param name
 * @returns {string}
 */
function addMarkerDefault(id, name, status) {
    var point = map.getCenter();
    addMarker(id, name, point.lng, point.lat, status);
    return (point.lng + " " + point.lat);
}

/**
 * 编辑Marker
 * @param id
 * @param flag  true enable otherwise disable
 * @constructor
 */
function EditMarker(id, flag) {
    var obj = getMarkerById(id);
    if (obj) {
        flag ? obj.marker.enableDragging() : obj.marker.disableDragging();
    }
}

/**
 * 转到点位
 * @param id
 */
function gotoMarker(id) {
    var obj = getMarkerById(id);
    if (obj) {
        map.centerAndZoom(obj.marker.getPosition(), 12);
    }
}

/**
 * 闪烁点位
 * @param id
 */
function animateMarker(id) {
    var obj = getMarkerById(id);
    if (obj) {
        var marker = obj.marker;
        map.centerAndZoom(marker.getPosition(), 12);
        marker.setAnimation(BMAP_ANIMATION_BOUNCE);
        setTimeout(function() {
            marker.setAnimation(null);
        }, 1000);
    }
}