Without further ado, just present the code;
The code copy is as follows:
<script>
var map = new BMap.Map('allmap');
var Bcenter = new BMap.Point(116.404,39.915);
map.centerAndZoom(Bcenter,11);
//Custom control
function staticControl(){
this.defaultAnchor = BMAP_ANCHOR_TOP_LEFT;
this.defaultOffset = new BMap.Size(10,10);
}
//Inheriting the Control API
staticControl.prototype = new BMap.Control();
//Initialize the control
staticControl.prototype.initialize=function(map){
var div = document.createElement('div');
var e1 = document.createElement('input');
e1.type = 'button';
e1.value = 'reset';
e1.onclick=function(){
statics();
}
div.appendChild(e1);
var e2=document.createElement('input');
e2.type = 'button';
e2.value = 'Zoom down';
e2.onclick=function(){
endStatics();
}
div.appendChild(e2);
var e3 = document.createElement("input");
e3.type = "button";
e3.value = "Zoom in";
e3.onclick = function () {
setStatics();
}
div.appendChild(e3);
//Add DOM elements to the map
map.getContainer().appendChild(div);
//Return to DOM
return div;
}
//Create a control instance
var staticsCtrl = new staticControl();
//Add to the map
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>
The above code is the customized control of Baidu Maps that I am using. I hope everyone can like it.