select graphics within extent

438
1
05-06-2011 08:14 AM
MikeJun
New Contributor II
I try to implement 'select graphics within extent' tool in my project.

I commented out the lines that I think it doesn't need but nothing happen. When I uncommented it, it only return value from one column.

What I need to do is to create a button for select graphic within extent and return results in my master datagrid.

Please help!


p.s. please see attachment for the entire code.

//Select EOC member by Polygon Extent, click event function




private function drawExtent():void
{

//var queryTask:QueryTask = new QueryTask("http://gisserver/ArcGIS/rest/services/EOC/MapServer/0");
//var query:Query = new Query();
//query.where = "EmpNo > 0";
//query.returnGeometry = true;
//query.outFields = ["EmpNo", "Fname", "Lname", "ADDRESS_LINE_1", "City", "Team", "PositionTitle", "Title", "DeptName", "HMPhone", "GIS_MILE"];


queryTask.execute(queryselect, new AsyncResponder(onResult, onFault));

function onResult(featureSet:FeatureSet, token:Object = null):void
{
for each (var myGraphic:Graphic in featureSet.features)
{
myGraphic.symbol = defaultSymbol;
myGraphicsLayer.add(myGraphic);
}
}
function onFault(info:Object, token:Object = null):void
{
Alert.show(info.toString());
}

drawToolbar.activate(Draw.EXTENT);
}

private function drawEndHandler(event:DrawEvent):void
{

var extent:Extent = event.graphic.geometry as Extent;
var graphic:Graphic;
var results:ArrayCollection = new ArrayCollection;
for (var i:Number = 0 ; i < myGraphicsLayer.numChildren ; i++)
{
graphic = myGraphicsLayer.getChildAt(i) as Graphic;
//if point is contained within extent, highlight it and add for display in results list
if (extent.contains(MapPoint(graphic.geometry)))
{
graphic.symbol = highlightedSymbol;
results.addItem(graphic.attributes.Fname);
}
//else if point was previously highlighted, reset its symbology
else if (graphic.symbol == highlightedSymbol)
{
graphic.symbol = defaultSymbol;
}
}
labelPoints.text = "# of points in extent = " + results.length;
//dg.visible = true;
//dg.dataProvider = results;

pnlDataGrid.visible = true;
resultsGrid.visible = true;
resultsGrid.dataProvider = results;

}



<esri:Query id="queryselect" where="EmpNo > 0" returnGeometry="true" outSpatialReference="{mainMap.spatialReference}">
<esri:outFields>
<mx:String>EmpNo</mx:String>
<mx:String>Fname</mx:String>
<mx:String>Lname</mx:String>
<mx:String>ADDRESS_LINE_1</mx:String>
<mx:String>City</mx:String>
<mx:String>Team</mx:String>
<mx:String>PositionTitle</mx:String>
<mx:String>Title</mx:String>
<mx:String>HMPhone</mx:String>
<mx:String>DeptName</mx:String>
<mx:String>GIS_MILE</mx:String>
</esri:outFields>
</esri:Query>

<!-- Identify Symbol for where the user clicked -->
<esri:SimpleMarkerSymbol id="clickPtSym" style="x" color="0xFF0000" size="12"/>
<esri:SimpleLineSymbol id="slsIdentify" style="solid" color="0x00FF00" width="2" alpha="1"/>
<esri:SimpleMarkerSymbol id="smsIdentify" style="square" color="0x0099FF" size="100"/>
<esri:SimpleFillSymbol id="sfsIdentify"/>



<esri:Navigation id="navToolbar" map="{mainMap}"/>

<!-- Layout -->
<mx:VBox height="100%" width="100%" verticalGap="0" >
<mx:Canvas id="cvMain" horizontalScrollPolicy="off" verticalScrollPolicy="off" height="100%" width="100%" borderThickness="1" cornerRadius="10" >

<!-- Map Service property-->
<esri:Map id="mainMap" openHandCursorVisible="false" logoVisible="false" >
<esri:extent>
<esri:Extent xmin="7567162" ymin="641343" xmax="7651652" ymax="703119">
<esri:SpatialReference wkid="2913"/>
</esri:Extent>
</esri:extent>


<esri:ArcGISTiledMapServiceLayer url="http://gisserver/ArcGIS/rest/services/BaseMap/MapServer" />
<esri:ArcGISDynamicMapServiceLayer url="http://gisserver/ArcGIS/rest/services/EOC/MapServer" />
<esri:GraphicsLayer id="myGraphicsLayer" graphicProvider="{queryTask.executeLastResult.features}" symbol="{resultsSymbol}"/>
</esri:Map>

<!-- TOP TOOL BAR -->
<mx:HBox id="topHBOX" horizontalAlign="center" width="100%" y="10">

<!-- Basic Tool bar -->
<mx:HBox id="toolBarBox" horizontalGap="5" x="5" width="100%" horizontalAlign="center" verticalAlign="middle">
<mx:Spacer width="1" />

<mx:Button toolTip="Select" click="drawExtent()" icon="@Embed(source='images/i_draw_rect.png')" height="41" width="41" styleName="main"/>

<components:MultiLineButton id="btnFindMember" label="Find Member" width="80" height="40" click="pnlFindMember.visible=true" color="0xffff00" fontSize="12" fontWeight="bold" styleName="main"/>

<mx:Spacer width="0.7" />
</mx:HBox>

</mx:HBox>




<ext:SuperPanel id="pnlDataGrid" enableResize="true" showControls="true" borderAlpha=".7" borderColor="#3399CC" title="Result"
width="750" height="320" visible="false" showEffect="zoomInEffect2" hideEffect="zoomOutEffect2" horizontalScrollPolicy="off" verticalScrollPolicy="off">
<mx:DataGrid id="resultsGrid" dataProvider="{queryTask.executeLastResult.attributes}" visible="{queryTask.executeLastResult != null}"
itemRollOver="onItemRollOver(event)" itemRollOut="onItemRollOut(event)"
width="100%" height="100%" verticalScrollPolicy="auto" horizontalScrollPolicy="auto"
selectedIndex="-1" click="doFind()">
<mx:columns>
<mx:DataGridColumn headerText="EMP ID" width="50" dataField="EmpNo"/>
<mx:DataGridColumn headerText="First name" width="60" dataField="Fname"/>
<mx:DataGridColumn headerText="Last name" width="60" dataField="Lname" />
<mx:DataGridColumn headerText="Address" width="135" dataField="ADDRESS_LINE_1" />
<mx:DataGridColumn headerText="City" width="60" dataField="City" />
<mx:DataGridColumn headerText="Team" width="45" dataField="Team" />
<mx:DataGridColumn headerText="EOC Title" width="100" dataField="PositionTitle" />
<mx:DataGridColumn headerText="City Title" width="120" dataField="Title" />
<mx:DataGridColumn headerText="Department" width="120" dataField="DeptName" />
<mx:DataGridColumn headerText="Hm Phone" width="80" dataField="HMPhone" />
<mx:DataGridColumn headerText="Buffer Radius(Mile)" width="50" dataField="GIS_MILE" />
</mx:columns>
</mx:DataGrid>
</ext:SuperPanel>
</mx:Canvas>

</mx:VBox>
</mx:Application>
Tags (2)
0 Kudos
1 Reply
AnthonyVandrunen
New Contributor
Have you seen this post?

Select Graphic within Extent
0 Kudos