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