Google Map API教程之使用GControl对象在地图上添加control按钮
三水清 2010-06-27 19:45:25
今天查看我网站的地图已经被谷歌收录了5900条,而百度也开始收录了,很欣慰~再接再厉,今天写的这一篇Google map api教程是关于在Google地图上添加control按钮的,用到的是Google Map API的GControl对象,通过initialize的方法插入一个div到地图上,再通过new GControlPosition设置按钮的位置,最后通过Gmap的addControl方法添加这个按钮。最终效果截图如下:
实现方法原理分析
首先建立一个GControl的原型control,然后定义其initialize 方法:主要是建立一个div,并且制定div的onclick事件,最后通过gmap.getContainer().appendChild(buttonDiv)插入到地图中去。
最后定义getDefaultPosition的方法,通过GControlPosition对象设置按钮所在地图的具体位置。
Google Map API 代码
function control() {}; control.prototype = new GControl(); control.prototype.initialize = function(gmap){ var buttonDiv = document.createElement("div"); buttonDiv.id = "control"; buttonDiv.appendChild(document.createTextNode("清除标点")); buttonDiv.onclick = function(){ gmap.clearOverlays(); }; gmap.getContainer().appendChild(buttonDiv); return buttonDiv; }; control.prototype.getDefaultPosition = function(){ return new GControlPosition(G_ANCHOR_TOP_LEFT, new GSize(510, 7)); };
最后我们再通过gmap.addControl(new control());将这个按钮加入到地图中
全国地图经纬度查询 | 利用GControl对象在地图上添加control按钮实例
声明:文章未声明为原创文章,本文链接 http://js8.in/564.html. 转载请注明转自 JS8.IN ™
