3 This file is part of Ext JS 4
5 Copyright (c) 2011 Sencha Inc
7 Contact: http://www.sencha.com/contact
9 GNU General Public License Usage
10 This file may be used under the terms of the GNU General Public License version 3.0 as published by the Free Software Foundation and appearing in the file LICENSE included in the packaging of this file. Please review the following information to ensure the GNU General Public License version 3.0 requirements will be met: http://www.gnu.org/copyleft/gpl.html.
12 If you are unsure which license is appropriate for your use, please contact the sales department at http://www.sencha.com/contact.
16 * @class Ext.ux.GMapPanel
18 * @author Shea Frederick
20 Ext.define('Ext.ux.GMapPanel', {
23 alias: 'widget.gmappanel',
25 requires: ['Ext.window.MessageBox'],
27 initComponent : function(){
39 Ext.applyIf(this,defConfig);
44 afterRender : function(){
46 var wh = this.ownerCt.getSize(),
49 Ext.applyIf(this, wh);
53 if (this.gmapType === 'map'){
54 this.gmap = new GMap2(this.body.dom);
57 if (this.gmapType === 'panorama'){
58 this.gmap = new GStreetviewPanorama(this.body.dom);
61 if (typeof this.addControl == 'object' && this.gmapType === 'map') {
62 this.gmap.addControl(this.addControl);
65 if (typeof this.setCenter === 'object') {
66 if (typeof this.setCenter.geoCodeAddr === 'string'){
67 this.geoCodeLookup(this.setCenter.geoCodeAddr);
69 if (this.gmapType === 'map'){
70 point = new GLatLng(this.setCenter.lat,this.setCenter.lng);
71 this.gmap.setCenter(point, this.zoomLevel);
73 if (typeof this.setCenter.marker === 'object' && typeof point === 'object'){
74 this.addMarker(point,this.setCenter.marker,this.setCenter.marker.clear);
77 if (this.gmapType === 'panorama'){
78 this.gmap.setLocationAndPOV(new GLatLng(this.setCenter.lat,this.setCenter.lng), {yaw: this.yaw, pitch: this.pitch, zoom: this.zoom});
82 GEvent.bind(this.gmap, 'load', this, function(){
87 onMapReady : function(){
88 this.addMarkers(this.markers);
89 this.addMapControls();
92 afterComponentLayout : function(w, h){
94 if (typeof this.getMap() == 'object') {
95 this.gmap.checkResize();
98 this.callParent(arguments);
101 setSize : function(width, height, animate){
103 if (typeof this.getMap() == 'object') {
104 this.gmap.checkResize();
107 this.callParent(arguments);
115 getCenter : function(){
117 return this.getMap().getCenter();
120 getCenterLatLng : function(){
122 var ll = this.getCenter();
123 return {lat: ll.lat(), lng: ll.lng()};
126 addMarkers : function(markers) {
128 if (Ext.isArray(markers)){
129 for (var i = 0; i < markers.length; i++) {
130 var mkr_point = new GLatLng(markers[i].lat,markers[i].lng);
131 this.addMarker(mkr_point,markers[i].marker,false,markers[i].setCenter, markers[i].listeners);
136 addMarker : function(point, marker, clear, center, listeners){
138 Ext.applyIf(marker,G_DEFAULT_ICON);
141 this.getMap().clearOverlays();
143 if (center === true) {
144 this.getMap().setCenter(point, this.zoomLevel);
147 var mark = new GMarker(point,marker);
148 if (typeof listeners === 'object'){
149 for (evt in listeners) {
150 if (!listeners.hasOwnProperty(evt)) {
153 GEvent.bind(mark, evt, this, listeners[evt]);
156 this.getMap().addOverlay(mark);
159 addMapControls : function(){
161 if (this.gmapType === 'map') {
162 if (Ext.isArray(this.mapControls)) {
163 for(var i=0;i<this.mapControls.length;i++){
164 this.addMapControl(this.mapControls[i]);
166 }else if(typeof this.mapControls === 'string'){
167 this.addMapControl(this.mapControls);
168 }else if(typeof this.mapControls === 'object'){
169 this.getMap().addControl(this.mapControls);
174 addMapControl : function(mc){
176 var mcf = window[mc];
177 if (typeof mcf === 'function') {
178 this.getMap().addControl(new mcf());
182 addOptions : function(){
184 if (Ext.isArray(this.mapConfOpts)) {
185 for(var i=0;i<this.mapConfOpts.length;i++){
186 this.addOption(this.mapConfOpts[i]);
188 }else if(typeof this.mapConfOpts === 'string'){
189 this.addOption(this.mapConfOpts);
193 addOption : function(mc){
195 var mcf = this.getMap()[mc];
196 if (typeof mcf === 'function') {
201 geoCodeLookup : function(addr) {
203 this.geocoder = new GClientGeocoder();
204 this.geocoder.getLocations(addr, Ext.Function.bind(this.addAddressToMap, this));
207 addAddressToMap : function(response) {
208 var place, addressinfo, accuracy, point;
209 if (!response || response.Status.code != 200) {
210 Ext.MessageBox.alert('Error', 'Code '+response.Status.code+' Error Returned');
212 place = response.Placemark[0];
213 addressinfo = place.AddressDetails;
214 accuracy = addressinfo.Accuracy;
215 if (accuracy === 0) {
216 Ext.MessageBox.alert('Unable to Locate Address', 'Unable to Locate the Address you provided');
219 Ext.MessageBox.alert('Address Accuracy', 'The address provided has a low accuracy.<br><br>Level '+accuracy+' Accuracy (8 = Exact Match, 1 = Vague Match)');
221 point = new GLatLng(place.Point.coordinates[1], place.Point.coordinates[0]);
222 if (typeof this.setCenter.marker === 'object' && typeof point === 'object'){
223 this.addMarker(point,this.setCenter.marker,this.setCenter.marker.clear,true, this.setCenter.listeners);