Select to view content in your preferred language

Add a label from the graphic layer.

7392
6
Jump to solution
04-26-2017 02:12 PM
Sai_AnandPeketi1
Deactivated User

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

6 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
Deactivated User

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
Deactivated User

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);
‍‍‍‍‍‍‍‍
hoogw
by
Regular Contributor

                   var text_symbol = new TextSymbol(result.address);

                  var graphic_item =  new Graphic({
                                                      attributes: result.attributes,
                                                      geometry: result.location,



                                                      // in use, text symbol as graphic label
                                                      symbol: text_symbol,


                                                      /*  not use,  -- simple marker symbol  --
                                                        symbol: {
                                                            // autocasts as new SimpleMarkerSymbol()
                                                            type: "simple-marker",
                                                            color: poi_color,   //"yellow",
                                                            size:  poi_size,  // all works "31pt", "31px",
                                                            style: poi_style, // diamond, triangle, cross, x, circle, path, square
                                                            // autocasts as new SimpleLineSymbol()
                                                            outline: {
                                                              // simple marker builder, https://sagewall.github.io/symbol-builder/simple-marker-symbol/
                                                              color: poi_outlineColor,  //"#efefef",
                                                              width: poi_outlineWidth
                                                            }
                                                        },
                                                        // -- end  -- simple marker symbol  --
                                                      */


                                                     
                                                      popupTemplate: {
                                                        title: "Name: {PlaceName}",

                                                        //not use lat, lng ... + result.location.x.toFixed(5) + "," + result.location.y.toFixed(5)
                                                        content:"Address: {Place_addr}" + "<br>Phone: {Phone}" + "<br>Type:  {Type}"  + "<br>URL:  {URL}"
                                                      }
                                                       



                                                })// graphic


                  // defaultPopupTemplateEnabled ( default is false ) https://developers.arcgis.com/javascript/latest/api-reference/esri-Graphic.html#getEffectivePopupTem...
                  graphic_item.getEffectivePopupTemplate(true)

                  view.graphics.add(graphic_item);
 
 
 
 
 

 

0 Kudos