@@ -175,6 +175,94 @@ export class MapManager {
175175 }
176176 } ;
177177
178+ // Patch the _print method to add footer text before converting to blob
179+ const originalPrint = bigImageControl . _print . bind ( bigImageControl ) ;
180+ bigImageControl . _print = function ( ) {
181+ const self = this ;
182+
183+ self . tilesImgs = { } ;
184+ self . markers = { } ;
185+ self . path = { } ;
186+ self . circles = { } ;
187+
188+ let dimensions = self . _map . getSize ( ) ;
189+
190+ self . zoom = self . _map . getZoom ( ) ;
191+ self . bounds = self . _map . getPixelBounds ( ) ;
192+
193+ self . canvas = document . createElement ( 'canvas' ) ;
194+ self . canvas . width = dimensions . x ;
195+ self . canvas . height = dimensions . y ;
196+ self . ctx = self . canvas . getContext ( '2d' ) ;
197+
198+ bigImageControl . _changeScale . call ( self , document . getElementById ( 'scale' ) . value ) ;
199+
200+ let promise = new Promise ( function ( resolve , reject ) {
201+ bigImageControl . _getLayers . call ( self , resolve ) ;
202+ } ) ;
203+
204+ promise . then ( ( ) => {
205+ return new Promise ( ( ( resolve , reject ) => {
206+ for ( const [ key , value ] of Object . entries ( self . tilesImgs ) ) {
207+ self . ctx . drawImage ( value . img , value . x , value . y , self . tileSize , self . tileSize ) ;
208+ }
209+ for ( const [ key , value ] of Object . entries ( self . path ) ) {
210+ bigImageControl . _drawPath . call ( self , value ) ;
211+ }
212+ for ( const [ key , value ] of Object . entries ( self . markers ) ) {
213+ self . ctx . drawImage ( value . img , value . x , value . y ) ;
214+ }
215+ for ( const [ key , value ] of Object . entries ( self . circles ) ) {
216+ bigImageControl . _drawCircle . call ( self , value ) ;
217+ }
218+
219+ // ADD FOOTER TEXT HERE - after all drawing is complete
220+ const canvas = self . canvas ;
221+ const ctx = self . ctx ;
222+
223+ // Set text style
224+ const fontSize = Math . max ( 16 , Math . floor ( canvas . width / 80 ) ) ; // Dynamic font size
225+ ctx . font = `${ fontSize } px Arial, sans-serif` ;
226+ ctx . textAlign = 'center' ;
227+ ctx . textBaseline = 'bottom' ;
228+
229+ // Draw text background for better readability
230+ const text = 'Generated by https://mapporncirclejerk.xyz/' ;
231+ const textMetrics = ctx . measureText ( text ) ;
232+ const textWidth = textMetrics . width ;
233+ const textHeight = fontSize * 1.5 ;
234+ const padding = fontSize * 0.5 ;
235+
236+ const x = canvas . width / 2 ;
237+ const y = canvas . height - padding ;
238+
239+ // Draw semi-transparent background
240+ ctx . fillStyle = 'rgba(255, 255, 255, 0.8)' ;
241+ ctx . fillRect (
242+ x - textWidth / 2 - padding ,
243+ y - textHeight ,
244+ textWidth + padding * 2 ,
245+ textHeight
246+ ) ;
247+
248+ // Draw text
249+ ctx . fillStyle = 'rgba(0, 0, 0, 0.9)' ;
250+ ctx . fillText ( text , x , y - padding / 2 ) ;
251+
252+ resolve ( ) ;
253+ } ) ) ;
254+ } ) . then ( ( ) => {
255+ self . canvas . toBlob ( function ( blob ) {
256+ let link = document . createElement ( 'a' ) ;
257+ link . download = "my-image.png" ;
258+ link . href = URL . createObjectURL ( blob ) ;
259+ link . click ( ) ;
260+ } ) ;
261+ self . _containerParams . classList . remove ( 'print-disabled' ) ;
262+ self . _loader . style . display = 'none' ;
263+ } ) ;
264+ } ;
265+
178266 // Prepare map for export when export button is clicked
179267 this . map . on ( 'click' , ( e : L . LeafletMouseEvent ) => {
180268 const target = e . originalEvent . target as HTMLElement ;
0 commit comments