K_Reverter的网页开发记录

要么不做,要么就当作艺术品来做!

导航

Google Maps API 2.0解析(13-支持以前1.0版本的GMap)

        从现在开始继续Google Maps API的代码分析工作,继续原来的工作,不过需要注意到是,上次为什么停下来了呢,除了比较忙一点之外,还有一个重要的原因是,上次分析到GMapBase对象,也就是最核心的对象,对这个对象的分析一开始就遇到了比较多杂乱无章到无法看懂的代码,实在分析不下去,所以在深受打击之后停顿了一阵子,现在我觉得这个工作还是完成比较好,所以就继续下去,不过我这次从文件末尾开始分析,也就是说倒着来,等到倒着分析到GMapBase对象,基本上很多地方也就应该明白了,所以现在你看到的是文件最后的内容。

        //为了对以前的GMap进行支持,由GMapBase继承出一个GMap类
        function GMap(a,b,c,d)
        
{
            
if(c&&d)
            
{
                GMapBase.call(
this,a,b,new GSize(c,d))
            }

            
else
            
{
                GMapBase.call(
this,a,b)
            }

            addListener(
this,GEvent_zoomend,function(e,f)
            
{
                trigger(
this,GEvent_zoom,this.parseZoom(e),this.parseZoom(f))
            }

            )
        }

        InheritClass(GMap,GMapBase);
        
//支持旧版本的getCenterLatLng
        GMap.prototype.getCenterLatLng=function()
        
{
            
var a=this.getCenter();
            
return new GPoint(a.lng(),a.lat())
        }
;
        
//支持旧版本的getBoundsLatLng
        GMap.prototype.getBoundsLatLng=function()
        
{
            
var a=this.getBounds();
            
return new GBounds([a.getSouthWest(),a.getNorthEast()])
        }
;
        
//支持旧版本的getSpanLatLng
        GMap.prototype.getSpanLatLng=function()
        
{
            
var a=this.getBounds().toSpan();
            
return new GSize(a.lng(),a.lat())
        }
;
        
//支持旧版本的getZoom
        GMap.prototype.getZoomLevel=function()
        
{
            
return this.parseZoom(this.getZoom())
        }
;
        
//支持旧版本的setMapType
        GMap.prototype.setMapType=function(a)
        
{
            
if(this.isLoaded())
            
{
                GMapBase.prototype.setMapType.call(
this,a)
            }

            
else
            
{
                
this.mapType=a
            }

        }
;
        
//支持旧版本的centerAndZoom
        GMap.prototype.centerAndZoom=function(a,b)
        
{
            
var c=new GLatLng(a.y,a.x);
            
if(this.isLoaded())
            
{
                
var d=this.parseZoom(b);
                
this.setCenter(c,d)
            }

            
else
            
{
                
var e=this.mapType;
                
var d=this.parseZoom(b);
                
this.setCenter(c,d,e)
            }

        }
;
        
//支持旧版本的centerAtLatLng
        GMap.prototype.centerAtLatLng=function(a)
        
{
            
this.setCenter(new GLatLng(a.y,a.x))
        }
;
        
//支持旧版本的recenterOrPanToLatLng
        GMap.prototype.recenterOrPanToLatLng=function(a)
        
{
            
this.panTo(new GLatLng(a.y,a.x))
        }
;
        
//支持旧版本的zoomTo
        GMap.prototype.zoomTo=function(a)
        
{
            
this.setZoom(this.parseZoom(a))
        }
;
        
//支持旧版本的openInfoWindow
        GMap.prototype.openInfoWindow=function(a,b,c,d,e)
        
{
            
var f=new GLatLng(a.y,a.x);//将旧版本的GPoint转化为新的GLatLng
            var g=
            
{
                pixelOffset:c,onOpenFn:d,onCloseFn:e
            }
;
            GMapBase.prototype.openInfoWindow.call(
this,f,b,g)
        }
;
        
//支持旧版本的openInfoWindowHtml
        GMap.prototype.openInfoWindowHtml=function(a,b,c,d,e)
        
{
            
var f=new GLatLng(a.y,a.x);//将旧版本的GPoint转化为新的GLatLng
            var g=
            
{
                pixelOffset:c,onOpenFn:d,onCloseFn:e
            }
;
            GMapBase.prototype.openInfoWindowHtml.call(
this,f,b,g)
        }
;
        
//支持旧版本的showMapBlowup
        GMap.prototype.showMapBlowup=function(a,b,c,d,e,f)
        
{
            
var g=new GLatLng(a.y,a.x);//将旧版本的GPoint转化为新的GLatLng
            var h=
            
{
                mapType:c,pixelOffset:d,onOpenFn:e,onCloseFn:f,zoomLevel:
this.parseZoom(b)
            }
;
            GMapBase.prototype.showMapBlowup.call(
this,g,h)
        }
;
        
//将旧版本缩放等级转化为新版
        GMap.prototype.parseZoom=function(a)
        
{
            
if(typeof a=="number")
            
{
                
return 17-a
            }

            
else
            
{
                
return a
            }

        }
;
        (
            
function()
            
{
                setWindows(
"GMap",GMap);
                
var a=GMap.prototype;
                setPrototype(GMap,
"getCenterLatLng",a.getCenterLatLng);
                setPrototype(GMap,
"getBoundsLatLng",a.getBoundsLatLng);
                setPrototype(GMap,
"getSpanLatLng",a.getSpanLatLng);
                setPrototype(GMap,
"getZoomLevel",a.getZoomLevel);
                setPrototype(GMap,
"setMapType",a.setMapType);
                setPrototype(GMap,
"centerAtLatLng",a.centerAtLatLng);
                setPrototype(GMap,
"recenterOrPanToLatLng",a.recenterOrPanToLatLng);
                setPrototype(GMap,
"zoomTo",a.zoomTo);
                setPrototype(GMap,
"centerAndZoom",a.centerAndZoom);
                setPrototype(GMap,
"openInfoWindow",a.openInfoWindow);
                setPrototype(GMap,
"openInfoWindowHtml",a.openInfoWindowHtml);
                setPrototype(GMap,
"openInfoWindowXslt",nullFunction);
                setPrototype(GMap,
"showMapBlowup",a.showMapBlowup)
            }

        )();
        setPrototype(GMarker,
"openInfoWindowXslt",nullFunction);
        (
            
function()
            
{
                
function GXml()
                
{
                }

                setWindows(
"GXml",GXml);
                SetProperty(GXml,
"parse",parse);
                SetProperty(GXml,
"value",value);
                setWindows(
"GXslt",GXslt);
                setPrototype(GXslt,
"transformToHtml",GXslt.prototype.transformToHtml)
            }

        )();
        
//这个window.GLoad可以用来在页面上定义API加载完成之后运行的函数,不能用GEvent做事件绑定,因为GEvent定义的时候,实际上API已经加载完成了
        if(window.GLoad)
        
{
            window.GLoad()
        }
;

posted on 2006-08-18 16:47  K_Reverter  阅读(1226)  评论(0编辑  收藏  举报