DIV CSS 佈局教程網

 DIV+CSS佈局教程網 >> 網頁腳本 >> JavaScript入門知識 >> 關於JavaScript >> 百度地圖自定義控件分享
百度地圖自定義控件分享
編輯:關於JavaScript     

廢話不多說了,直接奉上代碼;

復制代碼 代碼如下:
<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();
            }
            div.appendChild(e3);
            //添加DOM元素到地圖中
            map.getContainer().appendChild(div);
            //返回DOM
            return div;
        }
        //創建控件實例
        var staticsCtrl = new staticControl();
        //添加到地圖當中
        map.addControl(staticsCtrl);
        function statics(){
            map.centerAndZoom(new BMap.Point(116.404, 39.915), 11);
        }
        function endStatics(){
            map.setZoom(map.getZoom()-2);
        }
        function setStatics(){
            map.setZoom(map.getZoom()+2)
        }
    </script>

上面代碼就是個人正在使用的百度地圖的自定義控件,希望大家能夠喜歡。

XML學習教程| jQuery入門知識| AJAX入門| Dreamweaver教程| Fireworks入門知識| SEO技巧| SEO優化集錦|
Copyright © DIV+CSS佈局教程網 All Rights Reserved