Closed wfendler closed 3 years ago
Mapbox have two API endpoints documented at https://docs.mapbox.com/api/search/geocoding/#endpoints the origin was only intended to support Mapbox's endpoints.
localGeocoder
was originally designed so that you could add in some local data into the search results, eg. you have a shopping mall map with internal shop names appearing in the results. This helps people building with Mapbox for specific use cases why might be using Mapbox maps, but not need global search results.
When using localGeocoder
results from both the local source and Mapbox will be returned, localGeocoderOnly
turns of sourcing results from Mapbox, so in the shopping mall example will not return only global data, just your local data.
It wasn't designed to cover use with other geocoding APIs, while you might be able to get it to work that was, it's not the intended use.
I will admit there has been some feature creep, with a lack of clear project direction to consider what GL Geocoder should be.
If origin is used to set the mapbox.places
or mapbox.places-permanent
endpoint then is this just another way to do what options.mode
does?
options.mode
String A string specifying the geocoding endpoint to query. Options aremapbox.places
andmapbox.places-permanent
. Themapbox.places-permanent
mode requires an enterprise license for permanent geocodes. (optional, defaultmapbox.places
)
Ah sorry you're right.
I think origin
is used for Mapbox Atlas the on-premise solution so that you can point it to the locally hosted Mapbox Geocoding API.
Of course you can still point it to any other endpoint so long as the expected response format matches the Mapbox Geocoding API, though this library wasn't designed to support that kind of use case.
Oh that makes sense! I tried entering another API and it appended the paths/query that the Mapbox API expects so I didn't receive locations back (as expected).
I'll probably use localGeocoder
and localGeocoderOnly
for another API. I'll have to debounce requests to the API and reshape the data to match the Carmen GeoJSON format but I'll at least maintain a connection between the results and locations on the Mapbox map which should cut out about half the work of building a new geocoder.
Thanks for the clarification here!
Follow-up after putting a few hours into this: Just in case someone else finds this with the hope of accomplishing the same thing: localGeocoder
expects an array to be returned and afaik fetching data from an external API will always return a Promise. You'll be better off building your own here!
@wanfranck if you're fetching from a remove server then options.externalGeocoder
would be a better fit. localGeocoder
is when you have all the potential search results already downloaded to the client and you're just doing a simple client side search of that list.
@andrewharvey Hah, I completely missed that! I've been using this via react-map-gl-geocoder where it's not currently supported. I'll have to submit a PR to support that. It's exactly what I'm looking for!
@andrewharvey - I added the externalGeocoder
option to react-map-gl-geocoder
and implemented it with my API. It looks like, in order to accomplish this, we're missing an externalGeocoderOnly
option like localGeocoder
has.
The description of externalGeocoder
is:
A function accepting the query string and current features list which performs geocoding to supplement results from the Mapbox Geocoding API.
So, it looks like this is designed to take the results from the Mapbox API and enhance/modify them with some external source. Is this correct? Or do you know of a way to get the equivalent of localGeocoderOnly
and only use results from my externalGeocoder
function?
Edit: I just saw that there is some conversation around this in #393 - I'd be happy to jump over there to discuss this further!
I've tried in the past to help out with maintenance and development of this library, but some of these issues like #393 really need some thought from a top level project scope, so I'm not going to be able to help much further.
Your welcome to contribute to the discussion on #393 on how we could change the API design with though to all the different use cases.
Is origin used to set a different endpoint for other geocoding services or does mapbox have different endpoints that could be used here?
If that is used to set a non-mapbox endpoint is there information available on how the URL is constructed to request data from that endpoint? It looks like it will always use Mapbox's in the request (for example, 'events/v2' is used here) so I'm guessing the origin isn't designed to be used with other APIs.
Could you clarify what origin might be used for and how that might differ from using
localGeocoder
andlocalGeocoderOnly
?