function openDis(){
	//添加鼠标测距
	var myDis = new BMapLib.DistanceTool(baidMap);
	myDis.open();
}
var nearVhcsArr = [];
function addMenu(){
	baidubool = true;
	var contextMenu = new BMap.ContextMenu();
	var txtMenuItem =new Array();
	if(usertype =="0" || usertype=="1" || usertype=="2" || usertype=="-1"  || usertype=="10"){ 
		txtMenuItem.push({	
				 text:'添加标注',
				 callback:function(p){
			
								var x_pi = 3.14159265358979324 * 3000.0 / 180.0;
								var lng=p.lng;
								var lat=p.lat;
								var x = lng - 0.0065, y = lat - 0.006;
								var z = Math.sqrt(x * x + y * y) - 0.00002 * Math.sin(y * x_pi);
								var theta = Math.atan2(y, x) - 0.000003 * Math.cos(x * x_pi);
								lng = z * Math.cos(theta);
								lat = z * Math.sin(theta);
			
				        		$("#addMarkerGroupSelect").show();
		        				addMarkerGroupSelect();
				        		$("#markerName").text(language.tjbz);
				                $("#markerlat").val(lat);
				                $("#markerlng").val(lng);
				                $("#markertitle").val("");
								$("#markerdesc").val("");
								$("#addmarkermsg").text(language.btbnwk);
							    $("#addmarkermsg").css("color","rgb(153, 153, 153)");
								if($("#marker_group_option a").length!=1){
									$("#marker_group_option a").parent().siblings(".marker_group_select_txt").text($(".marker_group_option a").eq(0).text());
						            $("#markerGroupId").val($(".marker_group_option a").eq(0).attr("name"));
					            }
					            $("#markerImagesrc").css("backgroundImage","url(http://mapday.exlive.cn/mi/p/f/2/green.gif)");
					            	                       
					          //  markerArea=drawMarkerArea(getAreaSWLatlng(lat,lng,500),getAreaNELatLng(lat,lng,500));
								$( "#markerArea" ).slider( "value", 500 );
								
								$("#addMarkerButton").show();
								$("#updateMarkerButton").hide();
								
				                $("#markerContentWin").show();
				                $("#markerContentWin").center();
				      
				 }
				});
	  }
	  
  	  txtMenuItem.push({
			   text:'放大',
			   callback:function(){baidMap.zoomIn()}
			  });
	  txtMenuItem.push({
			   text:'缩小',
			   callback:function(){baidMap.zoomOut()}
			  });
	  txtMenuItem.push({
		   text:'附近车辆',
		   callback:function(p){
		  		var circle = new BMap.Circle(p,1000,{fillColor:"blue", strokeWeight: 1 ,fillOpacity: 0.3, strokeOpacity: 0.3});
		  		baidMap.addOverlay(circle);
		  		$("#nearvhcs").empty();
		  		$("#vhcsearchmm").val("");
		  		var counts = 0;
		  		nearVhcsArr = [];
		  		for( var i = 0; i < carList.data.length; i++){
		  			var x_pi = 3.14159265358979324 * 3000.0 / 180.0;
					var x = carList.data[i].positionLast.lng, y = carList.data[i].positionLast.lat;
					var z = Math.sqrt(x * x + y * y) + 0.00002 *Math.sin(y * x_pi);
					var theta = Math.atan2(y, x) + 0.000003 * Math.cos(x * x_pi);
					var lng = z *  Math.cos(theta) + 0.0065;
					var lat = z *  Math.sin(theta) + 0.006;
					var bpoints = new BMap.Point(lng,lat);
					var dis = baidMap.getDistance(bpoints,p);
					if(dis < 1000){
						if($("#nearvehicles").css("display")!="block"){
							$("#nearvehicles").show();
				        }
						nearVhcsArr[counts] = carList.data[i];
						counts ++;
						var html="<div onclick='centerMap("+carList.data[i].id+",0);' class='chepainame'>"+carList.data[i].vhcCode+"</div>";
						$("#nearvhcs").append(html);
					}
				}
		  		$("#nearvhcscounts").html("附近车辆("+counts+")");
		  		if(circle!=null)baidMap.removeOverlay(circle);
	  	   }
		  });
	  if(isShowTTs){
		  txtMenuItem.push({
			   text:'发送TTS播读',
			   callback:function(p){
			  			getLngLatRoad(p);
		  	   }
		  });
	  }
	 for(var i=0; i < txtMenuItem.length; i++){
	  contextMenu.addItem(new BMap.MenuItem(txtMenuItem[i].text,txtMenuItem[i].callback,100));
	  if(i==0 || i==1 || i==2) {
	   contextMenu.addSeparator();
	  }
	  if(isShowTTs && i==3){
		  contextMenu.addSeparator();
	  }
	 }
	 baidMap.addContextMenu(contextMenu);
}
var temp=0;
var traffic = new BMap.TrafficLayer();

function choosevhs(){
	var param = $("#vhcsearchmm").val();
	$("#nearvhcs").empty();
	var cc = 0;
	for ( var i = 0; i < nearVhcsArr.length; i++){
		if(nearVhcsArr[i].vhcCode.indexOf(param)>-1){
			var html="<div onclick='centerMap("+nearVhcsArr[i].id+",0);' class='chepainame'>"+nearVhcsArr[i].vhcCode+"</div>";
			$("#nearvhcs").append(html);
			cc ++;
		}
	}
	$("#nearvhcscounts").html("附近车辆("+cc+")");
}

function getLngLatRoad(p){
	
	var geoc = new BMap.Geocoder();
	geoc.getLocation(p, function(rs){
		var addComp = rs.addressComponents;
		var address = addComp.province + ", " + addComp.city + ", " + addComp.district + ", " + addComp.street + ", " + addComp.streetNumber;
		//alert(addComp.province + ", " + addComp.city + ", " + addComp.district + ", " + addComp.street + ", " + addComp.streetNumber);
		$("#content_tts").val("(TNC,"+p.lng+","+p.lat+","+address+"推荐");
	});
}

function addOrDelTra(){
	// 创建交通流量图层实例
	temp = temp+1;
	if(temp>2){
		temp=1;
	}
	if(temp == 1){
		baidMap.addTileLayer(traffic)
	}
	if(temp == 2){
		baidMap.removeTileLayer(traffic)
	}
}