Hi,
I would like to print a textSymbol on center of the ployLine using the Longitude and Latitude.
I Have written the below code, but Unable to print the textSymbol.
var labelGraphic = null; var startX = lLong[0];// These are string values var endX = lLong[lLong.length-1]; var startY= lLat[0]; var endY = lLat[lLat.length-1]; var midPointX = ((endX - startX) / 2); var midPointY = ((endY - startY) / 2); var font = new Font("12px", Font.STYLE_NORMAL, Font.STYLE_NULL, Font.VARIANT_NORMAL, Font.WEIGHT_NULL, "Arial"); var pipePoint = new Point(((parseFloat(lLong[0]))+midPointX ) , ((parseFloat(lLat[0]))+ midPointY), map.spatialReference);
labelGraphic = new Graphic(pipePoint, textSymbol); if (labelGraphic != null) map.graphics.add(labelGraphic); Please help me how to add the textSymbol to the polyline. | ||||||
Try to use the midpoint formula:
(this of course only works if you're dealing with straight lines)
Thankyou for help. But here my polyLine is dynamically changes the direction. I want to display the text along with the line. How do I do that?
Even I tried with
textSymbol.setVerticalAlignment()/ setHorizontalMethods also.
Calculate the angle of the line and set the rotation of the text symbol accordingly.
Is there any example to calculate the PolyLine angle?
Are your lines straight lines or real polylines?
Real polylines, we are drawing those using latitude and longitude.
I got this from an earlier post and used it to place an "arrow" (actually the letter "V") at the center of a polyline. Using your variables:
var rise = endX - startX;
var run = endY - startY;
var angle = (180/Math.PI) * Math.atan2(run,rise);
...
textSymbol.angle = angle;
Hi Tyrone,
Thank you for your update. But here I am using Latitude and Longitude to draw my polyLine.
Please help us to find the angle for PloyLine.
Thankyou!!
You can convert lat/long to XY
esri/geometry/webMercatorUtils | API Reference | ArcGIS API for JavaScript
You might consider using a label layer instead?