异步/等待承诺在某些功能参数中引发错误

I'm building a map using amcharts 4 library in a Gatsby project. I have a bunch of functions that amcharts documentation sets inside useEffect hook. To achieve this and clean up my code, I've set an async/await-based promise in order to make sure that every function does not trigger without a variable that needs to be set before.

Everything works fine until createPlaneContainer function triggers. It throws the following error:

无法读取未定义的属性“ lineObjects”

这是我的承诺:

  const buildMap = async (mapChart) => {
    createMap(mapChart);
    const polygonSeries = await setPolygonSeries(mapChart);
    const lineSeries = await addLineSeries(mapChart);
    await polygonTemplate(polygonSeries);
    await addDropShadowFilter(lineSeries);
    const shadowLineSeries = await addShadowLineSeries(mapChart);
    const mapCities = await addCities(mapChart);
    await setCity(mapCities);

    //EVERYTHING WORKS FINE UNTIL HERE
    const planeContainer = await createPlaneContainer(lineSeries, mapChart);
    const planeShadowContainer = await createPlaneShadowContainer(shadowLineSeries, mapChart);
    const plane = setPlane(planeContainer);
    const planeShadow = setPlaneShadow(planeShadowContainer);

  };

Here's my createPlaneContainer function:

  const createPlaneContainer = (lineSeries, mapChart) => {
    let planeContainer = lineSeries.mapLines.getIndex(0).lineObjects.create();
    planeContainer.position = 0;
    planeContainer.nonScaling = false;
    planeContainer.adapter.add(`scale`, (scale, target) => .5 * (1 - (Math.abs(.5 - target.position))) / mapChart.zoomLevel);

    return planeContainer;
  };

And here my addLineSeries function:

  const addLineSeries = mapChart => {
    let lineSeries = mapChart.series.push(new am4maps.MapArcSeries());
    lineSeries.mapLines.template.line.strokeWidth = 2;
    lineSeries.mapLines.template.line.stroke = am4core.color(`#d4a259`);
    lineSeries.mapLines.template.line.nonScalingStroke = true;
    lineSeries.mapLines.template.line.strokeDasharray = `.25rem`;
    lineSeries.zIndex = 10;

    return lineSeries;
  };

我做错了什么?

评论