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

The map slows down when zooming when there is a lot of data(5000 and more) #27

Open
bonya0329 opened this issue Nov 25, 2021 · 1 comment

Comments

@bonya0329
Copy link

Can you tell me if there are alternative solutions to this problem?

@jwasilgeo
Copy link
Owner

Hi @bonya0329 I have noticed this too but didn't have any fresh solutions for how to deal with it yet. Is it possible in your map to reduce how many flow lines between origin points and destination points are shown when zooming in more?

Here's a rough code example of listening to Leaflet map zoom events, checking the zoom level (let's say at level 10; whatever makes sense for your map), and then selecting only certain flow lines for display.

map.on("zoomend", function() {
  const newZoomLevel = map.getZoom();

  if (newZoomLevel >= 10) {
    // zoomed in at or past the zoom level 10 threshold
    // select only some flow lines for display
    // (but will also be called unfortunately anytime the zoom changes at or below 10)
    yourCanvasLayer.selectFeaturesForPathDisplay(selectionFeatures, selectionMode);
  } else {
    // zoom level changed and it is above 10
    // select all flow lines for display
    // (but will also be called unfortunately anytime the zoom changes above 10)
    yourCanvasLayer.selectAllFeaturesForPathDisplay();
  }
});

But please note this will fire and occur quite often, and the zoom event listening approach could be improved to only call yourCanvasLayer methods one time at or below 10, and only one time above 10.

https://leafletjs.com/reference.html#map-zoom

https://github.com/jwasilgeo/Leaflet.Canvas-Flowmap-Layer#method-summary

What do you think?

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

No branches or pull requests

2 participants