React-map-gl: fitBounds not a prop of MapGL

Created on 11 Jan 2020  路  5Comments  路  Source: visgl/react-map-gl

In the documentation is says you can set the bounds of your map by using the fitBounds prop.

There is no prop on the MapGL. fitBounds does nothing.

There is also no bounds prop

How can I set the bounds of the map?

Below is the interface of the Mapbox to show there is no fitBounds.

export interface MapboxProps extends Partial<ViewState> {
    container?: object;
    gl?: object;
    mapboxApiAccessToken?: string;
    attributionControl?: boolean;
    preserveDrawingBuffer?: boolean;
    reuseMaps?: boolean;
    transformRequest?: (url?: string, resourceType?: string) => MapRequest;
    mapOptions?: object;
    mapStyle?: string | object;
    visible?: boolean;
    onLoad?: (event: MapLoadEvent) => void;
    onError?: (e: MapError) => void;
    reuseMap?: boolean;
    width: number | string;
    height: number | string;
    viewState?: ViewState;
}

Most helpful comment

If someone finds this useful, here鈥檚 a complete example of using fitBounds in ReactMapGL to center points on map:
https://gist.github.com/tomsoderlund/a2040d659aafe4064e4060f561aca6d1

All 5 comments

Hi @Pessimistress , I see you've pointed @mnoster to a static-map for bounds, but is there anyway to set bound on an interactive-map temporarily, (say for example, on the creation of a marker or a LineString), and then allow control again? Not sure if I should open another thread. Thank you!

If someone finds this useful, here鈥檚 a complete example of using fitBounds in ReactMapGL to center points on map:
https://gist.github.com/tomsoderlund/a2040d659aafe4064e4060f561aca6d1

Was this page helpful?
0 / 5 - 0 ratings

Related issues

joseomar10 picture joseomar10  路  5Comments

tomrussell picture tomrussell  路  5Comments

bogdancaspar picture bogdancaspar  路  3Comments

AriLFrankel picture AriLFrankel  路  3Comments

miccferr picture miccferr  路  4Comments