Select to view content in your preferred language

Using TextSymbol

1146
6
Jump to solution
10-22-2012 09:50 AM
PhilipTownsend
Emerging Contributor
Ok, I hate to ask this question because it seems the answer should be quite clear, but it isn't (to me anyway). Classic ESRI--document a class in extreme detail but leave out possibly the most critical part. In this case, I need to know how, in ActionScript, to place a text symbol on a map next to a graphic symbol that I have just added. Again, the documentation seems to spell out every property and method associated with TextSymbol, but fails to explain how to get it on the map. Can anyone point me to a resource that explains how to place a TextSymbol on a map or layer? Thanks!
Tags (2)
0 Kudos
1 Solution

Accepted Solutions
RobertScheitlin__GISP
MVP Emeritus
Anthony, sorry for jumping in but that is not correct.


Philip,

Actually you do not have to add them separately you just have to use a composite symbol.

   Sample code:

import com.esri.ags.symbols.CompositeSymbol;  var PointAMarker:MapPoint = new MapPoint(64,31,map.spatialReference); var graphicsLayer:GraphicsLayer = new GraphicsLayer();  var txtSymA:TextSymbol = new TextSymbol(); txtSymA = new TextSymbol("Some Text",null,0x000000,true,0x000000,true,0xffffff,"middle",0,0,0); txtSymA.textFormat = txtFormat;  var graphicPointSym:PictureMarkerSymbol; var icon:String = "assets\images\i_pws.png"; graphicPointSym = new PictureMarkerSymbol(icon, 30, 30);  var compositeSym:CompositeSymbol; compositeSym = new CompositeSymbol([txtSymA, graphicPointSym]);  var graphicPointA:Graphic = new Graphic(PointAMarker, compositeSym); graphicsLayer.add(graphicPointA); map.addLayer(graphicsLayer);

View solution in original post

0 Kudos
6 Replies
AnthonyGiles
Honored Contributor
Philip,

You have to create a graphic from a point and a text symbol then add it to a graphics layer, see below which adds the text "some Text" to a point at 64,31:

var PointAMarker:MapPoint = new MapPoint(64,31,map.spatialReference);
var graphicsLayer:GraphicsLayer = new GraphicsLayer();
var txtSymA:TextSymbol = new TextSymbol();
txtSymA = new TextSymbol("Some Text",null,0x000000,true,0x000000,true,0xffffff,"middle",0,0,0);
txtSymA.textFormat = txtFormat;
var graphicPointA:Graphic = new Graphic(PointAMarker, txtSymA);
graphicsLayer.add(graphicPointA);
map.addLayer(graphicsLayer);


Hope this helps

Anthony
0 Kudos
PhilipTownsend
Emerging Contributor
This helps, but it seems now I can add either a symbol (SimpleMarkerSymbol) or a TextSymbol, but not both. What I need is a labeled symbol. Do I need to add both as separate entities?
0 Kudos
AnthonyGiles
Honored Contributor
Philip,

Yes you have to add them seperately unfortunately. You will notice the zeros at the end of the new text symbol, they allow you to set an offset x and y to move the label off the point

regards

Anthony
0 Kudos
RobertScheitlin__GISP
MVP Emeritus
Anthony, sorry for jumping in but that is not correct.


Philip,

Actually you do not have to add them separately you just have to use a composite symbol.

   Sample code:

import com.esri.ags.symbols.CompositeSymbol;  var PointAMarker:MapPoint = new MapPoint(64,31,map.spatialReference); var graphicsLayer:GraphicsLayer = new GraphicsLayer();  var txtSymA:TextSymbol = new TextSymbol(); txtSymA = new TextSymbol("Some Text",null,0x000000,true,0x000000,true,0xffffff,"middle",0,0,0); txtSymA.textFormat = txtFormat;  var graphicPointSym:PictureMarkerSymbol; var icon:String = "assets\images\i_pws.png"; graphicPointSym = new PictureMarkerSymbol(icon, 30, 30);  var compositeSym:CompositeSymbol; compositeSym = new CompositeSymbol([txtSymA, graphicPointSym]);  var graphicPointA:Graphic = new Graphic(PointAMarker, compositeSym); graphicsLayer.add(graphicPointA); map.addLayer(graphicsLayer);
0 Kudos
AnthonyGiles
Honored Contributor
Robert,

Thats handy to know thank you. I wasn't aware of the composite symbol. In coding terms does it make it any more efficient than adding two graphics?

Regards

Anthony
0 Kudos
RobertScheitlin__GISP
MVP Emeritus
Anthony,

   Other than Having one graphic to deal with, I do not know performance wise (but it would make sense that it would perform better). I use it with my weather underground widget to put the temps next to the observation locations.
0 Kudos