Google Maps API 2.0解析(3-GEvent事件功能支持)
生活随笔
收集整理的這篇文章主要介紹了
Google Maps API 2.0解析(3-GEvent事件功能支持)
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
//以a為參數(shù),運(yùn)行b和c函數(shù),如果a是一個html控件而且包含子控件,則以子控件為參數(shù)也運(yùn)行該函數(shù)
??function?RunFunction(a,b,c)
??{
???if(b)
???{
????b.call(null,a)
???}
???for(var?d=a.firstChild;d;d=d.nextSibling)
???{
????if(d.nodeType==1)
????{
?????arguments.callee.call(this,d,b,c)
????}
???}
???if(c)
???{
????c.call(null,a)
???}
??}
??//設(shè)置html控件的屬性
??function?setElementAttribute(a,b,c)
??{
???a.setAttribute(b,c)
??};
??var?GEvent_newcopyright="newcopyright";
??var?GEvent_click="click";
??var?GEvent_contextmenu="contextmenu";
??var?GEvent_dblclick="dblclick";
??var?GEvent_error="error";
??var?GEvent_load="load";
??var?GEvent_mousedown="mousedown";
??var?GEvent_mousemove="mousemove";
??var?GEvent_mouseout="mouseout";
??var?GEvent_mouseup="mouseup";
??var?GEvent_unload="unload";
??var?GEvent_remove="remove";
??var?GEvent_mouseover="mouseover";
??var?GEvent_closeclick="closeclick";
??var?GEvent_addmaptype="addmaptype";
??var?GEvent_addoverlay="addoverlay";
??var?GEvent_clearoverlays="clearoverlays";
??var?GEvent_infowindowclose="infowindowclose";
??var?GEvent_infowindowopen="infowindowopen";
??var?GEvent_maptypechanged="maptypechanged";
??var?GEvent_moveend="moveend";
??var?GEvent_movestart="movestart";
??var?GEvent_removemaptype="removemaptype";
??var?GEvent_removeoverlay="removeoverlay";
??var?GEvent_resize="resize";
??var?GEvent_zoom="zoom";
??var?GEvent_zoomend="zoomend";
??var?GEvent_dragstart="dragstart";
??var?GEvent_drag="drag";
??var?GEvent_dragend="dragend";
??var?GEvent_move="move";
??var?GEvent_clearlisteners="clearlisteners";
??var?AllEvents=[];
??//添加一個事件,參數(shù)分別為:對象、事件名稱、運(yùn)行句柄
??function?addListener(a,b,c)
??{
???var?d=new?GEventListener(a,b,c,0);
???AllEvents.push(d);
???return?d
??}
??//刪除一個事件
??function?removeListener(a)
??{
???a.remove();
???RemoveFromArray(AllEvents,a)
??}
??//刪除a對象的所有b事件
??function?clearListeners(a,b)
??{
???trigger(a,GEvent_clearlisteners,b);//先觸發(fā)clearlisteners事件
???RunMethodForAll(CopyEventArray(a),function()
???{
????if(this.isEvent(b))
????{
?????this.remove();
?????RemoveFromArray(AllEvents,this)
????}
???})
??}
??//刪除對象a的所有事件
??function?clearInstanceListeners(a)
??{
???trigger(a,GEvent_clearlisteners);
???RunMethodForAll(CopyEventArray(a),function()
???{
????this.remove();
????RemoveFromArray(AllEvents,this)
???})
??}
??//刪除系統(tǒng)之中的所有事件
??function?RemoveAllEvents()
??{
???var?a=[];
???var?b="__tag__";
???for(var?c=0;c<AllEvents.length;++c)
???{
????var?d=AllEvents[c];
????var?e=d.getSrcObject();//獲得事件源
????if(!e[b])
????{
?????e[b]=true;
?????trigger(e,GEvent_clearlisteners);//刪除源上的所有事件
?????a.push(e)
????}
????d.remove()
???}
???for(var?c=0;c<a.length;++c)//這一段代碼比較古怪,不過我覺得很可能是為了防止對象循環(huán)引用造成內(nèi)存不能釋放的原因
???{
????var?e=a[c];
????if(e[b])
????{
?????try
?????{
??????delete?e[b]
?????}
?????catch(f)
?????{
??????e[b]=false
?????}
????}
???}
???AllEvents.length=0
??}
??//復(fù)制事件數(shù)組
??function?CopyEventArray(a)
??{
???var?b=[];
???if(a["__e_"])
???{
????CopyArray(b,a["__e_"])
???}
???return?b
??}
??//返回a的事件監(jiān)視器列表數(shù)組
??function?getEventArray(a,b)
??{
???var?c=a["__e_"];
???if(!c)
???{
????if(b)
????{
?????c=(a["__e_"]=[])
????}
????else
????{
?????c=[]
????}
???}
???return?c
??}
??//觸發(fā)對象a的b事件
??function?trigger(a,b,c,d)
??{
???var?e=[];
???//將arguments之后的參數(shù)作為運(yùn)行參數(shù)
???CopyArray(e,arguments,2);
???RunMethodForAll(getEventArray(a),function()
???{
????if(this.isEvent(b))
????{
?????try
?????{
??????this.apply(a,e)
?????}
?????catch(f)
?????{
?????}
????}
???})
??}
??//實際上這個就是以前的那個AddBuiltInListener
??function?addDomListener(a,b,c)
??{
???var?d;
???if(browser.type==2&&b==GEvent_dblclick)
???{
????a["on"+b]=c;
????d=new?GEventListener(a,b,c,3)
???}
???else?if(a.addEventListener)
???{
????a.addEventListener(b,c,false);
????d=new?GEventListener(a,b,c,1)
???}
???else?if(a.attachEvent)
???{
????var?e=callback(a,c);
????a.attachEvent("on"+b,e);
????d=new?GEventListener(a,b,e,2)
???}
???else
???{
????a["on"+b]=c;
????d=new?GEventListener(a,b,c,3)
???}
???if(a!=window||b!=GEvent_unload)
???{
????AllEvents.push(d)
???}
???return?d
??}
??//將c的d方法綁定到a(HTML控件)的b事件
??function?bindDom(a,b,c,d)
??{
???var?e=.createAdapter(c,d);
???return?addDomListener(a,b,e)
??}
??//針對點擊,在IE之中特別處理
??function?bindClick(a,b,c)
??{
???bindDom(a,GEvent_click,b,c);
???if(browser.type==1)
???{//在IE之中綁定點擊的同時綁定雙擊
????bindDom(a,GEvent_dblclick,b,c)
???}
??}
??//將c的d方法綁定到a(非HTML控件)的b事件
??function?bind(a,b,c,d)
??{
???return?addListener(a,b,callback(c,d))
??}
??//這個可能是要實現(xiàn)事件冒泡的功能,要知道,在Google原有的事件系統(tǒng)之中,只有瀏覽器集成的事件可以冒泡,而Google擴(kuò)展的事件不支持的,
??//這個方法,將c對象的b事件綁定到a對象的b事件,這樣就能實現(xiàn)當(dāng)點擊一個GMark的時候,地圖也能捕獲到點擊事件的“冒泡”功能
??//這個方法的使用我還沒有看,因此還不知道這個方法會實現(xiàn)哪些功能
??function?bindEventToEvent(a,b,c)
??{
???return?addListener(a,b,function()
???{
????var?d=[c,b];
????CopyArray(d,arguments);
????trigger.apply(this,d)
???})
??}
??//返回一個事件適配器,因為IE之中事件發(fā)生時并不將Event對象作為參數(shù)傳遞,因此,必須用該適配器來讀取window.event的值
??function?.createAdapter(a,b)
??{
???return?function(c)
???{
????if(!c)
????{
?????c=window.event
????}
????if(c&&!c.target)
????{
?????c.target=c.srcElement
????}
????b.call(a,c,this)
???}
??}
??//取得對a的b方法的回調(diào)函數(shù)
??function?callback(a,b)
??{
???return?function()
???{
????return?b.apply(a,arguments)
???}
??}
??//取得對a的b方法的回調(diào)函數(shù),并將第二個參數(shù)之后的參數(shù)作為調(diào)用參數(shù)
??function?callbackArgs(a,b,c,d)
??{
???var?e=[];
???CopyArray(e,arguments,2);
???return?function()
???{
????return?b.apply(a,e)
???}
??}
??//這是一個listener的對象
??function?GEventListener(a,b,c,d)
??{
???var?e=this;
???e.object=a;
???e.event=b;
???e.handle=c;
???e.type=d;//listener的類型
???getEventArray(a,true).push(e)
??}
??//移除該listener
??GEventListener.prototype.remove=function()
??{
???var?a=this;
???switch(a.type)
???{
????case?1:
?????a.object.removeEventListener(a.event,a.handle,false);
?????break;
????case?2:
?????a.Z.detachEvent("on"+a.event,a.handle);
?????break;
????case?3:
?????a.object["on"+a.event]=null;
?????break;
???}
???RemoveFromArray(getEventArray(a.object),a)
??};
??//判斷是否a事件的綁定
??GEventListener.prototype.isEvent=function(a)
??{
???return?this.event==a
??};
??//運(yùn)行該listener的句柄
??GEventListener.prototype.apply=function(a,b)
??{
???return?this.handle.apply(a,b)
??};
??//獲得該listener的對象
??GEventListener.prototype.getSrcObject=function()
??{
???return?this.object
??};
??//靜態(tài)函數(shù),事件發(fā)生時,獲得該事件的對象,如果srcElement是文字,則為其父對象
??function?GetEventElement(a)
??{
???var?b=a.srcElement||a.target;
???if(b&&b.nodeType==3)
???{
????b=b.parentNode
???}
???return?b
??}
??//清除a和其包含的控件的所有事件
??function?clearNode(a)
??{
???RunFunction(a,clearInstanceListeners)
??};
《新程序員》:云原生和全面數(shù)字化實踐50位技術(shù)專家共同創(chuàng)作,文字、視頻、音頻交互閱讀
??function?RunFunction(a,b,c)
??{
???if(b)
???{
????b.call(null,a)
???}
???for(var?d=a.firstChild;d;d=d.nextSibling)
???{
????if(d.nodeType==1)
????{
?????arguments.callee.call(this,d,b,c)
????}
???}
???if(c)
???{
????c.call(null,a)
???}
??}
??//設(shè)置html控件的屬性
??function?setElementAttribute(a,b,c)
??{
???a.setAttribute(b,c)
??};
??var?GEvent_newcopyright="newcopyright";
??var?GEvent_click="click";
??var?GEvent_contextmenu="contextmenu";
??var?GEvent_dblclick="dblclick";
??var?GEvent_error="error";
??var?GEvent_load="load";
??var?GEvent_mousedown="mousedown";
??var?GEvent_mousemove="mousemove";
??var?GEvent_mouseout="mouseout";
??var?GEvent_mouseup="mouseup";
??var?GEvent_unload="unload";
??var?GEvent_remove="remove";
??var?GEvent_mouseover="mouseover";
??var?GEvent_closeclick="closeclick";
??var?GEvent_addmaptype="addmaptype";
??var?GEvent_addoverlay="addoverlay";
??var?GEvent_clearoverlays="clearoverlays";
??var?GEvent_infowindowclose="infowindowclose";
??var?GEvent_infowindowopen="infowindowopen";
??var?GEvent_maptypechanged="maptypechanged";
??var?GEvent_moveend="moveend";
??var?GEvent_movestart="movestart";
??var?GEvent_removemaptype="removemaptype";
??var?GEvent_removeoverlay="removeoverlay";
??var?GEvent_resize="resize";
??var?GEvent_zoom="zoom";
??var?GEvent_zoomend="zoomend";
??var?GEvent_dragstart="dragstart";
??var?GEvent_drag="drag";
??var?GEvent_dragend="dragend";
??var?GEvent_move="move";
??var?GEvent_clearlisteners="clearlisteners";
??var?AllEvents=[];
??//添加一個事件,參數(shù)分別為:對象、事件名稱、運(yùn)行句柄
??function?addListener(a,b,c)
??{
???var?d=new?GEventListener(a,b,c,0);
???AllEvents.push(d);
???return?d
??}
??//刪除一個事件
??function?removeListener(a)
??{
???a.remove();
???RemoveFromArray(AllEvents,a)
??}
??//刪除a對象的所有b事件
??function?clearListeners(a,b)
??{
???trigger(a,GEvent_clearlisteners,b);//先觸發(fā)clearlisteners事件
???RunMethodForAll(CopyEventArray(a),function()
???{
????if(this.isEvent(b))
????{
?????this.remove();
?????RemoveFromArray(AllEvents,this)
????}
???})
??}
??//刪除對象a的所有事件
??function?clearInstanceListeners(a)
??{
???trigger(a,GEvent_clearlisteners);
???RunMethodForAll(CopyEventArray(a),function()
???{
????this.remove();
????RemoveFromArray(AllEvents,this)
???})
??}
??//刪除系統(tǒng)之中的所有事件
??function?RemoveAllEvents()
??{
???var?a=[];
???var?b="__tag__";
???for(var?c=0;c<AllEvents.length;++c)
???{
????var?d=AllEvents[c];
????var?e=d.getSrcObject();//獲得事件源
????if(!e[b])
????{
?????e[b]=true;
?????trigger(e,GEvent_clearlisteners);//刪除源上的所有事件
?????a.push(e)
????}
????d.remove()
???}
???for(var?c=0;c<a.length;++c)//這一段代碼比較古怪,不過我覺得很可能是為了防止對象循環(huán)引用造成內(nèi)存不能釋放的原因
???{
????var?e=a[c];
????if(e[b])
????{
?????try
?????{
??????delete?e[b]
?????}
?????catch(f)
?????{
??????e[b]=false
?????}
????}
???}
???AllEvents.length=0
??}
??//復(fù)制事件數(shù)組
??function?CopyEventArray(a)
??{
???var?b=[];
???if(a["__e_"])
???{
????CopyArray(b,a["__e_"])
???}
???return?b
??}
??//返回a的事件監(jiān)視器列表數(shù)組
??function?getEventArray(a,b)
??{
???var?c=a["__e_"];
???if(!c)
???{
????if(b)
????{
?????c=(a["__e_"]=[])
????}
????else
????{
?????c=[]
????}
???}
???return?c
??}
??//觸發(fā)對象a的b事件
??function?trigger(a,b,c,d)
??{
???var?e=[];
???//將arguments之后的參數(shù)作為運(yùn)行參數(shù)
???CopyArray(e,arguments,2);
???RunMethodForAll(getEventArray(a),function()
???{
????if(this.isEvent(b))
????{
?????try
?????{
??????this.apply(a,e)
?????}
?????catch(f)
?????{
?????}
????}
???})
??}
??//實際上這個就是以前的那個AddBuiltInListener
??function?addDomListener(a,b,c)
??{
???var?d;
???if(browser.type==2&&b==GEvent_dblclick)
???{
????a["on"+b]=c;
????d=new?GEventListener(a,b,c,3)
???}
???else?if(a.addEventListener)
???{
????a.addEventListener(b,c,false);
????d=new?GEventListener(a,b,c,1)
???}
???else?if(a.attachEvent)
???{
????var?e=callback(a,c);
????a.attachEvent("on"+b,e);
????d=new?GEventListener(a,b,e,2)
???}
???else
???{
????a["on"+b]=c;
????d=new?GEventListener(a,b,c,3)
???}
???if(a!=window||b!=GEvent_unload)
???{
????AllEvents.push(d)
???}
???return?d
??}
??//將c的d方法綁定到a(HTML控件)的b事件
??function?bindDom(a,b,c,d)
??{
???var?e=.createAdapter(c,d);
???return?addDomListener(a,b,e)
??}
??//針對點擊,在IE之中特別處理
??function?bindClick(a,b,c)
??{
???bindDom(a,GEvent_click,b,c);
???if(browser.type==1)
???{//在IE之中綁定點擊的同時綁定雙擊
????bindDom(a,GEvent_dblclick,b,c)
???}
??}
??//將c的d方法綁定到a(非HTML控件)的b事件
??function?bind(a,b,c,d)
??{
???return?addListener(a,b,callback(c,d))
??}
??//這個可能是要實現(xiàn)事件冒泡的功能,要知道,在Google原有的事件系統(tǒng)之中,只有瀏覽器集成的事件可以冒泡,而Google擴(kuò)展的事件不支持的,
??//這個方法,將c對象的b事件綁定到a對象的b事件,這樣就能實現(xiàn)當(dāng)點擊一個GMark的時候,地圖也能捕獲到點擊事件的“冒泡”功能
??//這個方法的使用我還沒有看,因此還不知道這個方法會實現(xiàn)哪些功能
??function?bindEventToEvent(a,b,c)
??{
???return?addListener(a,b,function()
???{
????var?d=[c,b];
????CopyArray(d,arguments);
????trigger.apply(this,d)
???})
??}
??//返回一個事件適配器,因為IE之中事件發(fā)生時并不將Event對象作為參數(shù)傳遞,因此,必須用該適配器來讀取window.event的值
??function?.createAdapter(a,b)
??{
???return?function(c)
???{
????if(!c)
????{
?????c=window.event
????}
????if(c&&!c.target)
????{
?????c.target=c.srcElement
????}
????b.call(a,c,this)
???}
??}
??//取得對a的b方法的回調(diào)函數(shù)
??function?callback(a,b)
??{
???return?function()
???{
????return?b.apply(a,arguments)
???}
??}
??//取得對a的b方法的回調(diào)函數(shù),并將第二個參數(shù)之后的參數(shù)作為調(diào)用參數(shù)
??function?callbackArgs(a,b,c,d)
??{
???var?e=[];
???CopyArray(e,arguments,2);
???return?function()
???{
????return?b.apply(a,e)
???}
??}
??//這是一個listener的對象
??function?GEventListener(a,b,c,d)
??{
???var?e=this;
???e.object=a;
???e.event=b;
???e.handle=c;
???e.type=d;//listener的類型
???getEventArray(a,true).push(e)
??}
??//移除該listener
??GEventListener.prototype.remove=function()
??{
???var?a=this;
???switch(a.type)
???{
????case?1:
?????a.object.removeEventListener(a.event,a.handle,false);
?????break;
????case?2:
?????a.Z.detachEvent("on"+a.event,a.handle);
?????break;
????case?3:
?????a.object["on"+a.event]=null;
?????break;
???}
???RemoveFromArray(getEventArray(a.object),a)
??};
??//判斷是否a事件的綁定
??GEventListener.prototype.isEvent=function(a)
??{
???return?this.event==a
??};
??//運(yùn)行該listener的句柄
??GEventListener.prototype.apply=function(a,b)
??{
???return?this.handle.apply(a,b)
??};
??//獲得該listener的對象
??GEventListener.prototype.getSrcObject=function()
??{
???return?this.object
??};
??//靜態(tài)函數(shù),事件發(fā)生時,獲得該事件的對象,如果srcElement是文字,則為其父對象
??function?GetEventElement(a)
??{
???var?b=a.srcElement||a.target;
???if(b&&b.nodeType==3)
???{
????b=b.parentNode
???}
???return?b
??}
??//清除a和其包含的控件的所有事件
??function?clearNode(a)
??{
???RunFunction(a,clearInstanceListeners)
??};
《新程序員》:云原生和全面數(shù)字化實踐50位技術(shù)專家共同創(chuàng)作,文字、視頻、音頻交互閱讀
總結(jié)
以上是生活随笔為你收集整理的Google Maps API 2.0解析(3-GEvent事件功能支持)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Berkeley DB——Databas
- 下一篇: 一个很好的练听力的网站