<?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"> <s:layout> <s:VerticalLayout paddingBottom="6"/> </s:layout> <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 mx.collections.ArrayCollection; import mx.utils.StringUtil; private var lastAddedGraphic:Graphic = null; /** * Listen map mouse down handler */ protected function myMap_mapMouseDownHandler(event:MapMouseEvent):void { var grGeometry:MapPoint = event.mapPoint; var grAttributes:Object = new Object(); grAttributes.creationDate = new Date().toString(); var gr:Graphic = new Graphic(grGeometry, sms, grAttributes); gr.toolTip = gr.attributes.creationDate; var grId:String = myGraphicsLayer.add(gr); trace(StringUtil.substitute("Graphic with id: {0} added.", grId)); lastAddedGraphic = gr; } /** * Listen clear all button click handler */ protected function btnClearClick(event:MouseEvent):void { myGraphicsLayer.clear(); lastAddedGraphic = null; } /** * Listen remove button click handler */ protected function btnRemoveClick(event:MouseEvent):void { if (lastAddedGraphic != null) { try { var grId:String = lastAddedGraphic.id; myGraphicsLayer.remove(lastAddedGraphic); trace(StringUtil.substitute("Graphic with id: {0} removed.", grId)); lastAddedGraphic = null; } catch (err:Error) { trace(err.message); } } } ]]> </fx:Script> <fx:Declarations> <!-- Symbol for all point shapes --> <esri:SimpleMarkerSymbol id="sms" color="0x00FF00" size="12" style="{SimpleMarkerSymbol.STYLE_DIAMOND}"/> </fx:Declarations> <esri:Map id="myMap" mapMouseDown="myMap_mapMouseDownHandler(event)" level="3" wrapAround180="true"> <esri:ArcGISTiledMapServiceLayer url="http://server.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer"/> <esri:GraphicsLayer id="myGraphicsLayer"/> </esri:Map> <s:Button id="btnClearAll" label="Clear all graphics" click="btnClearClick(event)"/> <s:Button id="btnRemove" label="Remove last graphics" click="btnRemoveClick(event)"/> </s:Application>
Signed in members can post, follow updates, and more. New here? Register a free account.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.