-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathindex.html
118 lines (116 loc) · 3.39 KB
/
index.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
<!DOCTYPE html>
<html>
<!--
* ## How to embed PCDEditor to your plain html website
*
* 1. Download assets tarball (pcdeditor-VERSION-npm.tgz) from
* https://github.com/seqsense/pcdeditor/packages/773018
* and decompress.
*
* 2. Configure your server to host the assets.
*
* 3. Add main page like this file to your website.
* Note: replace the import path according to your configuration!
*
* For React-based website, see https://www.seqsense.org/pcdeditor/react-example
-->
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0" />
<style>
html, body, #container, #mapCanvas {
box-sizing: border-box;
height: 100%;
width: 100%;
margin: 0;
padding: 0;
overflow: hidden;
}
#container {
position: relative;
background-color: black;
}
#mapCanvas {
z-index: 1;
touch-action: none;
}
#menubox {
display: flex;
flex-wrap: wrap;
align-items: stretch;
position: absolute;
top: 0;
left: 0;
padding: 2px;
box-sizing: border-box;
}
#log {
font-size: 0.6em;
max-height: 20em;
position: absolute;
bottom: 1em;
left: 1em;
z-index: 2;
color: white;
pointer-events: none;
overflow: hidden;
}
</style>
</head>
<body>
<div id="container">
<canvas id="mapCanvas" tabindex="0"></canvas>
<div id="menubox">
<input id="loadFromFile"
accept=".pcd, .png, .yaml"
type="file" multiple
style="display: none;"
/>
<button id="load">load</button>
<button id="loadFrom">load from...</button>
</div>
<div id="log"></div>
</div>
</body>
<script type="module">
import PCDEditor from './pcdeditor.esm.js'
const editor = new PCDEditor()
editor.appendDefaultMenuboxTo('#menubox')
editor.attach().then(() => {
document.querySelector('#load').onclick = () => {
const pcdPath = '/fixture/map.pcd'
const yamlPath = '/fixture/map.yaml'
const imgPath = '/fixture/map.png'
editor.reset().catch(editor.logger)
editor.loadPCD(pcdPath).catch(editor.logger)
editor.load2D(yamlPath, imgPath).catch(editor.logger)
}
const loadFromFile = document.querySelector('#loadFromFile')
document.querySelector('#loadFrom').onclick = () => {
// to make sure onchange is called even if the same files are selected
loadFromFile.value = ''
loadFromFile.click()
}
loadFromFile.onchange = async (e) => {
let [pcdPath, yamlPath, imgPath] = [undefined, undefined, undefined]
Array.from(e.target.files).forEach(f => {
const url = URL.createObjectURL(f)
if (f.name.endsWith('.pcd')) {
pcdPath = url
} else if (f.name.endsWith('.png')) {
imgPath = url
} else if (f.name.endsWith('.yaml')) {
yamlPath = url
}
})
editor.reset().catch(editor.logger)
if (pcdPath) {
editor.loadPCD(pcdPath).catch(editor.logger)
}
if (imgPath && yamlPath) {
editor.load2D(yamlPath, imgPath).catch(editor.logger)
}
}
})
</script>
</html>