React-Leaflet-Draw:在保存时访问多边形的坐标数组

React-Leaflet-Draw: accessing a polygon's array of coordinates on save

我有一个组件可以在地图上放置一个可编辑的多边形。当用户点击 "save" 按钮时,我想访问多边形的新顶点数组,以便保存它们。我该怎么做?

我的组件:

<FeatureGroup>
    <EditControl
        position="topright"
        onEdited={e => console.log(e)}
        edit={{ remove: false }}
        draw={{
                marker: false,
                circle: false,
                rectangle: false,
                polygon: false,
                polyline: false
             }}
        />
        <Polygon positions={polygonCoords} />;
</FeatureGroup>

我得到的几篇参考文献:

https://github.com/alex3165/react-leaflet-draw

https://leaflet.github.io/Leaflet.draw/docs/leaflet-draw-latest.html#l-draw-event-draw:editstop

我知道我必须实现某种处理 onEdited 挂钩和由此生成的事件的函数,但是有人知道我如何从这个事件中获取新的顶点数组吗?

对于遇到此问题的其他人,这里有一个 ES6 的有效解决方案:

        <FeatureGroup>
            <EditControl
                position="topright"

                //this is the necessary function. It goes through each layer
                //and runs my save function on the layer, converted to GeoJSON 
                //which is an organic function of leaflet layers.

                onEdited={e => {
                    e.layers.eachLayer(a => {
                        this.props.updatePlot({
                            id: id,
                            feature: a.toGeoJSON()
                        });
                    });
                }}
                edit={{ remove: false }}
                draw={{
                    marker: false,
                    circle: false,
                    rectangle: false,
                    polygon: false,
                    polyline: false
                }}
            />
            <Polygon positions={[positions(this.props)]} />;
        </FeatureGroup>
    );