manubb / Leaflet.PixiOverlay

Bring Pixi.js power to Leaflet maps
MIT License
474 stars 84 forks source link

Export map with pixi overlay #74

Open mitow7821 opened 2 years ago

mitow7821 commented 2 years ago

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?

manubb commented 2 years ago

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 ?

mitow7821 commented 2 years ago

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 commented 2 years ago

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);
    });
  }