<?xml version="1.0" encoding="utf-8"?> <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:mx="library://ns.adobe.com/flex/mx" xmlns:esri="http://www.esri.com/2008/ags" xmlns:s="library://ns.adobe.com/flex/spark"> <!-- Adobe SDK 4.6.0 --> <!-- ArcGIS API for FLEX 3.0 --> <s:layout> <s:VerticalLayout horizontalAlign="center" /> </s:layout> <fx:Script> <![CDATA[ import com.esri.ags.Graphic; import com.esri.ags.events.GraphicEvent; import com.esri.ags.geometry.MapPoint; import com.esri.ags.symbols.InfoSymbol; /** * Listen graphic add handler */ protected function onGraphicAdd(event:GraphicEvent):void { var infoSymbol:InfoSymbol = new InfoSymbol(); infoSymbol.infoRenderer = new ClassFactory(MyInfoSymbolRenderer); event.graphic.symbol = infoSymbol; } /** * Listen button click handler */ protected function onAddClick(event:MouseEvent):void { var point:MapPoint = new MapPoint(Math.random()*10000000, Math.random()*10000000, map.spatialReference); var graphic:Graphic = new Graphic(point, null, {myTitle: txtTitle.text, x: point.x, y: point.y}); gLayer.add(graphic); } ]]> </fx:Script> <s:HGroup width="100%" horizontalAlign="center" verticalAlign="middle"> <s:Label text="Set title for new graphic:" /> <s:TextInput id="txtTitle" width="250"/> <s:Button label="Add graphic" click="onAddClick(event)" /> </s:HGroup> <esri:Map id="map"> <esri:ArcGISTiledMapServiceLayer url="http://server.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer"/> <esri:GraphicsLayer id="gLayer" autoMoveGraphicsToTop="true" graphicAdd="onGraphicAdd(event)"/> </esri:Map> </s:Application>
<?xml version="1.0" encoding="utf-8"?> <s:ItemRenderer xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark" xmlns:mx="library://ns.adobe.com/flex/mx" autoDrawBackground="true" dataChange="onDataChange(event)"> <fx:Script> <![CDATA[ import mx.events.FlexEvent; import mx.utils.StringUtil; protected function onDataChange(event:FlexEvent):void { if (data.myTitle && data.myTitle.toString().length > 0) { lblTitle.text = data.myTitle; } else if (data.x && data.x.toString().length > 0 && data.y && data.y.toString().length > 0) { lblTitle.text = StringUtil.substitute("X: {0} - Y: {1}", data.x, data.y); } } ]]> </fx:Script> <s:Label id="lblTitle" fontFamily="Helvetica" fontSize="14" fontStyle="italic" fontWeight="bold" backgroundColor="0xFFFF00"/> </s:ItemRenderer>
The text string to display.
The string representing the attribute of the graphic that should populate the "text" content.
The text function allows for the text of the text symbol to be dynamically picked - for example based on attributes or position of the graphic.
Plus some ActionScript code that initializes text, something like this:var txtFormat:TextFormat = new TextFormat(textFont.selectedItem.font, numTextSize.value, cpText.selectedColor, bold.selected, italic.selected, underline.selected);textSymbol.textFormat = txtFormat;textSymbol.angle = numTextRotation.value;graphic.symbol = textSymbol; // graphic obj takes geometry as a parameter
Aangemelde leden kunnen berichten plaatsen, updates volgen en meer. Nieuw hier? Registreer een gratis account.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.