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));