Leaflet.PixiOverlay icon indicating copy to clipboard operation
Leaflet.PixiOverlay copied to clipboard

Export map with pixi overlay

Open mitow7821 opened this issue 2 years ago • 3 comments

Hi, I'am trying to export leaflet map and all elements inside it. I use 'domtoimage' library to get blob file. Unfortunately pixi overlay is not included in my final blob image.

I've found this old issue (https://github.com/manubb/Leaflet.PixiOverlay/issues/19) which covers simillar export problem, with that difference I need full map image. I set value of preserveDrawingBuffer to true. Used methods from issue above... and still nothing. Every time I'am getting blank image :(

Is there any way to export map with its pixi overlay?

mitow7821 avatar Jan 25 '22 14:01 mitow7821

Hi. No precise idea of what is going on but aren't you in the situation described in https://github.com/tsayen/dom-to-image#things-to-watch-out-for ?

manubb avatar Jan 25 '22 14:01 manubb

We can ignore fact of using domtoimage library. I tried exporting pixi overlay only, using vanilla js and pixi methods described in linked issue. Please check sandbox from old issue (your last comment). In my case image is downloaded correctly only when overlay is updated. When I click download btn I get blank image.

mitow7821 avatar Jan 25 '22 16:01 mitow7821

With this code I'm able to dowload pixi layer:

  downloadLayer() {
    loader.load(() => {
      const { utils } = this.pixiLayer;
      const container = utils.getContainer();
      const renderer = utils.getRenderer();
      renderer.render(container);

      const elem = window.document.createElement("a");
      elem.href = renderer.view.toDataURL();
      elem.download = "image.png";
      document.body.appendChild(elem);
      elem.click();
      document.body.removeChild(elem);
    });
  }  

mitow7821 avatar Mar 29 '22 09:03 mitow7821