station-positions-map.js 11.4 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
/**
 * 百度地图
 * 
 */

var WorldsBMap = function () {
	
	var mapBValue = '',drawingManagerInit='';
	
	var Bmap = {
			
			init : function() {
				
				// 关闭左侧栏
				if (!$('body').hasClass('page-sidebar-closed')) {
					
					$('.menu-toggler.sidebar-toggler').click();
					
				}
				
				// 设置中心点,
				var CENTER_POINT = {lng : 121.528733,lat : 31.237425};
				
				// 百度API Key
				var bdKey = 'IGGrr4UjwIYzatoCRFKEL8sT';
				
				// 初始化百度地图
				mapBValue = new BMap.Map("bmap_basic");
				
				//中心点和缩放级别
				mapBValue.centerAndZoom(new BMap.Point(CENTER_POINT.lng,CENTER_POINT.lat), 15);
				
				//启用地图拖拽事件,默认启用(可不写)
				mapBValue.enableDragging(); 
				
				//启用地图滚轮放大缩小
				mapBValue.enableScrollWheelZoom(); 
				
				//禁用鼠标双击放大
				mapBValue.disableDoubleClickZoom();
				
				//启用键盘上下左右键移动地图
				mapBValue.enableKeyboard();
				
				return mapBValue;
			},
			
			// 获取百度地图map值
			getMapBValue : function(){
				
				return mapBValue;
			},
			
			initDrawingManager : function(map,styleOptions) {
				
				// 创建鼠标绘制管理类
				drawingManagerInit = new BMapLib.DrawingManager(map, {
					
					//是否开启绘制模式
					isOpen : false,
					
					//是否显示工具栏
					enableDrawingTool : false,
					
					drawingToolOptions : {
						
						//位置
						anchor : BMAP_ANCHOR_TOP_RIGHT,
						
						//偏离值
						offset : new BMap.Size(5, 5),
						
						//工具栏缩放比例
						scale : 0.8
						
					},
					
					//线的样式
					polygonOptions : styleOptions
					
				});
				
				// 添加绘画完成事件
				drawingManagerInit.addEventListener('polygoncomplete', function(e) {
					
					 drawingManagerInit.close();
					 
					 if (e.getPath().length <= 2) {
						 
						// 弹出提示消息
						layer.msg('坐标点不能小于等于两个...');
						 
						 // 清除地图覆盖物
						 map.clearOverlays();
						 
						 // 加载该线路下所有站点位置添加到地图上
						 return false;
						 
					 }else {
						 
						 var pointE = e;
						 
						 // 多变行质心点
						 var addSttationPoints_ = pointE.getBounds().getCenter().lng+ ' ' + pointE.getBounds().getCenter().lat;
						 
						 var PointsList = [];
						 
						 for ( var i = 0; i < pointE.getPath().length; i++) {
								
				 			 PointsList.push({potion: {lng: pointE.getPath()[i].lng, lat: pointE.getPath()[i].lat}});
					 			 
					 	 }
						 
						 PointsList.push({potion: {lng: pointE.getPath()[0].lng, lat: pointE.getPath()[0].lat}});
						 
						 var centre  = [{potion:{lng:pointE.getBounds().getCenter().lng,lat:pointE.getBounds().getCenter().lat}}];
						 
						 var gPloygonGrid = '';
							
						 var bPloygonGrid = '';
						 
						 var pointsListLen_ = PointsList.length;
						 
						 for(var k =0;k<pointsListLen_;k++) {
								
							 if(k==0) {
									
								 bPloygonGrid = PointsList[k].potion.lng + ' ' +PointsList[k].potion.lat;
									
							 }else {
									
								 bPloygonGrid = bPloygonGrid + ',' + PointsList[k].potion.lng + ' ' +PointsList[k].potion.lat;
									
							 }
								
						 }
						 
						 PublicFunctions.editSeteditStationParmasValue(addSttationPoints_,'','',bPloygonGrid,'','d','');
							
						 $.get('edit.html', function(m){$(pjaxContainer).append(m);});
						 
						 /*PublicFunctions.getFormPointEToWGS(PointsList,function(resultdata) {
							 
							 var gPloygonGrid = '';
								
							 var bPloygonGrid = '';
								
							 for(var k =0;k<resultdata.length;k++) {
									
								 if(k==0) {
										
									 gPloygonGrid = resultdata[k].WGSpotion.Lng + ' ' +resultdata[k].WGSpotion.Lat;
										
									 bPloygonGrid = resultdata[k].potion.lng + ' ' +resultdata[k].potion.lat;
										
								 }else {
										
									 gPloygonGrid = gPloygonGrid + ',' + resultdata[k].WGSpotion.Lng + ' ' +resultdata[k].WGSpotion.Lat;
										
									 bPloygonGrid = bPloygonGrid + ',' + resultdata[k].potion.lng + ' ' +resultdata[k].potion.lat;
										
								 }
									
							 }
							 
							 gPloygonGrid = 'POLYGON((' + gPloygonGrid + '))';
							 
							 bPloygonGrid = 'POLYGON((' + bPloygonGrid + '))';
							 
							 PublicFunctions.getFormPointEToWGS(centre,function(p) {
								 
								 var gLonx = p[0].WGSpotion.Lng;
									
								 var gLaty = p[0].WGSpotion.Lat;

								 PublicFunctions.editSeteditStationParmasValue(addSttationPoints_,gLonx,gLaty,bPloygonGrid,gPloygonGrid,'d','');
									
								$.get('edit.html', function(m){$(pjaxContainer).append(m);});
								 
							 });
							 
						  });*/
					 }
					 
				});
				
				return drawingManagerInit;
			},
			
			// 获取绘制工具类
			getDrawingManagerValue : function() {
				
				return drawingManagerInit;
			},
			
			// 打开绘画工具
			/*drawingManagerOpen : function() {
				
				// 清楚地图覆盖物
				mapB.clearOverlays();
				
				// 打开鼠标绘画工具
				drawingManager.open();
				
				// 设置属性
				drawingManager.setDrawingMode(BMAP_DRAWING_POLYGON);
				
			},*/
			
			// 编辑图形
			editShapes : function(stationShapesTypeV,mindex) {
				
				// 编辑圆
				if(stationShapesTypeV =='r') {
					
					var enCircle = PublicFunctions.getCircleObj();
					
					// 开启编辑功能
					enCircle.enableEditing();
					
					// 编辑圆监听事件
					enCircle.addEventListener('dblclick',function() {
						
						// 关闭提示弹出层
						layer.close(mindex);
						
						// 返回圆形的半径,单位为米。
						var newRadius = enCircle.getRadius();
						
						// 返回圆形的中心点坐标。
						var newCenter = enCircle.getCenter().lng + ' ' + enCircle.getCenter().lat;
						
						var centre_New = [{potion:{lng:enCircle.getCenter().lng,lat:enCircle.getCenter().lat}}];
						
						// 设置修改站点参数集合
						PublicFunctions.editSeteditStationParmasValue(newCenter, '', '','','','r',Math.round(newRadius));
						
						// 加载编辑页面
						$.get('edit.html', function(m){$(pjaxContainer).append(m);});
						
						// 中心百度坐标转WGS坐标
						/*PublicFunctions.getFormPointEToWGS(centre_New,function(p) {
							 
							// 设置修改站点参数集合
							PublicFunctions.editSeteditStationParmasValue(newCenter, p[0].WGSpotion.Lng , p[0].WGSpotion.Lat,'','','r',Math.round(newRadius));
							
							// 加载编辑页面
							$.get('edit.html', function(m){$(pjaxContainer).append(m);}); 
							
						});*/
						
					});
				
				// 编辑多变行
				}else if(stationShapesTypeV =='d') {
					
					var enPolygon = PublicFunctions.getCircleObj();
					
					// 开启编辑功能(自 1.1 新增)
					enPolygon.enableEditing();
					
					// 添加多变行编辑事件
					enPolygon.addEventListener('dblclick',function(e) {
						 
						 // 获取编辑的多边形对象
						 var edit_pointE = enPolygon;
						 
						 // 多边形坐标点集合
						 var eidt_PointsList = [];
							
						 for ( var i = 0; i < edit_pointE.getPath().length; i++) {
								
							 eidt_PointsList.push({potion: {lng: edit_pointE.getPath()[i].lng, lat: edit_pointE.getPath()[i].lat}});
					 			 
					 	 }
						 
						 eidt_PointsList.push({potion: {lng: edit_pointE.getPath()[0].lng, lat: edit_pointE.getPath()[0].lat}});
						 
						 var edit_centre  = [{potion:{lng:edit_pointE.getBounds().getCenter().lng,lat:edit_pointE.getBounds().getCenter().lat}}];
						 
						 // 多边形中心点
						 var centre_points = edit_pointE.getBounds().getCenter().lng + ' ' + edit_pointE.getBounds().getCenter().lat;
						 
						 // 多边形WGS坐标字符串
						 var eidt_gPloygonGrid = '';
						 
						 // 百度坐标字符串
						 var edit_bPloygonGrid = '';
						 
						 var eidt_PointsListLen_ = eidt_PointsList.length;
							
						 for(var k =0;k<eidt_PointsListLen_;k++) {
								
							 if(k==0) {
									
								 edit_bPloygonGrid = eidt_PointsList[k].potion.lng + ' ' +eidt_PointsList[k].potion.lat;
									
							 }else {
									
								 edit_bPloygonGrid = edit_bPloygonGrid + ',' + eidt_PointsList[k].potion.lng + ' ' +eidt_PointsList[k].potion.lat;
									
							 }
								
						 }
						 
						 // 设置编辑站点参宿集合
						 PublicFunctions.editSeteditStationParmasValue(centre_points,'','',edit_bPloygonGrid,'','d','');
						 
						 // 加载编辑页面
						 $.get('edit.html', function(m){$(pjaxContainer).append(m);});
						 
						 // 多边形坐标点集合转WGS坐标
						 /*PublicFunctions.getFormPointEToWGS(eidt_PointsList,function(resultdata) {
							 
							 // 多边形WGS坐标字符串
							 var eidt_gPloygonGrid = '';
							 
							 // 百度坐标字符串
							 var edit_bPloygonGrid = '';
								
							 for(var k =0;k<resultdata.length;k++) {
									
								 if(k==0) {
										
									 eidt_gPloygonGrid = resultdata[k].WGSpotion.Lng + ' ' +resultdata[k].WGSpotion.Lat;
										
									 edit_bPloygonGrid = resultdata[k].potion.lng + ' ' +resultdata[k].potion.lat;
										
								 }else {
										
									 eidt_gPloygonGrid = eidt_gPloygonGrid + ',' + resultdata[k].WGSpotion.Lng + ' ' +resultdata[k].WGSpotion.Lat;
										
									 edit_bPloygonGrid = edit_bPloygonGrid + ',' + resultdata[k].potion.lng + ' ' +resultdata[k].potion.lat;
										
								 }
									
							 }
							 
							 eidt_gPloygonGrid = 'POLYGON((' + eidt_gPloygonGrid + '))';
							 
							 edit_bPloygonGrid = 'POLYGON((' + edit_bPloygonGrid + '))';
							 
							 // 中心点坐标转WGS坐标
							 PublicFunctions.getFormPointEToWGS(edit_centre,function(p) {
								 
								 var edit_gLonx = p[0].WGSpotion.Lng;
									
								 var edit_gLaty = p[0].WGSpotion.Lat;
								 
								 // 设置编辑站点参宿集合
								 PublicFunctions.editSeteditStationParmasValue(centre_points,edit_gLonx,edit_gLaty,edit_bPloygonGrid,eidt_gPloygonGrid,'d','');
								 
								 // 加载编辑页面
								 $.get('edit.html', function(m){$(pjaxContainer).append(m);});
								 
							 });
							 
						  });*/
						
					});
					
				}
				
			},
			
			localSearchFromAdreesToPoint: function(Address,map,callback) {
				
				// 创建一个搜索类实例
				var localSearch = new BMap.LocalSearch(map);
				
				// 检索完成后的回调函数。
				localSearch.setSearchCompleteCallback(function (searchResult) {
					
					var resultPoints = '';
					
					if(searchResult) {
						
						// 返回索引指定的结果。索引0表示第1条结果
						var poi = searchResult.getPoi(0);
						
						if(poi) {
							
							//获取经度和纬度
							resultPoints = poi.point.lng + ' ' + poi.point.lat;
							
							callback && callback(resultPoints);
							
						}else {
							
							callback && callback(false);
							
						}
						
					}else {
						
						callback && callback(false);
					}
					
				});
				
				// 根据检索词发起检索。
				localSearch.search(Address);
				
			}
			
	}
	
	return Bmap;
	
}();