private function addtext():void { myMap.addEventListener(MapMouseEvent.MAP_CLICK, onClickFunction); } private function onClickFunction(event:MapMouseEvent):void { const mapPoint:MapPoint = event.mapPoint; mapPoint.spatialReference = new SpatialReference(102100); var myGraphicMarker:Graphic = new Graphic(mapPoint, new TextSymbol(labeltext.text,null,0x000000,1, tsBorder.selected,tsBorderColor.selectedColor,tsBackground.selected,tsColor2.selectedColor,placement.selectedItem,angle.value,xoffset.value,yoffset.value,new TextFormat(myFont.selectedItem, tfSize.value, tsColor1.selectedColor, tfBold.selected,tfItalic.selected, tfUnderline.selected), null,null)); theTextGraphic = myGraphicMarker //myGraphicMarker.toolTip = "Marker added with ActionScript"; pointGraphicsLayer.add(theTextGraphic); pointGraphicsLayer.refresh(); }
Solved! Go to Solution.
<?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" minWidth="955" minHeight="600" xmlns:esri="http://www.esri.com/2008/ags" creationComplete="application1_creationCompleteHandler(event)"> <fx:Script> <![CDATA[ import com.esri.ags.Graphic; import com.esri.ags.events.MapMouseEvent; import com.esri.ags.geometry.MapPoint; import com.esri.ags.symbols.TextSymbol; import mx.events.FlexEvent; //[Bindable] private var graphicContextMenu:ContextMenu = new ContextMenu(); protected function application1_creationCompleteHandler(event:FlexEvent):void { graphicContextMenu.hideBuiltInItems(); var item:ContextMenuItem; item = new ContextMenuItem("Delete me"); //item.enabled = true; item.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT, deleteGraphic_handler); graphicContextMenu.customItems.push(item); } protected function deleteGraphic_handler(event:ContextMenuEvent):void { trace("deleteGraphic_handler"); if (event.contextMenuOwner is Graphic) { var graphic:Graphic = event.contextMenuOwner as Graphic; graphic.graphicsLayer.remove(graphic); } } protected function map_mapClickHandler(event:MapMouseEvent):void { const mapPoint:MapPoint = event.mapPoint; var textSymbol:TextSymbol = new TextSymbol("myTextSymbol",null,0x000000, true,0,true); //2.5 api //var textSymbol:TextSymbol = new TextSymbol("myTextSymbol",null,0x000000, 1, true,0,true); // newer api var myGraphicMarker:Graphic = new Graphic(mapPoint, textSymbol); myGraphicMarker.contextMenu = graphicContextMenu; graphicsLayer.add(myGraphicMarker); graphicsLayer.refresh(); } ]]> </fx:Script> <fx:Declarations> <!-- Place non-visual elements (e.g., services, value objects) here --> </fx:Declarations> <esri:Map id="map" mapClick="map_mapClickHandler(event)" > <esri:extent> <esri:Extent xmin="-10753431" ymin="4624151" xmax="-10737799" ymax="4635884"> <esri:SpatialReference wkid="102100"/> </esri:Extent> </esri:extent> <esri:ArcGISTiledMapServiceLayer id="baseLayer" url="http://server.arcgisonline.com/ArcGIS/rest/services/World_Topo_Map/MapServer"/> <esri:GraphicsLayer id="graphicsLayer"/> </esri:Map> </s:Application>