Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ESRI ArcGIS Javascript : Polygon from JSON not working

If you reference the image, JSON string, and code snippets below, it outlines the code, console output and expected behavior of trying to draw a polygon (or really any geometry/graphic) using the ESRI ArcGIS Javascript API. Not sure what is going on....help please!

JSON String:

{"geometry":{"rings":[[[-91.89013671874848,38.03029444608522],[-91.653930664061,38.00865683368494],[-91.64843749999851,38.00432854459864],[-91.5935058593735,37.93070854451552],[-91.577026367186,37.88303274722063],[-91.577026367186,37.79192956603227],[-91.631958007811,37.73982010276601],[-91.70886230468598,37.73547599031287],[-91.763793945311,37.76587942393493],[-91.85168457031098,37.85701474874939],[-91.88464355468598,37.9956711998967],[-91.89013671874848,38.03029444608522]]],"spatialReference":{"wkid":4326}},"symbol":{"color":[0,0,0,64],"outline":{"color":[0,0,0,255],"width":1,"type":"esriSLS","style":"esriSLSSolid"},"type":"esriSFS","style":"esriSFSSolid"}}

Code to add Shape to Map:

    function createFromJSON(JSONText){
      console.log("In Create Function");
      dojo.disconnect(handle);

      var jsontext = JSON.parse(JSONText);
      var polygon = new esri.geometry.Polygon(jsontext);
      console.log("Here is the polygon object:");
      console.log(polygon);
      console.log("Now drawing polygon");
       map.graphics.add(new Graphic(polygon, new SimpleFillSymbol()));
      console.log("Polygon should be there");
    }

enter image description here

like image 402
JBizz Avatar asked Mar 27 '26 11:03

JBizz


1 Answers

The JSON string shown in the image is for Graphic object and not a geometry. As you can see it contains geometry & symbol, If you pass it to Graphic it will work.

map.graphics.add(new Graphic(jsontext));

Or if you just want the polygon then your code should be something like this.

var polygon = new esri.geometry.Polygon(jsontext.geometry);

Also, dont combine legacy and AMD style together.

like image 54
T Kambi Avatar answered Mar 29 '26 01:03

T Kambi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!