mapbox / mapbox/mapbox-gl-geocoder
Change countries option after init
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 388
- Forks
- 181
- PR merge metrics
- No merged PRs in 30d
Description
I'm using the MapboxGeocoder with the `countries` option set to a default country, but I would like to update this option if they change the country they are wanting to search in.
Current code:
```javascript
// Add the control to the map.
const geocoder = new MapboxGeocoder({
accessToken: mapboxgl.accessToken,
mapboxgl: mapboxgl,
marker: false,
countries: 'nz'
});
```
I'm using the [chosen plugin from harvest](https://harvesthq.github.io/chosen/), so I have the `on change` function working, I need to know if it's possible to change the `countries` option when they change the country so that results searched for will only return for the current country they have selected
```javascript
// Country selection changed
$('#country_id').on('change', function(evt, params) {
// Check it's not empty
if (params) {
// code to go in here to change 'countries' option
}
});
```
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at the MapboxGeocoder initialization and the `countries` option, then trace how the chosen change handler should interact with the geocoder instance. Confirm whether the documented API supports changing countries after initialization; done means searches are restricted to the selected country, with the empty-selection case handled.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- frontend
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100