Skip to content

Commit

Permalink
Add location properties to mapbox reverse geocode (#286)
Browse files Browse the repository at this point in the history
* add location properties to mapbox reverse geocode
* fix formatting
  • Loading branch information
dfliess committed Nov 22, 2020
1 parent e1efe48 commit 3398c8c
Showing 1 changed file with 21 additions and 17 deletions.
38 changes: 21 additions & 17 deletions src/geocoders/mapbox.ts
Expand Up @@ -21,6 +21,24 @@ export class Mapbox implements GeocoderAPI {
this.options.reverseQueryParams.access_token = accessToken;
}

_getProperties(loc) {
const properties = {
text: loc.text,
address: loc.address
};

for (let j = 0; j < (loc.context || []).length; j++) {
const id = loc.context[j].id.split('.')[0];
properties[id] = loc.context[j].text;

// Get country code when available
if (loc.context[j].short_code) {
properties['countryShortCode'] = loc.context[j].short_code;
}
}
return properties;
}

geocode(query: string, cb: GeocodingCallback, context?: any): void {
const params = this.options.geocodingQueryParams;
if (
Expand All @@ -46,26 +64,11 @@ export class Mapbox implements GeocoderAPI {
bbox = L.latLngBounds(center, center);
}

const properties = {
text: loc.text,
address: loc.address
};

for (let j = 0; j < (loc.context || []).length; j++) {
const id = loc.context[j].id.split('.')[0];
properties[id] = loc.context[j].text;

// Get country code when available
if (loc.context[j].short_code) {
properties['countryShortCode'] = loc.context[j].short_code;
}
}

results[i] = {
name: loc.place_name,
bbox: bbox,
center: center,
properties: properties
properties: this._getProperties(loc)
};
}
}
Expand Down Expand Up @@ -109,7 +112,8 @@ export class Mapbox implements GeocoderAPI {
results[i] = {
name: loc.place_name,
bbox: bbox,
center: center
center: center,
properties: this._getProperties(loc)
};
}
}
Expand Down

0 comments on commit 3398c8c

Please sign in to comment.