Can anyone point me to an example/sample of labeling polygon geometry at each vertex?
I have a requirement to label each vertex with coordinate info.
Javascript 3.x
Update: I've attempted to implement the Points for Labeling method on the Geometry service, as seen in this example but I'm getting an error
init.js:114 TypeError: Cannot read property '0' of undefined
at Object.labelPoints (init.js:2548)
getLabelPoints: function (geom) {
var geometryService = new GeometryService("https://utility.arcgisonline.com/ArcGIS/rest/services/Geometry/GeometryServer");
var geographicGeometries = [];
geographicGeometries.push(esri.geometry.webMercatorToGeographic(geom));
if (geom.rings.length > 0) {
geometryService.labelPoints(this.geom, function(labelPoints) {
var font = new Font("20px", Font.STYLE_NORMAL, Font.VARIANT_NORMAL, Font.WEIGHT_BOLDER);
array.forEach(this.labelPoints, function (labelPoint) {
// create a text symbol
var textSymbol = new TextSymbol(
"X: " + number.format(labelPoint.x) + ", Y: " + number.format(this.labelPoint.y),
font, new Color([0, 0, 0]));
var labelPointGraphic = new Graphic(this.labelPoint, textSymbol);
// add the label point graphic to the map
map.graphics.add(labelPointGraphic);
});
});
}
},
Solved! Go to Solution.
James,
The only way I can think of is to create a GraphicsLayer that uses a text symbol and loop through the polygons ring array to get the points and use those points as the geometry for the graphic.
James,
The only way I can think of is to create a GraphicsLayer that uses a text symbol and loop through the polygons ring array to get the points and use those points as the geometry for the graphic.
That makes sense. This should be fun and infuriating... I can tell already.
Thanks again!
I won't be able to implement this until finished up another requirement. Seems like your answer will be the way to go and I'll go ahead and mark as the answer.