3 * Copyright(c) 2006-2010 Ext JS, LLC
5 * http://www.extjs.com/license
8 * @class Ext.ux.GMapPanel
\r
10 * @author Shea Frederick
\r
12 Ext.ux.GMapPanel = Ext.extend(Ext.Panel, {
\r
13 initComponent : function(){
\r
25 Ext.applyIf(this,defConfig);
\r
27 Ext.ux.GMapPanel.superclass.initComponent.call(this);
\r
30 afterRender : function(){
\r
32 var wh = this.ownerCt.getSize();
\r
33 Ext.applyIf(this, wh);
\r
35 Ext.ux.GMapPanel.superclass.afterRender.call(this);
\r
37 if (this.gmapType === 'map'){
\r
38 this.gmap = new GMap2(this.body.dom);
\r
41 if (this.gmapType === 'panorama'){
\r
42 this.gmap = new GStreetviewPanorama(this.body.dom);
\r
45 if (typeof this.addControl == 'object' && this.gmapType === 'map') {
\r
46 this.gmap.addControl(this.addControl);
\r
49 if (typeof this.setCenter === 'object') {
\r
50 if (typeof this.setCenter.geoCodeAddr === 'string'){
\r
51 this.geoCodeLookup(this.setCenter.geoCodeAddr);
\r
53 if (this.gmapType === 'map'){
\r
54 var point = new GLatLng(this.setCenter.lat,this.setCenter.lng);
\r
55 this.gmap.setCenter(point, this.zoomLevel);
\r
57 if (typeof this.setCenter.marker === 'object' && typeof point === 'object'){
\r
58 this.addMarker(point,this.setCenter.marker,this.setCenter.marker.clear);
\r
61 if (this.gmapType === 'panorama'){
\r
62 this.gmap.setLocationAndPOV(new GLatLng(this.setCenter.lat,this.setCenter.lng), {yaw: this.yaw, pitch: this.pitch, zoom: this.zoom});
\r
66 GEvent.bind(this.gmap, 'load', this, function(){
\r
71 onMapReady : function(){
\r
72 this.addMarkers(this.markers);
\r
73 this.addMapControls();
\r
76 onResize : function(w, h){
\r
78 if (typeof this.getMap() == 'object') {
\r
79 this.gmap.checkResize();
\r
82 Ext.ux.GMapPanel.superclass.onResize.call(this, w, h);
\r
85 setSize : function(width, height, animate){
\r
87 if (typeof this.getMap() == 'object') {
\r
88 this.gmap.checkResize();
\r
91 Ext.ux.GMapPanel.superclass.setSize.call(this, width, height, animate);
\r
94 getMap : function(){
\r
99 getCenter : function(){
\r
101 return this.getMap().getCenter();
\r
104 getCenterLatLng : function(){
\r
106 var ll = this.getCenter();
\r
107 return {lat: ll.lat(), lng: ll.lng()};
\r
110 addMarkers : function(markers) {
\r
112 if (Ext.isArray(markers)){
\r
113 for (var i = 0; i < markers.length; i++) {
\r
114 var mkr_point = new GLatLng(markers[i].lat,markers[i].lng);
\r
115 this.addMarker(mkr_point,markers[i].marker,false,markers[i].setCenter, markers[i].listeners);
\r
120 addMarker : function(point, marker, clear, center, listeners){
\r
122 Ext.applyIf(marker,G_DEFAULT_ICON);
\r
124 if (clear === true){
\r
125 this.getMap().clearOverlays();
\r
127 if (center === true) {
\r
128 this.getMap().setCenter(point, this.zoomLevel);
\r
131 var mark = new GMarker(point,marker);
\r
132 if (typeof listeners === 'object'){
\r
133 for (evt in listeners) {
\r
134 GEvent.bind(mark, evt, this, listeners[evt]);
\r
137 this.getMap().addOverlay(mark);
\r
140 addMapControls : function(){
\r
142 if (this.gmapType === 'map') {
\r
143 if (Ext.isArray(this.mapControls)) {
\r
144 for(i=0;i<this.mapControls.length;i++){
\r
145 this.addMapControl(this.mapControls[i]);
\r
147 }else if(typeof this.mapControls === 'string'){
\r
148 this.addMapControl(this.mapControls);
\r
149 }else if(typeof this.mapControls === 'object'){
\r
150 this.getMap().addControl(this.mapControls);
\r
155 addMapControl : function(mc){
\r
157 var mcf = window[mc];
\r
158 if (typeof mcf === 'function') {
\r
159 this.getMap().addControl(new mcf());
\r
163 addOptions : function(){
\r
165 if (Ext.isArray(this.mapConfOpts)) {
\r
167 for(i=0;i<this.mapConfOpts.length;i++){
\r
168 this.addOption(this.mapConfOpts[i]);
\r
170 }else if(typeof this.mapConfOpts === 'string'){
\r
171 this.addOption(this.mapConfOpts);
\r
175 addOption : function(mc){
\r
177 var mcf = this.getMap()[mc];
\r
178 if (typeof mcf === 'function') {
\r
179 this.getMap()[mc]();
\r
183 geoCodeLookup : function(addr) {
\r
185 this.geocoder = new GClientGeocoder();
\r
186 this.geocoder.getLocations(addr, this.addAddressToMap.createDelegate(this));
\r
189 addAddressToMap : function(response) {
\r
191 if (!response || response.Status.code != 200) {
\r
192 Ext.MessageBox.alert('Error', 'Code '+response.Status.code+' Error Returned');
\r
194 place = response.Placemark[0];
\r
195 addressinfo = place.AddressDetails;
\r
196 accuracy = addressinfo.Accuracy;
\r
197 if (accuracy === 0) {
\r
198 Ext.MessageBox.alert('Unable to Locate Address', 'Unable to Locate the Address you provided');
\r
200 if (accuracy < 7) {
\r
201 Ext.MessageBox.alert('Address Accuracy', 'The address provided has a low accuracy.<br><br>Level '+accuracy+' Accuracy (8 = Exact Match, 1 = Vague Match)');
\r
203 point = new GLatLng(place.Point.coordinates[1], place.Point.coordinates[0]);
\r
204 if (typeof this.setCenter.marker === 'object' && typeof point === 'object'){
\r
205 this.addMarker(point,this.setCenter.marker,this.setCenter.marker.clear,true, this.setCenter.listeners);
\r
215 Ext.reg('gmappanel', Ext.ux.GMapPanel);