Skip to content

Commit 9e7a72e

Browse files
committed
Handle proximity for event logging; fix geolocate button
1 parent b701c46 commit 9e7a72e

File tree

3 files changed

+19
-5
lines changed

3 files changed

+19
-5
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
- Enables use of the value `'ip'` for `proximity` to bias around a user's location [#453](https://github.com/mapbox/mapbox-gl-geocoder/pull/453)
1111
- Adds `setAccessToken` method to update the accessToken after the Geocoder has been initialized [#449](https://github.com/mapbox/mapbox-gl-geocoder/pull/449)
12-
- Added geolocate functionality [#444](https://github.com/mapbox/mapbox-gl-geocoder/pull/444)
12+
- Added geolocate functionality to find user's location via the Browser API [#444](https://github.com/mapbox/mapbox-gl-geocoder/pull/444)
1313
- Upgraded system font stack to include Apple fonts. This is used for text if Open Sans is not available [#438](https://github.com/mapbox/mapbox-gl-geocoder/pull/438)
1414
- Adds `flipCoordinates` boolean option to support `lon,lat` coordinate order for reverse geocodes [#435](https://github.com/mapbox/mapbox-gl-geocoder/pull/435)
1515

lib/events.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,9 +149,17 @@ MapboxEventManager.prototype = {
149149
* @returns {Object} an event payload
150150
*/
151151
getEventPayload: function (event, geocoder) {
152+
// Handle proximity, whether null, lat/lng coordinate object, or 'ip'
152153
var proximity;
153-
if (!geocoder.options.proximity) proximity = null;
154-
else proximity = [geocoder.options.proximity.longitude, geocoder.options.proximity.latitude];
154+
if (!geocoder.options.proximity) {
155+
proximity = null;
156+
} else if (typeof geocoder.options.proximity === 'object') {
157+
proximity = [geocoder.options.proximity.longitude, geocoder.options.proximity.latitude];
158+
} else if (geocoder.options.proximity === 'ip') {
159+
proximity = [999,999]; // Alias for 'ip' in event logs
160+
} else {
161+
proximity = geocoder.options.proximity;
162+
}
155163

156164
var zoom = (geocoder._map) ? geocoder._map.getZoom() : undefined;
157165
var payload = {

lib/index.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -262,9 +262,15 @@ MapboxGeocoder.prototype = {
262262
el.appendChild(actions);
263263

264264
if (this.options.enableGeolocation && this.geolocation.isSupport()) {
265-
this._geolocateEl = this.createIcon('geolocate', '<path d="M12.999 3.677L2.042 8.269c-.962.403-.747 1.823.29 1.912l5.032.431.431 5.033c.089 1.037 1.509 1.252 1.912.29l4.592-10.957c.345-.822-.477-1.644-1.299-1.299z" fill="#4264fb"/>');
266-
actions.appendChild(this._geolocateEl);
265+
this._geolocateEl = document.createElement('button');
266+
this._geolocateEl.setAttribute('aria-label', 'Geolocate');
267267
this._geolocateEl.addEventListener('click', this._geolocateUser);
268+
this._geolocateEl.className = 'mapboxgl-ctrl-geocoder--button';
269+
270+
var geolocateIcon = this.createIcon('geolocate', '<path d="M12.999 3.677L2.042 8.269c-.962.403-.747 1.823.29 1.912l5.032.431.431 5.033c.089 1.037 1.509 1.252 1.912.29l4.592-10.957c.345-.822-.477-1.644-1.299-1.299z" fill="#4264fb"/>');
271+
this._geolocateEl.appendChild(geolocateIcon);
272+
273+
actions.appendChild(this._geolocateEl);
268274
this._showGeolocateButton();
269275
}
270276

0 commit comments

Comments
 (0)