1

I am using require.js

// output of polygonString is
// {"spatialReference":{"latestWkid":3414,"wkid":3414},"rings":[[[18240.432900000364,43817.389900000766],[18214.047899999656,43880.139900000766],[18303.02390000038,43896.1548999995],[18316.83990000002,43898.6389000006],[18331.732900000177,43815.97389999963],[18247.076899999753,43800.71189999953],[18240.432900000364,43817.389900000766]]]}
var polygon = JSON.parse($parameters.polygonString)

I am trying to convert the JSON object to a ESRI Polygon object, I had tried the following:

(1)

//doesn't seems to work
var new_polygon = new window.ArcGIS.Polygon({
      fromJSON: polygon
});

(2)

//return fromJSON is not a function
var new_polygon = new window.ArcGIS.Polygon();
console.log(new_polygon.fromJSON(polygon));

What is the correct way to use fromJSON?

1

The correct way would be,

var polyJson = JSON.parse($parameters.polygonString);
var poly = Polygon.fromJSON(polyJson);

Take a look here ArcGIS Docs - Using fromJSON

| improve this answer | |
  • great, it works.. cheers – Shi Xuan Mar 16 at 23:55
  • glad it help you! – cabesuon Mar 17 at 3:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.