Mapbox Direction GL - show/hide 行车说明

Mapbox Direction GL - show/hide driving instructions

我默认隐藏驾驶说明:

 var directions = new MapboxDirections({
            accessToken: mapboxgl.accessToken,
            controls: { instructions: false }
        });

我希望能够在单击按钮时 display/hide 它,但不确定需要如何完成。

mapbox-gl-directions plugin does not provide a setter method for the options.controls.instructions parameter. In other words, the boolean value specified at creation of the MapboxDirections instance cannot be toggled using a button. All instance members for MapboxDirections are documented in API.md.

您可以通过分叉插件或打开拉取请求来尝试自己实现此自定义功能,以将 MapboxDirections#setControlsInstructions 方法或类似的方法添加到 src/directions.js. This method could then be used with the button's click listener. This would require some careful state object management to ensure all visual interface elements are properly updated when the button is toggled (see src/reducers/index.js and src/controls/instructions.js)。