station-positions-function.js 11.9 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438
/**
 * 函数
 */

var PublicFunctions = function () {
	
	var stationObj = '';
	
	var stationId = '';
	
	var mapB = '';
	
	var circle = '';
	
	var polygon = '';
	
	var marker ='';
	
	var PubFun = {
			
			initStationInfo : function(id,map_) {
				
				stationId = id;
				
				mapB = map_;
				
				PublicFunctions.getStationRouteInfo(stationId,function(r) {
					
					stationObj = r;
					
					var len = r.length;
					
					if(len>0) {
						
						var stationShapesType = r[0].stationShapesType;
						
						// 获取中心坐标点字符串分割
						var BJwpoints = r[0].stationJwpoints.split(' ');
						
						// 中心坐标点
						var point = new BMap.Point(BJwpoints[0], BJwpoints[1]);
						
						var htm = 	'<HR style="border:1 dashed #987cb9" width="100%" color=#987cb9 SIZE=1>'+
						'<span style="color:#DDD;font-size: 15px;">站点名称:' + r[0].stationName + '</span>' + 
						'<span class="help-block" style="color:#DDD;font-size: 15px;">站点编码:' + r[0].stationCode + '</span>' +
						'<span class="help-block" style="color:#DDD;font-size: 15px;">站点序号:' + r[0].stationRouteCode + '</span>' +
						'<span class="help-block" style="color:#DDD;font-size: 15px;">纬度坐标:' + r[0].stationJwpoints + '</span>' +
						'<span class="help-block" style="color:#DDD;font-size: 15px;">范围半径:' + r[0].stationRadius + '</span>' +
						'<span class="help-block" style="color:#DDD;font-size: 15px;">版本 号:' + r[0].stationRouteVersions + '</span>' +
						'<span class="help-block"  style="width: 100%;font-size: 15px;;color:#DDD; overflow: hidden; white-space: nowrap;  text-overflow: ellipsis; " title="'+ 'ddd' +'" >说明/描述:' + 'ddd' + '</span>' ;
						
						// 信息窗口参数属性
				  		var opts = {
				  				
									// 信息窗口宽度
									width : 200,
									
									// 信息窗口高度
									height : 450,
									
									// 信息窗位置偏移值。
									offset: new BMap.Size(500,-80),
									
									//标题
									title : '<h4 style="color:#FFFFFF">'+r[0].stationName+'站详情</h4>',
									
									//设置不允许信窗发送短息
									enableMessage : false,
									
									//是否开启点击地图关闭信息窗口
									enableCloseOnClick : false,
									
									// 是否开启信息窗口打开时地图自动移动(默认开启)。(自 1.1 新增)
									enableAutoPan:true
							};
						
						if(stationShapesType == 'r') {
							
							// 画圆
							PublicFunctions.pointsCircle(r,point,htm,opts,mapB);
							
						}else if(stationShapesType == 'd'){
							
							// 画多边形
							PublicFunctions.pointsPolygon(r,point,htm,opts,mapB);
							
						}
						
					}
					
				});
			},
			
			editSeteditStationParmasValue : function(points,gLonx,gLaty,bPolygonGridValue,gPolygonGridVlaue,shapesTypeValue,radiusValue) {
				
				// 百度地图经纬度坐标中心点
				stationObj[0].stationJwpoints = points;
				
				// WGS经度
				stationObj[0].stationGlonx = gLonx;
				
				//  WGS经度
				stationObj[0].stationGlaty = gLaty;
				
				// 百度坐标点图形集合 
				stationObj[0].stationGPloyonGrid = gPolygonGridVlaue;
				
				// WGS坐标点图形集合
				stationObj[0].stationBPolyonGrid = bPolygonGridValue;
				
				// 图形类型
				stationObj[0].stationShapesType = shapesTypeValue;
				
				// 圆形半径
				stationObj[0].stationRadius = radiusValue;
				
			},
			
			// 原百度坐标转WGS坐标
			getFormPointEToWGS: function(points,callback) {
				
				// 获取长度
				var len = points.length;
				
				(function(){
					
					 if (!arguments.callee.count) {
						 
						 arguments.callee.count = 0;
						 
					 }
					 
					 arguments.callee.count++;
					 
					 var index = parseInt(arguments.callee.count) - 1;
					 
					 if (index >= len) {
						 
						 callback && callback(points);
			        	  
			              return;
			          }
					 
					 var f = arguments.callee;
					 
					 $.ajax({
						  
			              url: 'http://api.zdoz.net/bd2wgs.aspx',
			              
			              data: {lat: points[index].potion.lat , lng: points[index].potion.lng},
			              
			              dataType: 'jsonp',
			              
			              success: function(r){
			            	  
			            	  if(r) {
			            		  
			            		  points[index].WGSpotion = r;
			            		  
			            	  }
			            	  
			            	  f();
			              }
			          });
					
				})();
				
			},
			
			setFormValue : function() {

				// 站点ID
				$('#stationIdInput').val(stationObj[0].stationId);
				
				// 站点路由ID
				$('#stationRouteIdInput').val(stationObj[0].stationRouteId);
				
				// 站点路由线路Id
				$('#stationRouteLineInput').val(stationObj[0].stationRouteLine);
				
				// 线路编码
				$('#lineCodeInput').val(stationObj[0].stationRouteLIneCode);
				
				// WGS坐标点图形集合
				$('#bPolygonGridInput').val(stationObj[0].stationBPolyonGrid);
				
				// 百度坐标点图形集合 
				/*$('#gPolygonGridInput').val(stationObj[0].stationGPloyonGrid);*/
				
				// 获取站点名称元素设值
				$('#stationNameInput').val(stationObj[0].stationName);
				
				// 获取站点编码元素设值
				$('#stationCodInput').val(stationObj[0].stationCode);
				
				// 获取站点类型元素设值
				$('#stationMarkSelect').val(stationObj[0].stationRouteStationMark);
				
				// 获取站点方向元素设值
				$('#stationdirSelect').val(stationObj[0].stationRoutedirections);
				
				// 获取站点道路编码元素设值
				$('#roadCodingCodInput').val(stationObj[0].stationRoadCoding);
				
				// 百度地图经纬度坐标中心点
				$('#bJwpointsInput').val(stationObj[0].stationJwpoints);
				
				//  WGS经纬度
				/*$('#gJwpointsInput').val(stationObj[0].stationGlonx + ' ' + stationObj[0].stationGlaty);*/
				
				// 获取图形类型元素,并添加值
				$('#shapesTypeSelect').val(stationObj[0].stationShapesType);
				
				// 获取半径元素,并添加值
				$('#radiusInput').val(stationObj[0].stationRadius);
				
				// 是否撤销
				$('#destroySelect').val(stationObj[0].stationRouteDestroy);
				
				// 到站时间
				$('#toTimeInput').val(stationObj[0].stationRouteToTime);
				
				// 到站距离
				$('#distancesInput').val(stationObj[0].stationRouteDistances);
				
				// 描述/说明
				$('#descriptionsTextarea').val(stationObj[0].stationRouteDescriptions);
				
			},
			
			// 树数据获取
			getStation : function(id_,dir_,callback) {
				
				var treeDateJson = [];
						
				$get('/stationroute/findStations',{'line.id_eq' : id_ , 'directions_eq' : dir_},function(resultdata) {
					
					treeDateJson = createTreeData(resultdata);
							
					callback && callback(treeDateJson);
							
				});
						
			},
			
			findUpStationRouteCode : function(lineId,diraction,stationRouteCode,callback) {
				
				$get('/stationroute/findUpStationRouteCode',{lineId:lineId,direction:diraction,stationRouteCode:stationRouteCode},function(result) {
					
					callback && callback(result);
					
				});
				
			},
			
			getStationRouteInfo : function(stationId,callback){
				
				$get('/stationroute/findStationRouteInfo',{id:stationId},function(r) {
					
					callback && callback(r);
					
				});
				
			},
			
			pointsPolygon : function(r,pointPolygon,htm,opts_polygon,map) {
				
				// 获取多边形坐标字符串
				var stationBPolygonGrid = r[0].stationBPolyonGrid;
				
				// 截取多边形坐标字符串
				var stationBPolygonGridStr = stationBPolygonGrid.substring(9,stationBPolygonGrid.length-2);
				
				// 按逗号切割
				var pointPolygonArray = stationBPolygonGridStr.split(',');
				
				// 多边形坐标集合
				var polygonP = [];
				
				for(var v = 0;v<pointPolygonArray.length;v++) {
					
					polygonP.push(new BMap.Point(pointPolygonArray[v].split(" ")[0],pointPolygonArray[v].split(" ")[1]));
					
				}
				
				// 画多边形
				polygon = new BMap.Polygon(polygonP, {
					
					// 线条显色
		  			strokeColor : "blue",
		  			
		  			// 边线的宽度,以像素为单位。
		  			strokeWeight : 2,
		  			
		  			// 边线透明度,取值范围0 - 1。
		  			strokeOpacity : 0.5
		  		});
				
				// 增加地图覆盖物多边形
				map.addOverlay(polygon);  
		  		
				// 创建信息窗口
				infoWindow = new BMap.InfoWindow(htm, opts_polygon);
				
			  	// 自定义标注物图片
		  	    var icon_target = new BMap.Icon('/pages/base/stationroute/css/img/cz.png',new BMap.Size(20, 20));
		  	  	
		  	  	// 创建点
				marker = new BMap.Marker(pointPolygon,{icon : icon_target}); 
					
				// 把标注添物加到地图上
		  		map.addOverlay(marker);
		  		
		  		// 是否在平移过程中禁止动画。(自1.2新增)
		  		var PanOptions_ ={noAnimation :true};
		  		
		  		// 将地图的中心点更改为给定的点。
		  		map.panTo(pointPolygon,PanOptions_);
		  		
		  		// 将地图在水平位置上移动x像素,垂直位置上移动y像素。
		  		map.panBy(10,110,PanOptions_);
		  		
		  		//开启信息窗口
		  		marker.openInfoWindow(infoWindow,pointPolygon);
				
			},
			
			pointsCircle : function(r,point,htm,opts,map) {
				
				//创建圆
		  		circle = new BMap.Circle(point,r[0].stationRadius,{strokeColor:"blue", strokeWeight:2, strokeOpacity:0.5});
		  		
		  		// 允许覆盖物在map.clearOverlays方法中被清除
		  		circle.enableMassClear();
		  		
		  		// 百度地图添加覆盖物圆
		  		map.addOverlay(circle);
		  		
		  		// 创建信息窗口
		  		infoWindow = new BMap.InfoWindow(htm, opts);
		  		
			  	// 自定义标注物图片
		  	    var icon_target = new BMap.Icon('/pages/base/stationroute/css/img/cz.png',new BMap.Size(20, 20));
		  	  	
		  	  	// 创建点
				marker = new BMap.Marker(point,{icon : icon_target}); 
					
				// 把标注添物加到地图上
			  	map.addOverlay(marker);
			  		
			  	setTimeout(function(){
			  		//开启信息窗口
			  	  	marker.openInfoWindow(infoWindow,point);
					
			  	},100);
			  		
		  		// 是否在平移过程中禁止动画。(自1.2新增)
		  		var PanOptions_ ={noAnimation :true};
			  		
		  		// 将地图的中心点更改为给定的点。
		  		map.panTo(point,PanOptions_);
		  		
		  		//map.panBy(10,-50,PanOptions_);
			  		
		  		// 添加标志物监听事件
		  		marker.addEventListener("click",function() {
			  			
		  			//开启信息窗口
		  			marker.openInfoWindow(infoWindow,point);
			  			
			  	});
			},
			
			// 站点更新
			stationUpdate : function(station,callback) {
				
				$post('/station/stationUpdate',station,function(data) {
					
					callback && callback(data);
					
				});
				
			},
			
			clearRefresh : function() {
				
				// 清楚地图覆盖物
				mapB.clearOverlays();
				
				$('#eidt').attr("disabled",false);
			 	
			  	$('#eidt').removeClass('btn disabled');
			  	
			  	$('#eidt').addClass('btn');
				
				stationObj='';
				
				PublicFunctions.initStationInfo(stationId,mapB);
				
			},
			
			getstationObjData : function(){
				
				return stationObj;
			},
			
			getStationIdValue : function() {
				
				return stationId;
			},
			
			setStationNameValue : function(editStationName) {
				
				stationObj[0].stationName = editStationName;
				
				return stationObj;
			},
			
			getPolygonObj : function() {
				
				return polygon;
			},
			
			getMarkerObj : function() {
				
				return marker;
			},
			
			getCircleObj : function() {
				
				return circle;
				
			}
	}
	
	return PubFun ;
	
}();