Play Google

玩转谷歌--学习笔记,成长历程。

Google Map 上添加自定义按钮(继承自GControl类)

Blog 开张第一贴
继承自GControl()类

/*TextControl类 ============================================================================
*author Karry
*添加按钮扩展,
*继承自GControl()
*value--按钮的value 值
*left--按钮与左边框的距离(像素)
*top--按钮与上边框的距离(像素)
*/
        function TextControl(value,left,top,clickFunction) {
            this.value_ = value||"按钮";
            this.left_ = left||77;
            this.top_ = top||7;
            this.clickFunction_ = clickFunction;
        }
        TextControl.prototype = new GControl();
        TextControl.prototype.initialize = function(map)
        {
            var container = document.createElement("div");
            var containerDiv = document.createElement("div");
            this.setButtonStyle_(containerDiv);
            container.appendChild(containerDiv);
            containerDiv.appendChild(document.createTextNode(this.value_));
            GEvent.addDomListener(containerDiv, "click", this.clickFunction_);
            this.map_ = map;
            this.map_.getContainer().appendChild(container);       
            return container;
        }
        TextControl.prototype.getDefaultPosition = function()
        {
            return new GControlPosition(G_ANCHOR_TOP_LEFT, new GSize(this.left_,this.top_));
        }
        TextControl.prototype.setButtonStyle_ = function(button)
        {
            button.style.color = "#000000";
            button.style.backgroundColor = "white";
            button.style.font = "12px '宋体'";
            button.style.border = "1px solid black";
            button.style.padding = "2px";
            button.style.marginBottom = "3px";
            button.style.textAlign = "center";
            button.style.width = "4em";
            button.style.cursor = "pointer";
        }

/*TextControl类 end============================================================================*/

使用方法:

map.addControl(new TextControl("返回",77,7,load));

  • 相关文章:

发表评论:

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。

vinehoo,web2.0葡萄酒社区
vinehoo,web2.0葡萄酒社区

日历

最新评论及回复

最近发表

Powered By Karry 

Copyright © 2008 PlayGoogle.com. All Rights Reserved.