GMapPanel.html 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  5. <title>The source code</title>
  6. <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
  7. <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
  8. <style type="text/css">
  9. .highlight { display: block; background-color: #ddd; }
  10. </style>
  11. <script type="text/javascript">
  12. function highlight() {
  13. document.getElementById(location.hash.replace(/#/, "")).className = "highlight";
  14. }
  15. </script>
  16. </head>
  17. <body onload="prettyPrint(); highlight();">
  18. <pre class="prettyprint lang-js"><span id='Ext-ux-GMapPanel'>/**
  19. </span> * @class Ext.ux.GMapPanel
  20. * @extends Ext.Panel
  21. * @author Shea Frederick
  22. */
  23. Ext.define('Ext.ux.GMapPanel', {
  24. extend: 'Ext.panel.Panel',
  25. alias: 'widget.gmappanel',
  26. requires: ['Ext.window.MessageBox'],
  27. initComponent : function(){
  28. Ext.applyIf(this,{
  29. plain: true,
  30. gmapType: 'map',
  31. border: false
  32. });
  33. this.callParent();
  34. },
  35. afterFirstLayout : function(){
  36. var center = this.center;
  37. this.callParent();
  38. if (center) {
  39. if (center.geoCodeAddr) {
  40. this.lookupCode(center.geoCodeAddr, center.marker);
  41. } else {
  42. this.createMap(center);
  43. }
  44. } else {
  45. Ext.Error.raise('center is required');
  46. }
  47. },
  48. createMap: function(center, marker) {
  49. options = Ext.apply({}, this.mapOptions);
  50. options = Ext.applyIf(options, {
  51. zoom: 14,
  52. center: center,
  53. mapTypeId: google.maps.MapTypeId.HYBRID
  54. });
  55. this.gmap = new google.maps.Map(this.body.dom, options);
  56. if (marker) {
  57. this.addMarker(Ext.applyIf(marker, {
  58. position: center
  59. }));
  60. }
  61. Ext.each(this.markers, this.addMarker, this);
  62. },
  63. addMarker: function(marker) {
  64. marker = Ext.apply({
  65. map: this.gmap
  66. }, marker);
  67. if (!marker.position) {
  68. marker.position = new google.maps.LatLng(marker.lat, marker.lng);
  69. }
  70. var o = new google.maps.Marker(marker);
  71. Ext.Object.each(marker.listeners, function(name, fn){
  72. google.maps.event.addListener(o, name, fn);
  73. });
  74. return o;
  75. },
  76. lookupCode : function(addr, marker) {
  77. this.geocoder = new google.maps.Geocoder();
  78. this.geocoder.geocode({
  79. address: addr
  80. }, Ext.Function.bind(this.onLookupComplete, this, [marker], true));
  81. },
  82. onLookupComplete: function(data, response, marker){
  83. if (response != 'OK') {
  84. Ext.MessageBox.alert('Error', 'An error occured: &quot;' + response + '&quot;');
  85. return;
  86. }
  87. this.createMap(data[0].geometry.location, marker);
  88. },
  89. afterComponentLayout : function(w, h){
  90. this.callParent(arguments);
  91. this.redraw();
  92. },
  93. redraw: function(){
  94. var map = this.gmap;
  95. if (map) {
  96. google.maps.event.trigger(map, 'resize');
  97. }
  98. }
  99. });
  100. </pre>
  101. </body>
  102. </html>