从地图外部使用 React Leaflet Draw

Use React Leaflet Draw from outside of the map

我想自定义最初显示在地图上的绘图图标。

如何从地图外部调用每个动作?

我设法使用 redux 调用缩放控件并更改缩放状态。 是否有使用 redux 状态和打开或关闭绘图操作的有效选项。

这是编辑控件的当前实现

<Map
                 style={this.leafletMapService.getMapStyle()}
                 selectArea={true}
                 onAreaSelected={(event) => this.handleAreaSelection(event)}
                 boxZoom={false}
                 ref={map => {this.map = map}}
                 center={this.props.center}
                 zoom={this.props.zoom}
                 minZoom={this.props.minZoom}
                 maxZoom={this.props.maxZoom}
                 attributionControl={false}
                 doubleClickZoom={false}
                 zoomControl={false}
                 editable={true}
                 onZoomEnd={this.handleZoomEnd}
                 bounceAtZoomLimits={false}
                 crs={this.leafletMapService.getNonGeographicMapCRS()}
                 dragging={!!this.props.selectedSection}
                 scrollWheelZoom={false}>
                <FeatureGroup>
                    <EditControl position={'topright'}
                                 onCreated={(event) => this.onCreatedHandler(event)}
                                 onEdited={(event) => this.onEditedHandler(event)}
                                 onDeleted={(event) => this.onDeletedHandler(event)}
                    />
                    {this.props.children}
                </FeatureGroup>
            </Map>

如果你不能这个,你必须看看这个问题https://github.com/alex3165/react-leaflet-draw/issues/1

  _onDraw = () => {
        // this code is enable drawing polygon.
        this.drawControl._toolbars.draw._modes.polygon.handler.enable();
   }

   _onMounted = (drawControl) => {
        this.drawControl = drawControl;
    }
      <FeatureGroup >
         <EditControl
            onMounted={this._onMounted}
    ........ > .....</EditControl>