In my flash builder mxml file, I load a datagrid with data get from database through web service. In the datagrid I create a context menu "select and zoom" to select and zoom to a feature (attribute value from the datagrid selected row), but when I select a row, and call this "select and zoom" function, the busy cursor will always there.
From the map service page, I can successfully query the same feature as follows:
I can also confirm that the selected feature exist and loaded, but the situation is when I call the select function on datagrid selected row, it keep loading.
I am stuck at the problem for quite a long time but still cannot figure out what is wrong.
Don't know whether it is code issue or setting issue, my mxml code is listed below:
<viewer:BaseWidget xmlns:fx="http://ift.tt/rYUnH9"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
xmlns:viewer="com.esri.viewer.*"
xmlns:esri="http://ift.tt/1tsyegi"
right="420" bottom="220" width="850" height="449" layout="absolute"
widgetConfigLoaded="init()">
<fx:Script>
<![CDATA[
import com.esri.ags.FeatureSet;
import com.esri.ags.Graphic;
import com.esri.ags.geometry.Extent;
import com.esri.ags.geometry.Polyline;
import com.esri.ags.layers.GraphicsLayer;
import com.esri.ags.tasks.QueryTask;
import com.esri.ags.tasks.supportClasses.Query;
import com.esri.ags.layers.FeatureLayer;
import mx.collections.ArrayCollection;
import mx.controls.Alert;
import mx.rpc.AsyncResponder;
import mx.rpc.events.FaultEvent;
import mx.rpc.events.ResultEvent;
import mx.utils.StringUtil;
private var graphicsLayer:GraphicsLayer;
private var hashmapOfExistingGraphics:Object = new Object();
public function init():void {
graphicsLayer = new GraphicsLayer();
graphicsLayer.symbol = sfs;
map.addLayer(graphicsLayer);
ws.GetLoc();
var cm:ContextMenu = new ContextMenu();
cm.hideBuiltInItems();
var item:ContextMenuItem = new ContextMenuItem("Select and Zoom");
item.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT, onSelectItem);
cm.customItems.push(item);
datagrid.contextMenu = cm;
}
private function onSelectItem(e:ContextMenuEvent):void{
//event.contextMenuOwner
if(datagrid.selectedIndex >= 0){
this.cursorManager.setBusyCursor();
var query:Query = new Query;
query.where = "SELECT * from dev_db.DBO.BQ_Segment_1 WHERE BQ_no_ = '" + datagrid.selectedItem.bqNo + "' and Segment_ID = '" + datagrid.selectedItem.segmentID + "'";
queryTask.execute(query, new AsyncResponder(onResult, onFault));
function onResult(featureSet:FeatureSet, token:Object = null):void
{
graphicsLayer.clear();
if (featureSet.features.length == 0)
{
Alert.show("No feature found. Please try again.");
}
else
{
Alert.show("feature exist....");
var unionExtent:Extent;
var myFirstGraphic:Graphic = featureSet.features[0];
unionExtent = Polyline(myFirstGraphic.geometry).extent; // problem line
for each (var myGraphic1:Graphic in featureSet.features)
{
graphicsLayer.add(myGraphic1);
unionExtent = unionExtent.union(Polyline(myGraphic1.geometry).extent);
}
map.extent = unionExtent;
}
}
function onFault(info:Object, token:Object = null):void
{
Alert.show(info.toString());
}
}else{
Alert.show("Select a record first","ATTENTION");
}
}
public function GetLoc(event:ResultEvent):void {
// Databind data from webservice to datagrid
datagrid.dataProvider = event.result;
}
public function fault(event:FaultEvent):void {
// Oppps some error occured
Alert.show(event.toString());
}
]]>
</fx:Script>
<fx:Declarations>
<mx:WebService id="ws" wsdl="http://localhost/TestWebService/Service.asmx?WSDL" fault="fault(event)">
<mx:operation
name="GetLoc"
resultFormat="object"
result="GetLoc(event)"
/>
</mx:WebService>
<esri:SimpleFillSymbol id="sfs" alpha="0.7" color="0xFF0000"/>
<esri:QueryTask id="queryTask"
showBusyCursor="true"
url="http://localhost:6080/arcgis/rest/services/MyService/MapServer/1"
useAMF="false"/>
<esri:PictureMarkerSymbol id="sps"/>
</fx:Declarations>
<viewer:WidgetTemplate id="wTemplate" x="0" y="2" width="834.5" height="447"
textDecoration="none">
<viewer:layout>
<s:BasicLayout/>
</viewer:layout>
<s:HGroup x="44" y="10" width="757" height="350">
<s:DataGrid id="datagrid" width="732" height="329">
<s:columns>
<s:ArrayList>
<s:GridColumn headerText="BQ No" dataField="bqNo"/>
<s:GridColumn headerText="BQ Segment" dataField="bqSegment"/>
<s:GridColumn headerText="Contract No" dataField="contractNo"/>
<s:GridColumn headerText="Project Title" dataField="projectTitle"/>
<s:GridColumn headerText="Completion Date" dataField="completionDate"/>
<s:GridColumn headerText="Drain Name" dataField="drainName"/>
<s:GridColumn headerText="Road Name" dataField="roadName"/>
<s:GridColumn headerText="Description" dataField="shape"/>
</s:ArrayList>
</s:columns>
</s:DataGrid>
</s:HGroup>
</viewer:WidgetTemplate>
</viewer:BaseWidget>
I am using ArcGIS API for Flex 3.6.
Aucun commentaire:
Enregistrer un commentaire