1. sample source code:
<? 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: MX = "Library: // ns.adobe.com/flex/mx" xmlns: ESRI = "http://www.esri.com/2008/ags" minwidth = "955" minheight = "600" initialize = "Init ()"> <FX: SCRIPT> <! [CDATA [import COM. ESRI. AGS. graphic; import COM. ESRI. AGS. events. drawevent; import COM. ESRI. AGS. layers. arcgisdynamicmapservicelayer; import COM. ESRI. AGS. layers. graphicslayer; import COM. ESRI. AGS. layers. supportclasses. layerinfo; import MX. collections. arraycollection; import MX. events. itemclickevent; [Bindable] private var mylayer: arcgisdynamicmapservicelayer; private var mygraphiclayer: graphicslayer; Protected function Init (): void {// Add the layer mylayer = new arcgisdynamicmapservicelayer (); mylayer for the map control. url = "http: // localhost: 8399/ArcGIS/rest/services/testusa/mapserver"; mymap. addlayer (mylayer); // Add the Drawing Layer mygraphiclayer = new graphicslayer () for the map control; mymap. addlayer (mygraphiclayer); cb_nullcities.addeventlistener (event. change, cbclickhandler); cb_highways.addeventlistener (event. change, cbclickhandler); cb_sta Tes. addeventlistener (event. change, cbclickhandler); cb_counties.addeventlistener (event. change, cbclickhandler);} protected function cbclickhandler (Event: Event): void {var cbobj: checkbox = new checkbox (); cbobj1_checkbox(event.tar get); visiblelayer (cbobj. label, cbobj. selected);} // display the hidden layer protected function visiblelayer (layername: String, visible: Boolean): void {var visiblelayers: arraycollection; visiblelay ERS = mylayer. visiblelayers; var Infos: array = mylayer. layerinfos; // traverse layer for each (VAR info: layerinfo in Infos) {If (info. name = layername) {If (visible) {visiblelayers. additem (info. ID);} else {var alias: Int = visiblelayers. getitemindex (info. ID); If (success! =-1) {visiblelayers. removeitemat (KEYS) ;}} break ;}// obtain the map coordinate protected function mapmousemovehandle (Event: mouseevent): void {var Lon: Number = mymap. tomapfromstage (event. stagex, event. stagey ). x; var Lat: Number = mymap. tomapfromstage (event. stagex, event. stagey ). y; lab_x.text = "X:" + numberformater. format (Lon); lab_y.text = "Y:" + numberformater. format (LAT);} protected function toobar_clicked (Event: itemclickeve NT): void {// set the vertex style drawtool. markersymbol = SMS; // set the line style drawtool. linesymbol = SLS; // set the surface style drawtool. fillsymbol = SFS; Switch (event. index) {Case 0: drawtool. deactivate (); // close the Drawing Break; Case 1: mymap. zoomin (); // enlarge break; Case 2: mymap. zoomout (); // reduce break; Case 3: drawtool. activate (drawtool. mappoint); // click break; Case 4: drawtool. activate (drawtool. multipoint); // Multi-Point Break; Case 5: drawtool. activate (drawtool. Line); // line break; Case 6: drawtool. activate (drawtool. polyline); // line break; Case 7: drawtool. activate (drawtool. polygon); // polygon break; case 8: drawtool. activate (drawtool. freehand_polyline); // free line break; Case 9: drawtool. activate (drawtool. extent); // free break; case 10: drawtool. activate (drawtool. freehand_polygon); // rectangular break; Case 11: drawtool. activate (drawtool. circle); // circular break; Case 12: drawto Ol. activate (drawtool. ellipse); // elliptical break; Case 13: // mygraphiclayer. removechildat (1); // Delete the specified drawing mygraphiclayer. clear (); break ;}} protected function ondrawend (Event: drawevent): void {// after the drawing is complete, add the graph to the specified layer var graphic: graphic = event. graphic; mygraphiclayer. add (graphic) ;}]]> </FX: SCRIPT> <FX: declarations> <mx: numberformatter id = "numberformater" precision = "2"/> <ESRI: drawtool id = "drawtool" map = "{mymap} "Graphicslayer =" {mylayer as graphicslayer} "drawend =" ondrawend (event) "/> <! -- Set the drawing time point, line, and surface style --> <ESRI: simplelinesymbol id = "SLS" style = "solid" color = "0xff0000" width = "2" alpha = "1"/> <ESRI: simplemarkersymbol id = "SMS" style = "square" color = "0xff0000" size = "10"/> <ESRI: simplefillsymbol id = "SFS" style = "solid" color = "0xff0000" alpha = "0.5"/> </FX: declarations> <s: group left = "0" Right = "0" Top = "0" Height = "106"> <s: checkbox id = "cb_nullcities" x = "87" Y = "52" label = "Cities" selected = "true"/> <s: checkbox id = "cb_highways" x = "86" Y = "78" label = "highways" selected = "true"/> <s: checkbox id = "cb_states" x = "167" Y = "52" label = "States" selected = "true"/> <s: checkbox id = "cb_counties" x = "167" Y = "78" label = "counties" selected = "true"/> <s: label id = "lab_x" x = "11" Y = "56" width = "68" text = "X"/> <s: label id = "lab_y" x = "10" Y = "84" width = "68" text = "Y"/> <mx: togglebuttonbar itemclick = "toobar_clicked (Event) "> <mx: dataprovider> <FX: array> <FX: String> roaming </FX: String> <FX: String> zoom in </FX: String> <FX: string> zoom out </FX: String> <FX: String> point </FX: String> <FX: String> multiple Points </FX: String> <FX: string> line </FX: String> <FX: String> polygon </FX: String> <FX: string> free line </FX: String> <FX: String> rectangle </FX: String> <FX: String> free surface </FX: String> <FX: string> circle </FX: String> <FX: String> elliptical </FX: String> <FX: String> clear drawing </FX: String> </FX: array> </MX: dataprovider> </MX: togglebuttonbar> </S: group> <s: group Top = "106" width = "100%" Height = "100%"> <ESRI: map x = "0" Y = "0" width = "100%" Height = "100%" id = "mymap" mousemove = "mapmousemovehandle (event)"/> </s: group> </S: Application>
2. Example diagram: