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

Possibility to refresh GridLayer tiles #9100

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

yuri-karelics
Copy link

Hi, please consider the possibility to merge this PR.

Background
We are happy to use Leaflet in our Karelics.Cloud platform. One problem we faced with is map tiles update. If map was changed and client wants to update tiles the only available GridLayer method is 'redraw' - it deletes all tiles and creates them back. Blinking caused by tiles removal looks bad in case updates happen often.

What was done
In general, GridLayer logic was not touched. Just piece of code was extracted from _addTile into _initTileElement method to be reused.
Only new thing is method reloadTiles. It creates new HTML elements for each existing tile and replaces tile's HTML element with new one on success. There is no tile removal, so visually this way to update tiles looks much better.

Give me know in case some edge case was not considered. Thanks!

@Falke-Design
Copy link
Member

I haven't tested it but the browser cache should break that logic, because it doesn't make a new request.
There should be another PR where we discussed that already.

I understand the need and i think if it is possible we should consider implementing a solution for this issue.

@yuri-karelics
Copy link
Author

yuri-karelics commented Sep 22, 2023

I would say 'avoiding browser cache' is responsibility of createTile method, it could be anything, not only 'img', so maybe browser cache is not a problem at all. Responsibility of GridLayer is just to get new element and replace old one.

@yuri-karelics
Copy link
Author

@Falke-Design @mourner is there a chance to move this PR forward? I am open for discussion

@yuri-karelics
Copy link
Author

@Falke-Design @mourner still have intention to contribute into your repo =)

@yuri-karelics
Copy link
Author

@Falke-Design @mourner could you give me the person to contact regarding possibility to review this MR?

@@ -891,6 +908,27 @@ export const GridLayer = Layer.extend({
}
},

_tileUpdate(tile, err, el) {
Copy link
Member

Choose a reason for hiding this comment

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

This method is used only once (in refreshTiles()) and therefore I'd be tempted to hoist it in there, converting it into an anonymous function.

Copy link
Author

Choose a reason for hiding this comment

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

I tried to copy codestyle used in the code around, but no problem, done (hope I understood you right)

tile.el = el;
tile.loaded = +new Date();

this.fire('tileupdate', {
Copy link
Member

Choose a reason for hiding this comment

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

This event needs docstrings.

Copy link
Author

Choose a reason for hiding this comment

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

added

@@ -272,6 +272,17 @@ export const GridLayer = Layer.extend({
return document.createElement('div');
},

// @method refreshTiles: void
// Triggers creating of new tile HTML element for each existing tile
Copy link
Member

Choose a reason for hiding this comment

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

Compare with the redraw method. Give users some explanation (in the docstrings) why they should use one or the other.

Copy link
Author

Choose a reason for hiding this comment

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

explanation extended

}

el.classList.add('leaflet-tile-loaded');
tile.el.replaceWith(el);
Copy link
Member

Choose a reason for hiding this comment

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

I see, the element is created behind the curtains and replaced in the DOM once it's ready. Nice technique. 👍

@yuri-karelics
Copy link
Author

@IvanSanchez just realized that probably I should create MR to 'v1' branch... or you care about cherry-picks yourself?

@Falke-Design
Copy link
Member

@IvanSanchez just realized that probably I should create MR to 'v1' branch... or you care about cherry-picks yourself?

Hi,
no the main branch is fine, we will not add new features to v1 anymore.

@yuri-karelics
Copy link
Author

@Falke-Design @IvanSanchez is there a change to merge this PR this year? Also, do you already have a plan regarding v2 release? If no, I can create also PR to v1 branch.
P.S. We really want to remove ugly patch we are using in our code to achieve behavior implemented in this PR

@Malvoz Malvoz added the feature label Feb 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants