2 * Ext JS Library 2.2.1
\r
3 * Copyright(c) 2006-2009, Ext JS, LLC.
\r
4 * licensing@extjs.com
\r
6 * http://extjs.com/license
\r
10 * @author Shea Frederick
\r
13 Ext.namespace('Ext.ux');
\r
18 * @extends Ext.Panel
\r
20 Ext.ux.GMapPanel = Ext.extend(Ext.Panel, {
\r
21 initComponent : function(){
\r
33 Ext.applyIf(this,defConfig);
\r
35 Ext.ux.GMapPanel.superclass.initComponent.call(this);
\r
38 afterRender : function(){
\r
40 var wh = this.ownerCt.getSize();
\r
41 Ext.applyIf(this, wh);
\r
43 Ext.ux.GMapPanel.superclass.afterRender.call(this);
\r
45 if (this.gmapType === 'map'){
\r
46 this.gmap = new GMap2(this.body.dom);
\r
49 if (this.gmapType === 'panorama'){
\r
50 this.gmap = new GStreetviewPanorama(this.body.dom);
\r
53 if (typeof this.addControl == 'object' && this.gmapType === 'map') {
\r
54 this.gmap.addControl(this.addControl);
\r
57 if (typeof this.setCenter === 'object') {
\r
58 if (typeof this.setCenter.geoCodeAddr === 'string'){
\r
59 this.geoCodeLookup(this.setCenter.geoCodeAddr);
\r
61 if (this.gmapType === 'map'){
\r
62 var point = new GLatLng(this.setCenter.lat,this.setCenter.lng);
\r
63 this.gmap.setCenter(point, this.zoomLevel);
\r
65 if (typeof this.setCenter.marker === 'object' && typeof point === 'object'){
\r
66 this.addMarker(point,this.setCenter.marker,this.setCenter.marker.clear);
\r
69 if (this.gmapType === 'panorama'){
\r
70 this.gmap.setLocationAndPOV(new GLatLng(this.setCenter.lat,this.setCenter.lng), {yaw: this.yaw, pitch: this.pitch, zoom: this.zoom});
\r
74 GEvent.bind(this.gmap, 'load', this, function(){
\r
79 onMapReady : function(){
\r
80 this.addMarkers(this.markers);
\r
81 this.addMapControls();
\r
84 onResize : function(w, h){
\r
86 if (typeof this.getMap() == 'object') {
\r
87 this.gmap.checkResize();
\r
90 Ext.ux.GMapPanel.superclass.onResize.call(this, w, h);
\r
93 setSize : function(width, height, animate){
\r
95 if (typeof this.getMap() == 'object') {
\r
96 this.gmap.checkResize();
\r
99 Ext.ux.GMapPanel.superclass.setSize.call(this, width, height, animate);
\r
102 getMap : function(){
\r
107 getCenter : function(){
\r
109 return this.getMap().getCenter();
\r
112 getCenterLatLng : function(){
\r
114 var ll = this.getCenter();
\r
115 return {lat: ll.lat(), lng: ll.lng()};
\r
118 addMarkers : function(markers) {
\r
120 if (Ext.isArray(markers)){
\r
121 for (var i = 0; i < markers.length; i++) {
\r
122 var mkr_point = new GLatLng(markers[i].lat,markers[i].lng);
\r
123 this.addMarker(mkr_point,markers[i].marker,false,markers[i].setCenter, markers[i].listeners);
\r
128 addMarker : function(point, marker, clear, center, listeners){
\r
130 Ext.applyIf(marker,G_DEFAULT_ICON);
\r
132 if (clear === true){
\r
133 this.getMap().clearOverlays();
\r
135 if (center === true) {
\r
136 this.getMap().setCenter(point, this.zoomLevel);
\r
139 var mark = new GMarker(point,marker);
\r
140 if (typeof listeners === 'object'){
\r
141 for (evt in listeners) {
\r
142 GEvent.bind(mark, evt, this, listeners[evt]);
\r
145 this.getMap().addOverlay(mark);
\r
148 addMapControls : function(){
\r
150 if (this.gmapType === 'map') {
\r
151 if (Ext.isArray(this.mapControls)) {
\r
152 for(i=0;i<this.mapControls.length;i++){
\r
153 this.addMapControl(this.mapControls[i]);
\r
155 }else if(typeof this.mapControls === 'string'){
\r
156 this.addMapControl(this.mapControls);
\r
157 }else if(typeof this.mapControls === 'object'){
\r
158 this.getMap().addControl(this.mapControls);
\r
163 addMapControl : function(mc){
\r
165 var mcf = window[mc];
\r
166 if (typeof mcf === 'function') {
\r
167 this.getMap().addControl(new mcf());
\r
171 addOptions : function(){
\r
173 if (Ext.isArray(this.mapConfOpts)) {
\r
175 for(i=0;i<this.mapConfOpts.length;i++){
\r
176 this.addOption(this.mapConfOpts[i]);
\r
178 }else if(typeof this.mapConfOpts === 'string'){
\r
179 this.addOption(this.mapConfOpts);
\r
183 addOption : function(mc){
\r
185 var mcf = this.getMap()[mc];
\r
186 if (typeof mcf === 'function') {
\r
187 this.getMap()[mc]();
\r
191 geoCodeLookup : function(addr) {
\r
193 this.geocoder = new GClientGeocoder();
\r
194 this.geocoder.getLocations(addr, this.addAddressToMap.createDelegate(this));
\r
197 addAddressToMap : function(response) {
\r
199 if (!response || response.Status.code != 200) {
\r
200 Ext.MessageBox.alert('Error', 'Code '+response.Status.code+' Error Returned');
\r
202 place = response.Placemark[0];
\r
203 addressinfo = place.AddressDetails;
\r
204 accuracy = addressinfo.Accuracy;
\r
205 if (accuracy === 0) {
\r
206 Ext.MessageBox.alert('Unable to Locate Address', 'Unable to Locate the Address you provided');
\r
208 if (accuracy < 7) {
\r
209 Ext.MessageBox.alert('Address Accuracy', 'The address provided has a low accuracy.<br><br>Level '+accuracy+' Accuracy (8 = Exact Match, 1 = Vague Match)');
\r
211 point = new GLatLng(place.Point.coordinates[1], place.Point.coordinates[0]);
\r
212 if (typeof this.setCenter.marker === 'object' && typeof point === 'object'){
\r
213 this.addMarker(point,this.setCenter.marker,this.setCenter.marker.clear,true, this.setCenter.listeners);
\r
223 Ext.reg('gmappanel',Ext.ux.GMapPanel);