Skip to content

Adding a map resize event #1564

@turban

Description

@turban

Hi,

I often miss a "resize" event on the map container. I know I can create this by listening to window resize and then check if the size of the container div has changed, but it would be better to have this in the Leaflet core. It's especially useful when showing a Leaflet map in a responsive layout with custom layer controls etc.

To get this event with the current Leaflet core, I'm extending the _onResize method of L.Map:

_onResize: function () {
    var oldSize = this.getSize(),
        newSize = new L.Point(this._container.clientWidth, this._container.clientHeight);

    if (!newSize.equals(oldSize)) {
        this.fire('resize', newSize);
        L.Map.prototype._onResize.call(this)
    }
}

Bjorn

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions