所有的基本功能,最终将回到FLEX API。flexviewer是上层的一套优秀框架而已。
(1)query方法(支持图查属性和属性查图
图查属性:
private function doQuery(geom:Geometry):void{
try
{
var query:Query = new Query();
query.spatialRelationship = spatialRel.selectedItem.data;
query.geometry = geom;
query.returnGeometry = true;
queryTask.execute(query, new AsyncResponder(onResult, onFault));
function onResult(featureSet:FeatureSet, token:Object = null):void
{
if (featureSet.features.length > 0)
{
for each (var myGraphic:Graphic in featureSet.features)
{
myGraphicsLayer.add(myGraphic);
}
for each (var myGraphic:Graphic in featureSet.features)
{
// only add features that are not already in the graphics layer
var graphicID:String = myGraphic.attributes.CITY_NAME + "." + myGraphic.attributes.FID;
if (!hashmapOfExistingGraphics[graphicID]) // New feature (not already added to graphics layer)
{
hashmapOfExistingGraphics[graphicID] = 1;
myGraphic.id = graphicID;
myGraphic.toolTip = myGraphic.attributes.CITY_NAME;
myGraphicsLayer.add(myGraphic);
}
}
}
else
{
Alert.show("No parcels were found", "Try something else");
}}
function onFault(info:Object, token:Object = null):void
{
Alert.show(info.faultString + "\n\n" + info.faultDetail, "queryTask fault " + info.faultCode);
}
}
catch (error:Error)
{
Alert.show(error.toString(), "myGeometryService_simplifyCompleteHandler error");
}
}
protected function queryTask_faultHandler(event:FaultEvent):void
{
Alert.show(event.fault.faultString + "\n\n" + event.fault.faultDetail, "QueryTask Fault " + event.fault.faultCode);
}
属性查图:
/*属性查图 */
private function queryFeaturesText():void
{
hideInfoWindow();
var i:int = cboLayerText.selectedIndex;
queryLayer = configSearchText[i].layer;
if (queryLayer && !queryLayer.loaded)
{
queryLayer.addEventListener(LayerEvent.LOAD, queryLayer_loadHandler);
function queryLayer_loadHandler(event:LayerEvent):void
{
queryFeaturesText()
}
return;
}
queryExpr = configSearchText[i].expr;
queryFields = configSearchText[i].fields;
queryTitleField = configSearchText[i].titlefield;
queryLinkField = configSearchText[i].linkfield;
queryLinkAlias = configSearchText[i].linkalias;
if (queryLayer && txtSearch.text)
{
var query:Query = new Query();
var expr:String = queryExpr.replace(/\[value\]/g, txtSearch.text);
query.where = expr;
query.outSpatialReference = map.spatialReference;
queryLayer.queryFeatures(query, new AsyncResponder(onResult, onFault, queryFields));
showMessage(loadingLabel, true);
showStateResults();
function onResult(featureSet:FeatureSet, token:XMLList = null):void
{
try
{
searchResultAC = createSearchResults(featureSet, token);
addSharedData(widgetTitle, searchResultAC);
if (featureSet.features.length < 1)
{
showMessage(noResultLabel, false);
}
else
{
showMessage(selectionLabel + " " + featureSet.features.length, false);
}
}
catch (error:Error)
{
showMessage(error.message, false);
}
}
function onFault(info:Object, token:Object = null):void
{
showMessage(info.toString(), false);
}
}
}
(2) identifyTask方法
<?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"
pageTitle="Identify Features on the Map">
<fx:Script>
<![CDATA[
import com.esri.ags.Graphic;
import com.esri.ags.events.MapMouseEvent;
import com.esri.ags.geometry.Geometry;
import com.esri.ags.symbols.InfoSymbol;
import com.esri.ags.tasks.supportClasses.IdentifyParameters;
import com.esri.ags.tasks.supportClasses.IdentifyResult;
import mx.controls.Alert;
import mx.rpc.AsyncResponder;
[Bindable]private var lastIdentifyResultGraphic:Graphic;
private function mapClickHandler(event:MapMouseEvent):void
{
clickGraphicsLayer.clear();
var identifyParams:IdentifyParameters = new IdentifyParameters();
identifyParams.returnGeometry = true;
identifyParams.tolerance = 3;
identifyParams.width = myMap.width;
identifyParams.height = myMap.height;
identifyParams.geometry = event.mapPoint;
identifyParams.mapExtent = myMap.extent;
identifyParams.spatialReference = myMap.spatialReference;
var clickGraphic:Graphic = new Graphic(event.mapPoint, clickPtSym);
clickGraphicsLayer.add(clickGraphic);
identifyTask.execute(identifyParams, new AsyncResponder(myResultFunction, myFaultFunction, clickGraphic));
}
private function myResultFunction(results:Array, clickGraphic:Graphic = null):void
{
if (results && results.length > 0)
{
var result:IdentifyResult = results[0];
var resultGraphic:Graphic = result.feature;
switch (resultGraphic.geometry.type)
{
case Geometry.MAPPOINT:
{
resultGraphic.symbol = smsIdentify;
break;
}
case Geometry.POLYLINE:
{
resultGraphic.symbol = slsIdentify;
break;
}
case Geometry.POLYGON:
{
resultGraphic.symbol = sfsIdentify;
break;
}
}
lastIdentifyResultGraphic = resultGraphic;
// update clickGraphic (from mouse click to returned feature)
clickGraphic.symbol = new InfoSymbol(); // use default renderer
clickGraphic.attributes = resultGraphic.attributes;
}
}
private function myFaultFunction(error:Object, clickGraphic:Graphic = null):void
{
Alert.show(String(error), "Identify Error");
}
]]>
</fx:Script>
<fx:Declarations>
<!-- Symbol for where the user clicked -->
<esri:SimpleMarkerSymbol id="clickPtSym"
color="0xFF0000"
size="12"
style="x"/>
<!-- Symbol for Identify Result as Polyline -->
<esri:SimpleLineSymbol id="slsIdentify"
width="2"
alpha="1"
color="0x00FF00"
style="solid"/>
<!-- Symbol for Identify Result as Point -->
<esri:SimpleMarkerSymbol id="smsIdentify"
color="0x00FF00"
size="15"
style="diamond"/>
<!-- Symbol for Identify Result as Polygon -->
<esri:SimpleFillSymbol id="sfsIdentify"/>
<!-- Identify Task -->
<esri:IdentifyTask id="identifyTask"
concurrency="last"
url="http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Specialty/ESRI_StatesCitiesRivers_USA/MapServer"/>
</fx:Declarations>
<esri:Map id="myMap" mapClick="mapClickHandler(event)">
<esri:extent>
<esri:WebMercatorExtent minlon="-120" minlat="30" maxlon="-100" maxlat="50"/>
</esri:extent>
<esri:ArcGISTiledMapServiceLayer url="http://server.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer"/>
<esri:GraphicsLayer graphicProvider="{lastIdentifyResultGraphic}"/>
<esri:GraphicsLayer id="clickGraphicsLayer"/>
</esri:Map>
</s:Application>
(3)FindTask方法
(4)