Installer/Updater
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.

214 lines
6.5 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. /*!
  2. * Ext JS Library 3.3.1
  3. * Copyright(c) 2006-2010 Sencha Inc.
  4. * licensing@sencha.com
  5. * http://www.sencha.com/license
  6. */
  7. /**
  8. * @class Ext.ux.GMapPanel
  9. * @extends Ext.Panel
  10. * @author Shea Frederick
  11. */
  12. Ext.ux.GMapPanel = Ext.extend(Ext.Panel, {
  13. initComponent : function(){
  14. var defConfig = {
  15. plain: true,
  16. zoomLevel: 3,
  17. yaw: 180,
  18. pitch: 0,
  19. zoom: 0,
  20. gmapType: 'map',
  21. border: false
  22. };
  23. Ext.applyIf(this,defConfig);
  24. Ext.ux.GMapPanel.superclass.initComponent.call(this);
  25. },
  26. afterRender : function(){
  27. var wh = this.ownerCt.getSize();
  28. Ext.applyIf(this, wh);
  29. Ext.ux.GMapPanel.superclass.afterRender.call(this);
  30. if (this.gmapType === 'map'){
  31. this.gmap = new GMap2(this.body.dom);
  32. }
  33. if (this.gmapType === 'panorama'){
  34. this.gmap = new GStreetviewPanorama(this.body.dom);
  35. }
  36. if (typeof this.addControl == 'object' && this.gmapType === 'map') {
  37. this.gmap.addControl(this.addControl);
  38. }
  39. if (typeof this.setCenter === 'object') {
  40. if (typeof this.setCenter.geoCodeAddr === 'string'){
  41. this.geoCodeLookup(this.setCenter.geoCodeAddr);
  42. }else{
  43. if (this.gmapType === 'map'){
  44. var point = new GLatLng(this.setCenter.lat,this.setCenter.lng);
  45. this.gmap.setCenter(point, this.zoomLevel);
  46. }
  47. if (typeof this.setCenter.marker === 'object' && typeof point === 'object'){
  48. this.addMarker(point,this.setCenter.marker,this.setCenter.marker.clear);
  49. }
  50. }
  51. if (this.gmapType === 'panorama'){
  52. this.gmap.setLocationAndPOV(new GLatLng(this.setCenter.lat,this.setCenter.lng), {yaw: this.yaw, pitch: this.pitch, zoom: this.zoom});
  53. }
  54. }
  55. GEvent.bind(this.gmap, 'load', this, function(){
  56. this.onMapReady();
  57. });
  58. },
  59. onMapReady : function(){
  60. this.addMarkers(this.markers);
  61. this.addMapControls();
  62. this.addOptions();
  63. },
  64. onResize : function(w, h){
  65. if (typeof this.getMap() == 'object') {
  66. this.gmap.checkResize();
  67. }
  68. Ext.ux.GMapPanel.superclass.onResize.call(this, w, h);
  69. },
  70. setSize : function(width, height, animate){
  71. if (typeof this.getMap() == 'object') {
  72. this.gmap.checkResize();
  73. }
  74. Ext.ux.GMapPanel.superclass.setSize.call(this, width, height, animate);
  75. },
  76. getMap : function(){
  77. return this.gmap;
  78. },
  79. getCenter : function(){
  80. return this.getMap().getCenter();
  81. },
  82. getCenterLatLng : function(){
  83. var ll = this.getCenter();
  84. return {lat: ll.lat(), lng: ll.lng()};
  85. },
  86. addMarkers : function(markers) {
  87. if (Ext.isArray(markers)){
  88. for (var i = 0; i < markers.length; i++) {
  89. var mkr_point = new GLatLng(markers[i].lat,markers[i].lng);
  90. this.addMarker(mkr_point,markers[i].marker,false,markers[i].setCenter, markers[i].listeners);
  91. }
  92. }
  93. },
  94. addMarker : function(point, marker, clear, center, listeners){
  95. Ext.applyIf(marker,G_DEFAULT_ICON);
  96. if (clear === true){
  97. this.getMap().clearOverlays();
  98. }
  99. if (center === true) {
  100. this.getMap().setCenter(point, this.zoomLevel);
  101. }
  102. var mark = new GMarker(point,marker);
  103. if (typeof listeners === 'object'){
  104. for (evt in listeners) {
  105. GEvent.bind(mark, evt, this, listeners[evt]);
  106. }
  107. }
  108. this.getMap().addOverlay(mark);
  109. },
  110. addMapControls : function(){
  111. if (this.gmapType === 'map') {
  112. if (Ext.isArray(this.mapControls)) {
  113. for(i=0;i<this.mapControls.length;i++){
  114. this.addMapControl(this.mapControls[i]);
  115. }
  116. }else if(typeof this.mapControls === 'string'){
  117. this.addMapControl(this.mapControls);
  118. }else if(typeof this.mapControls === 'object'){
  119. this.getMap().addControl(this.mapControls);
  120. }
  121. }
  122. },
  123. addMapControl : function(mc){
  124. var mcf = window[mc];
  125. if (typeof mcf === 'function') {
  126. this.getMap().addControl(new mcf());
  127. }
  128. },
  129. addOptions : function(){
  130. if (Ext.isArray(this.mapConfOpts)) {
  131. var mc;
  132. for(i=0;i<this.mapConfOpts.length;i++){
  133. this.addOption(this.mapConfOpts[i]);
  134. }
  135. }else if(typeof this.mapConfOpts === 'string'){
  136. this.addOption(this.mapConfOpts);
  137. }
  138. },
  139. addOption : function(mc){
  140. var mcf = this.getMap()[mc];
  141. if (typeof mcf === 'function') {
  142. this.getMap()[mc]();
  143. }
  144. },
  145. geoCodeLookup : function(addr) {
  146. this.geocoder = new GClientGeocoder();
  147. this.geocoder.getLocations(addr, this.addAddressToMap.createDelegate(this));
  148. },
  149. addAddressToMap : function(response) {
  150. if (!response || response.Status.code != 200) {
  151. Ext.MessageBox.alert('Error', 'Code '+response.Status.code+' Error Returned');
  152. }else{
  153. place = response.Placemark[0];
  154. addressinfo = place.AddressDetails;
  155. accuracy = addressinfo.Accuracy;
  156. if (accuracy === 0) {
  157. Ext.MessageBox.alert('Unable to Locate Address', 'Unable to Locate the Address you provided');
  158. }else{
  159. if (accuracy < 7) {
  160. Ext.MessageBox.alert('Address Accuracy', 'The address provided has a low accuracy.<br><br>Level '+accuracy+' Accuracy (8 = Exact Match, 1 = Vague Match)');
  161. }else{
  162. point = new GLatLng(place.Point.coordinates[1], place.Point.coordinates[0]);
  163. if (typeof this.setCenter.marker === 'object' && typeof point === 'object'){
  164. this.addMarker(point,this.setCenter.marker,this.setCenter.marker.clear,true, this.setCenter.listeners);
  165. }
  166. }
  167. }
  168. }
  169. }
  170. });
  171. Ext.reg('gmappanel', Ext.ux.GMapPanel);