smeijer / leaflet-geosearch

A geocoding/address-lookup library supporting various api providers.
https://smeijer.github.io/leaflet-geosearch/
MIT License
1.05k stars 273 forks source link

Error: Bounds are not valid #253

Open i62lotor opened 3 years ago

i62lotor commented 3 years ago

Hi! I am trying to integrate leaflet-geosearch, but the same error is always repeated when I select an item from the result list

Uncaught (in promise) Error: Bounds are not valid.
...
    at n.showResult

My code is very basic, same as the documentation example:

import { SearchControl, OpenStreetMapProvider } from 'leaflet-geosearch';
const searchControl = new SearchControl({
  provider: new OpenStreetMapProvider(),
});
map.addControl(searchControl);

The OSM response is ok, but the error persist on showResult (no center map)

The map initilialization is:

const map = L.map('mapid').setView([0, 0], 5);

  var osmLayer = L.tileLayer('https://a.tile.openstreetmap.org/{z}/{x}/{y}.png',{
    attribution: '&copy; <a href="https://osm.org/copyright">OpenStreetMap</a> contributors'
   });
  osmLayer.addTo(map);

Could anyone help me, please?

Thanks.

smeijer commented 3 years ago

Hi :wave:

Which version of the lib do you use?

i62lotor commented 3 years ago

Hi, smeijer I have configured this dependency "leaflet-geosearch": "^3.1.0"

i62lotor commented 3 years ago

Hi, again some more information. if the map is created in the same file, as in this example it works fine

const mapElement = document.createElement("div");
  mapElement.setAttribute("id", "mapid");
  mapElement.className = "map";
  document.body.appendChild(mapElement);

  const map = L.map('mapid').setView([0, 0], 5);

  var osmLayer = L.tileLayer('https://a.tile.openstreetmap.org/{z}/{x}/{y}.png',{
    attribution: '&copy; <a href="https://osm.org/copyright">OpenStreetMap</a> contributors'
   });
  osmLayer.addTo(map);

const searchControl = new geoSearchControl({
  provider: new OpenStreetMapProvider(),
});
map.addControl(searchControl);

However if I create the map in another class, and pass it as an argument to initialize the geoSearchControl, the error occurs. Example:

export const initialize = (context) => {
     const searchControl = new geoSearchControl({
        provider: new OpenStreetMapProvider(),
     });
     context.map.addControl(searchControl);
}
lelumees commented 2 years ago

+1

euZebe commented 1 year ago

+1 This occurs with OpenStreetMapProvider, but not GeoApiFR for instance. And when retainZoomLevel is set to false, the error doesn't happen. (but This is not a satisfying solution).

mbajur commented 1 week ago

For me, setting retainZoomLevel to true fixes the issue but also - not a satisfying solution.