|
80 | 80 | divTextContainers.innerText = ""; |
81 | 81 |
|
82 | 82 | for (let result of results) { |
| 83 | + const l = result.localizationResult; |
83 | 84 | const p1 = { |
84 | | - x: Math.min( |
85 | | - result.localizationResult.x1, |
86 | | - result.localizationResult.x2, |
87 | | - result.localizationResult.x3, |
88 | | - result.localizationResult.x4 |
89 | | - ), |
90 | | - y: Math.min( |
91 | | - result.localizationResult.y1, |
92 | | - result.localizationResult.y2, |
93 | | - result.localizationResult.y3, |
94 | | - result.localizationResult.y4 |
95 | | - ), |
| 85 | + x: Math.min(l.x1, l.x2, l.x3, l.x4), |
| 86 | + y: Math.min(l.y1, l.y2, l.y3, l.y4), |
96 | 87 | }; |
97 | 88 | const p2 = { |
98 | | - x: Math.max( |
99 | | - result.localizationResult.x1, |
100 | | - result.localizationResult.x2, |
101 | | - result.localizationResult.x3, |
102 | | - result.localizationResult.x4 |
103 | | - ), |
104 | | - y: Math.max( |
105 | | - result.localizationResult.y1, |
106 | | - result.localizationResult.y2, |
107 | | - result.localizationResult.y3, |
108 | | - result.localizationResult.y4 |
109 | | - ), |
| 89 | + x: Math.max(l.x1, l.x2, l.x3, l.x4), |
| 90 | + y: Math.max(l.y1, l.y2, l.y3, l.y4), |
110 | 91 | }; |
| 92 | + |
111 | 93 | /** |
112 | 94 | * 'convertToPageCoordinates()' is used to converts coordinate of a barcode location to the coordinate related to the document. |
113 | 95 | * Then we can place a div element according to the converted coordinate. |
114 | 96 | */ |
115 | 97 | const convertedP1 = scanner.convertToPageCoordinates(p1); |
116 | 98 | const convertedP2 = scanner.convertToPageCoordinates(p2); |
| 99 | + |
117 | 100 | textContainer = document.createElement("div"); |
118 | | - textContainer.style.position = "absolute"; |
119 | | - textContainer.style.left = convertedP1.x + "px"; |
120 | | - textContainer.style.right = document.body.clientWidth - convertedP2.x + "px"; |
121 | | - textContainer.style.bottom = document.body.clientHeight - convertedP1.y + "px"; |
122 | | - textContainer.style.color = "#FE8E14"; |
| 101 | + Object.assign(textContainer.style, { |
| 102 | + position: "absolute", |
| 103 | + left: convertedP1.x + "px", |
| 104 | + right: document.documentElement.clientWidth - convertedP2.x + "px", |
| 105 | + bottom: document.documentElement.clientHeight - convertedP1.y + "px", |
| 106 | + color: "#FE8E14", |
| 107 | + }); |
123 | 108 | textContainer.innerText = result.barcodeText; |
124 | 109 | divTextContainers.append(textContainer); |
| 110 | + |
| 111 | + /** |
| 112 | + * You can also add more information, such as displaying product images. |
| 113 | + */ |
125 | 114 | } |
126 | 115 | }; |
127 | 116 |
|
|
0 commit comments