K_Reverter的网页开发记录

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

导航

Google Maps API的库JS文件分析(3)

        在Google Maps API提供的JS文件中,引用了一个后台的JS库文件,该文件针对不同的浏览器有三个版本,这几天因为我想给我的Google Map扩展一些功能,所以研究了这个文件,我现在正打算陆续将我注释过的该文件放在网上,该文件一共有7000多行,我会分段渐渐的注释出来,我是按照分类注释的,所以并不会按照该JS文件顺序。

        该文件Google作了处理,所有的变量名都被处理成了简单的a,b,c,d之类,所以理解起来比较费劲。

        该JS文件是以IE版本的http://maps.google.com/mapfiles/maps.21.js来分析的,其他的几个我觉得基本的架构也应该差不多,所以我没有仔细看,实际上,这个文件Google也会不停的更新(在我写这个文章的时候,我发现Google已经更新到maps.25.js了),不过我想架构上也不会有太大的变动吧。

        由于该文件是在比较复杂,所以难免会出现理解错误的情况,请谅解!

        下面是第三个(这是地图图片创建与处理的代码):

  1//img图片控件的类
  2    function ma()
  3    {
  4    }

  5//创建img图片控件的方法,参数分别为:
  6//a    图片的路径
  7//b    图片的宽度
  8//c    图片的高度
  9//d    图片的左位置style.left
 10//e    图片的上位置style.left
 11//f    图片的z-index属性
 12//i    i为true时,固定图片大小,i为false时,将拉伸图片
 13//g    图片的附加样式,比如noscreen
 14//h    document或其他用来创建img标签的对象
 15//m    自定义的创建img标签的函数,用a,i,h作参数
 16    ma.create=function(a,b,c,d,e,f,i,g,h,m)
 17    {
 18        var o;
 19        h=h||document;
 20        if(!m)
 21        {
 22            o=h.createElement("img");
 23            if(a)
 24            {
 25                o.src=a
 26            }

 27        }

 28        else
 29        {
 30            o=m(a,i,h)
 31        }

 32        if(b&&c)
 33        {
 34            o.style.width=k(b);
 35            o.style.height=k(c);
 36            o.width=b;
 37            o.height=c;
 38        }

 39        if(e||(d||(e==0||d==0)))
 40        {
 41            o.style.position="absolute";
 42            o.style.left=k(d);
 43            o.style.top=k(e)
 44        }

 45        if(f||f==0)
 46        {
 47            o.style.zIndex=f
 48        }

 49        if(t.type==1)
 50        {
 51            o.unselectable="on";
 52            o.onselectstart=Za    //返回false
 53        }

 54        else
 55        {
 56            o.style.MozUserSelect="none"
 57        }

 58        if(t.type==1)
 59        {
 60            o.galleryImg="no"    //不显示"My Pictures"图片工具栏
 61        }

 62        o.style.border="0";
 63        o.style.padding="0";
 64        o.style.margin="0";
 65        o.oncontextmenu=Za;    //返回false
 66        if(g)
 67        {
 68            Aa(o,g)
 69        }

 70        return o
 71    }
;
 72//img扩展图片控件的类
 73    function n()
 74    {
 75    }

 76//创建img图片控件的方法,参数说明参照ma,使用了自定义的createElement方法
 77    n.create=function(a,b,c,d,e,f,i,g,h)
 78    {
 79        return ma.create(a,b,c,d,e,f,i,g,h,n.createElement)
 80    }
;
 81//自定义的createElement方法,参数如下
 82//a    图片的路径
 83//b    i为true时,固定图片大小,i为false时,将拉伸图片
 84//c    document或其他用来创建img标签的对象
 85    n.createElement=function(a,b,c)
 86    {
 87        //定义hasFilters属性
 88        if(typeof arguments.callee.hasFilters=="undefined")
 89        {
 90            var d=document.createElement("div");
 91            arguments.callee.hasFilters=typeof d.style.filter!="undefined"
 92        }

 93        var e;
 94        if(arguments.callee.hasFilters)
 95        {
 96            //PNG_cache是没有图片的时候在该位置显示的一个替代层
 97            var f=c.PNG_cache;
 98            if(f&&f.childNodes.length>0)
 99            {
100                e=f.removeChild(f.lastChild)
101            }

102            else
103            {
104                e=c.createElement("div");
105                e.style.fontSize=k(1);
106                n.destroyBeforeUnload(e)    //在窗口退出时执行清理图片占用内存的任务
107            }

108            if(!e.loader)
109            {
110                e.loader=c.createElement("img");
111                e.loader.style.visibility="hidden";
112                e.loader.onload=function()    //在图片加载完成之后显示图片
113                {
114                    if(!e.cleared)
115                    {
116                        e.style.filter=n.alphaImageLoader(this.src,this.ieCrop);    //后台加载图片
117                        e.src=a
118                    }

119                }

120            }

121        }

122        else
123        {
124            e=c.createElement("img")
125        }

126        n.setImage(e,a,b);    设置图片加载路径
127        return e
128    }
;
129//生成后台加载图片的filter字符串
130    n.alphaImageLoader=function(a,b)
131    {
132        var c="DXImageTransform.Microsoft.AlphaImageLoader";
133        var d=",sizingMethod="+(b?"crop":"scale");
134        return"progid:"+c+'(src="'+a+'"'+d+")"
135    }
;
136//删除图片,a是待删除的图片,b是document对象
137    n.remove=function(a,b)
138    {
139        if(a.nodeName=="DIV")
140        {
141            if(!b.PNG_cache)
142            {
143                b.PNG_cache=b.createElement("div");
144                b.PNG_cache.style.display="none";
145                b.body.appendChild(b.PNG_cache)
146            }

147            b.PNG_cache.appendChild(a);
148            n.clearImage(a)
149        }

150        else
151        {
152            a.parentNode.removeChild(a)
153        }

154    }
;
155    //设置图片a的属性,b是图片路径,c可参考createElement的c参数
156    n.setImage=function(a,b,c)
157    {
158        if(a.tagName=="DIV")
159        {
160            a.cleared=false;
161            a.loader.ieCrop=c||false;
162            a.loader.src=b
163        }

164        else
165        {
166            a.src=b
167        }

168    }
;
169//清空图片a,假如设置了b(空图片的路径),则将a路径设置为b
170    n.clearImage=function(a,b)
171    {
172        if(a.tagName=="DIV")
173        {
174            a.cleared=true;
175            a.style.filter=""
176        }

177        else
178        {
179            a.src=b
180        }

181    }
;
182//设置在窗口退出时执行清理图片占用内存的任务
183    n.destroyBeforeUnload=function(a)
184    {
185        if(!n.cleanupQueue)
186        {
187            n.cleanupQueue=[];
188            j.addBuiltInListener(window,"unload",n.onUnload)
189        }

190        n.cleanupQueue.push(a)
191    }
;
192//执行清理图片占用内存的任务
193    n.onUnload=function()
194    {
195        for(var a=0;a<n.cleanupQueue.length;++a)
196        {
197            n.destroyImage(n.cleanupQueue[a])
198        }

199    }
;
200//清理图片占用内存
201    n.destroyImage=function(a)
202    {
203        if(a.loader)
204        {
205            a.loader.onload=null;
206            a.loader=null
207        }

208    }
;

posted on 2005-10-19 10:54  K_Reverter  阅读(605)  评论(0编辑  收藏  举报