Label Polygon Vertices

1193
3
Jump to solution
04-20-2018 12:11 PM
JamesCrandall
MVP Frequent Contributor

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);
                    });
                });
            }
           },
Tags (1)
0 Kudos
1 Solution

Accepted Solutions
RobertScheitlin__GISP
MVP Emeritus

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.

View solution in original post

3 Replies
RobertScheitlin__GISP
MVP Emeritus

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.

JamesCrandall
MVP Frequent Contributor

That makes sense.  This should be fun and infuriating... I can tell already.

Thanks again!

0 Kudos
JamesCrandall
MVP Frequent Contributor

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.

0 Kudos