react-leaflet icon indicating copy to clipboard operation
react-leaflet copied to clipboard

After updating from 2.6.1 to 2.6.3 I got "TypeError: Cannot read property 'addLayer' of undefined" error

Open Kbdq opened this issue 6 years ago • 4 comments

All components (leaflet, react, etc) are latest.

Call stack displays:

  1. setState([my variables for map content like markers, etc.])

  2. [internal react calls]

  3. Fall in MapLayer.js:40 at line this.layerContainer.addLayer(this.leafletElement);

When I downgrade back to to 2.6.1, everything works fine.

Don't know what else I can add to description. Project is huge enought and I cannot extract minimal code to reproduce.

Kbdq avatar Mar 16 '20 12:03 Kbdq

Please provide a simple example to reproduce the issue, this is not enough information to investigate.

PaulLeCam avatar Mar 16 '20 17:03 PaulLeCam

I think I narrowed down the problem. Look like changes between 2.6.1 and 2.6.3 are incompatible with react-leaflet-google-v2 module (https://github.com/TA-Geoforce/react-leaflet-google-v2) used to display Google maps.

The following works in both 2.6.1 and 2.6.3:

           <Map
               center={[this.state.lat, this.state.lng]}
                 zoom={this.state.zoom}
           >
                <TileLayer
                    attribution='&copy; <a href="http://osm.org/copyright">OpenStreetMap</a> contributors'
                    url='http://{s}.tile.osm.org/{z}/{x}/{y}.png'
                />
           </Map>

The following works in 2.6.1, but doesn't work in 2.6.3:

            <Map
                 center={[this.state.lat, this.state.lng]}
                 zoom={this.state.zoom}
            >
                <GoogleLayer maptype="ROADMAP" googlekey="<key>"/>
            </Map>

I don't know is it a problem with react-leaflet or react-leaflet-google-v2, but I hope you might know it better.

I would very happy if you could make a fix to support react-leaflet-google-v2 like in 2.6.1.

Kbdq avatar Mar 16 '20 21:03 Kbdq

Thanks for the details. It seems to be an issue with react-leaflet-google-v2 then, that should be raised in their repository rather than here.

Please feel free to reopen the issue if you can reproduce it with only the components provided by react-leaflet.

PaulLeCam avatar Mar 17 '20 09:03 PaulLeCam

I am seeing the same issue on 2.6.3, except I am using only react-leaflet to create a customComponent. It appears that the LayersControl.Overlay is not receiving the inherited props from LayersControl-

    <LayersControl.Overlay checked={showOnLoad} name={layerName}>
      <FeatureGroup ref={groupRef}>
         ...implementation...
      </FeatureGroup>
    </LayersControl.Overlay>
  );

which yields this -

missing_controlled_layer_props

You can see on line 16182 that addLayer is undefined on the object returned from ControlledLayer. Somehow the inherited class is not being applied?

I don't have easy access to data, which makes this webpack debugging a bit dicey. If you have ideas of why this might be happening, would be happy to investigate further.

nrakochy avatar Apr 08 '20 21:04 nrakochy