Esri / esri-leaflet-vector

Display ArcGIS Online vector basemaps w/ Esri Leaflet
51 stars 53 forks source link

Missing _resize function in MaplibreGLLayer.js module #152

Open NatEvatt opened 1 year ago

NatEvatt commented 1 year ago

Describe the bug

I am currently in the process of moving my production app from L.esri.BasemapLayer to your vector tiles plugin and running into an issue. When calling the map.invalidateSize() function, I run into a leaflet-src.js:588 Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'call')

When I jump into dev tools, this fire method within invalidateSize is passing the type resize to fire

return this.fire('resize', {
  oldSize: oldSize,
  newSize: newSize
});

Within the fire method, a listeners object is created, which pulls from _events by type, in this case, resize. Unfortunately, in the case of resize there is no function attached to that listener.

if (this._events) {
    var listeners = this._events[type];

    if (listeners) {
        this._firingCount = (this._firingCount + 1) || 1;
        for (var i = 0, len = listeners.length; i < len; i++) {
            var l = listeners[i];
            l.fn.call(l.ctx || this, event);
        }

        this._firingCount--;
    }
  }

I believe that I was able to trace the issue back to the MaplibreGLLayer.js module where the getEvents function references the "private" function _resize. However, this function does not exist in the MaplibreGLLayer.js.

      return {
        ...
        resize: this._resize
      };
    },

In order to get rid of my error, i have put in a dummy function for _resize and with this, my code works as expected. This function is obviously not doing anything very helpful, but I am looking to you all for what the expected functionality is.

  _resize: function (e) {
    this._resizing = true;
  },

Reproduction

https://codepen.io/natevatt-the-sasster/pen/YzLMJwg

open dev tools. Click button "click me".

Logs

leaflet-src.js:588 Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'call')
    at NewClass.fire (leaflet-src.js:588:1)
    at NewClass.invalidateSize (leaflet-src.js:3575:1)
    at Object.invalidateModalMapSize (modalMap.js:61:1)
    ...

### System Info

```shell
- leaflet: 1.7.1
- maplibre-gl: 2.4.0
- esri-leaflet: 3.0.8
- esri-leaflet-vector: 4.0.0

Additional Information

I am using Gulp to bundle for my production app.

gavinr commented 1 year ago

Thank you for the report!

To add an additiaonl debugging data point: