gmap.html 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
  2. "http://www.w3.org/TR/html4/loose.dtd">
  3. <html>
  4. <head>
  5. <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
  6. <title></title>
  7. <script type="text/javascript" src="../internal.js"></script>
  8. <style type="text/css">
  9. .content {
  10. width: 530px;
  11. height: 350px;
  12. margin: 10px auto;
  13. }
  14. .content table {
  15. width: 100%
  16. }
  17. .content table td {
  18. vertical-align: middle;
  19. }
  20. #address {
  21. width: 220px;
  22. height: 21px;
  23. background: #FFF;
  24. border: 1px solid #d7d7d7;
  25. line-height: 21px;
  26. }
  27. </style>
  28. <script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
  29. </head>
  30. <body>
  31. <div class="content">
  32. <table>
  33. <tr>
  34. <td><label for="address"><var id="lang_input_address"></var></label></td>
  35. <td><input id="address" type="text"/></td>
  36. <td><a id="doSearch" href="javascript:void(0)" class="button"><var id="lang_input_search"></var></a></td>
  37. </tr>
  38. </table>
  39. <div id="container" style="width: 100%; height: 340px;margin: 5px auto; border: 1px solid gray;"></div>
  40. </div>
  41. <script type="text/javascript">
  42. domUtils.on(window, "load", function () {
  43. var map = new google.maps.Map(document.getElementById('container'), {
  44. zoom: 3,
  45. streetViewControl: false,
  46. scaleControl: true,
  47. mapTypeId: google.maps.MapTypeId.ROADMAP
  48. });
  49. var imgcss;
  50. var marker = new google.maps.Marker({
  51. map: map,
  52. draggable: true
  53. });
  54. function doSearch() {
  55. var address = document.getElementById('address').value;
  56. var geocoder = new google.maps.Geocoder();
  57. geocoder.geocode({ 'address': address}, function (results, status) {
  58. if (status == google.maps.GeocoderStatus.OK) {
  59. var bounds = results[0].geometry.viewport;
  60. map.fitBounds(bounds);
  61. marker.setPosition(results[0].geometry.location);
  62. marker.setTitle(address);
  63. } else alert(lang.searchError);
  64. });
  65. }
  66. $G('address').onkeydown = function (evt) {
  67. evt = evt || event;
  68. if (evt.keyCode == 13) {
  69. doSearch();
  70. }
  71. };
  72. $G("doSearch").onclick = doSearch;
  73. dialog.onok = function () {
  74. var center = map.getCenter();
  75. var point = marker.getPosition();
  76. var url = "http://maps.google.com/maps/api/staticmap?center=" + center.lat() + ',' + center.lng() + "&zoom=" + map.zoom + "&size=520x340&maptype=" + map.getMapTypeId() + "&markers=" + point.lat() + ',' + point.lng() + "&sensor=false";
  77. editor.execCommand('inserthtml', '<img width="520" height="340" src="' + url + '"' + (imgcss ? ' style="' + imgcss + '"' : '') + '/>');
  78. };
  79. function getPars(str, par) {
  80. var reg = new RegExp(par + "=((\\d+|[.,])*)", "g");
  81. return reg.exec(str)[1];
  82. }
  83. var img = editor.selection.getRange().getClosedNode();
  84. if (img && img.src.indexOf("http://maps.google.com/maps/api/staticmap") != -1) {
  85. var url = img.getAttribute("src");
  86. var centers = getPars(url, "center").split(",");
  87. point = new google.maps.LatLng(Number(centers[0]), Number(centers[1]));
  88. map.setCenter(point);
  89. map.setZoom(Number(getPars(url, "zoom")));
  90. centers = getPars(url, "markers").split(",");
  91. marker.setPosition(new google.maps.LatLng(Number(centers[0]), Number(centers[1])));
  92. imgcss = img.style.cssText;
  93. } else {
  94. setTimeout(function () {
  95. doSearch();
  96. }, 30)
  97. }
  98. });
  99. </script>
  100. </body>
  101. </html>