Skip to content

Commit 4ecc5bf

Browse files
authored
[geolocate] fix auto when location blocked (visgl#1126)
1 parent 1fc8044 commit 4ecc5bf

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

examples/controls/src/app.js

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
11
import * as React from 'react';
22
import {Component} from 'react';
33
import {render} from 'react-dom';
4-
import MapGL, {Popup, NavigationControl, FullscreenControl, ScaleControl} from 'react-map-gl';
4+
import MapGL, {
5+
Popup,
6+
NavigationControl,
7+
FullscreenControl,
8+
ScaleControl,
9+
GeolocateControl
10+
} from 'react-map-gl';
511

612
import ControlPanel from './control-panel';
713
import Pins from './pins';
@@ -11,20 +17,27 @@ import CITIES from '../../.data/cities.json';
1117

1218
const TOKEN = ''; // Set your mapbox token here
1319

14-
const fullscreenControlStyle = {
20+
const geolocateStyle = {
1521
position: 'absolute',
1622
top: 0,
1723
left: 0,
1824
padding: '10px'
1925
};
2026

21-
const navStyle = {
27+
const fullscreenControlStyle = {
2228
position: 'absolute',
2329
top: 36,
2430
left: 0,
2531
padding: '10px'
2632
};
2733

34+
const navStyle = {
35+
position: 'absolute',
36+
top: 72,
37+
left: 0,
38+
padding: '10px'
39+
};
40+
2841
const scaleControlStyle = {
2942
position: 'absolute',
3043
bottom: 36,
@@ -90,6 +103,9 @@ export default class App extends Component {
90103

91104
{this._renderPopup()}
92105

106+
<div style={geolocateStyle}>
107+
<GeolocateControl />
108+
</div>
93109
<div style={fullscreenControlStyle}>
94110
<FullscreenControl />
95111
</div>

src/components/geolocate-control.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ export default class GeolocateControl extends BaseControl<
115115
isGeolocationSupported().then(result => {
116116
this.setState({supportsGeolocation: result});
117117
this._setupMapboxGeolocateControl(result);
118-
if (this.props.auto) {
118+
if (result && this.props.auto) {
119119
this._triggerGeolocate();
120120
}
121121
});

0 commit comments

Comments
 (0)