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

Reuse icon DOM #1726

Merged
merged 4 commits into from Jun 3, 2013
Merged

Reuse icon DOM #1726

merged 4 commits into from Jun 3, 2013

Conversation

robpvn
Copy link
Contributor

@robpvn robpvn commented May 31, 2013

This fixes issue #561 and related issues that occur when using setIcon in an eventhandler like dragstart or mouseover. It includes a new debug/tests file that can be used to verify the results.

The fix works by checking if a marker has a pre-existing DOM img element, and only creating a new element if there is none. Otherwise, it will take the existing element and update its src and style information to take on the appearance of the new icon.

No new automated tests have been added, but all the previous ones still pass.

Robert Nordan added 3 commits May 31, 2013 12:47
The icon should switch from blue to red and back, but does not in IE
because the DOMelement has disappeared, as in issue Leaflet#561. Instead, the
mouseover event is fired on any mouse motion in the marker. In addition,
in FF & Chrome the mouseover and mouseout events are continously fired
on any movement, which gives the correct visual results but causes
a lot of superflous event handling.
If there already exists a DOM object for this marker, reuse it by setting
a new src and style rather than creating a new one.
img = this._createImg(src);
this._setIconStyles(img, name);
} else {
img = this._createImg(src, oldIcon);
Copy link
Member

Choose a reason for hiding this comment

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

This implies that we can only change to a different icon with the same size/anchor/etc., but this is often not the case. So perhaps styles should be updates when reusing the icon too?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, crap! I did actually have that after the if and changed it to check something, then must have forgotten to change back. I'm 99% sure all we have to do is move this._setIconStyles(img, name); after the else clause and it'll work. I can fix it on Monday.

@mourner
Copy link
Member

mourner commented Jun 1, 2013

Thanks :) I think it looks quite good! I'll test it a bit after your update and merge if there are no visible regressions.

This fixes the error found in review.
@robpvn
Copy link
Contributor Author

robpvn commented Jun 3, 2013

OK, now things should be working as expected!

mourner added a commit that referenced this pull request Jun 3, 2013
@mourner mourner merged commit c54b6c1 into Leaflet:master Jun 3, 2013
@mourner
Copy link
Member

mourner commented Jun 3, 2013

Awesome, thanks!

@mourner
Copy link
Member

mourner commented Jun 23, 2013

Had to rewrite this a bit because of #1768

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants