others_mapPrint.html 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  1. <!--********************************************************************
  2. * Copyright© 2000 - 2021 SuperMap Software Co.Ltd. All rights reserved.
  3. *********************************************************************-->
  4. <!DOCTYPE html>
  5. <html>
  6. <head>
  7. <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
  8. <meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7,IE=9,IE=10,IE=11"/>
  9. <title data-i18n="resources.title_mapPrint"></title>
  10. <style type="text/css">
  11. .editPane {
  12. position: absolute;
  13. right: 180px;
  14. top: 10px;
  15. text-align: center;
  16. background: #FFF;
  17. z-index: 1000;
  18. }
  19. </style>
  20. </head>
  21. <body style=" margin: 0;overflow: hidden;background: #fff;width: 100%;height:100%;position: absolute;top: 0;">
  22. <div class='panel panel-primary editPane' id='editPane' style="z-index: 99999">
  23. <div class='panel-heading'>
  24. <h5 class='panel-title text-center' data-i18n="resources.text_mapPrint"></h5>
  25. </div>
  26. <div class='panel-body' id='params'>
  27. <p></p>
  28. <div align='right' class='button-group'>
  29. <input type='button' id='btn1' class='btn btn-primary' data-i18n="[value]resources.btn_marker" onclick="createMarker()"/>
  30. <input type='button' id='btn2' class='btn btn-primary' data-i18n="[value]resources.btn_print" onclick="createPrintMap('map')"/>
  31. <input type='button' id='btn3' class='btn btn-primary' data-i18n="[value]resources.text_input_value_clear" onclick="clearAllFeatures()"/>
  32. </div>
  33. </div>
  34. </div>
  35. <div id="map" style="margin:0 auto;width: 100%;height: 100%"></div>
  36. <script type="text/javascript" include="bootstrap,widgets.alert" src="../js/include-web.js"></script>
  37. <script type="text/javascript" exclude="iclient-classic" src="../../dist/classic/include-classic.js"></script>
  38. <script type="text/javascript">
  39. var map, layer, markerLayer;
  40. var host = window.isLocal ? window.server : "https://iserver.supermap.io";
  41. smCompanyArr = [
  42. ["北京超图软件股份有限公司上海分公司", 13522414.5106, 3662690.3875, "上海市闸北虬江路1000号聚源大厦办公楼1505室"],
  43. ["北京超图软件股份有限公司广州分公司", 12608758.6677, 2647887.5456, "广州市体育西路109号高盛大厦9楼G单元"],
  44. ["北京超图软件股份有限公司成都分公司", 11584664.2393, 3588559.6862, "成都市高新区天府大道中段1268号天府软件园E区"],
  45. ["北京超图软件股份有限公司杭州分公司", 13375617.5430, 3538667.9064, "杭州市天目山路159号现代国际大厦A座"],
  46. ["北京超图软件股份有限公司西安分公司", 12127616.0783, 4064501.0071, "西安高新区丈八一路一号 汇鑫IBC(A座)"],
  47. ["北京超图软件股份有限公司长沙分公司", 12573006.2587, 3277897.5105, "长沙市芙蓉中路二段359号佳天国际新城北栋8H"],
  48. ["北京超图软件股份有限公司沈阳分公司", 13740261.8165, 5131821.5120, "沈阳市沈河区市府大路262甲号新华科技大厦"]
  49. ],
  50. url = host + "/iserver/services/map-china400/rest/maps/China";
  51. function init() {
  52. //定义layer图层,TiledDynamicRESTLayer:分块动态 REST 图层
  53. layer = new SuperMap.Layer.TiledDynamicRESTLayer("China", url, {
  54. transparent: true,
  55. cacheEnabled: true
  56. }, {maxResolution: "auto", useCanvas: false, useCORS: true});
  57. //为图层初始化完毕添加addLayer()事件
  58. layer.events.on({"layerInitialized": addLayer});
  59. map = new SuperMap.Map("map", {
  60. controls: [
  61. new SuperMap.Control.LayerSwitcher(),
  62. new SuperMap.Control.OverviewMap(),
  63. new SuperMap.Control.ScaleLine(),
  64. new SuperMap.Control.Zoom(),
  65. new SuperMap.Control.Navigation({
  66. dragPanOptions: {
  67. enableKinetic: true
  68. }
  69. })
  70. ]
  71. });
  72. markerLayer = new SuperMap.Layer.Markers("Markers");
  73. }
  74. $(document).ready(function () {
  75. init();
  76. });
  77. function addLayer() {
  78. map.addLayers([layer, markerLayer]);
  79. map.setCenter(new SuperMap.LonLat(11733502.481499, 4614406.969325), 4);
  80. }
  81. //移除整个图层要素
  82. function clearAllFeatures() {
  83. markerLayer.clearMarkers();
  84. if (map.popups.length != 0) {
  85. var i = 0, lengthPopup = map.popups.length;
  86. while (i < lengthPopup) {
  87. map.removePopup(map.popups[0]);
  88. i++;
  89. }
  90. }
  91. }
  92. /**
  93. *打印地图,支持ie9及以上,chrome,firefox等.
  94. *请注意相关css,js文件是否存在.
  95. *Parameters:
  96. *id <String> id 为map div的id
  97. */
  98. function createPrintMap(id) {
  99. var broz = SuperMap.Browser.name;
  100. if (broz == 'msie' && parseInt(SuperMap.Browser.version) < 9) {
  101. widgets.alert.showAlert(resources.msg_supportPrint,false);
  102. return;
  103. }
  104. var printWindow = window.open("");
  105. var strInnerHTML = document.getElementById(id).innerHTML;
  106. var strHeader = "<!DOCTYPE html><html><head><META HTTP-EQUIV='pragma' CONTENT='no-cache'><META HTTP-EQUIV='Cache-Control' CONTENT='no-cache, must-revalidate'><META HTTP-EQUIV='expires' CONTENT='Wed, 26 Feb 1997 08:21:57 GMT'><meta http-equiv='Content-Type' content='text/html; charset=utf-8' /><meta name='viewport' content='width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0' /><meta name='apple-mobile-web-app-capable' content='yes' /><title>地图打印</title>";
  107. var strCSS = "<script type='text/javascript' include='style,sm-doc'exclude='iclient-classic' src='../../dist/classic/include-classic.js'>";
  108. var strScript = "<script src='https://cdn.staticfile.org/jquery/3.2.1/jquery.min.js'><\/script><script type = 'text/javascript'>" + "\n" + "function printDiv(){document.getElementsByClassName('newuiPrint')[0].style.display ='none';window.print();document.getElementsByClassName('newuiPrint')[0].style.display ='block';}<\/script>";
  109. var strBody = "</head><body><div class='print-header'><div class='superD'><h3>地图</h3></div><div id='" + id + "' >" + strInnerHTML + "</div><div id='superft'><div class='printClose'>" + "<span class='newuiPrint' onclick = 'printDiv()'></span></div></div></div></body></html>";
  110. var strHTML = strHeader + strCSS + strScript + strBody;
  111. printWindow.document.write(strHTML);
  112. printWindow.document.close();
  113. function onloadHTML() {
  114. var strDOM = printWindow.document.getElementById(id).children[0].children;
  115. for (var i = 0, length = strDOM.length; i < length; i++) {
  116. var idStr = strDOM[i].id;
  117. if (idStr.indexOf("SuperMap.Control.ScaleLine") == -1 && idStr.indexOf("SuperMap.Map") == -1) {
  118. strCss = strDOM[i].style.cssText;
  119. strCss = strCss + "display: none;";
  120. strDOM[i].style.cssText = strCss;
  121. }
  122. }
  123. var canvasPrint = printWindow.document.getElementsByTagName("canvas");
  124. var canvasMap = document.getElementsByTagName("canvas");
  125. for (var i = 0, length = canvasPrint.length; i < length; i++) {
  126. pasteCanvas(canvasMap[i], canvasPrint[i]);
  127. }
  128. }
  129. if (broz == 'firefox') {
  130. printWindow.onload = onloadHTML;
  131. } else if (broz == 'safari' || broz == 'chrome' || broz == 'msie') {
  132. window.setTimeout(onloadHTML, 50);
  133. }
  134. }
  135. //如果涉及到Canvas的图层打印,需要将范例发布出来运行,否则会产生跨域的问题
  136. function pasteCanvas(sCanvas/*source*/, dCanvas/*destination*/) {
  137. var w = sCanvas.width,
  138. h = sCanvas.height;
  139. dCanvas.width = w;
  140. dCanvas.height = h;
  141. var viewerImageSrc = sCanvas.toDataURL("image/png");
  142. var viewerImage = new Image();
  143. viewerImage.src = viewerImageSrc;
  144. var dContext = dCanvas.getContext("2d");
  145. dContext.drawImage(viewerImage, 0, 0, w, h);
  146. }
  147. //添加标注
  148. function createMarker() {
  149. markerLayer.clearMarkers();
  150. for (var i = 0, lengthCompany = smCompanyArr.length; i < lengthCompany; i++) {
  151. var point = new SuperMap.Geometry.Point(parseFloat(smCompanyArr[i][1]), parseFloat(smCompanyArr[i][2])),
  152. strContent = new Array(smCompanyArr[i][0], smCompanyArr[i][3]),
  153. size = new SuperMap.Size(32, 32),
  154. offset = new SuperMap.Pixel(-(size.w / 2), -size.h),
  155. feature = new SuperMap.Feature(markerLayer, new SuperMap.LonLat(point.x, point.y));
  156. feature.data.icon = new SuperMap.Icon("./images/markerflag.png", size, offset);
  157. var marker = feature.createMarker();
  158. var markerClick = function (evt, feature, strContent) {
  159. SuperMap.Event.stop(evt);
  160. this.win.open(feature, {
  161. "name": strContent[0],
  162. "informition": strContent[1]
  163. });
  164. };
  165. marker.events.register("click", feature, function (feature, strContent) {
  166. return function (evt) {
  167. markerClick(evt, feature, strContent);
  168. }
  169. }(feature, strContent));
  170. markerLayer.addMarker(marker);
  171. }
  172. }
  173. this.win = new InforWindow_z({"map": map});
  174. function InforWindow_z(param) {
  175. var t = this;
  176. t.infowin = null;
  177. t.map = null;
  178. t.init = function (param) {
  179. for (var key in param) {
  180. t[key] = param[key];
  181. }
  182. }
  183. t.open = function (feature, data) {
  184. t.close();
  185. t.create(feature, data);
  186. }
  187. t.create = function (feature, data) {
  188. var contentHTML = "<div style='font-size:.8em; opacity: 0.8; overflow-y:hidden;'>" +
  189. "<span style='font-weight: bold; font-size: 18px;'>详细信息</span><br>";
  190. contentHTML += "公司名称:" + data.name + "<br>";
  191. contentHTML += "公司地址:" + data.informition + "</div>";
  192. //初始化一个弹出窗口,当某个地图要素被选中时会弹出此窗口,用来显示选中地图要素的属性信息
  193. var popup = new SuperMap.Popup.FramedCloud("chicken",
  194. feature.marker.lonlat,
  195. null,
  196. contentHTML,
  197. null,
  198. true);
  199. feature.popup = popup;
  200. map.addPopup(popup);
  201. t.infowin = popup;
  202. }
  203. t.close = function () {
  204. if (t.infowin) {
  205. try {
  206. t.infowin.hide();
  207. t.infowin.destroy();
  208. }
  209. catch (e) {
  210. }
  211. }
  212. }
  213. t.init(param);
  214. }
  215. </script>
  216. </body>
  217. </html>