Trying to resize map using transforms
This commit is contained in:
parent
2734a38979
commit
3ae4f4343b
|
@ -6,8 +6,8 @@
|
||||||
<![endif]-->
|
<![endif]-->
|
||||||
<style type="text/css">
|
<style type="text/css">
|
||||||
#map {
|
#map {
|
||||||
height: 600px;
|
height: 612px; /* 8.5 inch at 72 dpi */
|
||||||
width: 80%;
|
width: 792px; /* 11 inch at 72 dpi */
|
||||||
}
|
}
|
||||||
#results {
|
#results {
|
||||||
width: 18%;
|
width: 18%;
|
||||||
|
|
88
print.html
88
print.html
|
@ -9,6 +9,12 @@
|
||||||
padding: 0;
|
padding: 0;
|
||||||
margin: 0;
|
margin: 0;
|
||||||
}
|
}
|
||||||
|
#printbutton {
|
||||||
|
position: absolute;
|
||||||
|
top: 0;
|
||||||
|
left: 0;
|
||||||
|
z-index: 999;
|
||||||
|
}
|
||||||
#map {
|
#map {
|
||||||
height: 2550px; /* 8.5 inch at 300 dpi */
|
height: 2550px; /* 8.5 inch at 300 dpi */
|
||||||
width: 3300px; /* 11 inch at 300 dpi */
|
width: 3300px; /* 11 inch at 300 dpi */
|
||||||
|
@ -19,6 +25,9 @@
|
||||||
size: 11in 8.5in;
|
size: 11in 8.5in;
|
||||||
margin: 0mm;
|
margin: 0mm;
|
||||||
}
|
}
|
||||||
|
#printbutton {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
htmlff,boffdy {
|
htmlff,boffdy {
|
||||||
height: 8.5in;
|
height: 8.5in;
|
||||||
width: 11in;
|
width: 11in;
|
||||||
|
@ -34,6 +43,7 @@
|
||||||
|
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
<input type="button" value="Print" id="printbutton" onclick="printMap()" />
|
||||||
<div id="map"></div>
|
<div id="map"></div>
|
||||||
|
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
|
@ -58,8 +68,6 @@
|
||||||
if(params["q"] && params["b0"] && params["b1"] && params["b2"] && params["b3"]){
|
if(params["q"] && params["b0"] && params["b1"] && params["b2"] && params["b3"]){
|
||||||
updateMap(decodeURIComponent(params["q"]),[[decodeURIComponent(params["b0"]), decodeURIComponent(params["b1"])],
|
updateMap(decodeURIComponent(params["q"]),[[decodeURIComponent(params["b0"]), decodeURIComponent(params["b1"])],
|
||||||
[decodeURIComponent(params["b2"]), decodeURIComponent(params["b3"])]]);
|
[decodeURIComponent(params["b2"]), decodeURIComponent(params["b3"])]]);
|
||||||
//uploadCanvas();
|
|
||||||
//print();
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
alert("No boundaries given!");
|
alert("No boundaries given!");
|
||||||
|
@ -71,37 +79,57 @@
|
||||||
map.fitBounds(bounds);
|
map.fitBounds(bounds);
|
||||||
};
|
};
|
||||||
|
|
||||||
function uploadCanvas(){
|
function printMap(){
|
||||||
var data = "<svg xmlns='http://www.w3.org/2000/svg' width='3300' height='2550'>" +
|
halveMap();
|
||||||
"<foreignObject width='100%' height='100%'>" +
|
print();
|
||||||
"<div xmlns='http://www.w3.org/1999/xhtml' >" +
|
|
||||||
document.getElementById("map").innerHTML+
|
|
||||||
"</div>" +
|
|
||||||
"</foreignObject>" +
|
|
||||||
"</svg>";
|
|
||||||
document.getElementById("map").innerHTML = data;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function drawCanvas(){
|
|
||||||
var canvas = document.getElementById("canvas");
|
function halveMap(){
|
||||||
var ctx = canvas.getContext("2d");
|
// Halve size of each leaflet tile AND decrease its offsets by half
|
||||||
var data = "<svg xmlns='http://www.w3.org/2000/svg' width='3300' height='2550'>" +
|
var leaflets = document.getElementsByClassName("leaflet-tile");
|
||||||
"<foreignObject width='100%' height='100%'>" +
|
for(var i=0; i < leaflets.length; i++){
|
||||||
"<div xmlns='http://www.w3.org/1999/xhtml' >" +
|
element = leaflets[i];
|
||||||
document.getElementById("map").innerHTML+
|
element.style.width = element.style.width.split("px")[0]/2+"px";
|
||||||
"</div>" +
|
element.style.height = element.style.height.split("px")[0]/2+"px";
|
||||||
"</foreignObject>" +
|
|
||||||
"</svg>";
|
computedStyle = window.getComputedStyle(element, null); // "null" means this is not a pesudo style.
|
||||||
var DOMURL = self.URL || self.webkitURL || self;
|
// You can retrieve the CSS3 matrix string by the following method.
|
||||||
var img = new Image();
|
var matrix = computedStyle.getPropertyValue('transform')
|
||||||
var svg = new Blob([data], {type: "image/svg+xml;charset=utf-8"});
|
|| computedStyle.getPropertyValue('-moz-transform')
|
||||||
var url = DOMURL.createObjectURL(svg);
|
|| computedStyle.getPropertyValue('-webkit-transform')
|
||||||
img.onload = function() {
|
|| computedStyle.getPropertyValue('-ms-transform')
|
||||||
ctx.drawImage(img, 0, 0);
|
|| computedStyle.getPropertyValue('-o-transform');
|
||||||
DOMURL.revokeObjectURL(url);
|
|
||||||
};
|
// Parse this string to obtain different attributes of the matrix.
|
||||||
img.src = url;
|
// This regexp matches anything looks like this: anything(1, 2, 3, 4, 5, 6);
|
||||||
|
// Hence it matches both matrix strings:
|
||||||
|
// 2d: matrix(1,2,3,4,5,6)
|
||||||
|
// 3d: matrix3d(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16);
|
||||||
|
var matrixPattern = /^\w*\((((\d+)|(\d*\.\d+)|(\-\d*)),\s*)*((\d+)|(\d*\.\d+)|(\-\d*))\)/i;
|
||||||
|
var matrixValue = [];
|
||||||
|
if (matrixPattern.test(matrix)) { // When it satisfy the pattern.
|
||||||
|
console.log(matrix);
|
||||||
|
var matrixCopy = matrix.replace(/^\w*\(/, '').replace(')', '');
|
||||||
|
console.log(matrixCopy);
|
||||||
|
m = matrixCopy.split(/\s*,\s*/);
|
||||||
|
console.log(m);
|
||||||
|
m[4] = m[4]/2;
|
||||||
|
m[5] = m[5]/2;
|
||||||
|
console.log(m);
|
||||||
|
element.style.webkitTransform = "matrix("+m[0]+", "+m[1]+", "+m[2]+", "+m[3]+", "+m[4]+", "+m[5]+")";
|
||||||
|
console.log(element.style.webkitTransform);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Halve size of map container (hopefully no redraw!)
|
||||||
|
|
||||||
|
map._container.style.width = window.getComputedStyle(map._container, null).width.split("px")[0]/2+"px";
|
||||||
|
map._container.style.height = window.getComputedStyle(map._container, null).height.split("px")[0]/2+"px";
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user