-
Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy pathdxf_2.html
More file actions
153 lines (143 loc) · 5.32 KB
/
dxf_2.html
File metadata and controls
153 lines (143 loc) · 5.32 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
<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" />
<style>
#myCanvas {
width: 100%;
height: 100%;
overflow: hidden;
}
</style>
</head>
<body>
<div id="app">
<div id="myCanvas"></div>
</div>
<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 {
Viewer2d,
} from "@x-viewer/core";
import {
AxisGizmoPlugin,
BottomBarPlugin,
Viewer2dToolbarPlugin,
HotpointPlugin,
LayerManagerPlugin,
MarkupPlugin,
MeasurementPlugin,
ScreenshotPlugin,
Settings2dPlugin,
StatsPlugin,
ToolbarMenuId,
} from "@x-viewer/plugins";
const models = [{
modelId: "dxf_2",
name: "dxf_2",
src: "./models/dxf/dxf_2.dxf",
merge: true,
visible: true,
}];
const language = "en"; // "en" or "zh"
const viewerCfg = {
containerId: "myCanvas",
language,
enableSpinner: true,
enableProgressBar: true,
enableLayoutBar: true,
};
const viewer = new Viewer2d(viewerCfg);
// const fontFiles = ["libs/fonts/Microsoft_YaHei_Regular.typeface.json"];
const fontFiles = ["./libs/fonts/hztxt.shx", "./libs/fonts/simplex.shx"];
await viewer.setFont(fontFiles);
window.viewer = viewer;
const menuConfig = {
[ToolbarMenuId.Layers]: {
onActive: () => {
console.log("[Toolbar]", "Activate Layers");
if (!window.layerManager) {
window.layerManager = new LayerManagerPlugin(window.viewer);
window.layerManager.addEventListener("visibilitychange", (visible) => {
const isActive = toolbarPlugin.isActive(ToolbarMenuId.Layers);
// do this check to avoid recursive call
if (isActive !== visible) {
toolbarPlugin.setActive(ToolbarMenuId.Layers, visible);
}
});
}
window.layerManager.setVisible(true);
},
onDeactive: () => {
console.log("[Toolbar]", "Deactivate Layers");
window.layerManager.setVisible(false);
},
mutexIds: [
ToolbarMenuId.Measure,
ToolbarMenuId.MeasureDistance,
ToolbarMenuId.MeasureArea,
ToolbarMenuId.MeasureAngle,
ToolbarMenuId.MeasureCoordinate,
],
},
};
new AxisGizmoPlugin(viewer, { ignoreZAxis: true })
new BottomBarPlugin(viewer);
new MarkupPlugin(viewer);
new MeasurementPlugin(viewer, { language });
new ScreenshotPlugin(viewer);
new Settings2dPlugin(viewer, { language, visible: false });
new StatsPlugin(viewer);
window.toolbarPlugin = new Viewer2dToolbarPlugin(viewer, { menuConfig, language });
let counter = 0; // to indicate how many models are loading
models.forEach((modelCfg) => {
if (modelCfg.visible === false) {
// visible is true by default
return; // only load visible ones
}
counter++;
const onProgress = (event) => {
const progress = ((event.loaded * 100) / event.total).toFixed(1);
console.log(`[Demo] Loading '${modelCfg.modelId}' progress: ${progress}%`);
};
try {
viewer
.loadModel(modelCfg, onProgress)
.then(() => {
console.log(`[Demo] Loaded model ${modelCfg.src}`);
})
.finally(() => {
counter--;
});
} catch (ex) {
console.log(ex);
}
});
</script>
</body>
</html>