You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

135 lines
5.9 KiB

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