AnsweredAssumed Answered

Create polygon from points / rings in 4.3 api

Question asked by gilbertgis on Jun 13, 2017
Latest reply on Jun 14, 2017 by TSolow-esristaff

Hi all, I am trying to create a polygon on my view from click points, I take the point and add it to a point collection, then I calculate the rings for the polygon.  I am able to create the polygon with hard coded rings, like in the esri examples, but when I build the array of rings programmatically, it doesn't draw.  I don't get any errors, the polygon just doesn't draw.  I am building the array as an array of objects, I logged the hard coded array to the console to see what the exact structure was, then I created that programmatically.  If I am overlooking something, I can't think of what it could be, the functions are exactly the same, except for the rings assignment.

 

    function putIDBoxOnMap() {  //draws polygon
      var polyID = new Polygon({
        spatialReference: view.spatialReference,
        rings: [
          [750916.6634999937,856041.7037500741],
          [757750.010500021,856291.7042500751],
          [758416.6785000238,852375.0297500595],
          [751666.6649999968,851791.6952500571],
          [750916.6634999937,856041.7037500741]
        ]
      });
      console.log(polyID.rings);
      polygonGraphic.geometry=polyID;
      polygonGraphic.symbol=simpleFill;
      view.graphics.add(polygonGraphic);
    }

 

This is the logged array from this function:(I only expanded one of the vertices to save space)

750916.6634999937,856041.7037500741,757750.010500021,856291.7042500751,758416.6785000238,852375.0297500595,750916.6634999937,856041.7037500741
   [
      0: [
         0: [
            0: 750916.6634999937,
            1: 856041.7037500741,
            length: 2
         ],
         1: [ ],
         2: [ ],
         3: [ ],
         length: 4
      ],
      length: 1
   ]


    function putPolyOnMap() {  //does not draw polygon
      var pRings=[];
      var pPtXY=[];
      for (i=0;i<ptCount;i++) {
        pPtXY[0]=ptColl[i].x;
        pPtXY[1]=ptColl[i].y;
        pRings[i]=pPtXY;
      }
      pPtXY[0]=ptColl[0].x;
      pPtXY[1]=ptColl[0].y;
      pRings[ptCount]=pPtXY; //closes the polygon
      var pRingsAll=[pRings];
      var idPolygon=new Polygon({
        rings: pRingsAll,
        spatialReference: view.spatialReference
      });
      console.log(pRingsAll);
      polygonGraphic.geometry=idPolygon;
      polygonGraphic.symbol=simpleFill;
      view.graphics.add(polygonGraphic);
    }
  });

Returns this array.

743749.9824999651,857375.0397500795,743749.9824999651,857375.0397500795,743749.9824999651,857375.0397500795,743749.9824999651,857375.0397500795
   [
      0: [
         0: [
            0: 743749.9824999651,
            1: 857375.0397500795,
            length: 2
         ],
         1: [ ],
         2: [ ],
         3: [ ],
         length: 4
      ],
      length: 1
   ]

 

I cannot see any difference in the structure of these arrays.

Thank you in advance for any help you could provide.

 

Jeff

Outcomes