167410843d2867d08e0e965baf8ba4b1008a3f14.svn-base 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. // ================================================================
  2. // CHEditor 5
  3. // ----------------------------------------------------------------
  4. var oEditor = null,
  5. centerLat = 0,
  6. centerLng = 0,
  7. latlng = 0,
  8. setZoom = 14,
  9. marker_lat = 0,
  10. marker_lng = 0,
  11. mapType = "roadmap",
  12. map,
  13. mapWidth = 512,
  14. mapHeight = 320,
  15. panorama,
  16. panoramaVisible = false,
  17. marker,
  18. staticMapsAPI = 'STATIC_MAPS_API_KEY';
  19. function doSubmit() {
  20. var mapImg = document.createElement("img"),
  21. panoramaPitch, panoramaHeading, panoramaZoom, panoramaPosition;
  22. if (marker_lat === 0) {
  23. marker_lat = centerLat;
  24. }
  25. if (marker_lng === 0) {
  26. marker_lng = centerLng;
  27. }
  28. mapImg.style.width = mapWidth + 'px';
  29. mapImg.style.height = mapHeight + 'px';
  30. mapImg.style.border = '1px #000 solid';
  31. mapImg.setAttribute('alt', 'Google Map');
  32. mapImg.onload = function () {
  33. oEditor.insertHtmlPopup(mapImg);
  34. oEditor.popupWinClose();
  35. };
  36. if (panoramaVisible) {
  37. panoramaPitch = panorama.getPov().pitch;
  38. panoramaHeading = panorama.getPov().heading;
  39. panoramaZoom = panorama.getPov().zoom;
  40. panoramaPosition = panorama.getPosition();
  41. mapImg.src = "http://maps.googleapis.com/maps/api/streetview?" +
  42. "location=" + panoramaPosition.lat() + ',' + panoramaPosition.lng() +
  43. "&pitch=" + panoramaPitch +
  44. "&heading=" + panoramaHeading +
  45. "&size=" + mapWidth + 'x' + mapHeight +
  46. "&zoom=" + panoramaZoom +
  47. "&sensor=false" +
  48. "&region=KR" +
  49. "&key=" + staticMapsAPI;
  50. } else {
  51. mapImg.src = "http://maps.google.com/maps/api/staticmap?" +
  52. "center=" + centerLat + ',' + centerLng +
  53. "&zoom=" + setZoom +
  54. "&size=" + mapWidth + 'x' + mapHeight +
  55. "&maptype=" + mapType +
  56. "&markers=" + marker_lat + ',' + marker_lng +
  57. "&sensor=false" +
  58. "&language=ko" +
  59. "&region=KR" +
  60. "&key=" + staticMapsAPI;
  61. }
  62. }
  63. function searchAddress() {
  64. var address = document.getElementById('fm_address').value,
  65. geocoder = new google.maps.Geocoder();
  66. geocoder.geocode({'address' : address},
  67. function (results, status) {
  68. if (status === google.maps.GeocoderStatus.OK) {
  69. centerLat = results[0].geometry.location.lat();
  70. centerLng = results[0].geometry.location.lng();
  71. latlng = new google.maps.LatLng(centerLat, centerLng);
  72. map.setCenter(latlng);
  73. map.setZoom(setZoom);
  74. marker = new google.maps.Marker({ 'map': map, 'draggable': true, 'position': latlng,
  75. animation: google.maps.Animation.DROP});
  76. marker.setMap(map);
  77. }
  78. });
  79. }
  80. function initMap(zoom) {
  81. var mapOptions = {
  82. zoom: zoom || setZoom,
  83. panControl: true,
  84. zoomControl: true,
  85. scaleControl: true,
  86. center: new google.maps.LatLng(37.566, 126.977),
  87. disableDefaultUI: false,
  88. streetViewControl: true,
  89. mapTypeId: google.maps.MapTypeId.ROADMAP
  90. };
  91. map = new google.maps.Map(document.getElementById("map_canvas"), mapOptions);
  92. centerLat = map.getCenter().lat();
  93. centerLng = map.getCenter().lng();
  94. google.maps.event.addListener(map, 'dragend', function () {
  95. centerLat = map.getCenter().lat();
  96. centerLng = map.getCenter().lng();
  97. });
  98. google.maps.event.addListener(map, 'maptypeid_changed', function () {
  99. mapType = map.getMapTypeId();
  100. });
  101. google.maps.event.addListener(map, 'zoom_changed', function () {
  102. centerLat = map.getCenter().lat();
  103. centerLng = map.getCenter().lng();
  104. });
  105. panorama = map.getStreetView();
  106. google.maps.event.addListener(panorama, 'visible_changed', function () {
  107. panoramaVisible = panorama.getVisible();
  108. });
  109. }
  110. function popupClose() {
  111. oEditor.popupWinCancel();
  112. }
  113. function init(dialog) {
  114. oEditor = this;
  115. oEditor.dialog = dialog;
  116. var dlg = new Dialog(oEditor),
  117. button = [
  118. { alt : "", img : 'submit.gif', cmd : doSubmit },
  119. { alt : "", img : 'cancel.gif', cmd : popupClose }
  120. ],
  121. buttonUrl = oEditor.config.iconPath + 'button/map_address.gif',
  122. search = new Image();
  123. dlg.showButton(button);
  124. search.src = buttonUrl;
  125. search.onclick = function () {
  126. searchAddress();
  127. };
  128. search.className = 'button';
  129. document.getElementById('map_search').appendChild(search);
  130. dlg.setDialogHeight();
  131. }