AnsweredAssumed Answered

text graphic at polygon centroid

Question asked by jamesfreddyc on Jul 25, 2018
Latest reply on Jul 25, 2018 by jamesfreddyc

Need an assist!  I cannot seem to get my text symbol to show up at a polygon graphic that gets generated from a point array. 

 

In my attached code:

  • mPolygon gets created and added with the correct symbol
  • Tsymbol seems to get created but doesn't get added to the map
  • Tsymbol does get added if there's only one point in the pointColl array for some reason!

 

Any assist is greatly appreciated.

function buildBoundary() {
        if (pointColl) {
            //complete poly with first collected point                   
            pointColl.push(pointColl[0])
            pointColl.push(pointColl[1])

            symbol = new SimpleFillSymbol(SimpleFillSymbol.STYLE_SOLID, new SimpleLineSymbol(SimpleLineSymbol.STYLE_SOLID, new Color([100, 0, 220]), 3), new Color([100, 0, 220, 0.10]));
                   
            var myPolygon = {
                "geometry": {
                    "rings": [pointColl], "spatialReference": { "wkid": 4326 }
                },
                "symbol": {
                    "color": [100, 0, 220, 64], "outline": {
                        "color": [0, 0, 0, 255],
                        "width": 1, "type": "esriSLS", "style": "esriSLSSolid"
                    },
                    "type": "esriSFS", "style": "esriSFSSolid"
                }
            };
                   
            var gra = new Graphic(myPolygon);
            map.graphics.add(gra);

            var area = geometryEngine.geodesicArea(gra.geometry, "acres");
            var acreFrmt = area.toFixed(2)
            alert(acreFrmt + " acres.")
            var font = new esri.symbol.Font();
            font.setSize(20);
            font.setWeight(25);

            var Tsymbol = new esri.symbol.TextSymbol();
            Tsymbol.setText(acreFrmt + " ac");
            Tsymbol.setColor(new Color([255, 255, 0]));
            Tsymbol.setFont(font);
            map.graphics.add(new Graphic(gra.geometry, Tsymbol));
                       
            pointColl = []
            //alert(acreFrmt)
        }
    };       

Outcomes