Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add circle to GeolocateControl showing accuracy of position #9253

Merged
merged 4 commits into from
Feb 6, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/ui/control/geolocate_control.js
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ class GeolocateControl extends Evented {
this._accuracyCircleMarker.setLngLat(center).addTo(this._map);
this._userLocationDotMarker.setLngLat(center).addTo(this._map);
this._accuracy = position.coords.accuracy;
if (this.options.trackUserLocation && this.options.showAccuracyCircle) {
if (this.options.showUserLocation && this.options.showAccuracyCircle) {
Meekohi marked this conversation as resolved.
Show resolved Hide resolved
this._updateCircleRadius();
}
} else {
Expand All @@ -288,7 +288,7 @@ class GeolocateControl extends Evented {
}

_onZoom() {
if (this.options.trackUserLocation && this.options.showAccuracyCircle) {
if (this.options.showUserLocation && this.options.showAccuracyCircle) {
this._updateCircleRadius();
}
}
Expand Down
26 changes: 26 additions & 0 deletions test/unit/ui/control/geolocate.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -479,3 +479,29 @@ test('GeolocateControl accuracy circle radius matches reported accuracy', (t) =>
geolocate._geolocateButton.dispatchEvent(click);
geolocation.send({latitude: 10, longitude: 20, accuracy: 700});
});

test('GeolocateControl shown even if trackUserLocation = false', (t) => {
const map = createMap(t);
const geolocate = new GeolocateControl({
trackUserLocation: false,
showUserLocation: true,
showAccuracyCircle: true,
});
map.addControl(geolocate);

const click = new window.Event('click');

geolocate.once('geolocate', () => {
map.jumpTo({
center: [10, 20]
});
map.once('zoomend', () => {
t.ok(geolocate._circleElement.style.width);
t.end();
});
map.zoomTo(10, {duration: 0});
});

geolocate._geolocateButton.dispatchEvent(click);
geolocation.send({latitude: 10, longitude: 20, accuracy: 700});
});