-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathdemo6.html
150 lines (119 loc) · 5.81 KB
/
demo6.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="minimal-ui, user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width">
<meta name="format-detection" content="telephone=no">
<meta name="msapplication-tap-highlight" content="no">
<title>SH3DO demo: edit an empty file</title>
<script type="text/javascript" src="https://demo.sh3d.online/lib/big.min.js" crossorigin="anonymous"></script>
<script type="text/javascript" src="https://demo.sh3d.online/lib/gl-matrix-min.js" crossorigin="anonymous"></script>
<script type="text/javascript" src="https://demo.sh3d.online/lib/jszip.min.js" crossorigin="anonymous"></script>
<script type="text/javascript" src="https://demo.sh3d.online/lib/jsXmlSaxParser.min.js" crossorigin="anonymous"></script>
<script type="text/javascript" src="https://demo.sh3d.online/lib/core.min.js" crossorigin="anonymous"></script>
<script type="text/javascript" src="https://demo.sh3d.online/lib/geom.min.js" crossorigin="anonymous"></script>
<script type="text/javascript" src="https://demo.sh3d.online/lib/stroke.min.js" crossorigin="anonymous"></script>
<script type="text/javascript" src="https://demo.sh3d.online/lib/swingundo.min.js" crossorigin="anonymous"></script>
<script type="text/javascript" src="https://demo.sh3d.online/lib/batik-svgpathparser.min.js" crossorigin="anonymous"></script>
<script type="text/javascript" src="https://demo.sh3d.online/lib/triangulator.min.js" crossorigin="anonymous"></script>
<script type="text/javascript" src="https://demo.sh3d.online/lib/graphics2d.min.js" crossorigin="anonymous"></script>
<script type="text/javascript" src="https://demo.sh3d.online/lib/sweethome3d.min.js" crossorigin="anonymous"></script>
<link rel="stylesheet" type="text/css" href="https://demo.sh3d.online/css/sweethome3d.css" crossorigin="anonymous">
<script src="https://code.jquery.com/jquery-3.5.1.min.js" integrity="sha256-9/aliU8dGd2tb6OSsuzixeV4y/faTqgFtohetphbbj0=" crossorigin="anonymous"></script>
<style type="text/css">
/* Add your own styles here */
#progress {
opacity: 70%;
z-index: 10;
position: absolute;
top: 0px;
height: 5px;
width: 100%;
}
#progress-bar {
background-color: blue;
height: 100%;
}
</style>
</head>
<body>
<div id="progress">
<div id="progress-bar" style="width: 0%;"></div>
</div>
<div id="home-pane">
<canvas id="home-3D-view" style="background-color: blue;"
tabIndex="1"></canvas>
<div id="home-plan" style="background-color: black; color: white"
tabIndex="2" ></div>
<div id="home-pane-toolbar"></div>
<div id="furniture-catalog"></div>
</div>
<script type="text/javascript">
var homeName = "emptyHome";
var urlBase = "https://demo.sh3d.online/";
var application = new SweetHome3DJSApplication(
{readHomeURL: urlBase + "api/readHome/12345/test/%s",
furnitureCatalogURLs: [urlBase + "lib/resources/DefaultFurnitureCatalog.json"],
furnitureResourcesURLBase: urlBase
});
// Set a few settings
application.getUserPreferences().setNewRoomFloorColor(0xFF9999A0);
application.getUserPreferences().setAerialViewCenteredOnSelectionEnabled(true);
// Read and display test file
application.getHomeRecorder().readHome(homeName,
{
homeLoaded: function(home) {
home.setName(homeName);
application.addHome(home);
addButton('custom-button-id', 'my new button', 'http://demo.sh3d.online/lib/search.gif', function() {
alert("hello from my new button");
});
setTimeout(function() {
document.getElementById('progress').style.display = "none";
}, 1000);
window.addEventListener("unload", function() {
application.deleteHome(home);
});
},
homeError: function(err) {
console.error(err);
},
progression: function(part, info, percentage) {
percentage = percentage * 100;
document.getElementById('progress-bar').style.width = `${percentage}%`;
}
});
function DownloadCanvasAsImage() {
let downloadLink = document.createElement('a');
downloadLink.setAttribute('download', 'alaprajz.png');
let canvas = document.getElementById('home-plan.canvas');
var planView = application.homeControllers[0].planController.planView;
var oldGridColor = planView.gridColor;
planView.gridColor = "white";
planView.repaint();
setTimeout(function() {
let dataURL = canvas.toDataURL('image/png');
let url = dataURL.replace(/^data:image\/png/, 'data:application/octet-stream');
downloadLink.setAttribute('href', url);
downloadLink.click();
planView.gridColor = oldGridColor;
planView.repaint();
}, 100);
}
function addButton(id, title, imageUrl, onclick) {
var toolbar = document.getElementById('home-pane-toolbar');
toolbar.insertAdjacentHTML('beforeend', "<span class='toolbar-button-group'><button title='"+title+"' class='toolbar-button toggle selected' id='"+id+"' style='background-image: url(""+imageUrl+""); background-position: center center; background-repeat: no-repeat;background-color:#fff'></button></span>");
document.getElementById(id).addEventListener('click', onclick);
}
function addSaveButton() {
var home_pane_toolbar = $("#home-pane-toolbar");
home_pane_toolbar.append("<span class='toolbar-button-group'><button title='Alaprajz mentése' class='toolbar-button toggle selected' id='download_button' style='background-image: url("https://megveszlak.hu/images/save.png"); background-position: center center; background-repeat: no-repeat;background-color:#fff'></button></span>");
$("#download_button").bind("click", function () {
DownloadCanvasAsImage();
});
}
//addSaveButton();
</script>
</body>
</html>