private function myResultFunction(results:Array, clickGraphic:Graphic = null):void { resultGraphicsLayer.clear(); if (results && results.length > 0) { var obj:Object = new Object(); for each (var identifyResult:IdentifyResult in results) { var resultGraphic:Graphic = identifyResult.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; merge(obj ,resultGraphic.attributes); } // update clickGraphic (from mouse click to returned feature) clickGraphic.symbol = new InfoSymbol(); // use default renderer clickGraphic.attributes = obj; } } private function merge(target:Object, source:Object):void{ for(var p:String in source){ target = source ; } }
<?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"> <!-- This sample shows how to identify features with a MapClick and the Identify task. The IdentifyParameters designate which layers are being identified. Identify operations can potentially return a lot of information depending on the number of layers being identified and a given tolerance. The tolerance is the number of pixels a feature is allowed to lie away from the clicked point in order to be counted as a result. In this sample, when user clicks the map, an "Identify" task is executed. When the task finishes executing, the executeCompleteHandler function loops through the features in the IdentifyResult and adds them to 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.geometry.MapPoint; import com.esri.ags.geometry.Polygon; import com.esri.ags.geometry.Polyline; 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.controls.DataGrid; import mx.rpc.AsyncResponder; [Bindable]private var lastIdentifyResultGraphic:Graphic; private function mapClickHandler(event:MapMouseEvent):void { clickGraphicsLayer.clear(); lastIdentifyResultGraphic = null; 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 { resultGraphicsLayer.clear(); if (results && results.length > 0) { for each (var identifyResult:IdentifyResult in results) { var resultGraphic:Graphic = identifyResult.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; } } resultGraphic.addEventListener(MouseEvent.MOUSE_OVER, onMouseOverHandler); resultGraphic.addEventListener(MouseEvent.MOUSE_OUT, onMouseOutHandler); resultGraphicsLayer.add(resultGraphic); } } } private function onMouseOutHandler(event:MouseEvent):void { myMap.infoWindow.hide(); } private function onMouseOverHandler(event:MouseEvent):void { var gr:Graphic = Graphic(event.target); lastIdentifyResultGraphic = new Graphic(getGeomCenter(gr),new InfoSymbol,gr.attributes); } //get geom center private function getGeomCenter(graphic:Graphic):MapPoint { var pt:MapPoint; switch (graphic.geometry.type) { case Geometry.MAPPOINT: { pt = graphic.geometry as MapPoint; break; } case Geometry.POLYLINE: { const pl:Polyline = graphic.geometry as Polyline; const pathCount:Number = pl.paths.length; const pathIndex:int = int((pathCount / 2) - 1); const midPath:Array = pl.paths[pathIndex]; const ptCount:Number = midPath.length; const ptIndex:int = int((ptCount / 2) - 1); pt = pl.getPoint(pathIndex, ptIndex); break; } case Geometry.POLYGON: { const poly:Polygon = graphic.geometry as Polygon; pt = poly.extent.center; break; } } return pt; } 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)" openHandCursorVisible="false"> <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 id="resultGraphicsLayer"/> <esri:GraphicsLayer graphicProvider="{lastIdentifyResultGraphic}"/> <esri:GraphicsLayer id="clickGraphicsLayer"/> </esri:Map> </s:Application>
var result:IdentifyResult = results[0];
Angemeldete Mitglieder können Beiträge verfassen, Updates folgen und mehr. Neu hier? Registriere ein kostenloses Konto.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.