Google Maps API 2.0解析(16-GLog进行输出和调试的类)

        这是API2.0的新类,这次2.0对开发过程进行了许多优化,这个是其中一个功能。
         // 实际就是GLog类的底层实现
         function  GLogBase()
        
{
            
var a=CreateElement("div",document.body);
            
var b=a.style;
            b.position
="absolute";
            b.left
=GetPixelValue(7);
            b.bottom
=GetPixelValue(4);
            b.zIndex
=10000;
            
var c=CreateLogDiv(a,new GPoint(2,2));
            
var d=CreateElement("div",a);
            b
=d.style;
            b.position
="relative";
            b.zIndex
=1;
            b.fontFamily
="VerdaGEvent_moveend,Arial,sans-serif";
            b.fontSize
="small";
            b.border
="1px solid black";
            
var e=[["Clear",this.clear],["Close",this.close]];//定义按钮名称和点击事件
            var f=CreateElement("div",d);
            b
=f.style;
            b.position
="relative";
            b.zIndex
=2;
            b.backgroundColor
="#979797";
            b.color
="white";
            b.fontSize
="85%";
            b.padding
=GetPixelValue(2);
            setCursor(f,
"default");
            SetUnSelectable(f);
            CreateTextNode(
"Log",f);
            
for(var g=0;g<e.length;g++)
            
{
                
var h=e[g];
                CreateTextNode(
" - ",f);
                
var i=CreateElement("span",f);
                i.style.textDecoration
="underline";
                CreateTextNode(h[
0],i);//按钮名称
                bindClick(i,this,h[1]);//按钮事件
                setCursor(i,"pointer")
            }

            bindDom(f,GEvent_mousedown,
this,this.onMouseDown);
            
var l=CreateElement("div",d);
            b
=l.style;
            b.backgroundColor
="white";
            b.width
=GetEMValue(24);
            b.height
=GetEMValue(10);
            
if(browser.isFirefox())
            
{
                b.overflow
="-moz-scrollbars-vertical"
            }

            
else
            
{
                b.overflow
="auto"
            }

            addDomListener(l,GEvent_mousedown,CancelEventBubble);
            
this.contentDiv=l;
            
this.container=a;
            
this.logDiv=c
        }

        
// 通过静态函数来创建GLogBase或获得已创建的GLogBase
        GLogBase.instance = function ()
        
{
            
var a=GLogBase.object;
            
if(!a)
            
{
                a
=new GLogBase();
                GLogBase.object
=a
            }

            
return a
        }
;
        
// 将指定的内容输出
        GLogBase.prototype.write = function (message,color)
        
{
            
var c=this.createLogItem();
            
if(b)
            
{
                c
=CreateElement("span",c);
                c.style.color
=color
            }

            CreateTextNode(message,c);
            
this.reDraw()
        }
;
        
// 输出指定的URL
        GLogBase.prototype.writeUrl = function (a)
        
{
            
var b=CreateElement("a",this.createLogItem());
            CreateTextNode(a,b);
            b.href
=a;
            
this.reDraw()
        }
;
        
// 输出指定的HTML内容
        GLogBase.prototype.writeHtml = function (a)
        
{
            
var b=CreateElement("span",this.createLogItem());
            b.innerHTML
=a;
            
this.reDraw()
        }
;
        
// 清空所有的输出
        GLogBase.prototype.clear = function ()
        
{
            removeNodeChildren(
this.contentDiv)
        }
;
        
// 删除GLogBase
        GLogBase.prototype.close = function ()
        
{
            deposeNode(
this.container)
        }
;
        
// 点击的时候开始拖动层
        GLogBase.prototype.onMouseDown = function (a)
        
{
            
if(!this.dragObject)
            
{
                
this.dragObject=new GDragPanel(this.container);
                
this.container.style.bottom=""
            }

        }
;
        
// 创建一个输出项目层
        GLogBase.prototype.createLogItem = function ()
        
{
            
var a=CreateElement("div",this.contentDiv);
            
var b=a.style;
            b.fontSize
="85%";
            b.whiteSpace
="nowrap";
            b.borderBottom
="1px solid silver";
            a.style.paddingBottom
=GetPixelValue(2);
            
var c=CreateElement("div",a);
            c.style.color
="gray";
            c.style.fontSize
="75%";
            CreateTextNode(
this.getlogTime(),c);
            
return a
        }
;
        
// 内容变化之后调整显示内容
        GLogBase.prototype.reDraw = function ()
        
{
            
this.contentDiv.scrollTop=this.contentDiv.scrollHeight;
            
this.keepSize()
        }
;
        
// 获取疏剪输出字符串
        GLogBase.prototype.getlogTime = function ()
        
{
            
var a=new Date();
            
return this.lb(a.getHours(),2)+":"+this.lb(a.getMinutes(),2)+":"+this.lb(a.getSeconds(),2)+":"+this.lb(a.getMilliseconds(),3)
        }
;
        
// 将事件中的8转化为08输出
        GLogBase.prototype.lb = function (a,b)
        
{
            
var c=a.toString();
            
while(c.length<b)
            
{
                c
="0"+c
            }

            
return c
        }
;
        
// 调整窗口,自适应大小
        GLogBase.prototype.keepSize = function ()
        
{
            SetSize(
this.logDiv,new GSize(this.container.offsetWidth,this.container.offsetHeight))
        }
;

你可能感兴趣的:(google maps api)