maplibre-gl-geocoder
maplibre-gl-geocoder copied to clipboard
Map shouldn't go to maximum zoom when selecting a single-item point results
As mentioned in https://github.com/maplibre/maplibre-gl-geocoder/issues/181#issuecomment-2739579269, it seems that maplibre-gl-geocoder always zooms in to the maximum level (which is very un-useful) when selecting a set of results (results event) that only contains a single result that is a point. This is in contrast to the way more expected behavior when selecting an actual single result (result event), which then applies the desired zoom level.
The public example at https://maplibre.org/maplibre-gl-js/docs/examples/geocoder/ has the same issue (when just hitting Enter on a search like Marubi, Berlin that finds one result, it zooms in super close, but it does go back to a more sensical zoom level after clicking the result in the dropdown):
Ideally I would want to achieve normal zoom on both. I tried setting a hardcoded "Berlin" bounding box of bbox: [52.6755, 13.0884, 52.3383, 13.7611] on the returned API result as an experiment, but it still zoomed in all the way.
For reference, with this bbox hardcoding attempt, here's the object I'm getting for the results event:
{
"type": "FeatureCollection",
"features": [
{
"id": 133198951,
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [
13.409537199999999,
52.5291878
]
},
"place_name": "Marubi, 187, Schönhauser Allee, Prenzlauer Berg, Pankow, Berlin, 10119, Germany",
"properties": {
"place_id": 133198951,
"osm_type": "node",
"osm_id": 1552567668,
"place_rank": 30,
"category": "amenity",
"type": "restaurant",
"importance": 0.00008875486381318407,
"addresstype": "amenity",
"name": "Marubi",
"display_name": "Marubi, 187, Schönhauser Allee, Prenzlauer Berg, Pankow, Berlin, 10119, Germany",
"address": {
"amenity": "Marubi",
"house_number": "187",
"road": "Schönhauser Allee",
"suburb": "Prenzlauer Berg",
"city_district": "Pankow",
"city": "Berlin",
"ISO3166-2-lvl4": "DE-BE",
"postcode": "10119",
"country": "Germany",
"country_code": "de"
}
},
"text": "Marubi, 187, Schönhauser Allee, Prenzlauer Berg, Pankow, Berlin, 10119, Germany",
"place_type": [
"place"
],
"bbox": [ // Hardcoded Berlin bounding box. Adding this or leaving this out doesn't change anything.
52.6755,
13.0884,
52.3383,
13.7611
]
}
],
"config": {
"limit": 5,
"language": [
"en-US"
],
"query": "marubi, berlin"
}
}
I see some other examples online using a much older version of maplibre-gl-geocoder that behave in a more expected way, not even showing intermediate zooming at all while not having selected a final place for example: https://www.maptoolkit.com/doc/geocoding/maplibre-example/
Thanks for taking the time to report this! Feel free to open a PR, the code is fairly straight forward.
I might at some point and often do, but at the moment I'm several layers of yak shaving deep into a side project of a side project and didn't immediately understand all the nuances of the code, so for now I'll leave it at filing the issue :)