<%@ page contentType="text/html;charset=UTF-8" pageEncoding="GBK"%>
<%@ page import="javax.servlet.jsp.*"%>
<%
String path = request.getContextPath(); 
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";


String iconTypes= request.getParameter("iconTypes");
String carnames = "";
if(request.getParameter("carnames") != null){
	carnames = new String(request.getParameter("carnames").getBytes("ISO-8859-1"),"gbk");
}
String carids= request.getParameter("carids");
String startTime= request.getParameter("startTime");
String endTime= request.getParameter("endTime");
%>


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
		<META HTTP-EQUIV="pragma" CONTENT="no-cache">
		<META HTTP-EQUIV="Cache-Control" CONTENT="no-cache, must-revalidate">
		<META HTTP-EQUIV="expires" CONTENT="Wed, 26 Feb 1900 08:21:57 GMT">
		<meta http-equiv="content-type" content="text/html; charset=GB2312" />
		<title>网上查车</title>
    <meta name="viewport" content="initial-scale=1.0, user-scalable=no">
    <meta charset="utf-8">
    <style>
      html, body, #map-canvas {
        height: 100%;
        margin: 0px;
        padding: 0px
      }
      .map_tanchu_wrap{background:#fff; border:1px solid #000; overflow:hidden; position: absolute; height:180px; line-height:17px; width:170px; font-family: Arial, Helvetica, sans-serif;padding:10px;}
    </style>
	<style>
	    .mask {position: absolute;top: 0px;filter: alpha(opacity=60);background-color: #FFF;z-index: 999;left: 0px;opacity:0.5;-moz-opacity:0.6;}       
    	.content{display:none;z-index:1000;position:fixed; text-align:center; color:#0d96e5; font-size:14px;}
	</style>
 <script type="text/javascript" src="http://ditu.google.cn/maps/api/js?sensor=false"></script>
 <script type="text/javascript" src="http://ditu.google.cn/maps/api/js?sensor=false&libraries=drawing&key=AIzaSyDZis631eei5VArZqB-lP2DDOSgPrhLR5A"></script>
 <script src="<%=path%>/gpsonline/js/table/jquery.min.js"></script>
<script>
	//初始化  
function getScript(src) {
		    $("head").append("<script src='"+src+"'><\/script>");
}
(function($){
    jQuery.fn.center = function () {  
        this.css('position','absolute');  
         this.css('top', ( $(window).height() - this.height() ) /2 +$(window).scrollTop() + 'px');  
         this.css('left', ( $(window).width() - this.width() ) / 2+$(window).scrollLeft() + 'px');  
         return this;  
    }  
})(jQuery);  //调用：$("#macoArea").center();
function openMask(){
	$("#mask").css({"height":"100%","width":"100%"}).show();		
	$(".content").show();
	$('#content').center();
	
}
function closeMask(){
    $("#mask").hide();
    $(".content").hide();
}
var map;
var max=0;
var tnum = 0;

var lnglat;

var dtype=1; //
var iconTypes = '<%=iconTypes%>';
var carnames='<%=carnames%>';
var carids='<%=carids%>';
var startTime='<%=startTime%>';
var endTime='<%=endTime%>';
var gotime;
var dayNums = 0;
var Ascending =0;
var Ascend =0;
var setT;
var times =[];

var arr =[];
var iconType=[];
var carname_=[];

var timesType=0;
var bol = false;
var array=[];
var topics = [];
var alldata = []; 
var speedvalue=500;
var url="<%=basePath%>";
var color1="#FF0000";
var color2="#9400D3";
var color3="#1E90FF";
var color4="#000000";
var color5="#008B00";
var data1;
var data2;
var data3;
var data4;
var data5;
var flightPath1;
var flightPath2;
var flightPath3;
var flightPath4;
var flightPath5;
var marker1;
var marker2;
var marker3;
var marker4;
var marker5;
var ibLabel1;
var ibLabel2;
var ibLabel3;
var ibLabel4;
var ibLabel5;
function initialize() {
    //初始化地图参数
	var mapOptions = {
          zoom: 5,
	  scaleControl: true,
          center: new google.maps.LatLng(34.2638, 108.9469),
	  streetViewControl: true,
	  mapTypeControl: true,
          mapTypeId: google.maps.MapTypeId.ROADMAP
        };
	map = new google.maps.Map(document.getElementById("map-canvas"), mapOptions);
	google.maps.event.addListener(map, 'click', function(e) {
		if(ibLabel1 != null){
			ibLabel1.close();
		}
		if(ibLabel2 != null){
			ibLabel2.close();
		}
		if(ibLabel3 != null){
			ibLabel3.close();
		}
		if(ibLabel4 != null){
			ibLabel4.close();
		}
		if(ibLabel5 != null){
			ibLabel5.close();
		}
	});
	arr = carids.split(",");
	iconType= iconTypes.split(",");
	carname_= carnames.split(",");
	
	Ascend = arr.length;
	for(var i=0;i<arr.length;i++){
		//alert(arr[i]);
	}
	lnglat = new google.maps.LatLngBounds();
	openMask();
	countTime(startTime,endTime);
}

function countTime(start,end){
	   var s2 = start;
	   var s1 = end;
	   s2 = s2.replace("-","/");
						s2=s2.replace("-","/");
						s2=s2.replace("T"," ");
	   s1 = s1.replace("-","/");
						s1=s1.replace("-","/");
						s1=s1.replace("T"," ");
	   var time = (new Date(s1).getTime()-new Date(s2).getTime());
	   //计算出相差天数
	   var day=new Date(s2).dateDiff("h",new Date(s1));
	   var days = day/24;
		if(new Date(s2).getHours()>new Date(s1).getHours()){
			days++;
		}
						
		var	date = new Date();
		date.setTime(new Date(s2.substring(0,10)+" 00:00:00").getTime()+(24*3600*1000-1000));
		days=parseInt(days);
			
			var time2 = "";
			var time3 = s1.substring(10,20);
			if(days>0){
				for(var k=0;k<=days;k++){
					if(k==0){
						times.push(s2+"|"+date.Format("yyyy/MM/dd hh:mm:ss"));
						date.setTime(new Date(s2.substring(0,10)+" 00:00:00").getTime()+(24*3600*1000));
						time2=date.Format("yyyy/MM/dd hh:mm:ss");
					}else if(k==days){
						date.setTime(new Date(s1.substring(0,10)+" "+time3).getTime());
						time3=date.Format("yyyy/MM/dd hh:mm:ss");
						times.push(time2+"|"+time3);
					}else{
						date.setTime(new Date(time2).getTime()+(24*3600*1000-1000));
						times.push(time2+"|"+date.Format("yyyy/MM/dd hh:mm:ss"));
						date.setTime(new Date(time2).getTime()+(24*3600*1000));
						time2=date.Format("yyyy/MM/dd hh:mm:ss");
					}
				}
				
			}else{
				times.push(s2+"|"+s1);
			}
			getScript("<%=basePath%>gpsonline/js/infobox.js");  
			dayNums=times.length;
			
			//AjaxGetData(times,datas);
			
			forGetData(times);
			for(var i=0;i<times.length;i++){
				//alert(times[i]);
			}
			setT=setTimeout("MapData()",500);
			
			
}

function forGetData(times){
 	
	carid = arr[Ascending];
	document.getElementById('loadingMsg').innerHTML = "正在读取 "+carname_[Ascending]+" 轨迹数据...";
	if(carid != ""){
	     	
	}
	for(var i=0;i<times.length;i++){
		$.ajax({
	        type: "POST",
	        dataType: "json", 
	        url: "<%=basePath%>pub/vehicleAction_GetJsonVdata.action",
			//data:{ vhcid:carid,cret:null,vehicle:"",key:"e617a19e0b2621bffb239dc0eb836bdf",
			//begin_time:times[i].substring(0,19).replace("/","-").replace("/","-"),end_time:times[i].substring(20,40).replace("/","-").replace("/","-"),datatype:1,intermin:0,timeorder:0,
			//ip:"117.21.178.22",port:"89",dtype:dtype,timeorder:timesType,interface:1},
			data:{ vhcid:carid,cret:null,vehicle:"",key:"e617a19e0b2621bffb239dc0eb836bdf",
			begin_time:times[i].substring(0,19).replace("/","-").replace("/","-"),end_time:times[i].substring(20,40).replace("/","-").replace("/","-"),datatype:1,intermin:0,timeorder:0,
			ip:"",port:"",dtype:dtype,timeorder:timesType},
	        success: function(data){
		        if(data.result==true){
			        if(data.topics.length>0){
			        		bol=true;
		        	}
		        	topics.push(data.topics);
		        	
		        }else{
		        	if(data.statecode=="10000"){
		        		alert("请先登录");
		        	}
		        }
	        },
	        error: function() {
	           
			}
	   });
	}
	
}

function forGetData2(times){
   		  if(dtype=="0"){
		   			dtype=1;
		  }else{
		   			dtype=0;
		  }
	for(var i=0;i<times.length;i++){
	
		$.ajax({
	        type: "POST",
	        dataType: "json", 
	        url: "<%=basePath%>pub/vehicleAction_GetJsonVdata.action",
			//data:{ vhcid:carid,cret:null,vehicle:"",key:"e617a19e0b2621bffb239dc0eb836bdf",
			//begin_time:times[i].substring(0,19).replace("/","-").replace("/","-"),end_time:times[i].substring(20,40).replace("/","-").replace("/","-"),datatype:1,intermin:0,timeorder:0,
			//ip:"117.21.178.22",port:"89",dtype:dtype,timeorder:timesType,interface:1},
			data:{ vhcid:carid,cret:null,vehicle:"",key:"e617a19e0b2621bffb239dc0eb836bdf",
			begin_time:times[i].substring(0,19).replace("/","-").replace("/","-"),end_time:times[i].substring(20,40).replace("/","-").replace("/","-"),datatype:1,intermin:0,timeorder:0,
			ip:"",port:"",dtype:dtype,timeorder:timesType,interface:1},
	        success: function(data){
	          if(data.result==true){
			      topics.push(data.topics);
		      }else{
		        	if(data.statecode=="10000"){
		        		alert("请先登录");
		        	}
		      }
	        },
	        error: function() {
	           
			}
	   });
	}
}


function MapData(){
	//alldata.push(array);
	//alert(topics.length+"   "+dayNums);
   	if(topics.length >= dayNums){
   		//alert(topics[10].length);
   		if(bol==false){
   			bol = true;
   			topics=[];
   			forGetData2(times);
   			setTimeout("MapData()",500);
   			
   			
   		}else{
   			
   			clearTimeout(setT);
   			if(times.length==1){
				alldata=topics;
			}else{
		   		for(var i=0;i<times.length;i++){
		   			for(var j=0;j<topics.length;j++){
		   				if(topics[j].length>0){
		   					if(new Date(times[i].substring(0,19)) < new Date(topics[j][0].recvt.replace("-","/").replace("-","/")) && new Date(times[i].substring(20,40)) > new Date(topics[j][0].recvt.replace("-","/").replace("-","/"))){
		   						alldata[i]=topics[j];
			   				}
		   				}
		   			}
		   		}
		   	}
	   		var datas = new Object();
			datas.topics = [];
	   		for(var k=0;k<alldata.length;k++){
	   			if(alldata[k]!=null && alldata[k].length>0){
	   				datas.topics=datas.topics.concat(alldata[k])
	   			}
	   		}
	   		
	   		
	   		if(datas.topics.length>max){
		   		
	   			max=datas.topics.length;
			}
	   		if(Ascending==0){
	   	    	data1=datas;
		    }
		    if(Ascending==1){
		    	data2=datas;
		    }
		    if(Ascending==2){
		    	data3=datas;
		    }
		    if(Ascending==3){
		    	data4=datas;
		    }
		    if(Ascending==4){
		    	data5=datas;
		    }
	   		DrawMap(datas,0);
	   		
	   	   
		
	   		/*if(datas.topics.length>0){
		   		
				
				
	   		}else{
		  		 times.length=0;
				 bol=false;
			 	 alert("对不起，没有找到行驶数据，请重新选择。");
	   		}*/
   		}
   		
   	}else{
   		setTimeout("MapData()",500);
   	}
}
function setIcon(icon){
	iconTypes=icon;
}
function DrawMap(datas,xb){
	
	if(datas.topics.length>0){
 	car = datas;
	
 	var cname=carname_[Ascending];
 
	var i=xb-1;
	var flightPlanCoordinates = [];
	while(i<(datas.topics.length-1)){
		i++;
	    flightPlanCoordinates.push(new google.maps.LatLng((datas.topics[i].lat+datas.topics[i].lat_xz),(datas.topics[i].lng+datas.topics[i].lng_xz)));
	    lnglat.extend(new google.maps.LatLng((datas.topics[i].lat+datas.topics[i].lat_xz),(datas.topics[i].lng+datas.topics[i].lng_xz)));
	}
	 var rgb = "";
	    if(Ascending==0){
	    	rgb=color1;
	    	flightPath1 = new google.maps.Polyline({
	  	      path: flightPlanCoordinates,
	  	      strokeColor: rgb,
	  	      strokeOpacity: 1.0,
	  	      strokeWeight: 3
	  	    });
	  	 	flightPath1.setMap(map);
	    }
	    if(Ascending==1){
	    	rgb=color2;
	    	flightPath2 = new google.maps.Polyline({
		  	      path: flightPlanCoordinates,
		  	      strokeColor: rgb,
		  	      strokeOpacity: 1.0,
		  	      strokeWeight: 3
		  	    });
		  	 	flightPath2.setMap(map);
	    }
	    if(Ascending==2){
	    	rgb=color3;
	    	flightPath3 = new google.maps.Polyline({
		  	      path: flightPlanCoordinates,
		  	      strokeColor: rgb,
		  	      strokeOpacity: 1.0,
		  	      strokeWeight: 3
		  	    });
		  	 	flightPath3.setMap(map);
	    }
	    if(Ascending==3){
	    	rgb=color4;
	    	flightPath4 = new google.maps.Polyline({
		  	      path: flightPlanCoordinates,
		  	      strokeColor: rgb,
		  	      strokeOpacity: 1.0,
		  	      strokeWeight: 3
		  	    });
		  	 	flightPath4.setMap(map);
	    }
	    if(Ascending==4){
	    	rgb=color5;
	    	flightPath5 = new google.maps.Polyline({
		  	      path: flightPlanCoordinates,
		  	      strokeColor: rgb,
		  	      strokeOpacity: 1.0,
		  	      strokeWeight: 3
		  	    });
		  	 	flightPath5.setMap(map);
	    }
	
			var s=10;
			var condition=car.topics[xb].state;
		  	var sp = parseInt(car.topics[xb].veo);
		  
		  	if (condition != null){
			if (condition.indexOf("不在线")>=0 || condition.indexOf("掉线")>=0)
				s = 2;
			else {
				if (condition.indexOf("速报警")>=0)
					s = 4;
				else if (condition.indexOf("报警")>=0)
					s = 3;
				else if (sp > 0.5)
					s = 0;
				else
					s = 1;

			}
			if (s != 4 && s != 3 && condition.indexOf("停车")>=0
					&& !condition.indexOf("不在线")>= 0){
										if(condition.indexOf("停车超时")>=0){
											s = 5;	
										}else{
											s = 6;
										}
								}
		}else{
			if (sp > 0.5)
				s = 0;
			else
				s = 1;
		}
	  	var state =s;
	  	var pngicon = "<%=basePath%>gpsonline/image/pic/"+iconType[Ascending]+"/red_0.gif";
		if(state == 0) pngicon = "<%=basePath%>gpsonline/image/pic/"+iconType[Ascending]+"/green_";
		else if(state == 1) pngicon = "<%=basePath%>gpsonline/image/pic/"+iconType[Ascending]+"/red_";
		else if(state == 2) pngicon = "<%=basePath%>gpsonline/image/pic/"+iconType[Ascending]+"/gray_";
		else if(state == 3) pngicon = "<%=basePath%>gpsonline/image/pic/"+iconType[Ascending]+"/yellow_";
		else if(state == 4) pngicon = "<%=basePath%>gpsonline/image/pic/"+iconType[Ascending]+"/pink_";
		else if(state == 5) pngicon = "<%=basePath%>gpsonline/image/pic/"+iconType[Ascending]+"/stopalarm";
		else pngicon = "<%=basePath%>gpsonline/image/pic/"+iconType[Ascending]+"/red_";
	  var ti = parseInt(car.topics[0].dir);
	  				if(ti>27 &&ti<=72){
				  		if(state == 5){
				  			var image=".gif";
				  		}else{
				  			var image="45.gif";
				  		}
						direction="东北";
					}else if(ti>72 && ti<=117){
						if(state == 5){
				  			var image=".gif";
				  		}else{
				  			var image="90.gif";
				  		}
						
						direction="东";
					}
					else if(ti>117 && ti<=162){
						if(state == 5){
				  			var image=".gif";
				  		}else{
				  			var image="135.gif";
				  		}
						direction="东南";
					}
					else if(ti>162 && ti<=207){
						if(state == 5){
				  			var image=".gif";
				  		}else{
				  			var image="180.gif";
				  		}
						direction="南";
					}
					else if(ti>207 && ti<=252){
						if(state == 5){
				  			var image=".gif";
				  		}else{
				  			var image="225.gif";
				  		}
						direction="西南";
					}
					else if(ti>252 && ti<=297){
						if(state == 5){
				  			var image=".gif";
				  		}else{
				  			var image="270.gif";
				  		}
						direction="西";
					}
					else if(ti>297 && ti<=342){
						if(state == 5){
				  			var image=".gif";
				  		}else{
				  			var image="315.gif";
				  		}
						direction="西北";
					}
					else {
						if(state == 5){
				  			var image=".gif";
				  		}else{
				  			var image="0.gif";
				  		}
						direction="北";
					}
			
	  var html="<div class='map_tanchu_wrap'>"
			    +"<b>设备名称：</b>"+cname+"</br>"
					+"<b>接收时间：</b>"+car.topics[xb].recvt+"</br>"
					+"<b>速度：</b>"+car.topics[xb].veo.toFixed(1)+"km/h </br>"
					+"<b>方向：</b>"+direction+"</br>"
					+"<b>状态：</b>"+car.topics[xb].state+"</br>"
					+"<b>位置：</b>"+car.topics[xb].posinfo+"</br>"
					+"</div>";


	   
	   

	    if(Ascending==0){
	    	 marker1 = new google.maps.Marker({
	   	      position: new google.maps.LatLng((datas.topics[xb].lat+datas.topics[xb].lat_xz),(datas.topics[xb].lng+datas.topics[xb].lng_xz)),
	   	      map: map,
	   	      icon: new google.maps.MarkerImage(pngicon+image, new google.maps.Size(30, 30),new google.maps.Point(0,0),new google.maps.Point(10, 10)),
	   	      title:carname_[Ascending]
	   		 });	
	    	 var myOptions = {
					 content: html
					,disableAutoPan: true
					
					,pixelOffset: new google.maps.Size(5, -210)
					,boxStyle: { 
					   
					 }
					,closeBoxURL: ""
					,infoBoxClearance: new google.maps.Size(1, 1)
					,isHidden: false
					,pane: "floatPane"
					,enableEventPropagation: false
			};	
			ibLabel1 = new InfoBox(myOptions);

			google.maps.event.addListener(marker1, "mouseover", function (e) {
				if(ibLabel1 != null){
					ibLabel1.close();
				}
				if(ibLabel2 != null){
					ibLabel2.close();
				}
				if(ibLabel3 != null){
					ibLabel3.close();
				}
				if(ibLabel4 != null){
					ibLabel4.close();
				}
				if(ibLabel5 != null){
					ibLabel5.close();
				}
				ibLabel1.open(map, this);
			});		
			google.maps.event.addListener(marker1, "mouseout", function() { 
				if(ibLabel1 != null){
					ibLabel1.close();
				}
			} );	
	    }
	    if(Ascending==1){
	    	 marker2 = new google.maps.Marker({
	   	      position: new google.maps.LatLng((datas.topics[xb].lat+datas.topics[xb].lat_xz),(datas.topics[xb].lng+datas.topics[xb].lng_xz)),
	   	      map: map,
	   	      icon: new google.maps.MarkerImage(pngicon+image, new google.maps.Size(30, 30),new google.maps.Point(0,0),new google.maps.Point(10, 10)),
	   	      title:carname_[Ascending]
	   		});	
	    	 var myOptions = {
					 content: html
					,disableAutoPan: true
					
					,pixelOffset: new google.maps.Size(5, -210)
					,boxStyle: { 
					   
					 }
					,closeBoxURL: ""
					,infoBoxClearance: new google.maps.Size(1, 1)
					,isHidden: false
					,pane: "floatPane"
					,enableEventPropagation: false
			};	
			ibLabel2 = new InfoBox(myOptions);

			google.maps.event.addListener(marker2, "mouseover", function (e) {
				if(ibLabel1 != null){
					ibLabel1.close();
				}
				if(ibLabel2 != null){
					ibLabel2.close();
				}
				if(ibLabel3 != null){
					ibLabel3.close();
				}
				if(ibLabel4 != null){
					ibLabel4.close();
				}
				if(ibLabel5 != null){
					ibLabel5.close();
				}
				ibLabel2.open(map, this);
			});
			google.maps.event.addListener(marker2, "mouseout", function() { 
				if(ibLabel2 != null){
					ibLabel2.close();
				}
			} );			
	    }
	    if(Ascending==2){
	    	 marker3 = new google.maps.Marker({
	   	      position: new google.maps.LatLng((datas.topics[xb].lat+datas.topics[xb].lat_xz),(datas.topics[xb].lng+datas.topics[xb].lng_xz)),
	   	      map: map,
	   	      icon: new google.maps.MarkerImage(pngicon+image, new google.maps.Size(30, 30),new google.maps.Point(0,0),new google.maps.Point(10, 10)),
	   	      title:carname_[Ascending]
	   		});	
	    	 var myOptions = {
					 content: html
					,disableAutoPan: true
					
					,pixelOffset: new google.maps.Size(5, -210)
					,boxStyle: { 
					   
					 }
					,closeBoxURL: ""
					,infoBoxClearance: new google.maps.Size(1, 1)
					,isHidden: false
					,pane: "floatPane"
					,enableEventPropagation: false
			};	
			ibLabel3 = new InfoBox(myOptions);

			google.maps.event.addListener(marker3, "mouseover", function (e) {
				if(ibLabel1 != null){
					ibLabel1.close();
				}
				if(ibLabel2 != null){
					ibLabel2.close();
				}
				if(ibLabel3 != null){
					ibLabel3.close();
				}
				if(ibLabel4 != null){
					ibLabel4.close();
				}
				if(ibLabel5 != null){
					ibLabel5.close();
				}
				ibLabel3.open(map, this);
			});
			google.maps.event.addListener(marker3, "mouseout", function() { 
				if(ibLabel3 != null){
					ibLabel3.close();
				}
			} );		
	    }
	    if(Ascending==3){
	    	 marker4 = new google.maps.Marker({
	   	      position: new google.maps.LatLng((datas.topics[xb].lat+datas.topics[xb].lat_xz),(datas.topics[xb].lng+datas.topics[xb].lng_xz)),
	   	      map: map,
	   	      icon: new google.maps.MarkerImage(pngicon+image, new google.maps.Size(30, 30),new google.maps.Point(0,0),new google.maps.Point(10, 10)),
	   	      title:carname_[Ascending]
	   		});	
	    	 var myOptions = {
					 content: html
					,disableAutoPan: true
					
					,pixelOffset: new google.maps.Size(5, -210)
					,boxStyle: { 
					   
					 }
					,closeBoxURL: ""
					,infoBoxClearance: new google.maps.Size(1, 1)
					,isHidden: false
					,pane: "floatPane"
					,enableEventPropagation: false
			};	
			ibLabel4 = new InfoBox(myOptions);

			google.maps.event.addListener(marker4, "mouseover", function (e) {
				if(ibLabel1 != null){
					ibLabel1.close();
				}
				if(ibLabel2 != null){
					ibLabel2.close();
				}
				if(ibLabel3 != null){
					ibLabel3.close();
				}
				if(ibLabel4 != null){
					ibLabel4.close();
				}
				if(ibLabel5 != null){
					ibLabel5.close();
				}
				ibLabel4.open(map, this);
			});	
			google.maps.event.addListener(marker4, "mouseout", function() { 
				if(ibLabel4 != null){
					ibLabel4.close();
				}
			} );			
	    }
	    if(Ascending==4){
	    	 marker5 = new google.maps.Marker({
	   	      position: new google.maps.LatLng((datas.topics[xb].lat+datas.topics[xb].lat_xz),(datas.topics[xb].lng+datas.topics[xb].lng_xz)),
	   	      map: map,
	   	      icon: new google.maps.MarkerImage(pngicon+image, new google.maps.Size(30, 30),new google.maps.Point(0,0),new google.maps.Point(10, 10)),
	   	      title:carname_[Ascending]
	   		});	
	    	 var myOptions = {
					 content: html
					,disableAutoPan: true
					
					,pixelOffset: new google.maps.Size(5, -210)
					,boxStyle: { 
					   
					 }
					,closeBoxURL: ""
					,infoBoxClearance: new google.maps.Size(1, 1)
					,isHidden: false
					,pane: "floatPane"
					,enableEventPropagation: false
			};	
			ibLabel5 = new InfoBox(myOptions);

			google.maps.event.addListener(marker5, "mouseover", function (e) {
				if(ibLabel1 != null){
					ibLabel1.close();
				}
				if(ibLabel2 != null){
					ibLabel2.close();
				}
				if(ibLabel3 != null){
					ibLabel3.close();
				}
				if(ibLabel4 != null){
					ibLabel4.close();
				}
				if(ibLabel5 != null){
					ibLabel5.close();
				}
				ibLabel5.open(map, this);
			});	
			google.maps.event.addListener(marker5, "mouseout", function() { 
				if(ibLabel5 != null){
					ibLabel5.close();
				}
			} );			
	    }

	   
 }
	 bol=false;
	 topics.length=0;
	 clearTimeout(setT);
	 Ascending++;
	 if(Ascending<Ascend){
		 	forGetData(times);
			setT=setTimeout("MapData()",500);
	 }else{
		 map.fitBounds(lnglat);
		
		 
		 closeMask();
		 gotime=setTimeout("go()",speedvalue);
	 }
}


function go(){
	//alert(data1);
	al(data1,marker1,iconType[0],ibLabel1,carname_[0]);
	al(data2,marker2,iconType[1],ibLabel2,carname_[1]);
	al(data3,marker3,iconType[2],ibLabel3,carname_[2]);
	al(data4,marker4,iconType[3],ibLabel4,carname_[3]);
	al(data5,marker5,iconType[4],ibLabel5,carname_[4]);
	gotime=setTimeout("go()",speedvalue);
}

function al(data,marker,icon,ibLabel,cname){
	if(data!=null && data.topics.length>tnum){
		car=data;
		var s=10;
		var condition=car.topics[tnum].state;
	  	var sp = parseInt(car.topics[tnum].veo);
	  	if (condition != null){
		if (condition.indexOf("不在线")>=0 || condition.indexOf("掉线")>=0)
			s = 2;
		else {
			if (condition.indexOf("速报警")>=0)
				s = 4;
			else if (condition.indexOf("报警")>=0)
				s = 3;
			else if (sp > 0.5)
				s = 0;
			else
				s = 1;
		}
		if (s != 4 && s != 3 && condition.indexOf("停车")>=0
				&& !condition.indexOf("不在线")>= 0){
									if(condition.indexOf("停车超时")>=0){
										s = 5;	
									}else{
										s = 6;
									}
							}
		}else{
			if (sp > 0.5)
				s = 0;
			else
				s = 1;
		}
		
	  	var state =s;
	  	var pngicon = "<%=basePath%>gpsonline/image/pic/"+icon+"/red_0.gif";
		if(state == 0) pngicon = "<%=basePath%>gpsonline/image/pic/"+icon+"/green_";
		else if(state == 1) pngicon = "<%=basePath%>gpsonline/image/pic/"+icon+"/red_";
		else if(state == 2) pngicon = "<%=basePath%>gpsonline/image/pic/"+icon+"/gray_";
		else if(state == 3) pngicon = "<%=basePath%>gpsonline/image/pic/"+icon+"/yellow_";
		else if(state == 4) pngicon = "<%=basePath%>gpsonline/image/pic/"+icon+"/pink_";
		else if(state == 5) pngicon = "<%=basePath%>gpsonline/image/pic/"+icon+"/stopalarm";
		else pngicon = "<%=basePath%>gpsonline/image/pic/"+icon+"/red_";
	 
	  var ti = parseInt(car.topics[tnum].dir);
	  				if(ti>27 &&ti<=72){
				  		if(state == 5){
				  			var image=".gif";
				  		}else{
				  			var image="45.gif";
				  		}
						direction="东北";
					}else if(ti>72 && ti<=117){
						if(state == 5){
				  			var image=".gif";
				  		}else{
				  			var image="90.gif";
				  		}
						
						direction="东";
					}
					else if(ti>117 && ti<=162){
						if(state == 5){
				  			var image=".gif";
				  		}else{
				  			var image="135.gif";
				  		}
						direction="东南";
					}
					else if(ti>162 && ti<=207){
						if(state == 5){
				  			var image=".gif";
				  		}else{
				  			var image="180.gif";
				  		}
						direction="南";
					}
					else if(ti>207 && ti<=252){
						if(state == 5){
				  			var image=".gif";
				  		}else{
				  			var image="225.gif";
				  		}
						direction="西南";
					}
					else if(ti>252 && ti<=297){
						if(state == 5){
				  			var image=".gif";
				  		}else{
				  			var image="270.gif";
				  		}
						direction="西";
					}
					else if(ti>297 && ti<=342){
						if(state == 5){
				  			var image=".gif";
				  		}else{
				  			var image="315.gif";
				  		}
						direction="西北";
					}
					else {
						if(state == 5){
				  			var image=".gif";
				  		}else{
				  			var image="0.gif";
				  		}
						direction="北";
					}

	  				
					var html="<div class='map_tanchu_wrap'>"
							    +"<b>设备名称：</b>"+cname+"</br>"
								+"<b>接收时间：</b>"+car.topics[tnum].recvt+"</br>"
								+"<b>速度：</b>"+car.topics[tnum].veo.toFixed(1)+"km/h </br>"
								+"<b>方向：</b>"+direction+"</br>"
								+"<b>状态：</b>"+car.topics[tnum].state+"</br>"
								+"<b>位置：</b>"+car.topics[tnum].posinfo+"</br>"
							+"</div>";		
	  				marker.setIcon(new google.maps.MarkerImage(pngicon+image, new google.maps.Size(30, 30),new google.maps.Point(0,0),new google.maps.Point(10, 10)));
					marker.setPosition(new google.maps.LatLng((car.topics[tnum].lat+car.topics[tnum].lat_xz),(car.topics[tnum].lng+car.topics[tnum].lng_xz)));
					ibLabel.setContent(html);

					}
	tnum++;
	if(tnum>max){
		//remove();
	}
}

function remove(){
	clearTimeout(gotime);
	data1=null;
	data2=null;
	data3=null;
	data4=null;
	data5=null;
	if(flightPath1 !=null){
		flightPath1.setMap(null);
	}
	if(flightPath2 !=null){
		flightPath2.setMap(null);
	}
	if(flightPath3 !=null){
		flightPath3.setMap(null);
	}
	if(flightPath4 !=null){
		flightPath4.setMap(null);
	}
	if(flightPath5 !=null){
		flightPath5.setMap(null);
	}
	if(marker1 !=null){
		marker1.setMap(null);
	}
	if(marker2 !=null){
		marker2.setMap(null);
	}
	if(marker3 !=null){
		marker3.setMap(null);
	}
	if(marker4 !=null){
		marker4.setMap(null);
	}
	if(marker5 !=null){
		marker5.setMap(null);
	}
}

Date.prototype.dateDiff = function(interval,endTime){
    switch (interval)
    {
         //計算秒差
         case "s":
                    return parseInt((endTime-this)/1000);

         //計算分差
         case "n":
                    return parseInt((endTime-this)/60000);

         //計算時差
         case "h":	
                    return parseInt((endTime-this)/3600000);

         //計算日差
         case "d":
                    return parseInt((endTime-this)/86400000);

         //計算週差
         case "w":
                    return parseInt((endTime-this)/(86400000*7));

         //計算月差
         case "m":
                     return (endTime.getMonth()+1)+((endTime.getFullYear()-this.getFullYear())*12)-(this.getMonth()+1);

        //計算年差
        case "y":
                   return endTime.getFullYear()-this.getFullYear();

        //輸入有誤
        default:
                   return undefined;
     }
}
Date.prototype.Format = function (fmt) { //author: meizz 
    var o = {
        "M+": this.getMonth() + 1, //月份 
        "d+": this.getDate(), //日 
        "h+": this.getHours(), //小时 
        "m+": this.getMinutes(), //分 
        "s+": this.getSeconds(), //秒 
        "q+": Math.floor((this.getMonth() + 3) / 3), //季度 
        "S": this.getMilliseconds() //毫秒 
    };
    if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
    for (var k in o)
    if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
    return fmt;
}
google.maps.event.addDomListener(window, 'load', initialize);


</script>
  </head>
  <body>
    <div id="map-canvas"></div>
	<div id="mask" class="mask"></div>
	<div class="content" id="content">
	      <img src="<%=path%>/gpsonline/image/monitor/loading.gif"></img>
	      <div style="text-align:center; margin-top:10px;"><span id="loadingMsg"></span></div>
	</div>
  </body>
</html>