-
Notifications
You must be signed in to change notification settings - Fork 6
/
demo.js
42 lines (38 loc) · 1 KB
/
demo.js
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
let src = '';
function updateVisibleValue() {
document.getElementById('cell-size-value').innerText = document.getElementById('cell-size').value;
if (src) {
poly()
}
}
function readURL(input) {
if (input.files && input.files[0]) {
const reader = new FileReader();
reader.onload = event => {
src = event.target.result;
poly();
document.getElementById('image-file').value = '';
};
reader.readAsDataURL(input.files[0]);
}
}
function poly() {
loading(true);
Polygonize({
src: src,
cellSize: parseInt(document.getElementById('cell-size').value),
progress: function (progress) {
// console.log(progress + '%');
},
onSuccess: function(canvas) {
const canvasContainer = document.getElementById('canvas')
canvasContainer.innerHTML = '';
canvasContainer.appendChild(canvas);
loading(false);
}
});
}
function loading(show) {
let loading = document.getElementById('loading');
loading.style.display = show ? "flex" : "none";
}