 var usertype = "";
 var path = "";
 var Url = {};
 var markerUrl = {};
 var electronicFenceUrl = {}; 
 var baidMap = {};
 var map ={};

 function startMarker(){
	 
 				 initparms();
 					
	 			  //添加标注菜单
		 	     addMarkerMenu();
		 	     
				 if(usertype=="-1000"||usertype=="-100"){ 
				 			  
		 			 document.getElementById("biaozhu_close").style.display = "none";
		 			 document.getElementById("markerPermissionsPanelBtn").style.display = "none";
		 			 document.getElementById("markerNamePermissionsPanelBtn").style.display = "none";
		 			 
				 }else{
				 	
				 	 //点击地图时关闭已经打开的弹出框
		 			  mapclickEvent();
		   
		  			  //获取标注Josn集
					  getMarkerJson();
					  
					  //获取标注组Json集
					  getGroupJson();
					  
					  //获取所有标注组Json集
					  getAllMarkerGroupJson();
					  
					  //绘制标注树
					  showMarkerGroupTree();
					    
					  //添加所有标注  
					  addAllMarker();
		 			
				 }

}

var isChrome = navigator.userAgent.toLowerCase().match(/chrome/) != null;
var markerGroupJson=null;
var allMarkerGroupJson=null;
var markerObject={
	markerJson : "",
	markerArr : {},
	myLatlng : null,
	infowindow : null,
	markerids : new Array(),
	markertitlearr : new Array(),
	addMarker : function(_id,_lat,_lng,_icon){
	this.markerids.push(_id);
					 this.myLatlng=new google.maps.LatLng(_lat,_lng);
					 var image = {
								    url: _icon,
								    // This marker is 20 pixels wide by 32 pixels tall.
								    size: new google.maps.Size(32, 32),
								    // The origin for this image is 0,0.
								    origin: new google.maps.Point(0,0),//位置
								    // The anchor for this image is the base of the flagpole at 0,32.
								    anchor: new google.maps.Point(16, 16)
								  };
					 
					 return new google.maps.Marker({
									      position: this.myLatlng,
									      map: map,
									      icon: image
									});
					 
	},
	addMarkerListener : function(_marker){
	
					google.maps.event.addListener(_marker.marker, "click", function (e) {
			
							 markerObject.closeInfowindow();
							 var contentHtml;
							 
							 contentHtml="<div style=\"width:200px;height:100px;overflow: hidden;\"><b>"+language.mc+"</b>&nbsp;&nbsp;&nbsp;&nbsp;"+_marker.title+"</br><b>"+language.jingdu+"</b>:&nbsp;&nbsp;&nbsp;&nbsp;"+_marker.lng.toFixed(5)+"</br><b>"+language.weidu+"</b>:&nbsp;&nbsp;&nbsp;&nbsp;"+_marker.lat.toFixed(5)+"</br><b>"+language.ms+"</b>&nbsp;&nbsp;&nbsp;&nbsp;"+_marker.text+"</br></div>";

							 
							 markerObject.infowindow = new google.maps.InfoWindow({ 
							     content:contentHtml,
							     maxWidth:200
							 }); 
							 
							 if(mapType==1){

								 openMarkerBaidu(_marker.id);

							 }else{
								 markerObject.infowindow.open(map,this);
							 }
							 
					 });
					
					 
	},
	deleteMarker : function(_id){
					

	},
	closeInfowindow : function(){
		if(this.infowindow!=null){
					 	this.infowindow.close();
					 }		
	}, 
	clear : function(){
	
	}
}

function getMarkerJson(){
		$.ajax({
	        type: "POST",
	        dataType: "json",
	        async:true,
	        url: path+"json/markerAction_getMarker.action",
	        success: function(json) {		         
		         if (json.flag==true) {
	         		 markerObject.markerJson=json;	
	         		 showMarkerBaidu(markerObject.markerJson);
	         		showMarkerGroupTree();
                 }else{
                 	//alert(json.msg);
                 }
	        },
	        error: function() {}
	   });	
}
function getAllMarkerGroupJson(){
		$.ajax({
	        type: "POST",
	        dataType: "json",
	        async:true,
	        url: path+"json/markerAction_getMarkerGroup.action",
	        success: function(json) {		         
		         if (json.flag==true) {
	         		 allMarkerGroupJson=json;		        	 					           				
                 }else{
                 	//alert(json.msg);
                 }
	        },
	        error: function() {}
	   });	
}


function getGroupJson(){
		$.ajax({
	        type: "POST",
	        dataType: "json",
	        async:false,
	        url: path+"json/markerAction_getUserMarkerGroup.action",
	        success: function(json) {		         
		         if (json.flag==true) {
	         		 markerGroupJson=json;		        	 					           				
                 }else{
                 	//alert(json.msg);
                 }
	        },
	        error: function() {}
	   });	
}
function addAllMarker(){

	if(typeof baidMap=="undefined"){
		setTimeout('addAllMarker()',500);
		return;
	}
	if(markerObject.markerJson==""){
		setTimeout('addAllMarker()',500);
		return;
	}
	
	var marker,json=markerObject.markerJson;
	
	if(null!=json&&""!=json&&json.totalcount>0){
		for(var i=0;i<json.totalcount;i++){
			
			if(typeof json.data[i].id=="number" && typeof json.data[i].lat2=="number" && typeof json.data[i].lng2=="number" && json.data[i].icon.length!=0 &&json.data[i].lat2!=0&&json.data[i].lng2!=0){			
				 
				
		 		 markerObject.markerArr[json.data[i].id]={};
			  	 
			  	 markerObject.markerArr[json.data[i].id].competence=json.data[i].competence;		
			  	 markerObject.markerArr[json.data[i].id].title=json.data[i].title;
			  	 markerObject.markerArr[json.data[i].id].text=json.data[i].text;
			  	 markerObject.markerArr[json.data[i].id].icon=json.data[i].icon;
			  	 markerObject.markerArr[json.data[i].id].lat=json.data[i].lng2;
			  	 markerObject.markerArr[json.data[i].id].lng=json.data[i].lat2;
			  	 markerObject.markerArr[json.data[i].id].groupid=json.data[i].groupid;
			  	 markerObject.markerArr[json.data[i].id].id=json.data[i].id;
			  	 markerObject.markerArr[json.data[i].id].bzType=json.data[i].bzType;
			  	 
			  	 markerObject.markerArr[json.data[i].id].customerNum=json.data[i].markcode;
			  	 
			  	 if(json.data[i].userMarkerArea){
			  	  	markerObject.markerArr[json.data[i].id].userMarkerArea = json.data[i].userMarkerArea;
			  	 }
			  	 
			  	

		  	 }
		}

	}
}
var menu=null;
function addMarkerMenu(){
	
}


//单击时关闭标注和设备弹出框
function mapclickEvent(){

	
}

function closeMarkerPanel(){

		$("#biaozhu_close").show();
		$("#biaozhu_open").hide();
}
	
function openMarkerPanel(){

	$("#biaozhu_open").show();
	$("#biaozhu_close").hide();
}

var treeObj = null;

function showMarkerGroupTree(){
	if( markerObject.markerJson==""||allMarkerGroupJson==null){
		setTimeout("showMarkerGroupTree()",500);
		return;
	}
	if(allMarkerGroupJson.totalcount!=0){
		var groupNodeTreeStr="[";
		for(var i=0;i<allMarkerGroupJson.data.length;i++){
			//optionStr+="<a name=\""+markerGroupJson.data[i].id+"\">"+markerGroupJson.data[i].groupName+"</a>";
			if(typeof allMarkerGroupJson.data[i]!="undefined"){
				groupNodeTreeStr+="{ \"id\":\"g_"+allMarkerGroupJson.data[i].id+"\",\"title\":\""+allMarkerGroupJson.data[i].groupName+"\",\"name\":\""+allMarkerGroupJson.data[i].groupName+"\",\"icon\":\""+markerUrl.groupNodeicon+"\",\"count\":\"0\",\"pId\": \"0\"},";
			}
		}
		groupNodeTreeStr=groupNodeTreeStr.substring(0,groupNodeTreeStr.length-1);
	    
	    groupNodeTreeStr="[{\"id\":\"root_g_-1000\",\"open\":\"true\",\"title\":\""+language.yhbz+"\",\"name\":\""+language.yhbz+"\",\"icon\":\""+electronicFenceUrl.allDom+"\",\"pId\": \"-1000\","+
								"\"children\":"+groupNodeTreeStr+"]}]";
								
	    groupNodeTreeStr=$.parseJSON(groupNodeTreeStr);
	    var setting={
	    		callback: {
					onClick: zTreeOnClick,
					onCheck: zTreeOnCheck
				},check: {
					enable: true
				},
				data: {
					simpleData: {
						enable: true,
						idKey: "id"
					}
				}		
	    }
		$.fn.zTree.init($("#markerGroupTree"),setting,groupNodeTreeStr);
		treeObj = $.fn.zTree.getZTreeObj("markerGroupTree");
		var parentNode,newNode;
		for(var i=0;i< markerObject.markerJson.data.length;i++){   
			addMarkerGroupTreeNode( markerObject.markerJson.data[i].id, markerObject.markerJson.data[i].groupid, markerObject.markerJson.data[i].title);
		}
		
	//	treeObj.checkNode(treeObj.getNodeByParam("id","root_g_-1000"), true, true);
		
	}
}

function addMarkerGroupTreeNode(id,parentId,title){
	    var newNode = [{'id':id,'name':title,"icon":markerUrl.markericon}];
		parentNode=treeObj.getNodeByParam("id","g_"+parentId);
		if(parentNode!=null){
			newNode=treeObj.addNodes(parentNode,newNode,true);
			
			parentNode.count=parseInt(parentNode.count)+1;
			parentNode.name =parentNode.title+"("+parentNode.count+")";
	        treeObj.updateNode(parentNode);			
		}else{
			parentNode=treeObj.getNodeByParam("id","g_0");
			newNode=treeObj.addNodes(parentNode,newNode,true);
			parentNode.count=parseInt(parentNode.count)+1;
			parentNode.name =parentNode.title+"("+parentNode.count+")";
	        treeObj.updateNode(parentNode);	
		}
		
		return newNode;
}
function addMarkerGroupTreeGroupNode(id,title){

		var newNode =null;
		if(treeObj==null){
			var setting={
	    		callback: {
					onClick: zTreeOnClick,
					onCheck: zTreeOnCheck
				},check: {
					enable: true
				},
				data: {
					simpleData: {
						enable: true,
						idKey: "id"
					}
				}	
    		}
    		
		   $.fn.zTree.init($("#markerGroupTree"),setting,[{id:"root_g_-1000",open:true,title:language.yhbz,name:language.yhbz,icon:electronicFenceUrl.allDom,pId: -1000,
								children:[{ id:"g_"+id, pId: 0,title: title,count:0,name:title,icon:markerUrl.groupNodeicon}]}]);
		    treeObj = $.fn.zTree.getZTreeObj("markerGroupTree");
		    
		}else{
		
			newNode= [{id:"g_"+id, pId: 0,title: title,count:0,name:title,"icon":markerUrl.groupNodeicon}];
			var parentNode=treeObj.getNodeByParam("id","root_g_-1000");
			
			treeObj.addNodes(parentNode,newNode,true);
		}

		//addHoverDom("markerGroupTree", newNode);
		//removeHoverDom("markerGroupTree", newNode);
		
		
	    //treeObj.destroy();
		//showMarkerGroupTree();
}
function deleteMarkerGroupTreeNode(nodeid){
	var curnode=treeObj.getNodeByParam("id",nodeid);
	var parentNode=curnode.getParentNode();
    treeObj.removeNode(curnode);  
    parentNode.count=parseInt(parentNode.count)-1;
    if(parentNode.count==0){
    	parentNode.name =parentNode.title;
    }else{
		parentNode.name =parentNode.title+"("+parentNode.count+")";
    }
    treeObj.updateNode(parentNode);	
}

var showmarkersArr = new Array();
function zTreeOnClick(event, treeId, treeNode) {

	if(!treeNode.isParent){
		treeObj.checkNode(treeNode, true, false, false);
		
		if(mapType==1 && baidMap!=undefined){
			//updateMarkerIsShow(treeNode.id,true,false);
			//showMarkersBaidu(treeNode.id,false);
			//openMarkerBaidu(treeNode.id);	
				
		}else{
			var curmarker=markerObject.markerArr[treeNode.id];
			
			if(curmarker!=null){
				curmarker.isShow=true;
		    }
			
			openMarker(treeNode.id);
		}
		
	}
	
}

function zTreeOnCheck(event, treeId, treeNode){

    if(mapType==2 && baidMap!=undefined){
		if(markerObject.infowindow!=null){
			markerObject.infowindow.close();
		}
	}
	
	markerObject.closeInfowindow();
	
	var isParent = false;
	
	var nodesNoChecked = treeObj.getCheckedNodes(false);
	
	for(var i=0;i<nodesNoChecked.length;i++){
		isParent=nodesNoChecked[i].isParent;
		if(!isParent){
				if(mapType==1 && baidMap!=undefined){
					updateMarkerIsShow(nodesNoChecked[i].id,false,false);
					hideMarkersBaidu(nodesNoChecked[i].id,false);	
						
				}else{
					var curmarker=markerObject.markerArr[nodesNoChecked[i].id];
		   			if(curmarker!=null){
		   				curmarker.isShow=false;
		   				if(curmarker.marker != null){
		   					if(curmarker.marker.getMap() != null){
		   						curmarker.marker.setMap(null);
		   					}
		   				}
		   				
		   				if(curmarker.area != null){
		   					if(curmarker.area.getMap() != null){
		   						curmarker.area.setMap(null);
		   					}
		   				}
		   			}
	   			}
		}
	}
	
	
	var nodes = treeObj.getCheckedNodes(true);
	
	var curmarker=null;
	
	for(var i=0;i<nodes.length;i++){
		
		isParent=nodes[i].isParent;
		
		if(!isParent){
			if(mapType==1 && baidMap!=undefined){
					updateMarkerIsShow(nodes[i].id,true,false);
					showMarkersBaidu(nodes[i].id,false);	
				
				}else{
						curmarker=markerObject.markerArr[nodes[i].id];
			   			if(curmarker!=null){
			   				curmarker.isShow=true;
			   				
			   				if(!curmarker.marker){
			   					initMarker(curmarker);
			   				}
			   				
			   				if(curmarker.marker != null){
			   					if(curmarker.marker.getMap() == null){
			   						curmarker.marker.setMap(map);
		   						}
			   				}
			   				
			   				if(curmarker.area != null){
			   					if(curmarker.area.getMap() == null){
			   						curmarker.area.setMap(map);
		   						}
			   				}
			   			}
	   			}
		}
	}
	
	if($("#bzShowNamekbox").attr("checked")){
		hideMarkerName();
	}
	
	
}

function openMarker(_id){
	if(markerObject.infowindow!=null){
		markerObject.infowindow.close();
	}
	var curmarker=markerObject.markerArr[_id];
    if(curmarker!=null){
	    map.setCenter(new google.maps.LatLng(curmarker.lat,curmarker.lng));
		map.setZoom(13);
		
		if(!curmarker.marker){
		
			initMarker(curmarker);
			
		}
		
		curmarker.marker.setMap(map);
		google.maps.event.trigger(curmarker.marker, 'click');

    }
}

function initMarker(curmarker){
 		 
		     var marker=markerObject.addMarker(curmarker.id,curmarker.lat,curmarker.lng,curmarker.icon);
		  	
		  	 markerObject.markerArr[curmarker.id].marker=marker;
		  	 
		  	 markerObject.addMarkerListener(markerObject.markerArr[curmarker.id]);
		  	 
		  	 if(markerObject.markerArr[curmarker.id].userMarkerArea!=null && markerObject.markerArr[curmarker.id].userMarkerArea.leftLat!=0 && markerObject.markerArr[curmarker.id].userMarkerArea.leftLon!=0 && markerObject.markerArr[curmarker.id].userMarkerArea.rightLat!=0 && markerObject.markerArr[curmarker.id].userMarkerArea.rightLon!=0 && markerObject.markerArr[curmarker.id].userMarkerArea.markerRadius!=0){
		  		 
		  		 if(markerObject.markerArr[curmarker.id].userMarkerArea.g_leftLat!=0 &&markerObject.markerArr[curmarker.id].userMarkerArea.g_leftLon!=0 &&markerObject.markerArr[curmarker.id].userMarkerArea.g_rightLat!=0 &&markerObject.markerArr[curmarker.id].userMarkerArea.g_rightLon!=0 &&markerObject.markerArr[curmarker.id].userMarkerArea.markerRadius!=0){
		  			
		  			markerObject.markerArr[curmarker.id].area=drawMarkerArea(new google.maps.LatLng(markerObject.markerArr[curmarker.id].userMarkerArea.g_leftLat,markerObject.markerArr[curmarker.id].userMarkerArea.g_leftLon),new google.maps.LatLng(markerObject.markerArr[curmarker.id].userMarkerArea.g_rightLat,markerObject.markerArr[curmarker.id].userMarkerArea.g_rightLon));
		  		 
		  		 }else{
		  			
		  		    markerObject.markerArr[curmarker.id].area=drawMarkerArea(new google.maps.LatLng(markerObject.markerArr[curmarker.id].userMarkerArea.leftLat,markerObject.markerArr[curmarker.id].userMarkerArea.leftLon),new google.maps.LatLng(markerObject.markerArr[curmarker.id].userMarkerArea.rightLat,markerObject.markerArr[curmarker.id].userMarkerArea.rightLon));
			  	 	 
		  		 }
		  		 
		  		 markerObject.markerArr[curmarker.id].area.setMap(map);
		  	 	 
		  	 }
		

}


function showMarkerName(element){
		
		if($(element).attr("checked")){
			
			for(var j=0;j<bzMarkers.length;j++){
	      		if(bzMarkers[j].label != null){
	      			if(bzMarkers[j].isShow){
	      				baidMap.addOverlay(bzMarkers[j].label);
	      			}
	      		}
		  	}
		}else{
			for(var j=0;j<bzMarkers.length;j++){
	      		if(bzMarkers[j].label != null){
	      			baidMap.removeOverlay(bzMarkers[j].label);
	      		}
		  	}
		}
	
	
}

function hideMarkerName(){
	for(var i=0;i<markerObject.markerids.length;i++){
		if(markerObject.markertitlearr[i]!=null){
			markerObject.markertitlearr[i].setMap(null);
			markerObject.markertitlearr[i]=null;
		}
	}
	markerObject.markertitlearr=new Array();
	
	if($("#bzShowNamekbox").attr("checked")){
		for(var i=0;i<markerObject.markerids.length;i++){
			if(markerObject.markerArr[markerObject.markerids[i]] != null && markerObject.markerArr[markerObject.markerids[i]].isShow && markerObject.markerArr[markerObject.markerids[i]].marker != null){
				markerObject.markertitlearr.push(new myLableMarker(map,"<div class=\"iconTheStyle\" style=\"background:#f5fcb8;  font-size:12px; color:#000000; font-weight:bold; white-space:nowrap; border:1px solid #666666;\" >"+markerObject.markerArr[markerObject.markerids[i]].title+"</div>",markerObject.markerArr[markerObject.markerids[i]].marker.getPosition(),markerObject.markerids[i]));
			}
		
		}
				
	}

}

/*
 *区域
 */
 var markerArea=null;
 var markersize=500;
 function loadAreaSlider(){
  $( "#markerArea" ).slider({
				range : "min",
				max : 5000,
				min : 50,
				value : 500,
				orientation : 'horizontal'
		  });
  $("#markerArea").bind('slidechange', function(event, ui) {
			/*var r=ui.value;
			var t=4;
			var w=100;
			var p=[500,800,1200,1500,2000,3000,5000];//[5000,3000,2000,1000,1500,800,500]
			var u=[0,20,40,60,80,100,120,140];
			for(var s=0,o=u.length-1;s<o;s++){
				if(r>=u[s]&&r<u[s+1]){
					t=s;
					break
				}
				if(r>=140){
					t=6;
					break
				}
			}*/
			markersize=ui.value;
			updateMarkerArea(ui.value,markerArea);
		});
 }

function drawMarkerArea(lefttoplatlng_,rigthbelowlatlng_){
			return rectangle = new google.maps.Rectangle({
				strokeColor: '#0000FF',
				strokeOpacity: 0.8,
				strokeWeight: 2,
				fillColor: '#0000cc',
				fillOpacity: 0.35,
				zIndex:0,
				map: map,
				bounds: new google.maps.LatLngBounds(
				  lefttoplatlng_,
				  rigthbelowlatlng_)
				});  
}

function updateMarkerArea(len_,markerArea_){
	$("#markersize").text(len_+"m");
	markerArea_.setBounds(new google.maps.LatLngBounds(getAreaSWLatlng(parseFloat($("#markerlat").val()),parseFloat($("#markerlng").val()),len_),getAreaNELatLng(parseFloat($("#markerlat").val()),parseFloat($("#markerlng").val()),len_)));
}

function getAreaNELatLng(lat_,lng_,len_){
	var dlat = len_/111.0/1000.0;
	var dlng = len_/85.567/1000.0;
	$("#rigthlat").val(lat_-dlat);
	$("#rigthlng").val(lng_+dlng);
	return new google.maps.LatLng(lat_-dlat,lng_+dlng);
}
function getAreaSWLatlng(lat_,lng_,len_){
	var dlat = len_/111.0/1000.0;
	var dlng = len_/85.567/1000.0;
	$("#leftlat").val(lat_+dlat);
	$("#leftlng").val(lng_-dlng);
	return new google.maps.LatLng(lat_+dlat,lng_-dlng);
}
function clearAreaLagLng(){
	$("#leftlat").val("");
	$("#leftlng").val("");
	$("#rigthlat").val("");
	$("#rigthlng").val("");
	markersize=500;
}
/*
 *tool
 */
	function showtoolPanel(){
	 	$("#tools_box").show();
	}
	function hidetoolPanel(){
		$("#tools_box").hide();
	}
	
Array.prototype.remove=function(dx){
　　if(isNaN(dx)||dx>this.length){return false;}
　　for(var i=0,n=0;i<this.length;i++){
　　　　if(this[i]!=this[dx]){
　　　　　　this[n++]=this[i]
　　　　}
　　}
　　this.length-=1
}
function initMarkerisShow(){
	if(mapType=="1" && baidMap!=undefined){
		var isParent = false;
		
		var nodesNoChecked = treeObj.getCheckedNodes(false);
		
		for(var i=0;i<nodesNoChecked.length;i++){
			isParent=nodesNoChecked[i].isParent;
			if(!isParent){			
					updateMarkerIsShow(nodesNoChecked[i].id,false,false);
					hideMarkersBaidu(nodesNoChecked[i].id,false);
			}
		}
		
		
		var nodes = treeObj.getCheckedNodes(true);
		
		var curmarker=null;
		
		for(var i=0;i<nodes.length;i++){
			isParent=nodes[i].isParent;
			if(!isParent){
					updateMarkerIsShow(nodes[i].id,true,false);
					showMarkersBaidu(nodes[i].id,false);
			}
		}
	}else{
		zTreeOnCheck(null,null,null);
	}
}


var LatLngBounds = null;
var ceneterLatlng = null;

var curmarkerNameLabe = null;



function initparms(){

	usertype = $("#usertypeId").val();
 	path =$("#serverPath").text(); 

	Url={
		distanceclose : path+"gpsonline/image/tool/close.gif",
		distancestart : path+"gpsonline/image/tool/dd-start.png",
		distanceend : path+"gpsonline/image/tool/mm_20_red.png",
		queryLoading : path+"gpsonline/image/monitor/guanli/recoderdeleting.gif"
	}
	
	markerUrl={
		groupNodeicon : path+"gpsonline/image/marker/organisation.png",
		markericon : path+"gpsonline/image/marker/pin.png"
	}
	
	electronicFenceUrl ={
		allDom : path+"gpsonline/image/electronicFence/data_n.png",
		polygon : path+"gpsonline/image/electronicFence/juxing_n.png",
		line : path+"gpsonline/image/electronicFence/luxian_n.png",
		linefirstMarker : path+"gpsonline/image/electronicFence/icon_greenA.png",
		eventPhoto : path+"gpsonline/image/electronicFence/ico_photo_n.png"
	}
}
function stopBubble(e){  
    // 如果传入了事件对象，那么就是非ie浏览器  
    if(e&&e.stopPropagation){  
        //因此它支持W3C的stopPropagation()方法  
        e.stopPropagation();  
    }else{  
        //否则我们使用ie的方法来取消事件冒泡  
        window.event.cancelBubble = true;  
    }  
}
var bzMarkers =[];
var latlngs =[];
var markerIds =[];
var markerObjs =[];
var markerIdAndNames =[];
var nums=1;
function showMarkersBaidu(id,bool){
	//var bzcheckbox = document.getElementsByName("bzcheckbox");
	if(bool){
		for(i=0;i<bzMarkers.length;i++){
				baidMap.addOverlay(bzMarkers[i].marker);
				baidMap.addOverlay(bzMarkers[i].polygon);
				/* if(bzcheckbox[0].checked){
					 baidMap.addOverlay(bzMarkers[i].label);
			     }*/
		}
	}else{
		for(i=0;i<bzMarkers.length;i++){
			if(bzMarkers[i].id==id){
				
				baidMap.addOverlay(bzMarkers[i].marker);
				baidMap.addOverlay(bzMarkers[i].polygon);
				/*if(bzcheckbox[0].checked){
					 baidMap.addOverlay(bzMarkers[i].label);
			     }*/
			}
		}
	}
	
}
function hideMarkersBaidu(id,bool){
	if(bool){
		for(i=0;i<bzMarkers.length;i++){
				baidMap.removeOverlay(bzMarkers[i].marker);
//				baidMap.removeOverlay(bzMarkers[i].polygon);
				baidMap.removeOverlay(bzMarkers[i].label); 
		}
	}else{
		for(i=0;i<bzMarkers.length;i++){
			if(bzMarkers[i].id==id){
				baidMap.removeOverlay(bzMarkers[i].marker);
//				baidMap.removeOverlay(bzMarkers[i].polygon);
				baidMap.removeOverlay(bzMarkers[i].label); 
			}
		}
	}
	
}
var markerObj;
var _operation;
var _bool=false;
function showMarkerBaidu(markersJson){
	if(markersJson == ""){
		return;
	}
	for(var i=0;i<markersJson.data.length;i++){
		(function(x){
			var blat;
			var blng;
			if(markersJson.data[i].blat>0 && markersJson.data[i].blng>0){
				blat=markersJson.data[i].blat;
				blng=markersJson.data[i].blng;
			}else{
				blat=markersJson.data[i].lat2;
				blng=markersJson.data[i].lng2;
			}
			var myLatlng = new BMap.Point(blat,blng);
			var myIcon = new BMap.Icon(markersJson.data[i].icon, new BMap.Size(35,35));
			var marker = new BMap.Marker(
					myLatlng
					,{icon:myIcon}
			);  // 创建标注
			//baidMap.addOverlay(marker);
			var opts = {
			  position : myLatlng,    // 指定文本标注所在的地理位置
			  offset   : new BMap.Size(15, -10)    //设置文本偏移量
			 
			}
			var label = new BMap.Label(markersJson.data[i].title, opts);  // 创建文本标注对象
			label.setStyle({
				 color : "#000000",
				 backgroundColor : "#f5fcb8",
				 borderColor : "#000000",
				 fontSize : "12px",
				 height : "16px",
				 lineHeight : "16px",
				 fontWeight:"bold",
				 fontFamily:""
			});
			//baidMap.addOverlay(label); 
			//创建信息窗口
			var html="<div style='font-weight:normal;'><b>名称：</b>"+markersJson.data[i].title+"</br>"
			+"<b>描述：</b>"+markersJson.data[i].text+"</br>"
			+"<b>经度：</b>"+blat+"</br>"
			+"<b>纬度：</b>"+blng+"</br>";
			
			var htm="<a href='javascript:openUpdateMarkerWin("+markersJson.data[i].id+");'><font color='#0000FF'>修改</font> | </a><a href='javascript:deleteMarker("+markersJson.data[i].id+");' ><font color='#0000FF'>删除</font></a> </div>";
			if(markersJson.data[i].competence==1){
				html=html+htm;
			}else{
				html=html+"</div>";
			}
			var infoWindow = new BMap.InfoWindow(html);
			marker.addEventListener("click", function(){this.openInfoWindow(infoWindow);});
			var pStart;
			var pEnd;
			if(markersJson.data[i].userMarkerArea == null || markersJson.data[i].userMarkerArea ==""){
				var pStart = new BMap.Point(0,0);
				var pEnd = new BMap.Point(0,0);
			}else{
				if(markersJson.data[i].userMarkerArea.b_leftLon == 0 || markersJson.data[i].userMarkerArea.b_leftLat == 0){
					var pStart = new BMap.Point(markersJson.data[i].userMarkerArea.leftLon,markersJson.data[i].userMarkerArea.leftLat);
					var pEnd = new BMap.Point(markersJson.data[i].userMarkerArea.rightLon,markersJson.data[i].userMarkerArea.rightLat);
					
				}else{
					var pStart = new BMap.Point(markersJson.data[i].userMarkerArea.b_leftLon,markersJson.data[i].userMarkerArea.b_leftLat);
					var pEnd = new BMap.Point(markersJson.data[i].userMarkerArea.b_rightLon,markersJson.data[i].userMarkerArea.b_rightLat);
					
				}
				
			}
			var polygon = new BMap.Polygon([
	              new BMap.Point(pStart.lng,pStart.lat),
				  new BMap.Point(pEnd.lng,pStart.lat),
				  new BMap.Point(pEnd.lng,pEnd.lat),
				  new BMap.Point(pStart.lng,pEnd.lat)
	          ], {strokeColor:"blue",fillColor:"blue", strokeWeight:2, strokeOpacity:0.5});
			//baidMap.addOverlay(polygon);
			
			markerManage = new Object();
			markerManage.id = markersJson.data[i].id;
			markerManage.title = markersJson.data[i].title;
			markerManage.label = label;
			markerManage.marker = marker;
			markerManage.polygon = polygon;
			markerManage.icon = markersJson.data[i].icon;
			markerManage.infowindow = infoWindow;
			markerManage.latlng = myLatlng;
			markerManage.isShow = false;
			bzMarkers.push(markerManage);
			
		})(i);
    }	
}
function updateMarkerIsShow(id,isShow,isAll){
	if(isAll){
		for(i=0;i<bzMarkers.length;i++){
				bzMarkers[i].isShow = isShow;
		}
	}else{
		for(i=0;i<bzMarkers.length;i++){
			if(bzMarkers[i].id==id){
				bzMarkers[i].isShow = isShow;
				break;
			}
		}
	}
	
}//olatlng,nlatlng