定義個DataRenderer
<?xml version="1.0" encoding="utf-8"?>
<s:DataRenderer xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark" implements="mx.core.IFactory"
xmlns:code="http://code.google.com/p/flex-iframe/"
creationComplete="datarenderer1_creationCompleteHandler(event)"
xmlns:mx="library://ns.adobe.com/flex/mx" xmlns:supportClasses="com.esri.ags.skins.supportClasses.*" xmlns:view="widgets.monitor.view.*" xmlns:template="com.depth.viewer.widget.template.*" xmlns:widget="com.depth.viewer.widget.*">
<fx:Script>
<![CDATA[
import com.depth.viewer.facade.IocAppFacade;
import com.esri.ags.Graphic;
import com.esri.ags.layers.FeatureLayer;
import com.xcsw.flex.facade.ConstFacade;
import mx.controls.Alert;
import mx.events.DragEvent;
import mx.events.FlexEvent;
import mx.events.MoveEvent;
import widgets.map.util.MapUtil;
/*
只顯示監控數據,雨量、水位、閘門開合度,沒有視頻
*/
protected function linkbutton3_clickHandler(event:MouseEvent):void
{
if(!data)//由渲染器使用者提供
return;
var feature:Graphic = data.feature as Graphic;
var fl:FeatureLayer = feature.graphicsLayer as FeatureLayer;
//獲取水位站對應的ID
var fId:String = feature.attributes[fl.layerDetails.objectIdField];
var site:String=data.station;
//水位信息警戒水位參數設置
IocAppFacade.getInstance().sendNotification(IocAppFacade.LOAD_WIDGET,{id:"TriggerlevelWidget",runingParams:{ID:fId,tablename:"M_Waterlevel",site:site}});
}
public function newInstance():*{
return new MonitorDataInfoSymbolRenderer();
}
protected function btnCloseButton_clickHandler(event:MouseEvent):void
{
if (currentState != "minState")
{
currentState = "minState";
}
}
protected function datarenderer1_creationCompleteHandler(event:FlexEvent):void
{
//addEventListener(MouseEvent.ROLL_OUT,rollOutHandler);
//addEventListener(MouseEvent.ROLL_OVER,rollOverHandler);
}
private function rollOverHandler(event:MouseEvent):void
{
if (currentState == "minState")
{
currentState = "normal";
}
}
private function rollOutHandler(event:MouseEvent):void
{
//var obj:Object=event.target;
}
protected function chkMonitorData_clickHandler(event:MouseEvent):void
{
var checkBox:CheckBox=event.target as CheckBox;
switch(checkBox.label){
case "雨量":
if(checkBox.selected)
break;
case "水位":
if(checkBox.selected)
break;
case "閘門":
if(checkBox.selected)
break;
}
}
protected function btnExpandButton_clickHandler(event:MouseEvent):void
{
if (currentState == "minState")
{
currentState = "normal";
}
}
]]>
</fx:Script>
<s:states>
<s:State name="normal"/>
<s:State name="minState"/>
</s:states>
<fx:Style>
@namespace s "library://ns.adobe.com/flex/spark";
@namespace mx "library://ns.adobe.com/flex/mx";
.InfoExpandButton {
disabledSkin: Embed(source="/assets/swf/skins2.swf", symbol="Callout_expandButtonDisabledSkin");
downSkin: Embed(source="/assets/swf/skins2.swf", symbol="Callout_expandButtonDownSkin");
overSkin: Embed(source="/assets/swf/skins2.swf", symbol="Callout_expandButtonOverSkin");
upSkin: Embed(source="/assets/swf/skins2.swf", symbol="Callout_expandButtonUpSkin");
}
.InfoCloseButton {
disabledSkin: Embed(source="/assets/swf/skins2.swf", symbol="Callout_closeButtonDisabledSkin");
downSkin: Embed(source="/assets/swf/skins2.swf", symbol="Callout_closeButtonDownSkin");
overSkin: Embed(source="/assets/swf/skins2.swf", symbol="Callout_closeButtonOverSkin");
upSkin: Embed(source="/assets/swf/skins2.swf", symbol="Callout_closeButtonUpSkin");
}
</fx:Style>
<fx:Declarations>
<!-- 將非可視元素(例如服務、值對象)放在此處 -->
</fx:Declarations>
<s:VGroup width="100%">
<s:HGroup verticalAlign="middle">
<s:Label text="監控點:"/>
<mx:Button id="btnExpandButton"
width="18" height="18"
click="btnExpandButton_clickHandler(event)"
includeIn="minState"
styleName="InfoExpandButton"/>
<mx:Button id="btnCloseButton"
width="18" height="18"
includeIn="normal"
click="btnCloseButton_clickHandler(event)"
styleName="InfoCloseButton" toolTip="關閉"/>
</s:HGroup>
<s:BorderContainer height="80" borderColor="#128EEE" includeIn="normal" >
<s:layout>
<s:VerticalLayout />
</s:layout>
<s:HGroup id="ghRain" verticalAlign="middle" fontSize="25">
<s:CheckBox id="chkMonitorDataRain" label="雨量" click="chkMonitorData_clickHandler(event)" />
<s:Label text=":" />
</s:HGroup>
<s:HGroup id="hgWater" verticalAlign="middle">
<s:CheckBox id="chkMonitorDataWater" label="水位" click="chkMonitorData_clickHandler(event)" />
<s:Label text=":" />
</s:HGroup>
<s:HGroup id="hgFloodgate" verticalAlign="middle">
<s:CheckBox id="chkMonitorDataFloodgate" label="閘門" click="chkMonitorData_clickHandler(event)" />
<s:Label text=":" />
</s:HGroup>
</s:BorderContainer>
<s:Label text="當前時間:" includeIn="normal" />
</s:VGroup>
</s:DataRenderer>
使用該renderer
protected function btnShowVideoInfo_clickHandler(event:MouseEvent):void
{
var videoLayerName:String="sde.SDE.MonitorPoint";
//var videoLayerName:String="sde.SDE.RainMonitory";
featureLayer=MapUtil.getFeatureLayerByName(videoLayerName);
//featureLayer增加feature
featureLayer.addEventListener(GraphicEvent.GRAPHIC_ADD,graphicAddedHandler);
featureLayer.visible=true;
/**
* feature添加處理函數
*/
function graphicAddedHandler(event:GraphicEvent):void{
/* var features:ArrayCollection=featureLayer.graphicProvider as ArrayCollection;
for each(var feature:Graphic in features){
displayFeatureInfoSymbol(feature);
} */
displayFeatureInfoSymbol(event.graphic);
}
}
private function displayFeatureInfoSymbol(feature:Graphic,data:Object=null):void{
var infoSymbol:InfoSymbol=new InfoSymbol();
infoSymbol.infoRenderer=new ClassFactory(MoniotorPointInfoSymbolRenderer);
feature.symbol=infoSymbol;
feature.alpha=0.8;
//feature.visible=false;
}