血透系统PC前端

map.html 6.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  5. <title></title>
  6. <script type="text/javascript" src="../internal.js"></script>
  7. <script type="text/javascript" src="https://api.map.baidu.com/api?v=1.3&services=true&s=1"></script>
  8. <style type="text/css">
  9. .content{
  10. width: 600px;
  11. height: 415px;
  12. margin: 20px;
  13. }
  14. .content table{width: 100%}
  15. .content table td{vertical-align: middle;}
  16. #city,#address{
  17. height: 26px;
  18. background: #FFF;
  19. border: 1px solid #ccc;
  20. line-height: 26px;
  21. border-radius: 5px;
  22. margin-left: 5px;
  23. }
  24. #city{width:76px}
  25. #address{width:178px}
  26. #is_dynamic_label span{vertical-align:middle;margin: 3px 0px 3px 3px;}
  27. #is_dynamic_label input{vertical-align:middle;margin: 3px 3px 3px 50px;}
  28. #search {
  29. display: block;
  30. text-align: center;
  31. line-height: 30px;
  32. text-decoration: none;
  33. height: 30px;
  34. width: 78px;
  35. border: 0;
  36. color: #838383;
  37. background-color: #3498db;
  38. border-radius: 5px;
  39. color: #fff;
  40. }
  41. </style>
  42. </head>
  43. <body>
  44. <div class="content">
  45. <table>
  46. <tr>
  47. <td><var id="lang_city"></var>:</td>
  48. <td><input id="city" type="text" /></td>
  49. <td><var id="lang_address"></var>:</td>
  50. <td><input id="address" type="text" value="" /></td>
  51. <td><a href="javascript:doSearch()" class="button" id="search"><var id="lang_search"></var></a></td>
  52. <td><label id="is_dynamic_label" for="is_dynamic"><input id="is_dynamic" type="checkbox" name="is_dynamic" /><span><var id="lang_dynamicmap"></var></span></label></td>
  53. </tr>
  54. </table>
  55. <div style="width:100%;height:363px;margin:20px auto;border:none" id="container"></div>
  56. </div>
  57. <script type="text/javascript">
  58. var map = new BMap.Map("container"),marker,point,styleStr;
  59. map.enableScrollWheelZoom();
  60. map.enableContinuousZoom();
  61. function doSearch(){
  62. if (!document.getElementById('city').value) {
  63. alert(lang.cityMsg);
  64. return;
  65. }
  66. var search = new BMap.LocalSearch(document.getElementById('city').value, {
  67. onSearchComplete: function (results){
  68. if (results && results.getNumPois()) {
  69. var points = [];
  70. for (var i=0; i<results.getCurrentNumPois(); i++) {
  71. points.push(results.getPoi(i).point);
  72. }
  73. if (points.length > 1) {
  74. map.setViewport(points);
  75. } else {
  76. map.centerAndZoom(points[0], 13);
  77. }
  78. point = map.getCenter();
  79. marker.setPosition(point);
  80. } else {
  81. alert(lang.errorMsg);
  82. }
  83. }
  84. });
  85. search.search(document.getElementById('address').value || document.getElementById('city').value);
  86. }
  87. //获得参数
  88. function getPars(str,par){
  89. var reg = new RegExp(par+"=((\\d+|[.,])*)","g");
  90. return reg.exec(str)[1];
  91. }
  92. function init(){
  93. var mapNode = editor.selection.getRange().getClosedNode(),
  94. isMapImg = mapNode && /api[.]map[.]baidu[.]com/ig.test(mapNode.getAttribute("src")),
  95. isMapIframe = mapNode && domUtils.hasClass(mapNode, 'ueditor_baidumap');
  96. if(isMapImg || isMapIframe){
  97. var url, centerPos, markerPos;
  98. if(isMapIframe) {
  99. url = decodeURIComponent(mapNode.getAttribute("src"));
  100. $G('is_dynamic').checked = true;
  101. styleStr = mapNode.style.cssText;
  102. } else {
  103. url = mapNode.getAttribute("src");
  104. styleStr = mapNode.style.cssText;
  105. }
  106. centerPos = getPars(url,"center").split(",");
  107. markerPos = getPars(url, "mMarkerarkers").split(",");
  108. point = new BMap.Point(Number(centerPos[0]),Number(centerPos[1]));
  109. marker = new BMap.Marker(new BMap.Point(Number(markerPos[0]), Number(markerPos[1])));
  110. map.addControl(new BMap.NavigationControl());
  111. map.centerAndZoom(point, Number(getPars(url,"zoom")));
  112. }else{
  113. point = new BMap.Point(116.404, 39.915); // 创建点坐标
  114. marker = new BMap.Marker(point);
  115. map.addControl(new BMap.NavigationControl());
  116. map.centerAndZoom(point, 10); // 初始化地图,设置中心点坐标和地图级别。
  117. }
  118. marker.enableDragging();
  119. map.addOverlay(marker);
  120. }
  121. init();
  122. document.getElementById('address').onkeydown = function (evt){
  123. evt = evt || event;
  124. if (evt.keyCode == 13) {
  125. doSearch();
  126. }
  127. };
  128. dialog.onok = function (){
  129. var center = map.getCenter();
  130. var zoom = map.zoomLevel;
  131. var size = map.getSize();
  132. var mapWidth = size.width;
  133. var mapHeight = size.height;
  134. var point = marker.getPosition();
  135. if($G('is_dynamic').checked) {
  136. var URL = editor.options.UEDITOR_HOME_URL,
  137. url = [URL + (/\/$/.test(URL) ? '':'/') + "dialogs/map/show.html" +
  138. '#center=' + center.lng + ',' + center.lat,
  139. '&zoom=' + zoom,
  140. '&width=' + mapWidth,
  141. '&height=' + mapHeight,
  142. '&markers=' + point.lng + ',' + point.lat,
  143. '&markerStyles=' + 'l,A'].join('');
  144. editor.execCommand('inserthtml', '<iframe class="ueditor_baidumap" src="' + url + '"' + (styleStr ? ' style="' + styleStr + '"' :'') + ' frameborder="0" width="' + (mapWidth+4) + '" height="' + (mapHeight+4) + '"></iframe>');
  145. } else {
  146. var url = "https://api.map.baidu.com/staticimage?center=" + center.lng + ',' + center.lat +
  147. "&zoom=" + zoom + "&width=" + size.width + '&height=' + size.height + "&markers=" + point.lng + ',' + point.lat;
  148. editor.execCommand('inserthtml', '<img width="'+ size.width +'" height="'+ size.height +'" src="' + url + '"' + (styleStr ? ' style="' + styleStr + '"' :'') + '/>');
  149. }
  150. };
  151. document.getElementById("address").focus();
  152. </script>
  153. </body>
  154. </html>