// This is an event listener function added on the init function when the drawtool settings are set after the drawtool is created outside the function import com.esri.ags.utils.GeometryUtil; public var drawPolygon : Graphic = new Graphic(); private function onDrawEnd(event:DrawEvent):void { drawToolbar.deactivate(); myGraphicsLayer.clear(); freehandbutton.selectedIndex = -1; multipointbutton.selectedIndex = -1; myMap.panEnabled = false; var geometry:Geometry = event.graphic.geometry; if (geometry is Polygon && GeometryUtil.polygonSelfIntersecting(geometry as Polygon)) { // Note: As of version 2.0, GeometryService returns geometries (instead of graphics). myGeometryService.simplify([ geometry ]); } if (geometry is Polygon && !GeometryUtil.polygonSelfIntersecting(geometry as Polygon)) { drawPolygon.geometry = event.graphic.geometry; drawPolygon.symbol = fillSymbolcounty; drawPolygon.autoMoveToTop = false; //keep graphics from moving to top //to not draw a polygon when I use the freehand polygon select tool I uncomment the next line, but right now I have this uncommented and on the zoomtorow function // I have this myPolygonGraphicsLayer.remove(drawPolygon) uncommented, so the polygon disappears when we zoom in and does not darken the view (it darkens the view //if I dont have the drawpolygon.symbol as fillSymbolcounty which is transparent inside myPolygonGraphicsLayer.add(drawPolygon); runQueryTask(event.graphic.geometry); // If using point draw tool then run querytask3 } else{ //Must be multipoint runQueryTaskcounty(event.graphic.geometry);} } import com.esri.ags.events.GeometryServiceEvent; import com.esri.ags.geometry.Geometry; import com.esri.ags.utils.GeometryUtil; import mx.rpc.events.FaultEvent; private function myGeometryService_simplifyCompleteHandler(event:GeometryServiceEvent):void { // Note: As of version 2.0, GeometryService returns geometries (instead of graphics) doQuery(event.result[0] as Geometry); } private function doQuery(geom:Geometry):void { try { queryTaskintersectingpolygon.showBusyCursor = true; var queryintersectingpolygon:Query = new Query(); queryintersectingpolygon.spatialRelationship = "esriSpatialRelIntersects"; queryintersectingpolygon.returnGeometry = true; //set to true because we want to place points on the map queryintersectingpolygon.outSpatialReference = myMap.spatialReference; queryintersectingpolygon.outFields = ['*']; queryintersectingpolygon.geometry = geom; queryintersectingpolygon.returnGeometry = true; queryTaskintersectingpolygon.execute(queryintersectingpolygon, 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) { //graphic.symbol = resultsSymbol; //myGraphicslayerpolygon.add(graphic); myGraphicsLayerintersectingpolygon.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); }
<esri:GeometryService id="myGeometryService" simplifyComplete="myGeometryService_simplifyCompleteHandler(event)" url="http://sampleserver3.arcgisonline.com/ArcGIS/rest/services/Geometry/GeometryServer"/> <esri:QueryTask id="queryTaskintersectingpolygon" fault="queryTask_faultHandler(event)" url="http://tfs-24279/ArcGIS/rest/services/ForestProducts/dynamic_layer_forest_products/MapServer/0" useAMF="false"/>
<esri:GraphicsLayer id="myGraphicsLayerintersectingpolygon"/>
Solved! Go to Solution.