Charmatzis / react-leaflet-google

GoogleMaps layer as React component for Leaflet | This repo is obsolete. Plz, use https://github.com/TA-Geoforce/react-leaflet-google
https://github.com/TA-Geoforce/react-leaflet-google
MIT License
29 stars 60 forks source link

TypeError: Cannot read property 'setCenter' of undefined #34

Open robotgo opened 5 years ago

robotgo commented 5 years ago

Hi,

i have a blinking problem on test server using this.map.fitBounds(boundCoords) in componentDidUpdate:

TypeError: Cannot read property 'setCenter' of undefined
    at n._handleZoomAnim (react-leaflet-google.js:1635)
    at n.fire (leaflet-src.js:593)
    at n._moveEnd (leaflet-src.js:4193)
    at n._resetView (leaflet-src.js:4137)
    at n.setView (leaflet-src.js:3191)
    at n.fitBounds (leaflet-src.js:3280)
    at t.value (Map.js:211)

And in the source code file dist/react-leaflet-google.js I see that there isn't check on undefined value of this._mutant in _handleZoomAnim like in other methods:

_handleZoomAnim: function _handleZoomAnim() {
        var center = this._map.getCenter();
        var _center = new google.maps.LatLng(center.lat, center.lng);
        this._mutant.setCenter(_center);
        this._mutant.setZoom(Math.round(this._map.getZoom()));
      },

In _resize method:

_resize: function _resize() {
        var size = this._map.getSize();
        if (this._mutantContainer.style.width === size.x && this._mutantContainer.style.height === size.y) return;
        this.setElementSize(this._mutantContainer, size);
        *if (!this._mutant) return;*
        google.maps.event.trigger(this._mutant, "resize");
      },

Should it be?