0

我正在为谷歌地图使用版本 2。代码如下

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}
}
});

如果我在 setCenter 中使用 geoCodeAddr,如下所示,我将获得对结果谷歌地图的控制,但使用上面的代码(lat/lng)我失去了控制。

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

有什么想法可以解决这个问题吗?

4

1 回答 1

0

好吧,在网上搜索后,我发现源代码 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();
});
于 2013-01-24T15:35:11.017 回答