Canvas size in Sweet Home 3D JS

This topic has been viewed 8230 times and has 10 replies
Thread status: Active
Questions about extending features and developing plug-ins [img]http://www.sweethome3d.com/images/flags/en_small.gif[/img]
kingoftailor
Posts: 21
Joined: Wed Jan 13, 2016 2:28 pm

Re: Sweet Home 3D JS Online

Post by kingoftailor »

I modified the code. I omitted the planView.paintComponent line and put back the part planView.gridColor = oldGridColor from the original code. Even so, the downloaded image is perfectly fine and I don't see any changes in the floor plan after reloading the page.

The final code:

Code: Select all

function AlaprajzMentes() {
                let downloadLink = document.createElement('a');
                downloadLink.setAttribute('download', 'alaprajz.jpg');

                let canvas = document.getElementById('home-plan.canvas');
                var planView = application.getHomeController(application.getHomes()[0]).getPlanController().getView();
                var oldGridColor = planView.gridColor;
                planView.gridColor = "white";
                planView.repaint();
                canvas.width = planView.getPreferredSize().width * 2;
                canvas.height = planView.getPreferredSize().height * 2;

                setTimeout(function () {
                    let dataURL = canvas.toDataURL('image/jpg');
                    let url = dataURL.replace(/^data:image\/jpg/, 'data:application/octet-stream');
                    downloadLink.setAttribute('href', url);
                    downloadLink.click();
                    planView.gridColor = oldGridColor;
                    planView.repaint();
                    window.location.reload();
                }, 100);
            }
Post Reply New Topic

Who is online

Users browsing this forum: No registered users and 2 guests