在异步操作后向MapView添加图形

时间:2017-10-09 15:41:43

标签: javascript arcgis esri

我试图利用ESRI的Arcgis Javascript 4.4 API从Geoserver中提取一些json数据。所有组件都会记录到控制台,但view.graphics.add()会抛出此错误:

+

我试图理解为什么我的尝试没有按预期工作,任何帮助都将受到赞赏。代码如下:

Uncaught TypeError: b.spatialReference.equals is not a function
    at e._projectGeometry (MapView.js:505)
    at e.doRender (MapView.js:503)
    at e.b.processRender (MapView.js:293)
    at b.renderChild (MapView.js:500)
    at b.e.renderChildren (MapView.js:290)
    at b.e.doRender (MapView.js:286)
    at b.processRender (MapView.js:293)
    at n.renderChild (MapView.js:427)
    at n.e.renderChildren (MapView.js:290)
    at n.e.doRender (MapView.js:286)

1 个答案:

答案 0 :(得分:0)

当我将此坐标用作路径时,您的代码正常工作。也许您data.features[0].geometry.coordinates的坐标与折线坐标格式不匹配。

view.then(function () {
    var polyline = {
        type: "polyline",
        paths: [
            [-111.30, 52.68],
            [-98, 49.5],
            [-93.94, 29.89]
        ],
        spatialReference: { wkid: 4326 }
    }
    console.log(polyline);
    var polylineSymbol = {
        type: "simple-line",
        color: [226, 119, 40],
        width: 4
    };
    console.log(polylineSymbol);
    var polylineAtt = {
        Name: "ExampleName",
    };
    console.log(polylineAtt)
    var polylineGraphic = new Graphic({
        geometry: polyline,
        symbol: polylineSymbol,
        attributes: polylineAtt
    })
    console.log(polylineGraphic);
    view.graphics.add(polylineGraphic);
});