esri 将图形从 json 添加到 graphicslayer 时出现错误

esri add graphic from json to graphicslayer is giving error

您好,我正在尝试将图形添加到 graphicslayer。问题来了。

我从 sketchviewmodel 创建函数得到 json 结果,它是图形的。

我将其存储到新的 json 对象中。 然后我尝试手动将此图形添加到 graphicslayer 中。但它给出了错误。

这里是 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
}

此代码出错

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

有什么建议吗?谢谢。

假设您正在使用 GraphictoJSON 方法生成 json 对象(在您的示例中为 data)。那么从 json 对象创建 Graphic 的正确方法是使用“反向”方法 fromJSON。这样的东西应该可以工作,

const [Graphic] = await loadModules(["esri/Graphic"]);
// here use fromJSON method to create the graphic
let g =  Graphic.fromJSON(data); // data which is json i gave.

ArcGIS API - Graphic fromJSON