2013-01-23 18 views
0

我正在使用Google Map版本2。代碼是如下谷歌地圖沒有得到控制當lat/lng用於中心點而不是地理編碼時extjs/gmapanel

var smallGoogleMap = new Ext.ux.GMapPanel({ 
xtype: 'gmappanel', 
id : 'gSmallSiteMap', 
width:'100%', 
height:1000, 
zoomLevel: 10, 
gmapType: 'map', 
mapConfOpts: ['enableScrollWheelZoom','enableDoubleClickZoom','enableDragging'], 
mapControls: ['GSmallMapControl','GMapTypeControl','NonExistantControl'], 
setCenter: { 
    lat: latitude, 
    lng: longitude, 
    marker:{ title: newTitle} 
} 
}); 

如果我使用geoCodeAddr如setCenter下面所示比我上導致谷歌地圖但與上述代碼(緯度/經度),我失去控制得到控制。

setCenter: { 
    geoCodeAddr: newAdd, 
    marker:{ title: newTitle} 
} 

任何想法來解決這個問題?

回答

0

在Web上搜索後,我發現源代碼GMapPanel.js必須修改以獲得理想的結果。

原始的代碼小便這就需要修改爲如下

...... 
if (typeof this.addControl == 'object' && this.gmapType === 'map') { 
     this.gmap.addControl(this.addControl); 
    } 

    if (typeof this.setCenter === 'object') { 
     if (typeof this.setCenter.geoCodeAddr === 'string'){ 
      this.geoCodeLookup(this.setCenter.geoCodeAddr); 
     }else{ 
      if (this.gmapType === 'map'){ 
       point = new GLatLng(this.setCenter.lat,this.setCenter.lng); 
       this.gmap.setCenter(point, this.zoomLevel);  
      } 
      if (typeof this.setCenter.marker === 'object' && typeof point === 'object'){ 
       this.addMarker(point,this.setCenter.marker,this.setCenter.marker.clear); 
      } 
     } 
     if (this.gmapType === 'panorama'){ 
      this.gmap.setLocationAndPOV(new GLatLng(this.setCenter.lat,this.setCenter.lng), {yaw: this.yaw, pitch: this.pitch, zoom: this.zoom}); 
     } 
    } 
GEvent.bind(this.gmap, 'load', this, function(){ 
     this.onMapReady(); 
    }); 
}, 
onMapReady : function(){ 
    this.addMarkers(this.markers); 
    this.addMapControls(); 
    this.addOptions(); 
}, 
........ 

它具有如下修改

...... 
if (typeof this.addControl == 'object' && this.gmapType === 'map') { 
     this.gmap.addControl(this.addControl); 
    } 

    GEvent.bind(this.gmap, 'load', this, function(){ 
     this.onMapReady(); 
    }); 

    if (typeof this.setCenter === 'object') { 
     if (typeof this.setCenter.geoCodeAddr === 'string'){ 
      this.geoCodeLookup(this.setCenter.geoCodeAddr); 
     }else{ 
      if (this.gmapType === 'map'){ 
       point = new GLatLng(this.setCenter.lat,this.setCenter.lng); 
       this.gmap.setCenter(point, this.zoomLevel);  
      } 
      if (typeof this.setCenter.marker === 'object' && typeof point === 'object'){ 
       this.addMarker(point,this.setCenter.marker,this.setCenter.marker.clear); 
      } 
     } 
     if (this.gmapType === 'panorama'){ 
      this.gmap.setLocationAndPOV(new GLatLng(this.setCenter.lat,this.setCenter.lng), {yaw: this.yaw, pitch: this.pitch, zoom: this.zoom}); 
     } 
    } 

}, 
onMapReady : function(){ 
    this.addMarkers(this.markers); 
    this.addMapControls(); 
    this.addOptions(); 
}, 
........ 

我們之前setCenter設置爲獲得中移動「GEvent.bind」在地圖上的控件。

GEvent.bind(this.gmap, 'load', this, function(){ 
    this.onMapReady(); 
});