Mapabc地图----生成路线

//下面这一段代码是一定要定义的  
//<---------------------------------开始---------------------------------------->
	/*
	 * 下面是生成线路的几个函数(请勿修改)<~----------------------------------------------------------------------------------->
	 * */
	var areaId;
	var resultStr="";
	var totalcount=0;//当前线路中一共选择的记录数
	var currentLineEqui = new Array(); //当前线路设备
	/***/
	function RouteSearch(){
		this.routeSType="rs";
		this.start_x = "";this.start_y = "";this.start_name = "";this.start_address = "";this.start_tel = "";this.start_pid = "";this.start_citycode = "";this.start_cityname = "";this.start_detailLink="";this.start_type="";
		this.end_x = "";this.end_y = "";this.end_name = "";this.end_address = "";this.end_tel = "";this.end_pid = "";this.end_citycode = "";	this.end_cityname = "";this.end_detailLink="";this.end_type="";
		this.route_segment;
	}
	var routeS = new RouteSearch();
	function createNewCashLine(){
		resultStr="";
		totalcount = 0;
		currentLineEqui = [];
		mapObj.removeOverlayById(areaId);
		document.getElementById("result").innerHTML="";
	}

	function routeSearch_CallBack(data){
		var resultStr="";
		if(data.error_message != null){
			resultStr="查询异常!"+data.error_message;
		}else{
		switch(data.message){
		case 'ok':
			var route_count = data.count;
			if(route_count==0){
				resultStr="<div>&nbsp;&nbsp;&nbsp;&nbsp;未查找到任何结果!</div>";
			}else{
				var route_text = "";var road_length = 0;
				var route_content = new Array();
				routeS.route_segment = new Array();
				for(var i=0;i<route_count;i++){
					routeS.route_segment[i] = data.segmengList[i].coor;//每一条路线的XY
				}
				var allover = new Array();
				var arr = new Array();
				var poi_xy_r = data.coors.split(",");
				var poi_xy_rl = poi_xy_r.length-2
				for(var j=0;j<poi_xy_rl;j=j+2){
					arr.push(new MLngLat(poi_xy_r[j],poi_xy_r[j+1]));
				}
				var lineopt = new MLineOptions();
				lineopt.lineStyle.thickness=6;
				lineopt.lineStyle.color=0x005cb5;
				lineopt.lineStyle.alpha=0.8;
				var line = new MPolyline(arr,lineopt);
				lineopt.canShowTip=false;
				allover.push(line);
				/*起点终点*/
				var lineStyle=new MLineStyle();
				lineStyle.thickness=2;
				lineStyle.alpha=1;
				lineStyle.lineType= LINE_DASHED;
				var fontStyle=new MFontStyle();
				fontStyle.name="Arial";
				fontStyle.size=12;
				fontStyle.color= 0xffffff;
				fontStyle.bold=true;
				var fontStyle1=new MFontStyle();
				fontStyle1.name="Arial";
				fontStyle1.size=13;
				fontStyle1.color= 0x000000;
				fontStyle1.bold=false;
				var fillStyle=new MFillStyle();
				fillStyle.color= 0xFFFFFF; //填充色
				fillStyle.alpha=1;
				var fillStyle1=new MFillStyle();
				fillStyle1.color= 0x005cb5; //填充色
				fillStyle1.alpha=1;
				
				mapObj.addOverlays(allover,true);
			}
		break;
		case 'error':
				resultStr= "<div class=\"default\"><div class=\"default_title\">对不起!网络繁忙!请稍后重新尝试!</div><div class=\"d_link\"><div class=\"d_right\"></div><div class=\"suggest\"><strong>建议:</strong><br />如果您刷新页后仍无法显示结果,请过几分钟后再次尝试或者与信息化小组联系。<br /></div></div></span>错误信息:"+data.message+"</div>";
			break;
			default:
				resultStr= "<div class=\"default\"><div class=\"default_title\">对不起!网络繁忙!请稍后重新尝试!</div><div class=\"d_link\"><div class=\"d_right\"></div><div class=\"suggest\"><strong>建议:</strong><br />如果您刷新页后仍无法显示结果,请过几分钟后再次尝试或者与信息化小组联系。<br /></div></div></span>错误信息:"+data.message+"</div>";
			}
		}
	}

//<---------------------------------结束---------------------------------------->
  //上面是基本线路生成的定义,下面是具体路线生成
//<----------------------------------------开始---------------------------------------->

	function generateLine(){//生成路线
		if(linetemp!=null ){
                //linetemp--->是一个数组
                /***
                  var equipmentArr = [];
                  var equipment1 = {
	                               'id':'01',
	                               'name':'01',
	                               'lon':'113.33034682099', //经度
	                               'lat':'23.136111090227', //纬度
	                               'address':'广州市天河区华康小学',
	                               'status':'0'
                    };
                   var equipment2 = {
	                              'id':'02',
	                              'name':'02',
	                              'lon':'113.33669829193', //经度
                            	      'lat':'23.131138554636', //纬度
	                              'address':'广州市天河区石牌西路东园小区',
	                              'status':'0'
                   };
                  var equipment3 = {
	                              'id':'03',
	                              'name':'03',
	                              'lon':'113.33738493744', //经度
	                              'lat':'23.125060760778', //纬度
	                              'address':'广州市天河区海乐路',
	                              'status':'1'
                   };
                   linetemp.push(equipment1);
                   linetemp.push(equipment2);
                   linetemp.push(equipment3);

               **/
		for(var i=0;i<linetemp.length;i++){
				var linest = new MLineStyle();
				  linest.alpha = 1;
				  linest.color = 0xFF3300 ;
				  linest.thickness = 3;
				  linest.lineType= LINE_DASHED;
				if(i==linetemp.length-1)return;
				mapObj.panTo(new MLngLat(linetemp[i+1].lon,linetemp[i+1].lat));
				var startXY= new MLngLat(linetemp[i].lon,linetemp[i].lat);
				var endXY = new MLngLat(linetemp[i+1].lon,linetemp[i+1].lat);
				var mls = new MRouteSearch();
				var opt =new MRouteSearchOptions();
				opt.per=90;//抽吸函数,表示在地图上画导航路径的关键点的个数。默认为150
				opt.routeType=0;//路径计算规则,0表示速度优先(默认)
				opt.name="";//避让区域名称
				var regionL="";//避让区域坐标
				routeS.start_x=linetemp[i].lon;
				routeS.start_y=linetemp[i].lat;
				routeS.end_x=linetemp[i+1].lon;
				routeS.end_y=linetemp[i+1].lat;
				mls.setCallbackFunction(routeSearch_CallBack);
				mls.routeSearchByTwoPoi(startXY,endXY,opt,linest);	
			}
		}
		
	}


//<----------------------------------------结束---------------------------------------->
 

你可能感兴趣的:(地图应用,Mapabc)