Skip to content

Commit

Permalink
support v6 api in MapboxGeocoder class
Browse files Browse the repository at this point in the history
pre-validate reverse coordinates to avoid v6 4xx response

fix limit=1 on reverse geocodes when single type set

enable multiple reverse results when no types or limit specified

fix promise resolution

revert package-lock file

fix potential problem with address strings for v5 and v6
  • Loading branch information
VladislavMedved committed May 10, 2023
1 parent 056c09c commit 9199750
Show file tree
Hide file tree
Showing 7 changed files with 254 additions and 46 deletions.
4 changes: 3 additions & 1 deletion debug/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,9 @@ var geocoder = new MapboxGeocoder({
.then(response => response.json())
}
},
mapboxgl: mapboxgl
mapboxgl: mapboxgl,
reverseGeocode: true,
version: 'v6',
});

map.addControl(geocoder)
Expand Down
67 changes: 65 additions & 2 deletions debug/mock-api.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,66 @@
[
{"id":"place.7673410831246050","type":"Feature","place_type":["place"],"relevance":1,"properties":{"wikidata":"Q61"},"text_en-US":"Washington","language_en-US":"en","place_name_en-US":"Washington, District of Columbia, United States of America","text":"Washington","language":"en","place_name":"SERVER: Washington, District of Columbia, United States of America","matching_place_name":"Washington, DC, United States of America","bbox":[-77.1197609567342,38.79155738,-76.909391,38.99555093],"center":[-77.0366,38.895],"geometry":{"type":"Point","coordinates":[-77.0366,38.895]},"context":[{"id":"region.14064402149979320","short_code":"US-DC","wikidata":"Q3551781","text_en-US":"District of Columbia","language_en-US":"en","text":"District of Columbia","language":"en"},{"id":"country.19678805456372290","wikidata":"Q30","short_code":"us","text_en-US":"United States of America","language_en-US":"en","text":"United States of America","language":"en"}]}
]
{
"type": "Feature",
"id": "address.7840146147075390",
"geometry": {
"type": "Point",
"coordinates": [22.476772, -33.991656]
},
"properties": {
"mapbox_id": "address.7840146147075390",
"feature_type": "address",
"name": "12 Main Street",
"coordinates": {
"longitude": 22.476772,
"latitude": -33.991656,
"accuracy": "proximate"
},
"place_formatted": "George, Western Cape 6529, South Africa",
"match_code": {
"address_number": "matched",
"street": "unmatched",
"postcode": "unmatched",
"place": "unmatched",
"region": "unmatched",
"locality": "not_applicable",
"country": "inferred",
"confidence": "low"
},
"context": {
"address": {
"id": "address.7840146147075390",
"street": "Main Street",
"address_number": "12",
"name": "12 Main Street"
},
"neighborhood": {
"id": "neighborhood.1846526",
"name": "Ballotsview"
},
"postcode": {
"id": "postcode.24039166",
"name": "6529"
},
"place": {
"id": "place.24643838",
"name": "George",
"wikidata_id": "Q370456"
},
"region": {
"id": "region.9470",
"name": "Western Cape",
"wikidata_id": "Q127167",
"region_code": "WC",
"region_code_full": "ZA-WC"
},
"country": {
"id": "country.8958",
"name": "South Africa",
"wikidata_id": "Q258",
"country_code": "ZA",
"country_code_alpha_3": "ZAF"
}
}
}
}
]
3 changes: 2 additions & 1 deletion lib/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,8 @@ MapboxEventManager.prototype = {
routing: geocoder.options.routing,
worldview: geocoder.options.worldview,
mapZoom: zoom,
keyboardLocale: this.locale
keyboardLocale: this.locale,
apiVersion: geocoder.options.version
}

// get the text in the search bar
Expand Down
Loading

0 comments on commit 9199750

Please sign in to comment.