2 * @class Ext.ux.GMapPanel
4 * @author Shea Frederick
6 Ext.define('Ext.ux.GMapPanel', {
9 alias: 'widget.gmappanel',
11 requires: ['Ext.window.MessageBox'],
13 initComponent : function(){
25 Ext.applyIf(this,defConfig);
30 afterRender : function(){
32 var wh = this.ownerCt.getSize(),
35 Ext.applyIf(this, wh);
39 if (this.gmapType === 'map'){
40 this.gmap = new GMap2(this.body.dom);
43 if (this.gmapType === 'panorama'){
44 this.gmap = new GStreetviewPanorama(this.body.dom);
47 if (typeof this.addControl == 'object' && this.gmapType === 'map') {
48 this.gmap.addControl(this.addControl);
51 if (typeof this.setCenter === 'object') {
52 if (typeof this.setCenter.geoCodeAddr === 'string'){
53 this.geoCodeLookup(this.setCenter.geoCodeAddr);
55 if (this.gmapType === 'map'){
56 point = new GLatLng(this.setCenter.lat,this.setCenter.lng);
57 this.gmap.setCenter(point, this.zoomLevel);
59 if (typeof this.setCenter.marker === 'object' && typeof point === 'object'){
60 this.addMarker(point,this.setCenter.marker,this.setCenter.marker.clear);
63 if (this.gmapType === 'panorama'){
64 this.gmap.setLocationAndPOV(new GLatLng(this.setCenter.lat,this.setCenter.lng), {yaw: this.yaw, pitch: this.pitch, zoom: this.zoom});
68 GEvent.bind(this.gmap, 'load', this, function(){
73 onMapReady : function(){
74 this.addMarkers(this.markers);
75 this.addMapControls();
78 afterComponentLayout : function(w, h){
80 if (typeof this.getMap() == 'object') {
81 this.gmap.checkResize();
84 this.callParent(arguments);
87 setSize : function(width, height, animate){
89 if (typeof this.getMap() == 'object') {
90 this.gmap.checkResize();
93 this.callParent(arguments);
101 getCenter : function(){
103 return this.getMap().getCenter();
106 getCenterLatLng : function(){
108 var ll = this.getCenter();
109 return {lat: ll.lat(), lng: ll.lng()};
112 addMarkers : function(markers) {
114 if (Ext.isArray(markers)){
115 for (var i = 0; i < markers.length; i++) {
116 var mkr_point = new GLatLng(markers[i].lat,markers[i].lng);
117 this.addMarker(mkr_point,markers[i].marker,false,markers[i].setCenter, markers[i].listeners);
122 addMarker : function(point, marker, clear, center, listeners){
124 Ext.applyIf(marker,G_DEFAULT_ICON);
127 this.getMap().clearOverlays();
129 if (center === true) {
130 this.getMap().setCenter(point, this.zoomLevel);
133 var mark = new GMarker(point,marker);
134 if (typeof listeners === 'object'){
135 for (evt in listeners) {
136 if (!listeners.hasOwnProperty(evt)) {
139 GEvent.bind(mark, evt, this, listeners[evt]);
142 this.getMap().addOverlay(mark);
145 addMapControls : function(){
147 if (this.gmapType === 'map') {
148 if (Ext.isArray(this.mapControls)) {
149 for(var i=0;i<this.mapControls.length;i++){
150 this.addMapControl(this.mapControls[i]);
152 }else if(typeof this.mapControls === 'string'){
153 this.addMapControl(this.mapControls);
154 }else if(typeof this.mapControls === 'object'){
155 this.getMap().addControl(this.mapControls);
160 addMapControl : function(mc){
162 var mcf = window[mc];
163 if (typeof mcf === 'function') {
164 this.getMap().addControl(new mcf());
168 addOptions : function(){
170 if (Ext.isArray(this.mapConfOpts)) {
171 for(var i=0;i<this.mapConfOpts.length;i++){
172 this.addOption(this.mapConfOpts[i]);
174 }else if(typeof this.mapConfOpts === 'string'){
175 this.addOption(this.mapConfOpts);
179 addOption : function(mc){
181 var mcf = this.getMap()[mc];
182 if (typeof mcf === 'function') {
187 geoCodeLookup : function(addr) {
189 this.geocoder = new GClientGeocoder();
190 this.geocoder.getLocations(addr, Ext.Function.bind(this.addAddressToMap, this));
193 addAddressToMap : function(response) {
194 var place, addressinfo, accuracy, point;
195 if (!response || response.Status.code != 200) {
196 Ext.MessageBox.alert('Error', 'Code '+response.Status.code+' Error Returned');
198 place = response.Placemark[0];
199 addressinfo = place.AddressDetails;
200 accuracy = addressinfo.Accuracy;
201 if (accuracy === 0) {
202 Ext.MessageBox.alert('Unable to Locate Address', 'Unable to Locate the Address you provided');
205 Ext.MessageBox.alert('Address Accuracy', 'The address provided has a low accuracy.<br><br>Level '+accuracy+' Accuracy (8 = Exact Match, 1 = Vague Match)');
207 point = new GLatLng(place.Point.coordinates[1], place.Point.coordinates[0]);
208 if (typeof this.setCenter.marker === 'object' && typeof point === 'object'){
209 this.addMarker(point,this.setCenter.marker,this.setCenter.marker.clear,true, this.setCenter.listeners);