map_events.html 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8">
  5. <title>
  6. Google Maps V3 API Events for google.maps.Map Demo
  7. </title>
  8. <style type="text/css">
  9. body {
  10. color: #585858;
  11. font-family: sans-serif;
  12. }
  13. table {
  14. border-spacing: 2px;
  15. text-align: left;
  16. }
  17. tr {
  18. background-color: white;
  19. -webkit-transition:background-color 0.2s linear;
  20. }
  21. #map-canvas {
  22. width: 600px;
  23. height: 400px;
  24. }
  25. #map {
  26. float: left;
  27. width: 650px;
  28. }
  29. #events {
  30. overflow: hidden;
  31. }
  32. </style>
  33. <script src="https://maps.google.com/maps/api/js?sensor=false"></script>
  34. <script type="text/javascript">
  35. var events = {
  36. 'bounds_changed': 'fired when the viewport bounds have changed.',
  37. 'center_changed': 'fired when the map center property changes.',
  38. 'click': 'fired when the user clicks on the map (but not when they click on a marker or infowindow).',
  39. 'dblclick': 'fired when the user double-clicks on the map. Note that the click event will also fire, right before this one.',
  40. 'drag': 'repeatedly fired while the user drags the map.',
  41. 'dragend': 'fired when the user stops dragging the map.',
  42. 'dragstart': 'fired when the user starts dragging the map.',
  43. 'heading_changed': 'fired when the map heading property changes.',
  44. 'idle': 'fired when the map becomes idle after panning or zooming.',
  45. 'maptypeid_changed': 'fired when the mapTypeId property changes.',
  46. 'mousemove': 'fired whenever the user\'s mouse moves over the map container.',
  47. 'mouseout': 'fired when the user\'s mouse exits the map container.',
  48. 'mouseover': 'fired when the user\'s mouse enters the map container.',
  49. 'projection_changed': 'fired when the projection has changed.',
  50. 'resize': 'Developers should trigger this event on the map when the div changes size: google.maps.event.trigger(map, \'resize\') .',
  51. 'rightclick': 'fired when the DOM contextmenu event is fired on the map container.',
  52. 'tilesloaded': 'fired when the visible tiles have finished loading.',
  53. 'tilt_changed': 'fired when the map tilt property changes.',
  54. 'zoom_changed': 'fired when the map zoom property changes.'
  55. };
  56. function setBackgroundColor(eventName, color) {
  57. var row = document.getElementById(eventName);
  58. row.style.backgroundColor = color;
  59. }
  60. function setupListener(map, name) {
  61. google.maps.event.addListener(map, name, function() {
  62. setBackgroundColor(name, '#99CCFF');
  63. setTimeout(function() {
  64. setBackgroundColor(name, 'white');
  65. }, 500);
  66. });
  67. }
  68. function initialize() {
  69. populateTable();
  70. var mapDiv = document.getElementById('map-canvas');
  71. var map = new google.maps.Map(mapDiv, {
  72. center: new google.maps.LatLng(37.4419, -122.1419),
  73. zoom: 13,
  74. mapTypeId: google.maps.MapTypeId.ROADMAP
  75. });
  76. var marker = new google.maps.Marker({position: new google.maps.LatLng(37.4419, -122.1419), map: map});
  77. for (eventName in events) {
  78. setupListener(map, eventName);
  79. }
  80. }
  81. // Dynamically create the table of events from the defined hashmap
  82. function populateTable() {
  83. var eventsTable = document.getElementById('event_descr');
  84. var content = '';
  85. for (var event in events) {
  86. content += '<tr id="' + event + '"> <th>' + event +
  87. '</th> <td> ' + events[event] + '</td></tr>';
  88. }
  89. eventsTable.innerHTML = content;
  90. }
  91. // Load the map
  92. google.maps.event.addDomListener(window, 'load', initialize);
  93. </script>
  94. </head>
  95. <body>
  96. <div id="main">
  97. <p>
  98. This page lists all the events that can be triggered for the
  99. <code>
  100. google.maps.Map
  101. </code>
  102. object and shows when that happens, by highlighting the names to the right.
  103. </p>
  104. </p>
  105. Play around with the map and see what happens.
  106. For more information check
  107. <a href="http://code.google.com/apis/maps/documentation/javascript/reference.html#Map">the API reference</a>.
  108. </p>
  109. <div id="map">
  110. <h2>
  111. Map
  112. </h2>
  113. <div id="map-canvas">
  114. </div>
  115. </div>
  116. <div id="events">
  117. <h2>
  118. Events
  119. </h2>
  120. <table width="100%" id="event_descr">
  121. </table>
  122. </div>
  123. </div>
  124. </div>
  125. </body>
  126. </html>