Skip to content

Commit 557e94c

Browse files
committed
print update
1 parent dd9adaa commit 557e94c

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

js/print.js

+33
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ var shapeLayer = L.geoJson(null);
99

1010
const ORIG_W = 1000;
1111
const ORIG_H = 1450;
12+
1213
// ######################################
1314
// LEAFLET MAP
1415

@@ -144,6 +145,8 @@ function changeDimensions(reset=false, preset=false) {
144145
// console.log("chosen preset: " + $('#presets').val(), reset, preset);
145146
var w;
146147
var h;
148+
var pagew = '21cm';
149+
var pageh = '29.7cm';
147150
if(reset) {
148151
// console.log("resetting");
149152
$(`.width`).val(ORIG_W);
@@ -166,34 +169,50 @@ function changeDimensions(reset=false, preset=false) {
166169
case "A3_300":
167170
w = 4960;
168171
h = 7016;
172+
pagew = '29.7cm';
173+
pageh = '42cm';
169174
break;
170175
case "A3_150":
171176
w = 1754;
172177
h = 2480;
178+
pagew = '29.7cm';
179+
pageh = '42cm';
173180
break;
174181
case "A2_300":
175182
w = 4960;
176183
h = 7016;
184+
pagew = '42cm';
185+
pageh = '59.4cm';
177186
break;
178187
case "A2_150":
179188
w = 2480;
180189
h = 3508;
190+
pagew = '42cm';
191+
pageh = '59.4cm';
181192
break;
182193
case "A1_300":
183194
w = 7016;
184195
h = 9933;
196+
pagew = '59.4cm';
197+
pageh = '84.1cm';
185198
break;
186199
case "A1_150":
187200
w = 3508;
188201
h = 4967;
202+
pagew = '59.4cm';
203+
pageh = '84.1cm';
189204
break;
190205
case "A0_300":
191206
w = 9933;
192207
h = 14043;
208+
pagew = '84.1cm';
209+
pageh = '118.9cm';
193210
break;
194211
case "A0_150":
195212
w = 4967;
196213
h = 7022;
214+
pagew = '84.1cm';
215+
pageh = '118.9cm';
197216
break;
198217
}
199218
$(`.width`).val(w);
@@ -206,6 +225,20 @@ function changeDimensions(reset=false, preset=false) {
206225
$(`.page`).css('width',`${w}px`);
207226
$(`.page`).css('height',`${h}px`);
208227

228+
// body cm height and width setting as per preset
229+
var cssRules = document.querySelector('style').sheet.cssRules;
230+
for (var i = 0; i < cssRules.length; i++) {
231+
// Check if the rule is inside the @media print block
232+
if (cssRules[i].media && cssRules[i].media.mediaText === 'print') {
233+
// Check if the rule targets the body element
234+
if (cssRules[i].selectorText === 'body') {
235+
// Change the width and height values
236+
cssRules[i].style.width = pagew;
237+
cssRules[i].style.height = pageh;
238+
}
239+
}
240+
}
241+
209242
map.invalidateSize();
210243
// from https://stackoverflow.com/questions/24412325/resizing-a-leaflet-map-on-container-resize
211244
//Checks if the map container size changed and updates the map if so — call it after you've changed the map size dynamically

0 commit comments

Comments
 (0)