<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
			   xmlns:s="library://ns.adobe.com/flex/spark"
			   xmlns:esri="http://www.esri.com/2008/ags"
			   xmlns:mx="library://ns.adobe.com/flex/mx"
			   xmlns:access="com.jtgh.yjpt.view.access.*"
			   xmlns:service="com.jtgh.yjpt.common.service.*"
			   xmlns:tdt="com.xt.hb.tdt.*"
			   xmlns:server="com.xt.hb.server.*"
			   minWidth="955" minHeight="600"
			   preloader="com.sys.NewProgressBar"
			   initialize="init(event)"
			   creationComplete="application_creationCompleteHandler(event)" xmlns:views="com.xt.hb.views.*">
	<fx:Metadata>
	</fx:Metadata>
	<fx:Declarations>
		<server:XMLDecoder id="xmlDecoder" menuConfigLoad="xmlDecoder_menuConfigLoadHandler(event)"/>
		<!-- 将非可视元素（例如服务、值对象）放在此处 -->
		<!-- <s:Move id="toolsCtMove" target="{toolsCt}" duration="500"/>
		<s:Move id="btnMove" target="{arrowLeft}" duration="500"/> -->
	</fx:Declarations>
	<fx:Script source="com/xt/hb/views/show.as"/>
	<fx:Script source="com/xt/hb/views/Main_MenuNavigation.as"/>
	<fx:Script>
		<![CDATA[
			import com.esri.ags.events.DetailsEvent;
			import com.esri.ags.events.ExtentEvent;
			import com.esri.ags.events.ZoomEvent;
			import com.esri.ags.geometry.MapPoint;
			import com.esri.ags.layers.FeatureLayer;
			import com.esri.ags.layers.Layer;
			import com.esri.ags.layers.supportClasses.LayerDetails;
			import com.esri.ags.renderers.SimpleRenderer;
			import com.esri.ags.symbols.PictureMarkerSymbol;
			import com.supermap.framework.events.BaseEventDispatcher;
			import com.tcb.ConvertListToXML;
			import com.xt.hb.ais.AisMgr;
			import com.xt.hb.events.DataConfigEvent;
			import com.xt.hb.events.MenusEvent;
			import com.xt.hb.events.NavigationEvent;
			import com.xt.hb.tdt.TianDiTuTiledMapServiceLayer;
			import com.xt.hb.utils.GisUtils;
			import com.xt.hb.utils.MapUtils;
			import com.xt.hb.utils.RemoteUtils;
			import com.xt.hb.utils.GlobalData;
			import com.xt.hb.views.TCKZModel;
			
			import mx.collections.ArrayCollection;
			import mx.core.FlexGlobals;
			import mx.events.FlexEvent;
			import mx.rpc.events.AbstractEvent;
			import mx.rpc.events.FaultEvent;
			import mx.rpc.events.ResultEvent;
			private var tckzModel:TCKZModel = new TCKZModel;
			
			public var menuConfig:XML = null;
			[bindable]
			public var menuXML:XML = null;
			public var tcArr:ArrayCollection = null;
			/** 当前是否显示了工具窗口 */
			private var toolsShow:Boolean = true;
			
			
			/** 当前选中图层ID */
			private var currSelectedLayerId:String;
			/** 当前图层 */
			private var fLayer:FeatureLayer;
			private var moveFlag1:Boolean = false;
			// 加载显示港口经营人块状图形数据
			private var jyrAreaFeatureSet:FeatureSet = null;
			// 港口经营人坐标数据
			private var jyrAllFeatureSet:FeatureSet = null;
			// 港区
			private var gqAreaFeatureSet:FeatureSet = null;
			// 码头
			private var mtAreaFeatureSet:FeatureSet = null;
			// 泊位
			private var bwAreaFeatureSet:FeatureSet = null;
			
			protected function init(event:FlexEvent):void
			{
//				RemoteUtils.callRemote("gpsCtl","queryGpsRealtime",function(e:AbstractEvent):void{
//					if(e is FaultEvent){
//						trace("error");
//					}else {
//						var gpsArr:ArrayCollection = ResultEvent(e).result as ArrayCollection;
//						trace(gpsArr.length);
//					}
//				});
			}
			
			// 默认显示地图
			private var currMapType:Number = 2;
			protected function application_creationCompleteHandler(event:FlexEvent):void
			{
				// 初始化系统全局参数
				RemoteUtils.callRemote("aisCtl","initFlexData",function(e:AbstractEvent):void{
					if(e is FaultEvent){
						trace("error initFlexData");
					}else {
						
						var resultObj:Object = ResultEvent(e).result as Object;
						// 初始化全局参数
						initFlexData(resultObj);
						//初始化默认加载项
						initDefaultLoad();
					}
				});
			}
			
			/**
			 * 初始化默认加载项
			 */
			public function initDefaultLoad():void{
				// 左边菜单栏-隐藏
				BaseEventDispatcher.getInstance().addEventListener(MenusEvent.MENUHIDE, movePenal);
				BaseEventDispatcher.getInstance().addEventListener(NavigationEvent.MENUCHAGE, navigationMenu);
				// 右边图层控制
				BaseEventDispatcher.getInstance().addEventListener(NavigationEvent.MENUCHANGETWO, navigationMenu);
				// 初始化触发加载左边港区港口港口企业 和 图层控制菜单
				BaseEventDispatcher.getInstance().dispatchEvent(
					new NavigationEvent(NavigationEvent.MENUCHAGE,"leftMenu"));
				BaseEventDispatcher.getInstance().dispatchEvent(
					new NavigationEvent(NavigationEvent.MENUCHANGETWO,"rightMenu"));
				// 初始化
				tckzModel.checkBoxClickHandler = checkBox_click;
			}
			
			public function initMap():void{
				var vec:TianDiTuTiledMapServiceLayer = new TianDiTuTiledMapServiceLayer();
				vec.id="地形";
				vec.baseURL="http://t";
				vec.baseURLs="vec";
				vec.showLevel="17";
				vec.visible=false;
				map.addLayer(vec,1);
				
				var img:TianDiTuTiledMapServiceLayer = new TianDiTuTiledMapServiceLayer();
				img.id="影像";
				img.baseURL="http://tile";
				img.baseURLs="img";
				img.showLevel="17";
				img.visible=true;
				map.addLayer(img,2);
			}
			private function movePenal(e:MenusEvent = null):void
			{
				/**this.toolsCtMove.end();
				if(toolsShow)
				{
					this.toolsCtMove.xTo=FlexGlobals.topLevelApplication.width;
				}else
				{
					this.toolsCtMove.xTo=FlexGlobals.topLevelApplication.width-this.toolsCt.width;
				}
				this.toolsCtMove.play();
				
				// 移动显示按钮
				this.btnMove.end();
				if(toolsShow)
				{
					this.btnMove.xTo=FlexGlobals.topLevelApplication.width-19;
				}else
				{
					this.btnMove.xTo=FlexGlobals.topLevelApplication.width;
				}
				this.btnMove.play();
				
				toolsShow = !toolsShow;**/
			}
			protected function xmlDecoder_menuConfigLoadHandler(event:DataConfigEvent):void
			{
//				this.menuConfig =  event.data as XML;
//				this.featureStyle = ConfigUtil.getFeatureStyle(this.menuConfig);
			}
			protected function map_mouseMoveHandler(event:MouseEvent):void
			{
				var mp:MapPoint= map.toMapFromStage(event.stageX,event.stageY);
				labelX.text="x:"+numFormater.format(mp.x);
				labelY.text="y:"+numFormater.format(mp.y);
			}
			public function getMap():Map
			{
				return this.map;
			}
			/**
			 * 清空所有图标
			 * @TODO
			 */
			public function clearAllTempLayer():void
			{
			}
			/** 安全系统图层 */
			protected function aqtc_clickHandler(event:MouseEvent = null,type:String = null):void
			{
//				PopUpManager.addPopUp(aqtcWindow,FlexGlobals.topLevelApplication as DisplayObject,false);
//				PopUpManager.centerPopUp(aqtcWindow);
			}
			
			protected function map_extentChangeHandler(event:ExtentEvent):void
			{
				// 当前比例尺
				var currScale:Number =  map.scale;
				trace(currScale);
				// 显示船舶ais
				if(currScale<250000){
					AisMgr.getInstance().refreshAis();
					GpsMgr.getInstance().refreshGps();
				}else{
					AisMgr.getInstance().stopAis();
					GpsMgr.getInstance().stopGps();
				}
				// 显示经营人
//				if(currScale<40000){
//					initGkjyrArea();
//				}else{
//					clearGkjyrArea();
//				}
				// 显示港区
				initGqArea();
				// 显示码头和泊位
				initMtBwArea();
				// 显示港口
				var layer:GraphicsLayer = MapUtils.getGraphicLayerByName(ConstUtil.L_ID_GK);
				if(currScale<1200000 && currScale>140000){
					layer.visible = true;
				}else{
					layer.clear();
					layer.visible = false;
				}
			}
			protected function map_zoomEndHandler(event:ZoomEvent):void
			{
				trace(event.level+":"+map.scale);
			}
			
			/**
			 * 按钮事件（地图切换 ）
			 */
			protected function butn_clickHandler(event:MouseEvent):void
			{
				if(currMapType == 1)
				{
					currMapType = 2;
					tcqh.toolTip="显示矢量地图";
					mapTransf(map);
					tcqh.source = "flexResources/map/map.png";
				}
				else if(currMapType == 2)
				{
					currMapType = 1;
					tcqh.toolTip="显示影像地图";					
					mapTransf(map);
					tcqh.source = "flexResources/map/satellite.png";
				}
			}
			/**
			 * 地图切换
			 */
			private function mapTransf(myMap:Map):void
			{
				for each(var layerObj:Layer in myMap.layers)
				{
					var layername:String=layerObj.id.toString();
					if(layername.indexOf("地形")!=-1)
					{
						if (currMapType==1) {
							layerObj.visible=true;
						} else {
							layerObj.visible=false;
						}
					}
					else if(layername.indexOf("影像")!=-1)
					{
						if (currMapType==2) {
							layerObj.visible=true;
						} else {
							layerObj.visible=false;
						}
					}
				}
			}
			
			protected function hiddenLable_clickHandler(event:MouseEvent):void
			{
				BaseEventDispatcher.getInstance().dispatchEvent(new MenusEvent(MenusEvent.MENUHIDE,"hide"));
			}
			
			private function onAllDetailsComplete(event:DetailsEvent):void  
			{  
				//这里只做了一个图层，不同的点，线，面，需要判断  
				var p:LayerDetails = event.allDetails.layersDetails[0];  
				var pSimpleRender:SimpleRenderer = (SimpleRenderer)(p.drawingInfo.renderer);  
				var pSymbol:PictureMarkerSymbol = (PictureMarkerSymbol)(pSimpleRender.symbol);  
				image.source = pSymbol.source;
			}  
			
			//  
			private function onFault(event:FaultEvent):void  
			{  
				trace("not ok");  
			}  
			
			private function hideModel(e:MouseEvent):void
			{
				this.movePenal();
			}  
			
			private function hideLeftModel(e:MouseEvent):void
			{
				this.moveLeftPanal();
			}
			
			private function moveLeftPanal(e:MenusEvent = null):void{
				
				this.moveEff.end();
				if(moveFlag1==false){
					if(e == null)
					{
						this.moveEff.xTo = 0;
						moveFlag1 = true;
						this.titleWin.getElementAt(1).visible = false;
					}
					
				}else{
					this.moveEff.xTo = 0 - this.resShowModel.width;
					moveFlag1 = false;
					this.titleWin.getElementAt(1).visible = true;
				}
				this.moveEff.play();
			}
		]]>
	</fx:Script>
	<fx:Style>
		@namespace esri "http://www.esri.com/2008/ags";
		esri|InfoWindowLabel
		{
			color: #333;
			fontFamily:宋体;
			font-size: 14;
			fontWeight: bold;
			verticalAlign: middle;
			height: 25;
			maxWidth: 250;
			top: 250;
			left: 8;
		}
		esri|InfoWindow
		{
			background-color: #DFF1F9;  
			font-size: 12;
			upper-left-radius: 10;
			upper-right-radius: 10;  
			info-placement: upperRight;  /** 窗口显示位置 */
			info-offset-y: 20;
			border-style: solid;
			border-width: 2;
			border-color: #A2F1F9;
		}
	</fx:Style>
	<fx:Declarations>
		<esri:Extent id="extentOfJs" xmax="114.32" xmin="114.26" ymax="30.57" ymin="30.54"/>
		<mx:NumberFormatter id="numFormater" precision="2"/>
		<esri:SpatialReference id="sr" wkid="4326"/>
		<s:Move id="moveEff" target="{this.titleWin}" duration="500"/>
	</fx:Declarations>
	<esri:Map id="map" width="100%" height="100%" extent="{extentOfJs}"
			  extentChange="map_extentChangeHandler(event)" logoVisible="false"
			  mouseMove="map_mouseMoveHandler(event)" scaleBarVisible="false"
			  zoomEnd="map_zoomEndHandler(event)" zoomSliderVisible="false">
	</esri:Map>
	<!-- 用于显示图层的样式的 -->  
	<s:Image id="image" left="10" bottom="50"/>  
	<s:Label id="labelX" left="10" bottom="15" fontSize="15"/>
	<s:Label id="labelY" left="100" bottom="15" fontSize="15"/>
	<s:Image id="tcqh" right="10" top="45" buttonMode="true" click="butn_clickHandler(event)"
			 source="flexResources/map/map.png" toolTip="显示地形地图"
			 useHandCursor="true"/>
	<tdt:MapOperateModel right="10" top="10"/>
	<!--左侧二级菜单-->
	<mx:HBox  id="titleWin" x="-262" y="0" height="100%" horizontalScrollPolicy="off" verticalScrollPolicy="auto" horizontalGap="0">
	</mx:HBox>
	<!-- 安全系统图层 -->
	<mx:Canvas id="shipPopWin" x="{this.width-400}" y="{this.height-210}" width="100%" height="110%"></mx:Canvas>
	<!-- 资源定位 -->
	<!--<s:Image id="arrowLeft" click="hiddenLable_clickHandler(event)" source="flexResources/arrowRight.png" useHandCursor="true" buttonMode="true" y="100"  x="{FlexGlobals.topLevelApplication.width}" />
	<views:MapTools id="toolsCt" y="100" x="{FlexGlobals.topLevelApplication.width-280}" width="280" height="520" menuXML="{this.menuXML}" treeClickFun="checkBox_click" />
	-->
	<!-- 资源查询 -->
</s:Application>
