import com.esri.ags.FeatureSet;
import com.esri.ags.Graphic;
import com.esri.ags.geometry.MapPoint;
import com.esri.ags.layers.GraphicsLayer;
import com.esri.ags.symbols.CompositeSymbol;
import com.esri.ags.symbols.LineSymbol;
import com.esri.ags.symbols.PictureMarkerSymbol;
import com.esri.ags.symbols.SimpleFillSymbol;
import com.esri.ags.symbols.SimpleLineSymbol;
import com.esri.ags.symbols.TextSymbol;
import com.xt.hb.ais.AisMgr;
import com.xt.hb.ais.GpsMgr;
import com.xt.hb.events.QueryLayerEvent;
import com.xt.hb.server.QueryAction;
import com.xt.hb.utils.ConfigUtil;
import com.xt.hb.utils.ConstUtil;
import com.xt.hb.utils.GisUtils;
import com.xt.hb.utils.GlobalData;
import com.xt.hb.utils.MapUtils;
import com.xt.hb.utils.RemoteUtils;
import com.xt.hb.utils.ServicesUtility;

import flash.events.Event;
import flash.events.MouseEvent;
import flash.net.URLRequest;
import flash.net.navigateToURL;

import mx.controls.Alert;
import mx.controls.Tree;
import mx.core.FlexGlobals;
import mx.rpc.events.AbstractEvent;
import mx.rpc.events.FaultEvent;
import mx.rpc.events.ResultEvent;

import spark.components.Label;


private var featureStyle:Object;

/**
 * 初始化全局参数
 */
private function initFlexData(resultObj:Object):void {
	GlobalData.bwLayerUrl = resultObj.BW_LAYER_URL;
	GlobalData.cbyjLayerUrl = resultObj.CBYJ_LAYER_URL;
	GlobalData.gkLayerUrl = resultObj.GK_LAYER_URL;
	GlobalData.gqLayerUrl = resultObj.GQ_LAYER_URL;
	GlobalData.jyrLayerUrl = resultObj.JYR_LAYER_URL;
	GlobalData.mtLayerUrl = resultObj.MT_LAYER_URL;
	GlobalData.qskLayerUrl = resultObj.QSK_LAYER_URL;
	GlobalData.spjkUrl = resultObj.SPJK_URL;
	GlobalData.spLayerUrl = resultObj.SP_LAYER_URL;
	GlobalData.yjwlLayerUrl = resultObj.YJWL_LAYER_URL;
}
/**
 * 图层控制checkbox勾选事件
 */
private function checkBox_click(event:Event):void
{
	if(!featureStyle)
		featureStyle = new Object();
	var state:String = Tree(event.currentTarget).selectedItem.@checkState;
	var layerId:String =  Tree(event.currentTarget).selectedItem.@cdid;
	trace(layerId);
	trace(Tree(event.currentTarget).selectedItem.@cdmc);
	if(layerId=="ALL")
	{
		checkAllLayer(state);
		return;
	}
	featureStyle[layerId] = Tree(event.currentTarget).selectedItem.@CDTB;
	if(state == "1")
	{
		var query:QueryAction = new QueryAction();
		//		query.queryLayer(layerId,QueryLayerEvent.QUERY_SUCCESS,"");
		queryLayer(layerId,QueryLayerEvent.QUERY_SUCCESS,"");
	}
	else
	{
		clearOneCheckedMenu(layerId);
	}
}

/**
 * 图层权限按钮处理
 */
private function checkAllLayer(state:String):void
{
	if(state == "1")
	{
		// 遍历所有菜单配置
		var list:XMLList = FlexGlobals.topLevelApplication.M_ZYZS_TCKZ_XML.children();
		for each( var xmlChildren:XML in list)  
		{
			if(xmlChildren.@cdid=="ALL")
			{
				continue;
			}
			if("0" == xmlChildren.@checkState) {
				xmlChildren.@checkState="1";
				queryLayer(xmlChildren.@cdid,QueryLayerEvent.QUERY_SUCCESS,"");
			}
		}
	}
	else
	{
		map.infoWindow.closeButton.dispatchEvent(new MouseEvent(MouseEvent.CLICK));
		clearAllCheckedMenu();
	}
	return;
}
public function clearAllCheckedMenu():void
{
	var list:XMLList = FlexGlobals.topLevelApplication.M_ZYZS_TCKZ_XML.children();
	for each( var xmlChildren:XML in list)  
	{
		xmlChildren.@checkState = "0";
		clearOneCheckedMenu(xmlChildren.@cdid);
	}
}

//查询成功在地图上显示
private function clearOneCheckedMenu(layerId:String):void
{
	if(ConstUtil.L_ID_AIS == layerId) {
		// 清空船舶ais
		AisMgr.getInstance().stopAis();
		//解除聚焦闪烁
		MapUtils.clearAISGraphic();
	} if(ConstUtil.L_ID_GPS == layerId) {
		// 清空船舶ais
		GpsMgr.getInstance().stopGps();
		//解除聚焦闪烁
		MapUtils.clearAISGraphic();
	} else if(ConstUtil.L_ID_GQ == layerId) {
		clearGqArea();
	}  else if(ConstUtil.L_ID_MT == layerId) {
		clearMtArea();
	}   else if(ConstUtil.L_ID_BW == layerId) {
		clearBwArea();
	} else if(ConstUtil.L_ID_JYR == layerId
		|| ConstUtil.L_ID_AQ_WXHWQY == layerId || 
		ConstUtil.L_ID_AQ_ZDWXYQY == layerId) {
		/** L_ID_JYR、L_ID_AQ_WXHWQY、L_ID_AQ_ZDWXYQY */
		var jyrChkState:String = "0";
		var wxhwChkState:String = "0";
		var zdwxyChkState:String = "0";
		var list:XMLList = FlexGlobals.topLevelApplication.M_ZYZS_TCKZ_XML.children();
		// 获取check状态
		for each( var xmlChildren:XML in list)  
		{
			if (ConstUtil.L_ID_JYR == xmlChildren.@cdid) {
				jyrChkState = xmlChildren.@checkState;
			} else if (ConstUtil.L_ID_AQ_WXHWQY == xmlChildren.@cdid) {
				wxhwChkState = xmlChildren.@checkState;
			} else if (ConstUtil.L_ID_AQ_ZDWXYQY == xmlChildren.@cdid) {
				zdwxyChkState = xmlChildren.@checkState;
			}
		}
		// 获取图层
		var jyrLayer:GraphicsLayer = MapUtils.getGraphicLayerByName(ConstUtil.L_ID_JYR);
		var wxhwLayer:GraphicsLayer = MapUtils.getGraphicLayerByName(ConstUtil.L_ID_AQ_WXHWQY);
		var zdwxyLayer:GraphicsLayer = MapUtils.getGraphicLayerByName(ConstUtil.L_ID_AQ_ZDWXYQY);
		// 清空
		if(jyrChkState == "0") {
			jyrLayer.clear();
			if(wxhwChkState == "0") {
				wxhwLayer.clear();
			}
			if(zdwxyChkState == "0") {
				zdwxyLayer.clear();
			}
		}
	} else {
		var layer:GraphicsLayer = MapUtils.getGraphicLayerByName(layerId);
		layer.clear();
	}
}

public function queryLayer(layerId:String,eventFlag:String,
						   where:String = null,isExpectCount:Boolean = false):void
{
	//	TC17	AIS		L_ID_AIS
	//	TC18	应急网络	L_ID_YJWL
	//	TC19	码头	L_ID_MT
	//	TC20	经营人	L_ID_JYR
	//	TC21	泊位	L_ID_BW
	//	TC22	船舶预警	L_ID_CBYJ
	//	TC22	视频	L_ID_SP
	if(ConstUtil.L_ID_AIS == layerId) {
		//		var mp:MapPoint = new MapPoint(114.27748,30.593765,null);
		//		map.level = 15;
		//		map.centerAt(mp);
		// 当前比例尺
		var currScale:Number =  map.scale;
		// 显示船舶ais
		if(currScale<250000){
			AisMgr.getInstance().refreshAis();
		}
	} else if(ConstUtil.L_ID_GPS == layerId) {
		//		var mp:MapPoint = new MapPoint(114.27748,30.593765,null);
		//		map.level = 15;
		//		map.centerAt(mp);
		// 当前比例尺
		var currScale1:Number =  map.scale;
		// 显示船舶ais
		GpsMgr.getInstance().refreshGps();
	} else if(ConstUtil.L_ID_GQ == layerId) {
		initGqArea();
	} else if(ConstUtil.L_ID_MT == layerId) {
		initMtArea();
		// 港口经营人、港口危险货物企业、重大危险源企业
	} else if(ConstUtil.L_ID_JYR == layerId
		|| ConstUtil.L_ID_AQ_WXHWQY == layerId || 
		ConstUtil.L_ID_AQ_ZDWXYQY == layerId) {
		queryJyrLayer();
	} else if(ConstUtil.L_ID_BW == layerId) {
		initBwArea();
	} else if(ConstUtil.L_ID_CBYJ == layerId) {
		queryCbyjLayer();
	} else if(ConstUtil.L_ID_SP == layerId) {
		querySpLayer();
	} else if(ConstUtil.L_ID_AQ_QSK == layerId) {
		queryQskLayer();
	}
}

/**
 * Yjwl
 */
public function queryYjwlLayer():void
{
	GisUtils.callGisServer(GlobalData.yjwlLayerUrl,onYjwlResult,"");
}

//查询成功在地图上显示
private function onYjwlResult(featureSet:FeatureSet,token:Object = null):void
{
	var layer:GraphicsLayer = MapUtils.getGraphicLayerByName(ConstUtil.L_ID_YJWL);
	layer.clear();
	for each(var graphic:Graphic in featureSet.features)
	{
		//graphic.attributes.ID
		//graphic.geometry.x
		var symbol:PictureMarkerSymbol = new PictureMarkerSymbol("flexResources/map/cxtj.png", 20, 20);
		graphic.symbol = symbol;
		layer.add(graphic);
		//resultlist.push({"ID":graphic.attributes.OBJECTID,"STATE_NAME":graphic.attributes.STATE_NAME})
	}
}

/**
 * 码头
 */
public function queryMtLayer():void
{
	GisUtils.callGisServer(GlobalData.mtLayerUrl,onMtResult,"");
}

//查询成功在地图上显示
private function onMtResult(featureSet:FeatureSet,token:Object = null):void
{
	mtAreaFeatureSet = featureSet;
	var layer:GraphicsLayer = MapUtils.getGraphicLayerByName(ConstUtil.L_ID_MT);
	layer.clear();
	for each(var graphic:Graphic in featureSet.features)
	{
		graphic.useHandCursor=true;
		graphic.buttonMode = true;
		graphic.symbol = MapUtils.getOwnerSymbolStyle(0xD7CCBB,1,0xF5FAFE,1,
			SimpleLineSymbol.STYLE_SOLID,SimpleFillSymbol.STYLE_SOLID);
		graphic.addEventListener(MouseEvent.CLICK,mtMouseClick);
		graphic.addEventListener(MouseEvent.MOUSE_OVER,MapUtils.graphicMouseOver);
		graphic.addEventListener(MouseEvent.MOUSE_OUT,function(e:MouseEvent):void{
			var graphic:Graphic=e.currentTarget as Graphic;
			graphic.symbol = MapUtils.getOwnerSymbolStyle(0xD7CCBB,1,0xF5FAFE,1,
				SimpleLineSymbol.STYLE_SOLID,SimpleFillSymbol.STYLE_SOLID);
		});
		layer.add(graphic);
	}
}

/**
 * 经营人
 */
public function queryJyrLayer():void
{
	if(null == jyrAllFeatureSet) {
		var array:Array = new Array();
		array.push("type");
		GisUtils.callGisServer(GlobalData.jyrLayerUrl,onJyrResult,"",array);
	} else {
		onJyrResult(jyrAllFeatureSet, null);
	}
}

//查询成功在地图上显示
private function onJyrResult(featureSet:FeatureSet,token:Object = null):void
{
	jyrAllFeatureSet = featureSet;
	/** L_ID_JYR、L_ID_AQ_WXHWQY、L_ID_AQ_ZDWXYQY */
	var jyrChkState:String = "0";
	var wxhwChkState:String = "0";
	var zdwxyChkState:String = "0";
	var list:XMLList = FlexGlobals.topLevelApplication.M_ZYZS_TCKZ_XML.children();
	// 获取check状态
	for each( var xmlChildren:XML in list)  
	{
		if (ConstUtil.L_ID_JYR == xmlChildren.@cdid) {
			jyrChkState = xmlChildren.@checkState;
		} else if (ConstUtil.L_ID_AQ_WXHWQY == xmlChildren.@cdid) {
			wxhwChkState = xmlChildren.@checkState;
		} else if (ConstUtil.L_ID_AQ_ZDWXYQY == xmlChildren.@cdid) {
			zdwxyChkState = xmlChildren.@checkState;
		}
	}
	// 获取图层
	var jyrLayer:GraphicsLayer = MapUtils.getGraphicLayerByName(ConstUtil.L_ID_JYR);
	var wxhwLayer:GraphicsLayer = MapUtils.getGraphicLayerByName(ConstUtil.L_ID_AQ_WXHWQY);
	var zdwxyLayer:GraphicsLayer = MapUtils.getGraphicLayerByName(ConstUtil.L_ID_AQ_ZDWXYQY);
	// 清空
	jyrLayer.clear();
	wxhwLayer.clear();
	zdwxyLayer.clear();
	// var jyrArr:ArrayCollection = jyrLayer.graphics as ArrayCollection;
	// 添加坐标点
	for each(var graphic:Graphic in featureSet.features)
	{
		var type:int = graphic.attributes.TYPE;
		var tempLayer:GraphicsLayer = null;
		tempLayer = jyrLayer;
		//   >=8 重大危险源    >=5 危货企业     >=0 普通企业
		var imgName:String = "";
		if(jyrChkState == "1") {
			if(type >= 8) {
				tempLayer = zdwxyLayer;
				imgName = "aq_zdwxy.gif";
			} else if(type >= 5) {
				tempLayer = wxhwLayer;
				imgName = "aq_wxhwqy.png";
			} else {
				tempLayer = jyrLayer;
				imgName = "aq_jyr.png";
			}
		} else {
			var flg:Boolean = false;
			if(wxhwChkState == "1") {
				if(type >= 5 && type < 8) {
					tempLayer = wxhwLayer;
					imgName = "aq_wxhwqy.png";
					flg = true;
				}
			}
			if(zdwxyChkState == "1") {
				if(type >= 8) {
					tempLayer = zdwxyLayer;
					imgName = "aq_zdwxy.gif";
					flg = true;
				}
			}
			if(!flg) {
				continue;
			}
		}
		graphic.useHandCursor=true;
		graphic.buttonMode = true;
		var fillSymbol:SimpleFillSymbol = MapUtils.getOwnerSymbolStyle(0x0000FF,0.2,0xE36C09,3,
			SimpleLineSymbol.STYLE_DASHDOT,SimpleFillSymbol.STYLE_NULL);
		graphic.addEventListener(MouseEvent.CLICK,jyrMouseClick);
		graphic.addEventListener(MouseEvent.MOUSE_OVER,MapUtils.graphicMouseOver);
		graphic.addEventListener(MouseEvent.MOUSE_OUT,function(e:MouseEvent):void{
			var graphic:Graphic=e.currentTarget as Graphic;
			graphic.symbol = MapUtils.getOwnerSymbolStyle(0x0000FF,0.2,0xE36C09,3,
				SimpleLineSymbol.STYLE_DASHDOT,SimpleFillSymbol.STYLE_NULL);
		});
		graphic.symbol = fillSymbol;
		//layer.add(new Graphic(graphic.geometry.extent.center, MapUtils.getTextSymbol("我要显示啦！！")));
		tempLayer.add(graphic);
		var centerPoint:MapPoint = graphic.geometry.extent.center;
		var cent:Graphic = new Graphic();
		cent.geometry = centerPoint;
		var symbol:PictureMarkerSymbol = new PictureMarkerSymbol("flexResources/png/"+imgName, 20, 20);
		cent.symbol = symbol;
		cent.attributes = graphic.attributes;
		cent.useHandCursor=true;
		cent.buttonMode = true;
		cent.addEventListener(MouseEvent.CLICK,jyrMouseClick);
		cent.addEventListener(MouseEvent.DOUBLE_CLICK, function(e:MouseEvent):void{
			var graphic:Graphic=e.currentTarget as Graphic;
			// 定位
			var mp:MapPoint = new MapPoint(graphic.geometry["x"],graphic.geometry["y"],null);
			map.level = 16;
			map.centerAt(mp);
		});
		tempLayer.add(cent);
	}
}

/**
 * 泊位
 */
public function queryBwLayer():void
{
	GisUtils.callGisServer(GlobalData.bwLayerUrl,onBwResult,"");
}

//查询成功在地图上显示
private function onBwResult(featureSet:FeatureSet,token:Object = null):void
{
	bwAreaFeatureSet = featureSet;
	var layer:GraphicsLayer = MapUtils.getGraphicLayerByName(ConstUtil.L_ID_BW);
	layer.clear();
	for each(var graphic:Graphic in featureSet.features)
	{
		graphic.useHandCursor=true;
		graphic.buttonMode = true;
		graphic.symbol = MapUtils.getOwnerSymbolStyle(0x76A2DF,1,0xD3E1EA,1,
			SimpleLineSymbol.STYLE_SOLID,SimpleFillSymbol.STYLE_SOLID);
		graphic.addEventListener(MouseEvent.CLICK,bwMouseClick);
		graphic.addEventListener(MouseEvent.MOUSE_OVER,MapUtils.graphicMouseOver);
		graphic.addEventListener(MouseEvent.MOUSE_OUT,function(e:MouseEvent):void{
			var graphic:Graphic=e.currentTarget as Graphic;
			graphic.symbol = MapUtils.getOwnerSymbolStyle(0x76A2DF,1,0xD3E1EA,1,
				SimpleLineSymbol.STYLE_SOLID,SimpleFillSymbol.STYLE_SOLID);
		});
		layer.add(graphic);
	}
}

/**
 * 船舶预警
 */
public function queryCbyjLayer():void
{
	GisUtils.callGisServer(GlobalData.cbyjLayerUrl,onCbyjResult,"");
}

//查询成功在地图上显示
private function onCbyjResult(featureSet:FeatureSet,token:Object = null):void
{
	var layer:GraphicsLayer = MapUtils.getGraphicLayerByName(ConstUtil.L_ID_CBYJ);
	layer.clear();
	for each(var graphic:Graphic in featureSet.features)
	{
		graphic.useHandCursor=true;
		graphic.buttonMode = true;
		graphic.symbol = MapUtils.getOwnerSymbolStyle(0x0000FF, 0.2, 0xFF0000, 2);
		graphic.addEventListener(MouseEvent.CLICK,cbyjMouseClick);
		graphic.addEventListener(MouseEvent.MOUSE_OVER,MapUtils.graphicMouseOver);
		graphic.addEventListener(MouseEvent.MOUSE_OUT,function(e:MouseEvent):void{
			var graphic:Graphic=e.currentTarget as Graphic;
			graphic.symbol = MapUtils.getOwnerSymbolStyle(0x0000FF, 0.2, 0xFF0000, 2);
		});
		layer.add(graphic);
	}
}

/**
 * 视频
 */
public function querySpLayer():void
{
	GisUtils.callGisServer(GlobalData.spLayerUrl,onSpResult,"");
}

//查询成功在地图上显示
private function onSpResult(featureSet:FeatureSet,token:Object = null):void
{
	var layer:GraphicsLayer = MapUtils.getGraphicLayerByName(ConstUtil.L_ID_SP);
	layer.clear();
	var resultlist:Array=new Array();
	for each(var graphic:Graphic in featureSet.features)
	{
		graphic.useHandCursor=true;
		graphic.buttonMode = true;
		var symbol:PictureMarkerSymbol = new PictureMarkerSymbol("flexResources/png/aq_sxt.png", 20, 20);
		graphic.symbol = symbol;
		graphic.addEventListener(MouseEvent.CLICK,spMouseClick);
		layer.add(graphic);
	}
}

/**
 * 视频
 */
public function queryQskLayer():void
{
	GisUtils.callGisServer(GlobalData.qskLayerUrl,onQskResult,"");
}

//查询成功在地图上显示
private function onQskResult(featureSet:FeatureSet,token:Object = null):void
{
	var layer:GraphicsLayer = MapUtils.getGraphicLayerByName(ConstUtil.L_ID_AQ_QSK);
	layer.clear();
	var resultlist:Array=new Array();
	for each(var graphic:Graphic in featureSet.features)
	{
		graphic.useHandCursor=true;
		graphic.buttonMode = true;
		var symbol:PictureMarkerSymbol = new PictureMarkerSymbol("flexResources/png/aq_qsk.png", 20, 20);
		graphic.symbol = symbol;
		graphic.addEventListener(MouseEvent.CLICK,qskMouseClick);
		layer.add(graphic);
	}
}

//////////////////////  图形点击事件  ////////////////////////////////////////

/**
 * 经营人图形点击事件
 */ 
public function qskMouseClick(e:MouseEvent):void
{
	var obj:Object = e.currentTarget.attributes;
	var g:Graphic=e.currentTarget as Graphic;
	// 远程调用
	RemoteUtils.callRemote("aisCtl","querySingleQsk",function(ae:AbstractEvent):void{
		if(ae is FaultEvent){
			Alert.show("ERROR Call aisCtl querySingleQsk");
		}else {
			var resultObj:Object = ResultEvent(ae).result as Object;
			// 弹出信息
			ServicesUtility.showFeatrueToMap(
				ConstUtil.L_ID_AQ_QSK,g,resultObj,e);
		}
	},obj.ID);
}

/**
 * 港区图形点击事件
 */ 
public function gqMouseClick(e:MouseEvent):void
{
	var obj:Object = e.currentTarget.attributes;
	var g:Graphic=e.currentTarget as Graphic;
	// 远程调用
	RemoteUtils.callRemote("aisCtl","querySingleGq",function(ae:AbstractEvent):void{
		if(ae is FaultEvent){
			Alert.show("ERROR Call aisCtl querySingleGq");
		}else {
			var resultObj:Object = ResultEvent(ae).result as Object;
			// 弹出信息
			ServicesUtility.showFeatrueToMap(
				ConstUtil.L_ID_GQ,g,resultObj,e,true);
		}
	},obj.ID);
}

/**
 * 海事码头点击事件
 */ 
private function mtMouseClick(e:MouseEvent):void
{
	var obj:Object = e.currentTarget.attributes;
	var g:Graphic=e.currentTarget as Graphic;
	// 远程调用
	RemoteUtils.callRemote("aisCtl","querySingleMt",function(ae:AbstractEvent):void{
		if(ae is FaultEvent){
			Alert.show("ERROR Call aisCtl querySingleMt");
		}else {
			var resultObj:Object = ResultEvent(ae).result as Object;
			// 弹出信息
			ServicesUtility.showFeatrueToMap(
				ConstUtil.L_ID_MT,g,resultObj,e);
		}
	},obj.ID);
}

/**
 * 海事泊位点击事件
 */ 
private function bwMouseClick(e:MouseEvent):void
{
	var obj:Object = e.currentTarget.attributes;
	var g:Graphic=e.currentTarget as Graphic;
	// 远程调用
	RemoteUtils.callRemote("aisCtl","querySingleBw",function(ae:AbstractEvent):void{
		if(ae is FaultEvent){
			Alert.show("ERROR Call aisCtl querySingleBw");
		}else {
			var resultObj:Object = ResultEvent(ae).result as Object;
			// 弹出信息
			ServicesUtility.showFeatrueToMap(
				ConstUtil.L_ID_BW,g,resultObj,e);
		}
	},obj.ID);
}

/**
 * 经营人图形点击事件
 */ 
public function jyrMouseClick(e:MouseEvent):void
{
	var obj:Object = e.currentTarget.attributes;
	var g:Graphic=e.currentTarget as Graphic;
	// 远程调用
	RemoteUtils.callRemote("aisCtl","querySingleJyr",function(ae:AbstractEvent):void{
		if(ae is FaultEvent){
			Alert.show("ERROR Call aisCtl querySingleJyr");
		}else {
			var resultObj:Object = ResultEvent(ae).result as Object;
			// 弹出信息
			ServicesUtility.showFeatrueToMap(
				ConstUtil.L_ID_JYR,g,resultObj,e);
		}
	},obj.ID);
}

/**
 * 船舶预警点击事件
 */ 
private function cbyjMouseClick(e:MouseEvent):void
{
	var obj:Object = e.currentTarget.attributes;
	var g:Graphic=e.currentTarget as Graphic;
	// 远程调用
	RemoteUtils.callRemote("aisCtl","querySingleCbyj",function(ae:AbstractEvent):void{
		if(ae is FaultEvent){
			Alert.show("ERROR Call aisCtl querySingleCbyj");
		}else {
			var resultObj:Object = ResultEvent(ae).result as Object;
			// 弹出信息
			ServicesUtility.showFeatrueToMap(
				ConstUtil.L_ID_CBYJ,g,resultObj,e);
		}
	},obj.ID);
}

/**
 * 海事视频点击事件
 */ 
private function spMouseClick(e:MouseEvent):void
{
	var obj:Object = e.currentTarget.attributes;
	var url:String = GlobalData.spjkUrl + obj.ID;
	navigateToURL(new URLRequest(url),"_blank");
}


/**
 * 初始化港口经营人块状显示
 */ 
private function initGkjyrArea():void
{
	if(null == jyrAreaFeatureSet) {
		var array:Array = new Array();
		array.push("mc");
		GisUtils.callGisServer(GlobalData.jyrLayerUrl,onJyrAreaResult,"",array);
	} else {
		//onJyrAreaResult(jyrAreaFeatureSet, null);
		var layer:GraphicsLayer = MapUtils.getGraphicLayerByName(ConstUtil.L_ID_JYRAREA);
		layer.visible = true;
	}
}
/**
 * 初始化港口经营人块状显示
 */ 
private function clearGkjyrArea():void
{
	var layer:GraphicsLayer = MapUtils.getGraphicLayerByName(ConstUtil.L_ID_JYRAREA);
	if(null != layer) {
		layer.visible = false;
	}
}

//查询成功活显示
private function onJyrAreaResult(featureSet:FeatureSet,token:Object = null):void
{
	jyrAreaFeatureSet = featureSet;
	var layer:GraphicsLayer = MapUtils.getGraphicLayerByName(ConstUtil.L_ID_JYRAREA);
	layer.clear();
	for each(var graphic:Graphic in featureSet.features)
	{
		graphic.useHandCursor=true;
		graphic.buttonMode = true;
		var fillSymbol:SimpleFillSymbol = MapUtils.getOwnerSymbolStyle(0x0000FF,0.2,0xE36C09,3,
			SimpleLineSymbol.STYLE_DASHDOT,SimpleFillSymbol.STYLE_NULL);
		graphic.addEventListener(MouseEvent.CLICK,jyrMouseClick);
		graphic.addEventListener(MouseEvent.MOUSE_OVER,MapUtils.graphicMouseOver);
		graphic.addEventListener(MouseEvent.MOUSE_OUT,function(e:MouseEvent):void{
			var graphic:Graphic=e.currentTarget as Graphic;
			graphic.symbol = MapUtils.getOwnerSymbolStyle(0x0000FF,0.2,0xE36C09,3,
				SimpleLineSymbol.STYLE_DASHDOT,SimpleFillSymbol.STYLE_NULL);
		});
		graphic.symbol = fillSymbol;
		//layer.add(new Graphic(graphic.geometry.extent.center, MapUtils.getTextSymbol("我要显示啦！！")));
		layer.add(graphic);
	}
}


/**
 * 初始化港口经营人块状显示
 */ 
private function initGqArea():void
{
	var currScale:Number =  map.scale;
	var layer:GraphicsLayer = MapUtils.getGraphicLayerByName(ConstUtil.L_ID_GQ);
	var state:String = ConfigUtil.getMapLayerState(ConstUtil.L_ID_GQ);
	if(ConstUtil.CHECK_STATE_1 == state && currScale<300000 && currScale>10000) {
		// 显示船舶ais
		layer.visible = true;
		if(null == gqAreaFeatureSet) {
			GisUtils.callGisServer(GlobalData.gqLayerUrl,onGqAreaResult,"");
		}
	} else {
		layer.visible = false;
	}
}
/**
 * 清空港口
 */ 
private function clearGqArea():void
{
	var layer:GraphicsLayer = MapUtils.getGraphicLayerByName(ConstUtil.L_ID_GQ);
	if(null != layer) {
		//layer.clear();
		layer.visible = false;
	}
}

//查询成功活显示
private function onGqAreaResult(featureSet:FeatureSet,token:Object = null):void
{
	gqAreaFeatureSet = featureSet;
	var layer:GraphicsLayer = MapUtils.getGraphicLayerByName(ConstUtil.L_ID_GQ);
	layer.clear();
	for each(var graphic:Graphic in featureSet.features)
	{
		graphic.useHandCursor=true;
		graphic.buttonMode = true;
		//		var label:Label = new Label();
		//		label.width = 60;
		//		label.height = 30;
		//		label.setStyle("verticalAlign","middle");
		//		label.setStyle("horizontalAlign","middle");
		//		label.setStyle("fontFamily","宋体");
		//		label.setStyle("fontSize","10");
		//		label.text = "武汉鑫源石化有限公司";
		//		graphic.addChild(label);
		//		graphic.automationName = "啦啦啦啦啦"; 
		graphic.symbol = MapUtils.getOwnerSymbolStyle(0x0000FF,0.2,0x7030A0,2);
		graphic.addEventListener(MouseEvent.CLICK,gqMouseClick);
		graphic.addEventListener(MouseEvent.MOUSE_OVER,MapUtils.graphicMouseOver);
		graphic.addEventListener(MouseEvent.MOUSE_OUT,function(e:MouseEvent):void{
			var graphic:Graphic=e.currentTarget as Graphic;
			graphic.symbol = MapUtils.getOwnerSymbolStyle(0x0000FF,0.2,0x7030A0,3);
		});
		layer.add(graphic);
	}
}

/**
 * 显示码头和泊位
 */
private function initMtBwArea():void
{
	initMtArea();
	initBwArea();
}

/**
 * 显示码头和泊位
 */
private function initMtArea():void
{
	var currScale:Number =  map.scale;
	var mtLayer:GraphicsLayer = MapUtils.getGraphicLayerByName(ConstUtil.L_ID_MT);
	var mtState:String = ConfigUtil.getMapLayerState(ConstUtil.L_ID_MT);
	// 码头
	if(ConstUtil.CHECK_STATE_1 == mtState && currScale<20000) {
		// 显示船舶ais
		mtLayer.visible = true;
		if(null == mtAreaFeatureSet) {
			GisUtils.callGisServer(GlobalData.mtLayerUrl,onMtResult,"");
		}
	} else {
		mtLayer.visible = false;
	}
}

/**
 * 显示码头和泊位
 */
private function initBwArea():void
{
	var currScale:Number =  map.scale;
	var bwLayer:GraphicsLayer = MapUtils.getGraphicLayerByName(ConstUtil.L_ID_BW);
	var bwState:String = ConfigUtil.getMapLayerState(ConstUtil.L_ID_BW);
	//泊位
	if(ConstUtil.CHECK_STATE_1 == bwState && currScale<20000) {
		// 显示船舶ais
		bwLayer.visible = true;
		if(null == bwAreaFeatureSet) {
			GisUtils.callGisServer(GlobalData.bwLayerUrl,onBwResult,"");
		}
	} else {
		bwLayer.visible = false;
	}
}

/**
 * 清空码头和泊位
 */ 
private function clearMtArea():void
{
	var layer:GraphicsLayer = MapUtils.getGraphicLayerByName(ConstUtil.L_ID_MT);
	if(null != layer) {
		layer.visible = false;
	}
}

/**
 * 清空码头和泊位
 */ 
private function clearBwArea():void
{
	var layer:GraphicsLayer = MapUtils.getGraphicLayerByName(ConstUtil.L_ID_BW);
	if(null != layer) {
		layer.visible = false;
	}
}