首页 > 语言 > JavaScript > 正文

百度地图自定义控件分享

2024-05-06 14:45:09
字体:
来源:转载
供稿:网友

废话不多说了,直接奉上代码;

代码如下:
<script>
        var map = new BMap.Map('allmap');
        var Bcenter = new BMap.Point(116.404,39.915);
        map.centerAndZoom(Bcenter,11);
        //自定义控件
        function staticControl(){
            this.defaultAnchor = BMAP_ANCHOR_TOP_LEFT;
            this.defaultOffset = new BMap.Size(10,10);
        }
        //继承Control的API
        staticControl.prototype = new BMap.Control();
        //初始化控件
        staticControl.prototype.initialize=function(map){
            var div = document.createElement('div');
            var e1 = document.createElement('input');
            e1.type = 'button';
            e1.value = '重置';
            e1.onclick=function(){
                statics();
            }
            div.appendChild(e1);
            var e2=document.createElement('input');
            e2.type = 'button';
            e2.value = '缩小';
            e2.onclick=function(){
                endStatics();
            }
            div.appendChild(e2);
            var e3 = document.createElement("input");
            e3.type = "button";
            e3.value = "放大";
            e3.onclick = function () {
               setStatics();

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表

图片精选