Google Maps事件
2015-05-07 10:02
645 查看
您可以利用事件监听器在您的程序里面加入动态元素。一个对象导出命名事件,您的程序可以用静态方法GEvent.addListener和GEvent.bind来"监听"这些事件。例如,这个代码片断在每次用户点击的时候显示一个警告框:
var map = new
GMap2(document.getElementByIdx("map"));map.setCenter(new
GLatLng(37.4419, -122.1419), 13);GEvent.addListener(map, "click",
function() { alert("You clicked the map.");});
GEvent.addListener把一个函数当作第三个参数,用来指定时间句柄的相应函数。想把事件绑定到类实例的方法上,可以用GEvent.bind方法。在下面的例子里,应用程序类实例把地图事件绑定在他的方法上,在触发的时候修改类的状态:
function MyApplication() { this.counter = 0; this.map = new
GMap2(document.getElementByIdx("map")); this.map.setCenter(new
GLatLng(37.4419, -122.1419), 13); GEvent.bind(this.map, "click",
this, this.onMapClick);}MyApplication.prototype.onMapClick =
function() { this.counter++; alert("You have clicked the map " +
this.counter + " " + (this.counter == 1 ?"time" : "times"));}var
application = new MyApplication(); //
参照JavaScript自定义对象和类的方法理解说明:
prototype属性可算是JavaScript与其他面向对象语言的一大不同之处。简而言之,prototype就是“一个给类的对象添加方法的方法”,通过prototype属性,可以给类动态地添加方法。
#电子地图api
var map = new
GMap2(document.getElementByIdx("map"));map.setCenter(new
GLatLng(37.4419, -122.1419), 13);GEvent.addListener(map, "click",
function() { alert("You clicked the map.");});
GEvent.addListener把一个函数当作第三个参数,用来指定时间句柄的相应函数。想把事件绑定到类实例的方法上,可以用GEvent.bind方法。在下面的例子里,应用程序类实例把地图事件绑定在他的方法上,在触发的时候修改类的状态:
function MyApplication() { this.counter = 0; this.map = new
GMap2(document.getElementByIdx("map")); this.map.setCenter(new
GLatLng(37.4419, -122.1419), 13); GEvent.bind(this.map, "click",
this, this.onMapClick);}MyApplication.prototype.onMapClick =
function() { this.counter++; alert("You have clicked the map " +
this.counter + " " + (this.counter == 1 ?"time" : "times"));}var
application = new MyApplication(); //
参照JavaScript自定义对象和类的方法理解说明:
prototype属性可算是JavaScript与其他面向对象语言的一大不同之处。简而言之,prototype就是“一个给类的对象添加方法的方法”,通过prototype属性,可以给类动态地添加方法。
#电子地图api
相关文章推荐
- Google Maps事件
- google Maps API(1)
- FW:Google Maps API编程资源大全
- google Maps API(1)
- google Maps覆盖对象
- 在线生成Google Sitemaps试用手记
- 【原创】Google Chrome …
- Google搜索技巧终极收集 -&nb…
- google X Lab:人工脑自动学习什么…
- Google Spanner和F1介绍
- Google Maps API 进级:监听键盘鼠标事件 加载KML或者GEORSS文档
- 【转】2006 上交笔试题【Google】
- 献给我的爱机——google nexus s
- google Chrome浏览器看视频时多次…
- 详细教程C#中的委托和事件应用 一
- flex group 拖动事件&nb…
- Google Chrome 的 …
- 如何用好 Google 等搜索引擎?
- 两个onload 、onclick事件处理的办…
- 谷歌下周推Google Drive iOS应用程…