Tips: This example shows how to select or reverse a geometry in a layer, trigger the Mapclick event when clicking on a map, activate Querytask, and query.geometry in query = Event.mappoint; Use the point of the mouse click to find the polygon that includes the selection, then add the queried geometry to the graphicslayer and zoom in one level, and when you click the selected feature again, the Unselectgraphic event is triggered. and remove the feature from the Graphicslayer . Specific and code as follows:
1<?xml version= "1.0" encoding= "Utf-8"?>2<s:application xmlns:fx= "http://ns.adobe.com/mxml/2009"3Xmlns:s= "Library://ns.adobe.com/flex/spark"4Xmlns:esri= "Http://www.esri.com/2008/ags"5Pagetitle= "Select and Zoom" >6 7<fx:Script>8<![cdata[9 Importcom.esri.ags.Graphic;Ten Importcom.esri.ags.events.MapMouseEvent; One Importcom.esri.ags.events.QueryEvent; A Importcom.esri.ags.geometry.Extent; - ImportCom.esri.ags.utils.GraphicUtil; - the Importmx.collections.ArrayCollection; - Importmx.collections.ArrayList; - - Privatevar Mapclicktoggler:boolean =true; + - Privatefunction Mapclickhandler (event:mapmouseevent):void + { A if(Mapclicktoggler) at { -Query.geometry =Event.mappoint; - querytask.execute (query); - } - } - in Privatefunction Executecompletehandler (event:queryevent):void - { to forEach (var mygraphic:graphic in event.featureSet.features) + { -Mygraphic.symbol =Mysymbol; the Mygraphic.addeventlistener (Mouseevent.click, unselectgraphic); * //Mygraphic.addeventlistener (Mouseevent.roll_over, Togglemapclick); $ //Mygraphic.addeventlistener (Mouseevent.roll_out, Togglemapclick);Panax Notoginseng Mygraphicslayer.add (mygraphic); - } the zoomtographics (); + } A the Privatefunction Zoomtographics ():void + { -var graphicprovider:arraycollection =Mygraphicslayer.graphicprovider as arraycollection; $var graphicsextent:extent =graphicutil.getgraphicsextent (Graphicprovider.toarray ()); $ - if(graphicsextent) - { theMymap.extent =graphicsextent; - Wuyi //Make sure the whole extent is visible the if(!myMap.extent.contains (graphicsextent)) - { Wumymap.level--; - } About } $ } - - Privatefunction Unselectgraphic (event:mouseevent):void - { A Mygraphicslayer.remove (event.currenttarget as Graphic); + zoomtographics (); the } - $ Privatefunction Togglemapclick (event:mouseevent):void the { theMapclicktoggler =!Mapclicktoggler; the } the]]> -</fx:Script> in the<fx:Declarations> the<esri:querytask id= "Querytask" AboutExecutecomplete= "Executecompletehandler (event)" theUrl= "HTTP://SAMPLESERVER1.ARCGISONLINE.COM/ARCGIS/REST/SERVICES/DEMOGRAPHICS/ESRI_CENSUS_USA/MAPSERVER/5" theUseamf= "false"/> the<esri:query id= "Query" +Outspatialreference= "{mymap.spatialreference}" -Returngeometry= "true"/> the<esri:simplefillsymbol id= "Mysymbol"BayiAlpha= "0.7" theColor= "#D3D1D1" the> -</esri:SimpleFillSymbol> -</fx:Declarations> the the<s:controlBarContent> the<s:richtext width= "100%" > the This is sample demonstrates how to select or deselect a graphic - In a graphics layer. This was accomplished by using a querytask to the add features to a graphics layer, or remove graphics from the graphics theLayer by clicking on the that graphic. The GraphicutilclassIs also used theInch Thissample to get the extent of the graphics in the graphics94Layer and adjust the map extent and scale based uponifThe features the is contained within the current extent. the Click on a state to select or unselect it. The map would zoom to current selection. the</s:RichText>98</s:controlBarContent> About -<esri:map id= "MyMap" mapclick= "Mapclickhandler (event)" >101<esri:extent>102<esri:extent xmin= " -13901000" ymin= "3292000" xmax= " -8812000" ymax= "6154000" >103<esri:spatialreference wkid= "102100"/>104</esri:Extent> the</esri:extent>106<esri:arcgistiledmapservicelayer url= "http://server.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/ MapServer "/>107<esri:arcgisdynamicmapservicelayer url= "http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/ Demographics/esri_census_usa/mapserver "visiblelayers=" {New ArrayList ([5])} "/>108<esri:graphicslayer id= "Mygraphicslayer"/>109</esri:Map> the 111</s:Application>
ArcGIS for Flex Learning mapping---Select and zoom