i cant add graphic from json

10-15-2020 04:08 PM
New Contributor

hi i am trying to add graphic to graphicslayer. here is the problem.

i get json result from sketchviewmodel create function which is graphic.

i store this in to new jsonobject. then i try to add this graphic into graphicslayer manually. but its giving error.

here is the json

{ "geometry":{     "spatialReference":{      "latestWkid":3857,      "wkid":102100   },   "x":243208.09643883476,   "y":2940285.766420703,   "z":351.9580905416081 }, "symbol":{   "type":"point-3d",   "symbolLayers":[      {         "type":"Icon",         "material":{                     },         "resource":{            "primitive":"kite"         },         "size":15,         "outline":{            "color":[               0,               0,               0            ],            "size":2.25         }      }   ] },   "attributes":{      },    "popupTemplate":null }

this code gives error

const [Graphic] = await loadModules(["esri/Graphic"]); let g =  new Graphic(data); // data which is json i gave.

any adivce ? Thank you.

Tags (1)
0 Kudos
1 Reply
Esri Regular Contributor

You have couple of issues in your json object. Please see the code below with comments.

 var graphic = {
    "type": "point",       // You must set your geometry type. 
       "type":"icon",   // Types are case sensitvie. This should be lower case icon
       "material":{ },