-
Notifications
You must be signed in to change notification settings - Fork 24
Expand file tree
/
Copy pathdxf_compare_2_viewports.html
More file actions
214 lines (200 loc) · 8.48 KB
/
dxf_compare_2_viewports.html
File metadata and controls
214 lines (200 loc) · 8.48 KB
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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
<html>
<head>
<link rel="icon" href="./favicon.ico" />
<link rel="stylesheet" type="text/css" href="./global.css" />
<link rel="stylesheet" type="text/css" href="./iconfont/iconfont.css" />
<link rel="stylesheet" type="text/css" href="./iconfont/iconfont2.css" />
<link rel="stylesheet" href="./compare/dxfComparePanel.css" />
<style>
body {
font-size: 0;
}
#myCanvas1,
#myCanvas2 {
width: calc(50% - 1px);
height: 100%;
margin: 0;
padding: 0;
display: inline-block;
overflow: hidden;
}
.split {
display: inline-block;
width: 1px;
height: 100%;
margin: 0;
padding: 0;
background-color: #eee;
}
#syncCamera {
position: absolute;
top: 16px;
left: 50%;
transform: translateX(-50%);
min-width: 32px;
min-height: 32px;
padding: 4px 6px;
font-size: 18px; /* icon size */
line-height: 1;
border-radius: 6px;
border: 1px solid #409effaa;
background-color: rgba(64, 158, 255, 0.4);
color: #fff;
cursor: pointer;
}
</style>
</head>
<body>
<div id="app" class="app">
<div id="myCanvas1"></div>
<div class="split"></div>
<div id="myCanvas2"></div>
</div>
<!-- Use an icon-style button to indicate synced/unsynced state (unlocked = unsynced, locked = synced) -->
<button id="syncCamera" title="Click to toggle camera sync">🔓</button>
<script>
// Auto-detect environment and set import map for x-viewer packages
(function () {
const wl = window.location;
const isDevEnv = false;
const resolvePath = (pkgName) =>
isDevEnv
? `../packages/${pkgName}/dist/index.esm.js`
: `https://cdn.jsdelivr.net/npm/@x-viewer/${pkgName}@latest/dist/index.esm.js`;
const corePath = resolvePath("core");
const pluginsPath = resolvePath("plugins");
const uiPath = resolvePath("ui");
const importMap = document.createElement("script");
importMap.type = "importmap";
importMap.textContent = JSON.stringify({
imports: {
"@x-viewer/core": corePath,
"@x-viewer/plugins": pluginsPath,
"@x-viewer/ui": uiPath,
},
});
document.head.appendChild(importMap);
})();
</script>
<script type="module">
import {
DxfCompareHelper,
} from "@x-viewer/core";
import {
AxisGizmoPlugin,
BottomBarPlugin,
Viewer2dToolbarPlugin,
LayerManagerPlugin,
MeasurementPlugin,
ScreenshotPlugin,
Settings2dPlugin,
ToolbarMenuId,
} from "@x-viewer/plugins";
import DxfComparePanel from "./compare/dxfComparePanel.js";
const url1 = "./models/dxf/doors_and_windows.dxf";
const url2 = "./models/dxf/doors_and_windows_mopdified.dxf";
const compareHelper = new DxfCompareHelper(
{
containerId: "myCanvas1",
},
{
containerId: "myCanvas2",
}
);
window.compareHelper = compareHelper;
const fontFiles = ["./libs/fonts/hztxt.shx", "./libs/fonts/simplex.shx"];
await compareHelper.setFont(fontFiles);
new AxisGizmoPlugin(compareHelper.viewer, { ignoreZAxis: true });
new BottomBarPlugin(compareHelper.viewer);
new MeasurementPlugin(compareHelper.viewer);
new MeasurementPlugin(compareHelper.viewer2);
new ScreenshotPlugin(compareHelper.viewer)
new ScreenshotPlugin(compareHelper.viewer2)
compareHelper.viewer.toolbar?.updateMenus(
overrideToolbarConfig(compareHelper.viewer)
);
compareHelper.viewer2.toolbar?.updateMenus(
overrideToolbarConfig(compareHelper.viewer2)
);
const syncCameraBtn = document.getElementById("syncCamera");
let enableSyncCamera = false;
syncCameraBtn.onclick = function () {
enableSyncCamera = !enableSyncCamera;
if (enableSyncCamera) {
compareHelper.enableSyncCamera(true);
syncCameraBtn.textContent = "🔒";
syncCameraBtn.title = "Click to unsync cameras";
} else {
compareHelper.enableSyncCamera(false);
syncCameraBtn.textContent = "🔓";
syncCameraBtn.title = "Click to sync cameras";
}
};
const onProgress = (event) => {
const progress = ((event.loaded * 100) / event.total).toFixed(2);
console.log(`[Demo] Compare progress: ${progress}%`);
};
// compare two specific dxf by default
compareHelper.compare({ src: url1, modelId: "dxf_3" }, { src: url2, modelId: "dxf_3_1" }, undefined, onProgress).then(() => {
console.log(`[Demo] Compared models: ${url1}, ${url2}`);
new DxfComparePanel(compareHelper, compareHelper.container);
}).catch((reason) => {
console.error(`[Demo] Failed to compare models: ${url1}, ${url2}. reason: ${reason}`);
});
function overrideToolbarConfig(viewer) {
return [
{
menuId: ToolbarMenuId.Layers,
config: {
onActive: () => {
console.log("[Toolbar]", "Activate Layers");
if (!viewer.layerManager) {
viewer.layerManager = new LayerManagerPlugin(viewer);
}
viewer.layerManager.show();
},
onDeactive: () => {
console.log("[Toolbar]", "Deactivate Layers");
viewer.layerManager.hide();
},
},
mutexIds: [
ToolbarMenuId.Measure,
ToolbarMenuId.MeasureDistance,
ToolbarMenuId.MeasureArea,
ToolbarMenuId.MeasureAngle,
ToolbarMenuId.MeasureCoordinate,
],
},
{
menuId: ToolbarMenuId.MarkupVisibility,
config: {
visible: false,
},
},
{
menuId: ToolbarMenuId.Fullscreen,
config: {
onClick: (bimViewer, toolbar) => {
const isFullScreen = !!document.fullscreenElement;
const onResize = () => {
const toolbarMenu = toolbar?.menuList.get(
ToolbarMenuId.Fullscreen
);
toolbarMenu && toolbarMenu.setActive(isFullScreen);
};
if (isFullScreen) {
document.exitFullscreen();
window.removeEventListener("resize", onResize);
} else {
compareHelper.container.requestFullscreen();
}
window.addEventListener("resize", onResize);
},
},
},
];
}
</script>
</body>
</html>