React-map-gl: GeolocateControl zooming too much after clicking on locate me

Created on 14 Sep 2019  路  5Comments  路  Source: visgl/react-map-gl

Hi ,
Awesome package 馃憤

I ran exmaple for geolocatecontrol , it worked fine but when I used geolocatecontrol with my project it is causing problem.

Current status
When I click on locate me , It moves map to my location and zooms too much that I can't see anything. Then I have to click zoomout button 17 times to get a proper view.

Expected
Should work same as shown in exmaple

code

    <ReactMapGL
        {...this.state.viewport}
        width="100vw"
        height="100vh"
        mapStyle="mapbox://styles/mapbox/dark-v9"
        onViewportChange={this._onViewportChange}
        mapboxApiAccessToken={TOKEN}
    >
        {this.state.data.map(this._renderCityMarker)}

        {this._renderPopup()}

        <GeolocateControl
          style={geolocateStyle}
          positionOptions={{enableHighAccuracy: true}}
          fitBoundsOptions ={{maxZoom: 4}}
          trackUserLocation={true}
        />
        <div  style={fullscreenControlStyle}>
           <FullscreenControl />
        </div>
        <div  style={navStyle}>
           <NavigationControl />
        </div>

    </ReactMapGL>

I tried to fix this by using fitBoundOptions but nothing changed.

Thanks,

Most helpful comment

@cngeru found it...

<GeolocateControl
          onViewportChange={this._onViewportChange}
          style={geolocateStyle}
          positionOptions={{ enableHighAccuracy: true }}
          trackUserLocation={true}
        />

Set zoom level after map moves as you want

_onViewportChange = (viewport) => {
   viewport.zoom=3 //Whatever zoom level you want
    this.setState({ viewport })
  }

All 5 comments

any solution to this

@cngeru Not yet.... :(

@cngeru found it...

<GeolocateControl
          onViewportChange={this._onViewportChange}
          style={geolocateStyle}
          positionOptions={{ enableHighAccuracy: true }}
          trackUserLocation={true}
        />

Set zoom level after map moves as you want

_onViewportChange = (viewport) => {
   viewport.zoom=3 //Whatever zoom level you want
    this.setState({ viewport })
  }

closing it

Can you auto geolocate user on component mounting ?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

tomrussell picture tomrussell  路  5Comments

sicksid picture sicksid  路  3Comments

iamvdo picture iamvdo  路  5Comments

tbergman picture tbergman  路  3Comments

xoddong picture xoddong  路  4Comments