@@ -196,6 +196,9 @@ L.Control.Screenshot = L.Control.extend({
196196 ` ;
197197 document . body . appendChild ( loadingDiv ) ;
198198
199+ // Get current filter
200+ const currentFilter = tileLayer . getContainer ( ) . style . filter ;
201+
199202 // Capture the map
200203 html2canvas ( document . getElementById ( 'app-container' ) , {
201204 useCORS : true ,
@@ -207,6 +210,34 @@ L.Control.Screenshot = L.Control.extend({
207210 // Ignore the loading indicator if it's inside app-container (it shouldn't be, but just in case)
208211 // Also ignore data selector if it's hidden (html2canvas usually handles hidden, but let's be safe)
209212 return element . classList . contains ( 'data-selector' ) && element . style . display === 'none' ;
213+ } ,
214+ onclone : ( clonedDoc ) => {
215+ // Apply filter to tiles manually since html2canvas doesn't support CSS filters
216+ if ( currentFilter && currentFilter !== 'none' && currentFilter !== '' ) {
217+ const clonedTileImages = clonedDoc . querySelectorAll ( '.leaflet-tile-pane img' ) ;
218+ const originalTileImages = document . querySelectorAll ( '.leaflet-tile-pane img' ) ;
219+
220+ clonedTileImages . forEach ( ( img , index ) => {
221+ const originalImg = originalTileImages [ index ] ;
222+ if ( originalImg && originalImg . complete ) {
223+ const canvas = clonedDoc . createElement ( 'canvas' ) ;
224+ canvas . width = originalImg . naturalWidth || originalImg . width ;
225+ canvas . height = originalImg . naturalHeight || originalImg . height ;
226+
227+ // Copy styles
228+ canvas . style . cssText = img . style . cssText ;
229+ canvas . className = img . className ;
230+
231+ const ctx = canvas . getContext ( '2d' ) ;
232+ ctx . filter = currentFilter ;
233+ ctx . drawImage ( originalImg , 0 , 0 , canvas . width , canvas . height ) ;
234+
235+ if ( img . parentNode ) {
236+ img . parentNode . replaceChild ( canvas , img ) ;
237+ }
238+ }
239+ } ) ;
240+ }
210241 }
211242 } ) . then ( canvas => {
212243 // Remove loading indicator
@@ -227,30 +258,6 @@ L.Control.Screenshot = L.Control.extend({
227258 const imgData = canvas . toDataURL ( 'image/png' ) ;
228259 pdf . addImage ( imgData , 'PNG' , 0 , 0 , cropWidth , cropHeight ) ;
229260
230- // Add simulation timestamp at top right with semi-transparent background and border
231- const timestamp = `Time: ${ formatTime ( timeStamp ) } ` ;
232- const fontSize = Math . max ( 12 , cropHeight / 30 ) ;
233- pdf . setFont ( "helvetica" , "bold" ) ;
234- pdf . setFontSize ( fontSize ) ;
235-
236- // Calculate text dimensions for background
237- const textWidth = pdf . getTextWidth ( timestamp ) ;
238- const textHeight = fontSize * 0.7 ; // Approximate line height
239-
240- // Position at top right with margin
241- const margin = 10 ;
242- const rectX = cropWidth - textWidth - margin * 2 ;
243- const rectY = margin ;
244-
245- // Add semi-transparent white background with black border
246- pdf . setFillColor ( 255 , 255 , 255 , 0.9 ) ; // Semi-transparent white background
247- pdf . setDrawColor ( 0 , 0 , 0 ) ; // Black border
248- pdf . rect ( rectX , rectY , textWidth + margin * 2 , textHeight + margin * 2 , 'FD' ) ; // Fill and stroke
249-
250- // Add black text on top
251- pdf . setTextColor ( 255 , 255 , 255 ) ; // White text
252- pdf . text ( timestamp , rectX + margin , rectY + textHeight + margin ) ;
253-
254261 // Save the PDF
255262 const filename = `road_network_${ new Date ( ) . toISOString ( ) . slice ( 0 , 19 ) . replace ( / : / g, '-' ) } .pdf` ;
256263 pdf . save ( filename ) ;
0 commit comments