visgl/react-map-gl

[Feat] Optional width and height parameters in Map viewState

StanislavMyakishev opened this issue · 1 comments

Target Use Case

Map's view state is exposed as a prop for external source to control. But now the viewState is not described in the docs.
If the use case does not require the map to be resized once it's mounted, it is makes it harder to manipulate the view state as we are obliged to provide the container size dimensions as width and height are mandatory.

Proposal

It would be great to have a way to control the map's view state without the need to provide the container size dimensions.
Mention of the viewState prop in the API reference would also be nice.

_updateSize would probably would look somewhat like

_updateSize(nextProps: MapboxProps<StyleT>): boolean {
  const { viewState } = nextProps;
  if (viewState) {
    const map = this._map;
    const isWidthUpdated = 'width' in viewState && viewState.width !== map.transform.width;
    const isHeightUpdated = 'height' in viewState && viewState.height !== map.transform.height;
    if (isWidthUpdated || isHeightUpdated) {
      map.resize();
      return true;
    }
  }
  return false;
}

viewState is not documented because you are not supposed to use it. What is your use case that cannot be achieved otherwise?