Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hide position indicator on layer 'mouseout' #53

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/L.Control.Elevation.js
Original file line number Diff line number Diff line change
Expand Up @@ -669,6 +669,7 @@ L.Control.Elevation = L.Control.extend({
}
if (layer) {
layer.on("mousemove", this._handleLayerMouseOver.bind(this));
layer.on("mouseout", this._hidePositionMarker.bind(this));
Copy link

@fbonzon fbonzon May 7, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a problem if the elevation profile is removed from the Leaflet map. The layer would still have listeners pointing to an elevation profile that no longer exists. I think we should take care of removing listeners too.

Try this. Here, change lines 670-673 to:

        if (layer) {
            this._layer = layer;
            layer.on("mousemove", this._handleLayerMouseOver, this).
            on("mouseout", this._hidePositionMarker, this);
        }

And add in onRemove at top of file:

        if (this._layer) {
            this._layer.off("mousemove", this._handleLayerMouseOver, this).
            off("mouseout", this._hidePositionMarker, this);
        }

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point. I guess in theory addData could be called multiple times, so we would need to keep a list of layers. clear should probably also remove listeners.

I won't update this right now, maybe later. Feel free to share an alternative PR and I'll close mine.

}
},

Expand Down