Add a label from the graphic layer.

5679
5
Jump to solution
04-26-2017 02:12 PM
Sai_AnandPeketi1
New Contributor III

Hello everyone,

                           I want to add the label for the graphic layer.I have a graphic layer contain graphic,symbol and attributes. Now, I want to add a label from that graphic layer. Is it possible, if yes can anyone share the code because i see the sample of the 'esri/layers/LabelLayer' all are coming from the feature layer.

Thanks for the help.

1 Solution

Accepted Solutions
RobertScheitlin__GISP
MVP Emeritus

Then you get the polygons extent using 

var pnt = geometry.getExtent().getCenter();
var txtSym = new TextSymbol("Hello World");
var lblGra = new Graphic(pnt, txtSym);
bufferGL.add(lblGra);
‍‍‍‍‍‍‍‍

View solution in original post

5 Replies
RobertScheitlin__GISP
MVP Emeritus

Sai,

   Probably the easiest way to do this is to add another graphic (the center of the extent for polygons or polylines) using a TextSymbol as the graphics symbol.

Sai_AnandPeketi1
New Contributor III

Thanks Robert.

Can you share the javascript code for above logic. I am not understand how we can set center of the graphics into the center of the graphics symbol.

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Sai,

   What is the geometry type that you are trying to label?

Sai_AnandPeketi1
New Contributor III

Thank Robert.

Polygon type. Need to work on this code Draw polygon feature when ever use click on the map 

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Then you get the polygons extent using 

var pnt = geometry.getExtent().getCenter();
var txtSym = new TextSymbol("Hello World");
var lblGra = new Graphic(pnt, txtSym);
bufferGL.add(lblGra);
‍‍‍‍‍‍‍‍