Igor-Vladyka / leaflet.browser.print

A leaflet plugin which allows users to print the map directly from the browser
https://igor-vladyka.github.io/leaflet.browser.print/
MIT License
154 stars 76 forks source link

marker.ClusterGroup not working #58

Closed runtimeavl closed 4 years ago

runtimeavl commented 5 years ago

Dear Igor, I would like your help with the following: I have a markerClusterGroup with almost 500 markers, when I zoom in and marker.ClusterGroup shows many markes, browser.print works ok, but when zoomed out and marker.ClusterGroup shows only a few or no markers, browser.print throws me an error: too much recursion.

What am I doing wring? Please advice

image

Igor-Vladyka commented 5 years ago

Hi there. Can you provide any working example (jsfiddle or any other) that I can take a look?

curtis18 commented 5 years ago

Dear Igor,

@Igor-Vladyka Thank you for your plugin. It is very nice. I encounter the similar issue like @runtimeavl, but I have over 6000 markers. I can provide you more information and I hope this problem can be solved.

For auto print or custom select print, except I zoom in a lot and only a few unclustered markers shown on screen, otherwise, it will have error messages below when the screen displays ClusterGroup and stop popup printing windows dialog.

In Firefox, the error message is too much recursion leaflet.browser.print.js line 127 > eval:14:1

In Chrome, the error message is leaflet.browser.print.utils.js:159 Uncaught RangeError: Maximum call stack size exceeded at Function.[Symbol.hasInstance] () at Object.__getRenderer (leaflet.browser.print.utils.js:159) at Object.cloneLayer (leaflet.browser.print.utils.js:129) at Object.cloneOptions (leaflet.browser.print.utils.js:22) at Object.eval [as builder] (leaflet.browser.print.utils.js:79) at Object.cloneLayer (leaflet.browser.print.utils.js:137) at Object.cloneOptions (leaflet.browser.print.utils.js:22) at Object.eval [as builder] (leaflet.browser.print.utils.js:79) at Object.cloneLayer (leaflet.browser.print.utils.js:137) at Object.cloneOptions (leaflet.browser.print.utils.js:22)

Thank you.

curtis18 commented 5 years ago

Dear Igor,

@Igor-Vladyka I have created a jsfuddle https://jsfiddle.net/curtis18/gLd2m3ab/ that is based on the example of markercluster https://leaflet.github.io/Leaflet.markercluster/example/marker-clustering-realworld.388.html and combined it with browser print. Thank you.

Igor-Vladyka commented 5 years ago

Hello, just fixed it in latest v0.9.2. Please take a look. Here is working fiddle: https://jsfiddle.net/8ce3bx9w/

curtis18 commented 5 years ago

@Igor-Vladyka Thank you very much for your fix. The issue basically has been solved. But I found that the performance and memory usage has problem when I have over 6000 markers on the map. Even when I select a small area to print, it will be either browser freezing and wait a lot of time for printing or out of memory and crash. Please help. Thank you.

Zoom in and select a small area selection

Browser Freeze freeze

Out of memory outofmemory

Igor-Vladyka commented 5 years ago

Hi guys,

Released new version of the plugin, with a MarkerClusterGroup registration moved out of the plugin. You will need to add your own registration/copy-paste it from documentation to make it work with latest.

Regards, Igor

curtis18 commented 5 years ago

@Igor-Vladyka Thanks a lot. I am going to update it according to the documentation.

Igor-Vladyka commented 4 years ago

Hi there,

Here is a bit dirty hack how to make it work without outofmemory exceptions:

// We are not cloning markercluster to preserve original clasterization behavior and prevent OutOfMemory problems
L.Control.BrowserPrint.Utils.registerLayer(L.MarkerClusterGroup, 'L.MarkerClusterGroup', function (layer, utils) {
    return layer;
});

// On print end we invalidate markercluster to update markers;
map.on(L.Control.BrowserPrint.Event.PrintEnd, function(e) {
    map.removeLayer(markers);
    map.addLayer(markers);
});

Regards, Igor

curtis18 commented 4 years ago

@Igor-Vladyka Thanks for your great help.

patriciogutierrez commented 4 years ago

How do I set the same zoom that is on my base map when printing? I don't want the MarkerCluster expands when i print the map