question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Error: Bounds are not valid (React-Leaflet)

See original GitHub issue

I’m trying to integrate this library with React-Leaflet in the following way.

var provider = new EsriProvider();
class Search extends MapControl {

  createLeafletElement() {
      
    return GeoSearchControl({
      provider:  provider,
      style: 'bar',
      showMarker: true,
      showPopup: false,
      autoClose: true,
      retainZoomLevel: false,
      animateZoom: true,
      keepResult: false,
      searchLabel: 'search'
    });
  }
}
 return (
            <Map
                className="map-surface"
                center={[39, -104]}
                zoom={5}
                minZoom={2}
                ref="map"
                worldCopyJump={true}
                zoomControl={false}
            >
                { this.props.children }

                <ZoomControl
                    position="topright"
                    zoomInTitle="Zoom in"
                    zoomOutTitle="Zoom out"
                />

                <ScaleControl
                    className="scale"
                />

                <Search />

                <TileLayer
            attribution="&amp;copy <a href=&quot;http://osm.org/copyright&quot;>OpenStreetMap</a> contributors"
            url="https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png"
          />
            </Map>
        );

And I’m getting the next error:

leaflet-src.js:2548 Uncaught (in promise) Error: Bounds are not valid.
    at NewClass.fitBounds (leaflet-src.js:2548)
    at NewClass.centerMap (leafletControl.js:406)
    at NewClass.showResult (leafletControl.js:340)
    at NewClass.<anonymous> (leafletControl.js:323)
    at eval (eval at processIncludes (runtime.js:36), <anonymous>:3:4725)

I’m doing something wrong or is a bug in the library?

Thanks!

Issue Analytics

  • State:open
  • Created 5 years ago
  • Comments:7 (1 by maintainers)

github_iconTop GitHub Comments

4reactions
hancocbcommented, Jul 6, 2018

I did not get the exact same error as you, but I was able to get the plugin working with leaflet-react v2 by wrapping my custom component with the withLeaflet() component (see Creating custom components).

import { Map, TileLayer, Marker, MapControl, Popup, withLeaflet } from "react-leaflet";
import { GeoSearchControl, OpenStreetMapProvider } from "leaflet-geosearch";

class AddressControl extends MapControl {
  createLeafletElement() {
    const provider = new OpenStreetMapProvider();
    return GeoSearchControl({ provider: provider });
  }
}
class MyMap extends React.Component {
  ...
  render() {
    const AddressSearch = withLeaflet(AddressControl);
    return (
      <Map ...>
        <AddressSearch />
    ...
    ...

Don’t forget to add the leaflet-geosearch CSS too.

2reactions
Felipedelima123commented, Oct 16, 2020

I was having this same problem, also with react leaflet. I used as @hancocb mentioned, but still not working. I figured out, that if I change the property: retainZoomLevel to true it works. For those who still getting this problem, change to somenthing like:

createLeafletElement() {
    const provider = new OpenStreetMapProvider();
    return GeoSearchControl({
      provider,
      showMarker: false,
      showPopup: false,
      retainZoomLevel: true, 
      animateZoom: false,
      autoClose: false,
      searchLabel: 'Digite sua busca aqui',
      keepResult: false,
    });
  }

Maybe we are going to receive a fix for this?

Read more comments on GitHub >

github_iconTop Results From Across the Web

React Leaflet Bound not working as expected - Stack Overflow
The error Cannot read properties of undefined (reading 'lat') is because you are passing an empty array of markers to <Rectangle> .
Read more >
L.geoJson() - Error: Bounds are not valid - GIS Stack Exchange
I am iterating through an array of zipcodes and passing each to Mapbox Geocoding API. With every iteration, on success, I pass to...
Read more >
View bounds - React Leaflet
Click a rectangle to fit the map to its bounds. ... const [bounds, setBounds] = useState(outerBounds). const map = useMap(). const innerHandlers =...
Read more >
Fit a map's bounds to contents of a FeatureGroup in React ...
... Fit a map's bounds to contents of a FeatureGroup in React-Leaflet-Reactjs. ... in react native · Marker click event on react native...
Read more >
leaflet-geosearch - npm
With retainZoomLevel on true , the map is only panned. animateZoom controls whether or not the pan/zoom moment is being animated. autoClose ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found