package com.xt.hb.utils
{
//	import com.object.FieldObject;
//	import com.server.GeometryType;
//	import com.supermap.web.core.Feature;
//	import com.supermap.web.core.Point2D;
//	import com.supermap.web.core.geometry.GeoLine;
//	import com.supermap.web.core.geometry.GeoPoint;
//	import com.supermap.web.core.geometry.GeoRegion;
//	import com.supermap.web.core.geometry.Geometry;
//	import com.supermap.web.core.styles.PictureMarkerStyle;
//	import com.supermap.web.core.styles.PredefinedFillStyle;
//	import com.supermap.web.core.styles.PredefinedLineStyle;
//	import com.supermap.web.core.styles.PredefinedMarkerStyle;
//	import com.supermap.web.mapping.Map;
//	import com.supermap.web.mapping.TiledDynamicRESTLayer;
	import com.esri.ags.Graphic;
	import com.esri.ags.geometry.MapPoint;
	import com.xt.hb.ais.BwxqModel;
	import com.xt.hb.object.FieldObject;
	
	import flash.events.MouseEvent;
	
	import mx.containers.Grid;
	import mx.containers.GridItem;
	import mx.containers.GridRow;
	import mx.controls.Alert;
	import mx.controls.HRule;
	import mx.controls.Image;
	import mx.controls.LinkButton;
	import mx.core.FlexGlobals;
	
	import spark.components.Label;
	
	
	
	public class ServicesUtility
	{
		public function ServicesUtility()
		{
		}
		
		
		/**
		 * 地图上的弹出框
		 * layerId：点的是什么东西
		 * obj：数据
		 * 
		 * */
		public static function showFeatrueToMap(layerId:String,graphic:Graphic,
				obj:Object,e:MouseEvent=null, isUseMousePoint:Boolean=false):void
		{
			try
			{
				var grid:Grid = new Grid();
				grid.setStyle("verticalGap",0);
				grid.setStyle("backgroundColor","#FFFFFF");
				
				var row:GridRow;
				var rowItem:GridItem;
				var label:Label;
				var img:Image;
				
				row = new GridRow();
				row.height = 10;
				rowItem = new GridItem();
				rowItem.colSpan = 4;
				rowItem.setStyle("horizontalAlign","center");
				
				row.addChild(rowItem);
				grid.addChild(row);
				
				var fieldArr:Array = FieldsUtility.getShowFields(layerId);
				var hRule:HRule;
				var i:int=0;
				
				for each(var f:FieldObject in fieldArr)
				{
					row = new GridRow();
					//row.height = 24;
					//前面留白
					rowItem = new GridItem();
					rowItem.width = 8;
					row.addChild(rowItem);
					
					rowItem = new GridItem();
					rowItem.setStyle("verticalAlign","middle");
					rowItem.setStyle("horizontalAlign","left");
					rowItem.setStyle("fontFamily","宋体");
					rowItem.setStyle("fontSize","12");
					
					label = new Label();
					label.text = f.getLabel() + "：";
					label.setStyle("color","#4c4c4c");
					
					rowItem.addChild(label);
					row.addChild(rowItem);
					//留白
					rowItem = new GridItem();
					rowItem.width = 15;
					row.addChild(rowItem);
					
					rowItem = new GridItem();
					rowItem.setStyle("verticalAlign","middle");
					rowItem.setStyle("horizontalAlign","left");
					rowItem.setStyle("fontFamily","宋体");
					rowItem.setStyle("fontSize","12");
					label = new Label();
					if(null != obj && typeof(obj[f.getField()]) != "object") {
						label.text = obj[f.getField()];
					}
					label.maxWidth = 160;
					label.minHeight = 24;
					label.setStyle("verticalAlign","middle");
					label.maxDisplayedLines=0; // 默认多行显示，不截取
					rowItem.addChild(label);
					row.addChild(rowItem);
					//后面留白
					rowItem = new GridItem();
					rowItem.width = 10;
					row.addChild(rowItem);
					
					grid.addChild(row);
					
					row = new GridRow();
					row.height = 4;
					
					if( i < fieldArr.length)
					{
						i++;
					}
					// 如果泊位则加详情
					if(layerId==ConstUtil.L_ID_BW ) {
						var fieldObj:FieldObject = fieldArr[fieldArr.length-1] as FieldObject;
						if(f.getField() == fieldObj.getField()) {
							addBwxq(grid, obj);
						}
					}
				}
				row = new GridRow();
				row.height = 5;
				
				grid.addChild(row);
				FlexGlobals.topLevelApplication.map
				MapUtils.map.infoWindow.content = grid;
				MapUtils.map.infoWindow.label = FieldsUtility.getTitleByLayerID(layerId);
				setInfoWindowStyle();
				if(isUseMousePoint) {
					MapUtils.map.infoWindow.show(MapUtils.map.toMapFromStage(
						e.stageX + 5, e.stageY - 5));
				} else {
					if(graphic.geometry.type == "esriGeometryPoint") {
						MapUtils.map.infoWindow.show(new MapPoint(graphic.geometry["x"],graphic.geometry["y"],null));
					} else {
						MapUtils.map.infoWindow.show(graphic.geometry.extent.center);
					}
				}
			}
			catch(error:Error) 
			{
				Alert.show("显示资源信息出错："+error.message);
			}
		}
		public static function setInfoWindowStyle(type:String = null):void
		{
			MapUtils.map.infoWindow.closeButtonVisible = true;
			MapUtils.map.infoWindow.labelVisible = true;
			MapUtils.map.infoWindow.setStyle("backgroundColor","#e2ecf1");
			MapUtils.map.infoWindow.setStyle("borderColor","#999999");
			MapUtils.map.infoWindow.setStyle("border-style","solid");
//			map.infoWindow.infoPlacement = "";
//			"upperRight", "lowerRight", "upperLeft", "lowerLeft", "left", "right", "top", "bottom", and "center".
//			map.infoWindow.infoWindowLabel.setStyle('color', "#333");
//			map.infoWindow.infoWindowLabel.setStyle('fontFamily', "宋体");
//			map.infoWindow.infoWindowLabel.setStyle('fontSize', "14");
//			map.infoWindow.infoWindowLabel.setStyle('fontWeight', "bold");
//			map.infoWindow.infoWindowLabel.setStyle('verticalAlign', "middle");
//			map.infoWindow.infoWindowLabel.height = 25;
//			map.infoWindow.infoWindowLabel.maxWidth=250;
//			map.infoWindow.infoWindowLabel.top = 18;
//			map.infoWindow.infoWindowLabel.left = 8;
			/*map.infoWindow.maintainProjectionCenter=false;*/
			/*var img:Image=new Image();
			map.infoWindow.addElement();*/
		}
		
		/**
		 * 增加泊位详情
		 */
		private static function addBwxq(grid:Grid, obj:Object):void {
			var id:String = obj.ID;
			// 定义link
			var link:LinkButton=new LinkButton();
			link.addEventListener(MouseEvent.CLICK,function (e:MouseEvent):void {ServicesUtility.bwInfo(e,id);});
			link.label="详 情>> ";
//			link.useHandCursor = true;
//			link..buttonMode = true;
			link.setStyle("color","#2F6EA1");
			// 将link插入表行
			var row:GridRow = new GridRow();
			var rowItem:GridItem = new GridItem();
			rowItem.colSpan = 5;
			rowItem.addChild(link);
			rowItem.setStyle("horizontalAlign","center");
			row.addChild(rowItem);
			grid.addChild(row);
		}
		
		/**
		 * 增加泊位详情
		 */
		private static function bwInfo(e:MouseEvent, id:String):void {
			if(null == id || typeof(id) == "undefined") {
			} else {
				var bwxqModel:BwxqModel = new BwxqModel;
				bwxqModel.bwid = id;
				var width:int = FlexGlobals.topLevelApplication.stage.stageWidth;
				var height:int = FlexGlobals.topLevelApplication.stage.stageHeight;
				var x:Number = width/2-230;
				var y:Number = height/2 - 165;
				CommonUtility.showTitleWindow(bwxqModel, false, x, y);
			}
			
		}
	}
}