LargeFormatPrints.js 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. (function(){
  2. var imgSize = {
  3. "A0":{
  4. width:parseInt(118.9*28.3),
  5. height:parseInt(84.1*28.3)
  6. },
  7. "A1":{
  8. width:parseInt(84.1*28.3),
  9. height:parseInt(59.4*28.3)
  10. }
  11. }
  12. var LargeFormatPrint = {};
  13. /**
  14. * url:"http://localhost:8090/iserver/services/map-china400/rest/maps/China"
  15. * projection:"3857"
  16. * scale:0.000000004339
  17. * center:new SuperMap.LonLat(0,0)
  18. * pageSize:"A0",仅支持A1和A0
  19. * */
  20. LargeFormatPrint.excute = function(url,projection,scale,center,pageSize,map,callback){
  21. if(url&&projection&&scale&&center&&pageSize){
  22. //向服务端请求一张整张的图片
  23. var requestUrl = url+"/image.png?";
  24. requestUrl += "scale="+scale;
  25. requestUrl += "&center={\"x\":"+center.lon+",\"y\":"+center.lat+"}";
  26. var size = imgSize[pageSize];
  27. requestUrl += "&width="+size.width+"&height="+size.height;
  28. requestUrl += "&transparent=false&prjCoordSys={\"epsgCode\":"+projection+"}";
  29. var img = new Image();
  30. img.src = requestUrl;
  31. if (img.addEventListener) {
  32. img.addEventListener("load", onImgLoad, false);
  33. } else if (element.attachEvent) {
  34. img.attachEvent('onload', onImgLoad);
  35. }
  36. }
  37. else{
  38. alert("参数不正确");
  39. }
  40. function onImgLoad(){
  41. //将图片放到页面上先预览效果,如果觉得不对,可点击取消重来
  42. var div = document.createElement("div");
  43. div.style.position = "absolute";
  44. div.style.top = "0px";
  45. div.style.zIndex = 999;
  46. div.style.left = "0px";
  47. //div.style.border = "solid 5px #4c4c4c";
  48. div.style.background = "#ffffff";
  49. div.style.height = "558px";
  50. div.style.width = "100%";
  51. document.body.appendChild(div);
  52. var imgDiv = document.createElement("div");
  53. imgDiv.style.position = "relative";
  54. imgDiv.style.height = "520px";
  55. imgDiv.style.textAlign = "center";
  56. imgDiv.style.border = "1px solid #4c4c4c";
  57. img.style.position="relative";
  58. //img.style.verticalAlign = "middle";
  59. // img.style.zIndex = 999;
  60. //img.style.left="0px";
  61. //img.style.top = "38px";
  62. // img.style.width = "935px";
  63. img.style.height = "520px";
  64. img.style.width = "auto";
  65. imgDiv.appendChild(img);
  66. //window.body.appendChild(img);
  67. var div1 = document.createElement("div");
  68. div1.style.position = "relative";
  69. div1.style.height = "38px";
  70. div.appendChild(div1);
  71. div.appendChild(imgDiv);
  72. var button = document.createElement("button");
  73. div1.appendChild(button);
  74. button.innerHTML = "打印";
  75. button.onclick = function(){
  76. //将图片放于页面上,并调用浏览器打印接口
  77. document.body.removeChild(div);
  78. img.style.left="0px";
  79. img.style.top = "0px";
  80. img.style.width = "";
  81. img.style.height = "";
  82. img.style.zIndex = 999;
  83. img.style.border = "";
  84. document.body.appendChild(img);
  85. if(map)map.div.style.display = "none";
  86. window.print();
  87. if(map)map.div.style.display = "block";
  88. document.body.removeChild(img);
  89. if(callback)callback();
  90. }
  91. var button1 = document.createElement("button");
  92. div1.appendChild(button1);
  93. button1.innerHTML = "取消";
  94. button1.onclick = function(){
  95. document.body.removeChild(div);
  96. if(callback)callback();
  97. }
  98. }
  99. }
  100. window.LargeFormatPrint = LargeFormatPrint;
  101. })()