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