Label on polyline mid point

3710
1
09-23-2014 12:11 AM
FrankyFergus
New Contributor

Dear all,

 

I am trying to put a label(TextSymbol) at a polyline midpoint (graphics layer). This is my code so far:

 

            var startX = coorX[0];             var endX = coorX[coorX.length - 1];                         var midPointX = ((endX - startX) / 2).toFixed(2);              var startY = coorY[0];             var endY = coorY[coorY.length - 1];             var midPointY = ((endY - startY) / 2).toFixed(2);              var font = new Font("12px", Font.STYLE_NORMAL, Font.STYLE_NULL, Font.VARIANT_NORMAL, Font.WEIGHT_NULL, "Arial");                          var pipePoint = new Point(midPointX, midPointY, map.spatialReference);              // create a text symbol             var textSymbol = new TextSymbol("LABEL TEXT!!!", font, new Color([0, 0, 0]));              var labelGraphic = new Graphic(pipePoint, textSymbol);              // add the label point graphic to the map             map.graphics.add(labelGraphic);

 

Can't see the label anywhere. I tried to increase the font size but with no success. I'd appreciate some help.

 

Thanks in advance.

 

Frank

Tags (2)
0 Kudos
1 Reply
FrankyFergus
New Contributor

I found the problem. What I did is I removed the toFixed(2) method and I added replaced the pipePoint with the following:

var pipePoint = new Point((coorX[0] + midPointX), (coorY[0] + midPointY), map.spatialReference);

0 Kudos