AnsweredAssumed Answered

Construct array of corrdinate pairs for polygon

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

Ultimately, I'm attempting to build polygon graphics from array of coordinate pairs.  I'm not exactly sure if I'm constructing the "final" array of coordiates correctly though.

 

I'm attempting to call the buildBoundary() function and use the pointColl array to generate the polygon and add it as a graphic.

 

Any comment is appreciated!

 

//this is from the <script> section of an html page
var pointColl = []
function storeCoordinate(x, y, array) {
                array.push(x);
                array.push(y);
                pointColl.push(array)
};

function showLocation(location) {               
                var tPts = []
                storeCoordinate(location.coords.longitude, location.coords.latitude, tPts)               
};

function buildBoundary() {
                pointColl = JSON.parse("[" + pointColl + "]")
               
                var myPolygon = {
                    "geometry": {
                        "rings": pointColl, "spatialReference": { "wkid": 3857 }
                    },
                    "symbol": {
                        "color": [0, 0, 0, 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);               
            };
     
document.getElementById("build-boundary-btn").onclick = function () {
                buildBoundary();
            };

Outcomes