Skip to content

Commit 0d13bee

Browse files
authored
feat: Add label on the bottom of the photo (#58)
2 parents 6276233 + d03ac56 commit 0d13bee

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

src/scripts/CanvasManager.ts

+33
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { type Message, MessageState } from "./Message.type";
33
import ObserverPublisher from "./ObserverPublisher";
44
import Publisher from "./Publisher.class";
55
import { log } from "./console.ts";
6+
import { DOMAIN_LABEL } from "./constans.ts";
67

78
// 4/3
89
const MAX_WIDTH = 1280;
@@ -92,6 +93,32 @@ export default class CanvasManager extends ObserverPublisher(Publisher) {
9293
this.context?.drawImage(image, x, y);
9394
}
9495

96+
protected drawLabel(
97+
label: string,
98+
image: HTMLImageElement,
99+
position: MapPosition,
100+
) {
101+
const { x, y } = this.getMapPosition(position, image);
102+
const fontSize = 16;
103+
const font = `${fontSize}px sans-serif`;
104+
const barHeight = fontSize * 2;
105+
const bawWidth = image.width;
106+
107+
const labelX = x;
108+
const labelY = y + image.height - barHeight;
109+
const padding = fontSize / 2;
110+
111+
if (!this.context) {
112+
return;
113+
}
114+
115+
this.context.fillStyle = "#2c3e50";
116+
this.context.fillRect(labelX, labelY, bawWidth, barHeight);
117+
this.context.fillStyle = "white";
118+
this.context.font = font;
119+
this.context.fillText(label, labelX + padding, labelY + fontSize * 1.25);
120+
}
121+
95122
update(publication: Message) {
96123
if (publication.state === MessageState.Reset) {
97124
this.resizeFor(MAX_WIDTH, MAX_HEIGHT);
@@ -105,6 +132,12 @@ export default class CanvasManager extends ObserverPublisher(Publisher) {
105132

106133
if (publication.state === MessageState.MapImageReady) {
107134
this.drawMap(publication.data.image, publication.data.position);
135+
this.drawLabel(
136+
DOMAIN_LABEL,
137+
publication.data.image,
138+
publication.data.position,
139+
);
140+
108141
this.publish({
109142
state: MessageState.CanvasWithMapReady,
110143
data: this.selector,

src/scripts/constans.ts

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export const DOMAIN_LABEL = "maponphoto.eu";

0 commit comments

Comments
 (0)