<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@page import="cn.exlive.mygpsonline.util.MyApplicationContextUtil"%>
<%
String path = request.getContextPath(); 
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!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>
<style type="text/css"> 
     html{height:100%}
	 body{height:100%;margin:0px;padding:0px}
     #map_canvas{position: absolute; width:100%;height:100%; bottom:0px; }
     #container_baidu{height:100%}
</style>
<style type="text/css">
.guiji_ceng{margin-left:25px; overflow:hidden;}
.b1,.b2,.b3,.b4,.b1b,.b2b,.b3b,.b4b,.b{display:block;}
.b1,.b2,.b3,.b1b,.b2b,.b3b{height:1px; display:block;}
.b2,.b3,.b4,.b2b,.b3b,.b4b,.b{border-left:1px solid #999;border-right:1px solid #999;}
.b1,.b1b{margin:0 5px;background:#999;}
.b2,.b2b{margin:0 3px;border-width:2px;}
.b3,.b3b{margin:0 2px;}
.b4,.b4b{height:2px;margin:0 1px;}
.b{  padding: 2px 10px;  font-size:12px; line-height:20px; border:1px solid #999; border-radius: 7px;}
.b_1{ padding: 2px 10px;  font-size:12px; line-height:20px; border-left:1px solid #999;border-right:1px solid #999;white-space:nowrap;}
.d1{background:#F7F8F9;}
.guiji_sanjiao{font-size:0px; line-height:0px; width:0px; height:0px; border-width:10px; border-style:dashed solid dashed dashed; border-color:transparent #666 transparent transparent; position:absolute; margin-left:-20px; margin-top:-42px;}
.guiji_sanjiao_2{font-size:0px; line-height:0px; width:0px; height:0px; border-width:10px; border-style:dashed solid dashed dashed; border-color:transparent #F7F8F9 transparent transparent; position:absolute;  margin-left:-19px; margin-top:-42px;}
</style>
    <script type="text/javascript" src="http://api.map.baidu.com/api?v=1.5&amp;ak=<%=MyApplicationContextUtil.map_baidu_key%>"></script>
    <!--<script type="text/javascript" src="http://ditu.google.cn/maps/api/js?sensor=false&libraries=drawing&key=AIzaSyDZis631eei5VArZqB-lP2DDOSgPrhLR5A"></script> -->
    <link href="<%=path%>/gpsonline/css/monitor/v3/login.css" rel="stylesheet" type="text/css" />
    
    <script type="text/javascript"	src="<%=basePath%>/gpsonline/js/baiduMap/baiduMapBack.js"></script>
	<script type="text/javascript" src="<%=path%>/gpsonline/js/MianMap/MianMap.js"></script>
	<script type="text/javascript" src="<%=path%>/gpsonline/js/google/google.js"></script>
<script type="text/javascript">
	function getScript(src){
			    $("head").append("<script src='"+src+"'><\/script>");
	}	
	
   var map;
   var tnum = 0;
   var mapOptions; 
   var url="<%=basePath%>";
   var switchb = true;
   var marker;
   var vehicle;
   var oldStart;
   var oldEnd;
   var infowindow;
   var carid;
   var stopCarList = [];
   var stopCarTime = 600000;
   var markerStops = [];
   var markerPhotos = [];
   (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();
    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;
}
   function openMask(){
		$("#mask").css({"height":"100%","width":"100%"}).show();		
		$(".content").show();
		$('#content').center();
		
	}
	function closeMask(){
	    $("#mask").hide();
	    $(".content").hide();
	}
   function g(o){return document.getElementById(o);}
   
   function  onZoomEnd(){
	   for(var j=0;j<markerPhotos.length;j++){
       		markerPhotos[j].infoWin.close();
	    }
       for(var j=0;j<markerStops.length;j++){
	          markerStops[j].infoWin.close();
	    }
   }
   var gjtriesLimtes = 0;//限制次数 获取谷歌地图api 次数限制为10次 超多 就提示
   function initialize2(){
	    if(typeof(google)=="undefined"){
		    if(gjtriesLimtes>=10){
				alert("获取谷歌地图api失败，稍候尝试!");
				return;
			}
		    gjtriesLimtes ++;
			setTimeout('initialize2()',500);
			return;
		}
   		loadTime();
   		var secheltLoc = new google.maps.LatLng(34, 108);
		var myMapOptions = {
			 zoom: 4
			,center: secheltLoc
			,mapTypeId: google.maps.MapTypeId.ROADMAP,
	          mapTypeControlOptions: {
                   mapTypeIds: [google.maps.MapTypeId.ROADMAP, google.maps.MapTypeId.HYBRID, google.maps.MapTypeId.SATELLITE, "MAPabc"]
               }
		};
		map = new google.maps.Map(document.getElementById("map_canvas"), myMapOptions);
		
		getScript("<%=basePath%>gpsonline/js/infobox.js");
		var type = g("uType").value;
		var name = g("uName").value;
		var pass = g("uPass").value;
		var startTime = g("startTime").value;
		var endTime = g("endTime").value;
		var jiekoukg = false;
		if(name != "null" && pass != "null"){
		     if(type == "null"){
		     	type=-100;
		     }
			 $('#startplay').attr('disabled', true);
			 $.ajax({
			       type: "POST",
			       dataType: "json",
			       cache:true,
			       url: "json/loginAction_login.action?request_locale=zh_CN",
			       data: { userName: name, userPass: pass,userType:type},
			       success: function(json) {
				         if (json.flag==true) {	  
				        	$('#startplay').attr('disabled', false);
				        	document.getElementById("carid").value=json.data[0].id;
							if(startTime!="null" && endTime != "null"){
							  startTime = startTime.replace("-","/");
							  startTime=startTime.replace("-","/");
							  startTime=startTime.replace("T"," ");
				   					
				 			  endTime = endTime.replace("-","/");
							  endTime=endTime.replace("-","/");
							  endTime=endTime.replace("T"," ");
								  if(new Date(endTime).getTime() - new Date(startTime).getTime()<=864000000){
									  $("#start").val(startTime);
									  $("#end").val(endTime);
									  play();
								  }else{
								  	alert_("对不起，日期数据不合法，请对照接口文档检查.");
								  }
							}
		  
		
				         }else {
				         	  var name2 = g("uName2").value;
				        	  $.ajax({
							       type: "POST",
							       dataType: "json",
							       cache:true,
							       url: "json/loginAction_login.action?request_locale=zh_CN",
							       data: { userName: name2, userPass: pass,userType:type},
							       success: function(json) {
								         if (json.flag==true) {	  
								        	$('#startplay').attr('disabled', false);
								        	document.getElementById("carid").value=json.data[0].id;
								        	 if(startTime!="null" && endTime != "null"){
								        	  startTime = startTime.replace("-","/");
											  startTime=startTime.replace("-","/");
											  startTime=startTime.replace("T"," ");
								   					
								 			  endTime = endTime.replace("-","/");
											  endTime=endTime.replace("-","/");
											  endTime=endTime.replace("T"," ");
												 if(new Date(endTime).getTime() - new Date(startTime).getTime()<=864000000){
													 $("#start").val(startTime);
													 $("#end").val(endTime);
												 	play();
												 }else{
												  	alert_("对不起，日期数据不合法，请对照接口文档检查.");
												 }
											 }
								         }else {
								        	  alert_(json.msg);
								         }
							       },
							       error: function() {
							            //alert_('获取账号信息失败...请稍后重试!');
							       }
							  });
				         }
			       },
			       error: function() {
			            //alert_('获取账号信息失败...请稍后重试!');
			       }
			  });
		}
		else if(startTime!="null" && endTime != "null"){
			// $("#start").val(startTime);
			// $("#end").val(endTime);
			 $("#start").val(startTime);
			 $("#end").val(endTime);
	
		      startTime = startTime.replace("-","/");
			  startTime=startTime.replace("-","/");
			  startTime=startTime.replace("T"," ");
   					
 			  endTime = endTime.replace("-","/");
			  endTime=endTime.replace("-","/");
			  endTime=endTime.replace("T"," ");
			  if(new Date(endTime).getTime() - new Date(startTime).getTime()<=5184000000){
			  	play();
			  }else{
			  	  alert_("对不起，日期数据不合法或超出60天。");
			  }
		}
			
		addMAPabc(map);
		startMarker();
		openMarkerPanel();
   }
   var dayNums = 0;
   var Ascending =0;
   function DrawMap(datas,xb){
  
					if(datas.topics.length>0){
					
			     		$( "#slider" ).slider( "option", "max", datas.topics.length-1);
			     		car = datas;
			      		mapOptions = {
					          center: new google.maps.LatLng((datas.topics[xb].lat+datas.topics[xb].lat_xz),(datas.topics[xb].lng+datas.topics[xb].lng_xz)),
					          zoom: 13,
					          mapTypeId: google.maps.MapTypeId.ROADMAP,
						          mapTypeControlOptions: {
				                    mapTypeIds: [google.maps.MapTypeId.ROADMAP, google.maps.MapTypeId.HYBRID, google.maps.MapTypeId.SATELLITE, "MAPabc"]
				                }
				        };
				        map = new google.maps.Map(document.getElementById("map_canvas"),
				            mapOptions);


				        google.maps.event.addListener(map, "dragend", function(e) {
							
							  for(var j=0;j<markerPhotos.length;j++){
						       		markerPhotos[j].infoWin.close();
							    }
						       for(var j=0;j<markerStops.length;j++){
							          markerStops[j].infoWin.close();
							    }
						       
							});
							
						google.maps.event.addListener(map, "zoom_changed",function(e) {
							  for(var j=0;j<markerPhotos.length;j++){
						       		markerPhotos[j].infoWin.close();
							    }
						       for(var j=0;j<markerStops.length;j++){
							          markerStops[j].infoWin.close();
							    }
						});
						google.maps.event.addListener(map, "click", function(e) {
							  for(var j=0;j<markerPhotos.length;j++){
						       		markerPhotos[j].infoWin.close();
							    }
						       for(var j=0;j<markerStops.length;j++){
							          markerStops[j].infoWin.close();
							    }
						});
			            
				        getScript("<%=basePath%>gpsonline/js/infobox.js");
			            addMAPabc(map);
				        qidian = 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: url+"gpsonline/image/map/marker_qidian.png",
					      title:"起点"
					    });
					    zhongdian = new google.maps.Marker({
					      position: new google.maps.LatLng((datas.topics[datas.topics.length-1].lat+datas.topics[datas.topics.length-1].lat_xz),(datas.topics[datas.topics.length-1].lng+datas.topics[datas.topics.length-1].lng_xz)),
					      map: map,
					      icon: url+"gpsonline/image/map/marker_zhongdian.png",
					      title:"终点"
					    });
					   
				    //画线
				    var rgb = "#00A";
					var i=xb-1;
					var flightPlanCoordinates = [];
					while(i<(datas.topics.length-1)){
						i++;
						if(wuxiaobool==false &&datas.topics[i].av=="0"){

						}else{
							flightPlanCoordinates.push(new google.maps.LatLng((datas.topics[i].lat+datas.topics[i].lat_xz),(datas.topics[i].lng+datas.topics[i].lng_xz)));
									 
						}
					  
					}
					var flightPath = new google.maps.Polyline({
					      path: flightPlanCoordinates,
					      strokeColor: rgb,
					      strokeOpacity: 1.0,
					      strokeWeight: 3
					    });
					 flightPath.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/<%=request.getParameter("icon")%>/red_0.gif";
						if(state == 0) pngicon = "<%=basePath%>gpsonline/image/pic/<%=request.getParameter("icon")%>/green_";
						else if(state == 1) pngicon = "<%=basePath%>gpsonline/image/pic/<%=request.getParameter("icon")%>/red_";
						else if(state == 2) pngicon = "<%=basePath%>gpsonline/image/pic/<%=request.getParameter("icon")%>/gray_";
						else if(state == 3) pngicon = "<%=basePath%>gpsonline/image/pic/<%=request.getParameter("icon")%>/yellow_";
						else if(state == 4) pngicon = "<%=basePath%>gpsonline/image/pic/<%=request.getParameter("icon")%>/pink_";
						else if(state == 5) pngicon = "<%=basePath%>gpsonline/image/pic/<%=request.getParameter("icon")%>/stopalarm";
						else pngicon = "<%=basePath%>gpsonline/image/pic/<%=request.getParameter("icon")%>/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 carname = '<%=request.getParameter("carname")%>';
					      	// var b = new Base64();  
					        // var str =b.decode(carname);  
							
							
					  var html="<div class='guiji_ceng'>"
								+"<b class='b1'></b>"
							    +"<b class='b2 d1'></b>"
							    +"<b class='b3 d1'></b>"
							    +"<b class='b4 d1'></b>"
							    +"<div class='b_1 d1'><b>设备名称：</b>"+strCarName+"</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].oil.toFixed(1)+" L </br>"
									+"<b>状态：</b>"+car.topics[xb].state+"</br>"
									+"<b>当日里程：</b>"+(car.topics[xb].totaldistance-car.topics[0].totaldistance).toFixed(2)+" km </br>"
									+"<b>总里程：</b>"+car.topics[xb].totaldistance.toFixed(2)+" km </br>"
									+"</div> <b class='b4b d1'></b>"
									    +"<b class='b3b d1'></b>"
									    +"<b class='b2b d1'></b>"
									    +"<b class='b1b'></b>"
									    +"<div> <span class='guiji_sanjiao'></span>"
    									+"<span class='guiji_sanjiao_2'></span></div>"
									+"</div>";

		/*var myOptions = {
			 content: html,
			 zIndex:1000
			,boxStyle: {
				
			 }
			,disableAutoPan: true
			,pixelOffset: new google.maps.Size(-5, -82)
			,position: new google.maps.LatLng((datas.topics[xb].lat+datas.topics[xb].lat_xz),(datas.topics[xb].lng+datas.topics[xb].lng_xz))
			,closeBoxURL: ""
			,isHidden: false
			,pane: "mapPane"
			,enableEventPropagation: false
		};*/
		 var myOptions = {
							 content: html
							,disableAutoPan: false
							,maxWidth: 0
							,pixelOffset: new google.maps.Size(-5, -140)
							,zIndex: null
							,boxStyle: { 
							
							 }
							,closeBoxMargin: "10px 10px 0px -20px"
							,closeBoxURL: ""
							,infoBoxClearance: new google.maps.Size(1, 1)
							,isHidden: false
							,pane: "floatPane"
							,enableEventPropagation: false
						};			
		var ibLabel = new InfoBox(myOptions);
								var icon_id=<%=request.getParameter("icon")%>;
								var icon_size=real(icon_id);
								marker = 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(icon_size, icon_size),new google.maps.Point(0,0),new google.maps.Point(10, 10)),
								      title:"x"
								});	 
								
								google.maps.event.addListener(marker, "click", function (e) {
									ibLabel.open(map, this);
								});
								ibLabel.open(map,marker);					
								vehicle = new Object();
								vehicle.marker = marker;
								vehicle.infowindow = ibLabel;
				
					 $("#startplay").val("暂停回放");
	   		 		 playkg = true;
	   				 curveb = true;
	   		 		 $( "#slider" ).slider( "option", "disabled", false );
	   		 		 closeMask();
	   		 		 curve();
	   		 		 clearTimeout(setT);
				 }
   		
}
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;
         }
   }

   var setT;
   var times =[];
   function initialize(start,end){
	   openMask();
	   var s2 = start;
	   var s1 = end;
	   if(s2 == "" || s1 == ""){
			alert("结束或开始时间不能为空!");
			return;
	   }	
	   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);
		}
		dayNums=times.length;
		//AjaxGetData(times,datas);
		topics = [];
		topics.length =0;
		forGetData(times);
		setT=setTimeout("MapData()",500);
    }
    var bol = false;
    function forGetData(times){
    	carid = document.getElementById("carid").value;
    	 if(carid == "null"){
		     	carid="";
		     }
    	var loadType= "";
	   		if(dtype==0){
	   			loadType= "轨迹文件";
	   		}else{
	   			loadType= "数据库";
	   		}
	   
		document.getElementById('loadingMsg').innerHTML = "正在从"+loadType+"读取轨迹数据";
		console.info(times.length);
    	for(var i=0;i<times.length;i++){
        	console.info(times[i].substring(0,19));
    		$.ajax({
		        type: "POST",
		        dataType: "json", 
		        url: "json/vehicleAction_GetJsonVdata.action",
		        //data:{ vhcid:"5418464",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:"125.64.92.118",port:"89",dtype:dtype,timeorder:timesType,interface:1},
				data:{ vhcid:carid,cret:null,vehicle:carname,key:"e617a19e0b2621bffb239dc0eb836bdf",
				begin_time:times[i].substring(0,19).replace("/","-").replace("/","-"),end_time:times[i].substring(20,40).replace("/","-").replace("/","-"),datatype:tingchedianbool,intermin:0,timeorder:0,
				ip:"",port:"",dtype:dtype,timeorder:timesType,LbsIsShow:jzIsShow,bfIsShow:bfIsShow},
		        success: function(data){
			        console.info(JSON.stringify(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){
    
    	var loadType= "";
	   		  if(dtype=="0"){
			   			dtype=1;
			   			loadType= "数据库";
			  }else{
			   			dtype=0;
			   			loadType= "轨迹文件";
			  }
		document.getElementById('loadingMsg').innerHTML = "正在从"+loadType+"读取轨迹数据";
		
    	for(var i=0;i<times.length;i++){
    		$.ajax({
		        type: "POST",
		        dataType: "json", 
		        url: "json/vehicleAction_GetJsonVdata.action",
				//data:{ vhcid:"5418464",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:"125.64.92.118",port:"89",dtype:dtype,timeorder:timesType,interface:1},
				data:{ vhcid:carid,cret:null,vehicle:carname,key:"e617a19e0b2621bffb239dc0eb836bdf",
				begin_time:times[i].substring(0,19).replace("/","-").replace("/","-"),end_time:times[i].substring(20,40).replace("/","-").replace("/","-"),datatype:tingchedianbool,intermin:0,timeorder:0,
				ip:"",port:"",dtype:dtype,timeorder:timesType,LbsIsShow:jzIsShow,bfIsShow:bfIsShow},
		        success: function(data){
		          if(data.result==true){
				      topics.push(data.topics);
			      }else{
			        	if(data.statecode=="10000"){
			        		alert_("请先登录");
			        	}
			      }
		        },
		        error: function(){
		           
				}
		   });
    	}
    }
     //导出
     function DownLoadTrack(){
    		 var btime = $("#start").val();
    		 var etime = $("#end").val();
    		 if(btime == "" || etime == ""){
    				alert("结束或开始时间不能为空!");
    				return;
    		   }	
    		 var s2 = btime.replace("-","/");
    		 var s1 = etime.replace("-","/");
    		  
    		 var day=new Date(s2).dateDiff("d",new Date(s1));
    		 if(day >=5){
    			alert("下载轨迹不能超过5天!");
 				return;
             }
    		 carid = document.getElementById("carid").value;
    		 var key = "e617a19e0b2621bffb239dc0eb836bdf";
    		 var params = "vhcid="+carid+"&vehicle="+carname+"&key="+key+
    		 "&begin_time="+btime+"&end_time="+etime+"&datatype="+tingchedianbool+"&intermin=0&timeorder=0"+
    		 "&ip=&port=&dtype=1&timeorder="+timesType+"&excel=1";
    		 var url ="json/vehicleAction_trackExcel.action?"+params;
    		 var str = "<%=basePath%>";
 			 window.location.href= str + url;
    	}
     
    var array=[];
    function MapData(){
    	//alldata.push(array);
	   	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>0){
		   			document.getElementById('loadingMsg').innerHTML = "正在绘制轨迹路线...";
		   			
		   			var s = datas.topics[0].gpst.replace("-","/");
					s=s.replace("-","/");
					var date1=new Date(s);  //开始时间
					var s2 = datas.topics[datas.topics.length-1].gpst.replace("-","/");
					s2=s2.replace("-","/");
					var date2=new Date(s2);    //结束时间
					//alert_(date2);
					var date3=date2.getTime()-date1.getTime();  //时间差的毫秒数
					//alert_(date2.getTime());
					//计算出相差天数
					var days=Math.floor(date3/(24*3600*1000));
					//计算出小时数
					var leave1=date3%(24*3600*1000);    //计算天数后剩余的毫秒数
					var hours=Math.floor(leave1/(3600*1000));
					//计算相差分钟数
					var leave2=leave1%(3600*1000) ;       //计算小时数后剩余的毫秒数
					var minutes=Math.floor(leave2/(60*1000));
					 
					//计算相差秒数
					var leave3=leave2%(60*1000);     //计算分钟数后剩余的毫秒数
					var seconds=Math.round(leave3/1000);
					if(days==0){
						document.getElementById("time").innerHTML="时间："+hours+" 小时  "+minutes+"  分钟   "+seconds+" 秒";
					}else{
						document.getElementById("time").innerHTML="时间："+days+" 天  "+hours+" 小时  "+minutes+"  分钟   "+seconds+" 秒";
					}
					/*if(datas.topics[0].oil != null){
						if(datas.topics[datas.topics.length-1].oil-datas.topics[0].oil==0){
							document.getElementById("youh").style.display="none";
						}else{
							document.getElementById("youh").innerHTML="油耗："+(datas.topics[datas.topics.length-1].oil-datas.topics[0].oil)+" 升";
						} 
					}else{
							document.getElementById("youh").style.display="none";
						}*/
					/*if(datas.topics[0].totaldistance != null){
						if(datas.topics[datas.topics.length-1].totaldistance-datas.topics[0].totaldistance<=0){
							document.getElementById("lic").style.display="none";
							document.getElementById("lic").innerHTML="里程："+rldis+"公里";
						}else{
							document.getElementById("lic").innerHTML="里程："+((datas.topics[datas.topics.length-1].totaldistance-datas.topics[0].totaldistance).toFixed(2))+"公里";
						}
					}else{
							document.getElementById("lic").style.display="none";
					}*/
		   			if(1==mapType){
						baiduMapDraw(datas,0);
					}else{
						DrawMap(datas,0);
					}
		   		}else{
		   			 closeMask();
				 	 $("#startplay").val("轨迹回放");
				 	 $('#f5').attr('disabled', true);
				 	 $('#end').attr('disabled', false); 
			  		 $('#start').attr('disabled', false);
			  		 times.length=0;
			  		 var radio = document.getElementsByName("gjdata");
					 for(var i=0;i<radio.length;i++){
						  if(radio[i].checked==true){
						  	dtype=radio[i].value;
						  }
					 }
					 bol=false;
				 	 alert_("对不起，没有找到行驶数据，请重新选择。");
		   		}
	   		}
	   		
	   	}else{
	   		setTimeout("MapData()",500);
	   	}
   }
    function al(){
    	if( playkg == true){
		    if(tnum<car.topics.length){
		    				switchb = false;
		    				$( "#slider" ).slider( "option", "value", tnum );
		    				if(wuxiaobool==false &&car.topics[tnum].av=="0") return;
							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/<%=request.getParameter("icon")%>/red_0.gif";
						if(state == 0) pngicon = "<%=basePath%>gpsonline/image/pic/<%=request.getParameter("icon")%>/green_";
						else if(state == 1) pngicon = "<%=basePath%>gpsonline/image/pic/<%=request.getParameter("icon")%>/red_";
						else if(state == 2) pngicon = "<%=basePath%>gpsonline/image/pic/<%=request.getParameter("icon")%>/gray_";
						else if(state == 3) pngicon = "<%=basePath%>gpsonline/image/pic/<%=request.getParameter("icon")%>/yellow_";
						else if(state == 4) pngicon = "<%=basePath%>gpsonline/image/pic/<%=request.getParameter("icon")%>/pink_";
						else if(state == 5) pngicon = "<%=basePath%>gpsonline/image/pic/<%=request.getParameter("icon")%>/stopalarm";
						else pngicon = "<%=basePath%>gpsonline/image/pic/<%=request.getParameter("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 carname2 = '<%=request.getParameter("carname")%>';
							 var html ="<div class='guiji_ceng'>"
								+"<b class='b1'></b>"
							    +"<b class='b2 d1'></b>"
							    +"<b class='b3 d1'></b>"
							    +"<b class='b4 d1'></b>"
							    +"<div class='b_1 d1'> <b>设备名称：</b>"+strCarName+"</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].oil.toFixed(1)+" L </br>"
													+"<b>状态：</b>"+car.topics[tnum].state+"</br>"
													//+"<b>当日里程：</b>"+(car.topics[tnum].totaldistance-car.topics[0].totaldistance).toFixed(2)+" km </br>"
													+"<b>总里程：</b>"+car.topics[tnum].totaldistance.toFixed(2)+" km </br>"
										+"</div> <b class='b4b d1'></b>"
									    +"<b class='b3b d1'></b>"
									    +"<b class='b2b d1'></b>"
									    +"<b class='b1b'></b>"
									    +"<div> <span class='guiji_sanjiao'></span>"
    									+"<span class='guiji_sanjiao_2'></span></div>"
									+"</div>";
									
								var icon_id=<%=request.getParameter("icon")%>;
								var icon_size=real(icon_id);
								
								vehicle.marker.setIcon(new google.maps.MarkerImage(pngicon+image, new google.maps.Size(icon_size,icon_size),new google.maps.Point(0,0),new google.maps.Point(10, 10)));
								vehicle.marker.setPosition(new google.maps.LatLng((car.topics[tnum].lat+car.topics[tnum].lat_xz),(car.topics[tnum].lng+car.topics[tnum].lng_xz)));
								
								vehicle.infowindow.setContent(html);
								//vehicle.infowindow.setPosition(new google.maps.LatLng((car.topics[tnum].lat+car.topics[tnum].lat_xz),(car.topics[tnum].lng+car.topics[tnum].lng_xz)));
								vehicle.infowindow.panBox_();
								
							if(photobool==true && car.topics[tnum].photo !="" && car.topics[tnum].photo !=null){
								for(var i = tnum;i < tnum+1; i++) {
						        	(function(n){
								           var markerPhoto = new google.maps.Marker({
											      position:new google.maps.LatLng((car.topics[tnum].lat+car.topics[tnum].lat_xz),(car.topics[tnum].lng+car.topics[tnum].lng_xz)),
											      map: map,
											      icon:url+"gpsonline/image/map/photo.png"//new google.maps.MarkerImage(pngicon+image, new google.maps.Size(30, 30),new google.maps.Point(0,0),new google.maps.Point(10, 10)),
											      
											});

								           var myOptions = {
													 content: "<div style='position:absolute;margin-top:-300px;border:1px solid #ccc; background:#fff; padding:5px;'>"
															+"<div> <img src='"+photourl+car.topics[tnum].photo+"'/></div>"
															+"</div>"
													,disableAutoPan: true
													
													,pixelOffset: new google.maps.Size(-145, 0)
													,boxStyle: {
																
													 }
													,closeBoxURL: ""
													,infoBoxClearance: new google.maps.Size(1, 1)
													,isHidden: false
													,pane: "floatPane"
													,enableEventPropagation: false
												};
									
									
										var infoWin = new InfoBox(myOptions);
											
										
											var markerPhotoManager = new Object();
											markerPhotoManager.markerPhoto = markerPhoto;
											markerPhotoManager.infoWin = infoWin;
											markerPhotos.push(markerPhotoManager);
								            google.maps.event.addListener(markerPhoto, 'click', function(e) {
								                for(var j=0;j<markerPhotos.length;j++){
								                	markerPhotos[j].infoWin.close();
											    }
								                for(var j=0;j<markerStops.length;j++){
											          markerStops[j].infoWin.close();
											    }
								                infoWin.open(map,markerPhoto);
								            });
								        })(i);
							    }
							}	
							if(sp==0){
								stopCar= new Object();
								stopCar.time = car.topics[tnum].recvt;
								stopCar.latlng =new google.maps.LatLng((car.topics[tnum].lat+car.topics[tnum].lat_xz),(car.topics[tnum].lng+car.topics[tnum].lng_xz));
								stopCarList.push(stopCar);
						  	}else{
						  		if(stopCarList.length>0){
						  			var stopTime =stopCarList[0].time.replace("-","/");
									stopTime=stopTime.replace("-","/");
									stopTime=stopTime.replace("T"," ");
									
									var startTime =car.topics[tnum].recvt.replace("-","/");
									startTime=startTime.replace("-","/");
									startTime=startTime.replace("T"," ");
									
									var timeStr = new Date(startTime).getTime()- new Date(stopTime).getTime();

									if(timeStr>stopCarTime){
										var days=Math.floor(timeStr/(24*3600*1000));
										//计算出小时数
										var leave1=timeStr%(24*3600*1000);    //计算天数后剩余的毫秒数
										var hours=Math.floor(leave1/(3600*1000));
										//计算相差分钟数
										var leave2=leave1%(3600*1000) ;       //计算小时数后剩余的毫秒数
										var minutes=Math.floor(leave2/(60*1000));
										 
										//计算相差秒数
										var leave3=leave2%(60*1000);     //计算分钟数后剩余的毫秒数
										var seconds=Math.round(leave3/1000);
										var timeMsg = "";
										if(days==0){
											timeMsg=""+hours+" 小时  "+minutes+"  分钟   "+seconds+" 秒";
										}else{
											timeMsg="停车时间："+days+" 天  "+hours+" 小时  "+minutes+"  分钟   "+seconds+" 秒";
										}
									    for(var i = tnum;i < tnum+1; i++) {
								        	(function(n){
										           var markerStop = new google.maps.Marker({
													      position: stopCarList[0].latlng,
													      map: map,
													      icon:  url+"gpsonline/image/map/marker_stop.png"//new google.maps.MarkerImage(pngicon+image, new google.maps.Size(30, 30),new google.maps.Point(0,0),new google.maps.Point(10, 10)),
													      
													});
													var infoWin = new google.maps.InfoWindow({
												        map: map,
												        content:"<b>停车时间：</b>"+timeMsg+"</br>"
													+"<b>开始时间：</b>"+stopTime+"</br>"
													+"<b>结束时间：</b>"+startTime+"</br>"
													+"<b>位置：</b>"+car.topics[tnum].posinfo+"</br>"
												    });
												    infoWin.close();
													var markerStopManager = new  Object();
													markerStopManager.markerStop = markerStop;
													markerStopManager.infoWin = infoWin;
													markerStops.push(markerStopManager);
										            google.maps.event.addListener(markerStop, 'click', function(e) {
										            	 for(var j=0;j<markerPhotos.length;j++){
											                	markerPhotos[j].infoWin.close();
														    }
											                for(var j=0;j<markerStops.length;j++){
														          markerStops[j].infoWin.close();
														    }
										                infoWin.open(map,markerStop);
										            });
										        })(i);
									    }
									}else{
									
									}
								    stopCarList.length=0;
						  		}
						  	}
							$("#mingxi_main").scrollTop($("#mingxi_main")[0].scrollHeight);
		
			}else{
			   //curveb = false;
			   playkg = false;
			   $("#startplay").val("开始回放");
		   	   tnum=0;
		   	   //$( "#slider" ).slider( "option", "disabled", false );
			}
			switchb = true;
		}
    }
   function DblClick(id){
   		
 	  	
   }
   $( "#slider" ).slider({
 	 change: function( event, ui ){
 	 			//	curveb = false;
 	 		
 	 		if(switchb == true){
 	 				curveb = false;
 	 				clearTimeout(yctime);
 	 				tnum = ui.value;
 	 				var tnun = ui.value;
 	 				if(car!=null){
					  	  var chart = $('#container').highcharts();
					      if (chart.series.length) {
					             chart.series[0].setData([]);
					             chart.series[1].setData([]);
					             chart.series[2].setData([]);
					      }
					      for(var i=0;i<=car.topics.length;i++){
					      		$('#row'+i).remove();
					      }
					  	  $("#startplay").val("轨迹回放");
					  	  row_count = 1;
				  	}
				  	 if(1==mapType){
				  	 	baiduMap();
				  	 	markers.length=0;
					    baiduMapDraw(car,ui.value);
					  }else{
						DrawMap(car,ui.value);
					  }
					playkg = true;
					//alcurve();
 	 		}
 	 	}
   });
  //地图添加MAPabc
	function addMAPabc(map){//添加MAPabc的瓦片 参数为地图对象  
	    var _tileSize = new google.maps.Size(256,256);
	    var getTileUrl = function(tile,zoom){
	        return "http://emap" + ((tile.x + tile.y) % 4) + ".mapabc.com/mapabc/maptile?v=w2.99&x=" + tile.x + "&y=" + tile.y + "&zoom=" + (17-zoom);  
	    }; 
	    var imageMapType = new google.maps.ImageMapType({alt:"MAPabc",isPng:true,maxZoom:18,minZoom:1,name:"MAPabc",tileSize: new google.maps.Size(256, 256),opacity:1.0,getTileUrl:getTileUrl});  
	    map.mapTypes.set('MAPabc',imageMapType);  
	}  
	
	/*为了工程机械共用一个页面*/
	function alert_(msg){
		if(typeof(parent.ExMsg) == "undefined"){
			alert(msg);
		}else{
			parent.ExMsg.alert("轨迹回放", msg);
		}
	}
	
</script>
<style type="text/css">


.address{width: 420px; height: 20px; line-height: 20px; position: absolute; z-index: 10; background: none repeat scroll 0 0 #F7F7F7; }
.address span{display:inline-block; float:left;}
.address .map_time{margin-left:5px; margin-right:15px;}


/*--map 弹出框--*/
.map_tanchu_wrap p{
margin:0; 
padding:5px 10px; 
font-size:12px;
background:#fff;
}
.map_tanchu_wrap {
background: transparent; 
width:300px; 
margin:0 3px;
margin-left:100px;
box-shadow:0px 2px 2px #d9d7d4
}

.xtop, .xbottom {
display:block; 
background:transparent; 
font-size:1px;
}
.xb1, .xb2, .xb3, .xb4 {
display:block; 
overflow:hidden;
}
.xb1, .xb2, .xb3 {
height:1px;
}
.xb2, .xb3, .xb4 {
background:#fff; 
border-left:1px solid #c2c1be;
border-right:1px solid #c2c1be;
}
.xb1 {
margin:0 5px; 
background:#c2c1be;
}
.xb2 {
margin:0 3px;
border-width:0 2px;
}
.xb3 {
margin:0 2px;
}
.xb4 {
height:2px; 
margin:0 1px;
}

.xboxcontent {
display:block; 
border:0 solid #c2c1be; 
border-width:0 1px; 
height:auto;

}

span {
	_overflow: hidden;
}
.arrow {
	position: absolute;
	margin-top:-2px;
	margin-left:50px;
	width: 0;
	height: 0;
	font-size: 0;
	border-width: 12px;
	border-style: solid dashed dashed dashed;
	border-color: #ffffff transparent transparent transparent;
	z-index:20;
}
.arrow_bg{
	position: absolute;
	margin-top:-1px;
	margin-left:50px;
	width: 0;
	height: 0;
	font-size: 0;
	border-width: 12px;
	border-style: solid dashed dashed dashed;
	border-color: #c2c1be transparent transparent transparent;
	z-index:15;
}

.arrow1 {
	position: absolute;
	margin-top:-2px;
	margin-left:150px;
	width: 0;
	height: 0;
	font-size: 0;
	border-width: 12px;
	border-style: solid dashed dashed dashed;
	border-color: #ffffff transparent transparent transparent;
	z-index:20;
}
.arrow_bg1{
	position: absolute;
	margin-top:-1px;
	margin-left:150px;
	width: 0;
	height: 0;
	font-size: 0;
	border-width: 12px;
	border-style: solid dashed dashed dashed;
	border-color: #c2c1be transparent transparent transparent;
	z-index:15;
}
.weizhi_bg1{background:#000; -moz-opacity:0.6; -webkit-opacity:0.6; opacity:0.6; filter:progid:DXImageTransform.Microsoft.Alpha(Opacity=60);  height:30px; line-height:30px; position:absolute; width:100%}
</style>
 </head>
  <body>
            	<div id="div4" class="core" style="position:absolute; z-index:100078; bottom:60px; color:#fff; width:220px; left:50%; margin-left:-250px;">        
                	<div style="margin-left:10px;">
                    		<span id="time"></span>
							<span id="lic" style="margin-right: 20px;">里程：220</span>
							<span id="youh" style="margin-right:20px; display:none;"></span>
                	</div>
            	</div> 
	  	<div id="selectdiv" style="position: absolute; top: 18px; z-index: 800; right: 20px; z-index:1000089;">
	  		<select id="select" onchange="cutoverMap();" style="border:none;">
		 		 <option value="1" >百度地图</option>
		         <option value="2" selected>谷歌地图</option>
		 	</select>
	  	</div>
  	<ul><li class="error" id="autoDir"></li></ul>
    <div id="map_canvas"></div>
    <div id="container_baidu" style="display:none;"></div>
  </body>
</html>