
//交通
var trafficUtils={
	idlist:[],
	drawLine:function(points,type){
		if(!waitMapReady(this))return;
		this.clear();
		this.setClearButton(true);
		omapApi.zoomto(4);
		omapApi.go2xy(points[0].x,points[0].y);
		
		this.drawTrafficLine(points,type);
	},
	drawComplexLine:function(line){
		if(!waitMapReady(this))return;
		var segments=line.route.segments;
		
		this.clear();
		this.setClearButton(true);
		omapApi.zoomto(4);
		omapApi.go2xy(line.route.start.x,line.route.start.y);
		
		for(var i=0;i<segments.length;i++){
			var segment=segments[i];
			if(segment.type=='BUS'){
				this.drawTrafficLine(segment.points,null,i);
			}
			else if(segment.type=='SUBWAY'){
				this.drawTrafficLine(segment.points,segment.type,i);
			}
			else if(segment.type=='WALK'){
				this.drawWalkLine(segment.points);
			}
		}
	},
	drawTrafficLine:function(points,type,lineNum){
		if(!waitMapReady(this))return;
		var data=this.transformData(points);
		var option={autoZoom:true,strokecolor:'#00FF00',strokeweight:3,stroked:true,endarrow:'block',filled:false};
		if(type=='SUBWAY')option.strokecolor='#FF3300';
		omapApi.getMap().mapApi.drawLine2('line'+this.getRnd(),data.linePoints,option);
		
		var signType='busStation';
		if(type=='SUBWAY')signType='subwayStation';
		var stations=data.stations;
		if(lineNum>0){
			if(signType=='busStation')stations[0].ico='bus2.png';
			else if(signType=='subwayStation')stations[0].ico='sw2.png';
			omapApi.removePop('lineSt'+stations[0].id);
		}
		for(var i=0;i<stations.length;i++){
			delete stations[i].type;
			//stations[i].type=signType;
			//this.idlist[this.idlist.length]=omapApi.createUserPop(stations[i],{global:true,display:true,idStr:'lineSt'+stations[i].id});
			this.idlist[this.idlist.length]=omapApi.createSignExt(signType,stations[i],{global:true,display:true,idStr:'lineSt'+stations[i].id});
		}
	},
	transformData:function(points){
		var linePoints=[];
		var stations=[];
		for(var i=0;i<points.length;i++){
			var point=points[i];
			if(point.id){
				stations.push({id:point.id,name:point.name,x:point.x,y:point.y,type:point.type});
			}
			linePoints.push({x:point.x,y:point.y});
		}
		return {linePoints:linePoints,stations:stations};
	},
	drawWalkLine:function(points){
		var data=this.transformData(points);
		var option={autoZoom:true,strokecolor:'yellow',strokeweight:3,stroked:true,endarrow:'block',dashstyle:'dash',filled:false};
		omapApi.getMap().mapApi.drawLine2('line'+this.getRnd(),data.linePoints,option);
		return;
		var signType='busStation';
		var stations=data.stations;
		for(var i=1;i<stations.length-1;i++){
			if(stations[i].type=='SUBWAY') signType='subwayStation';
			else if(stations[i].type=='SUBWAY_EXIT') signType='subwayExitStation';
			else signType='busStation';
			//this.idlist[this.idlist.length]=omapApi.createUserPop(stations[i],{global:true,display:true,idStr:'lineSt'+stations[i].id});
			this.idlist[this.idlist.length]=omapApi.createSignExt(signType,stations[i],{global:true,display:true,idStr:'lineSt'+stations[i].id});
		}
	},
	setClearButton:function(flag){
		if(flag)$g('divMapClear').style.display='';
		else $g('divMapClear').style.display='none';
	},
	clear:function(){
		popomap.destroyAllG();
		for(var i=0;i<this.idlist.length;i++){
			var id=this.idlist[i];
			popomap.removePop(id);
		}
		this.idlist=[];
		this.setClearButton(false);
	},
	getRnd:function(){
		var d=new Date();
		return d.getTime()+'_'+Math.floor(1000*Math.random());
	}
};