@@ -3,6 +3,7 @@ import { type Message, MessageState } from "./Message.type";
3
3
import ObserverPublisher from "./ObserverPublisher" ;
4
4
import Publisher from "./Publisher.class" ;
5
5
import { log } from "./console.ts" ;
6
+ import { DOMAIN_LABEL } from "./constans.ts" ;
6
7
7
8
// 4/3
8
9
const MAX_WIDTH = 1280 ;
@@ -92,6 +93,32 @@ export default class CanvasManager extends ObserverPublisher(Publisher) {
92
93
this . context ?. drawImage ( image , x , y ) ;
93
94
}
94
95
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
+
95
122
update ( publication : Message ) {
96
123
if ( publication . state === MessageState . Reset ) {
97
124
this . resizeFor ( MAX_WIDTH , MAX_HEIGHT ) ;
@@ -105,6 +132,12 @@ export default class CanvasManager extends ObserverPublisher(Publisher) {
105
132
106
133
if ( publication . state === MessageState . MapImageReady ) {
107
134
this . drawMap ( publication . data . image , publication . data . position ) ;
135
+ this . drawLabel (
136
+ DOMAIN_LABEL ,
137
+ publication . data . image ,
138
+ publication . data . position ,
139
+ ) ;
140
+
108
141
this . publish ( {
109
142
state : MessageState . CanvasWithMapReady ,
110
143
data : this . selector ,
0 commit comments