代码
var map = new BMap.Map('map');
map.centerAndZoom(new BMap.Point(116.404, 39.915), 11);

// 创建地图类型空间
var mapTypeControl = new BMap.MapTypeControl({
  anchor: BMAP_ANCHOR_TOP_LEFT,
  offset: new BMap.Size(20, 20),
  type: BMAP_MAPTYPE_CONTROL_DROPDOWN,
});

// 创建平移缩放控件
var navigationControl = new BMap.NavigationControl({
  anchor: BMAP_ANCHOR_TOP_RIGHT,
  offset: new BMap.Size(20, 20),
  type: BMAP_NAVIGATION_CONTROL_LARGE,
  showZoomInfo: true,
  enableGeolocation: false,
});

// 创建比例尺控件
var scaleControl = new BMap.ScaleControl({
  anchor: BMAP_ANCHOR_BOTTOM_LEFT,
});

// 创建定位控件
var geolocationControl = new BMap.GeolocationControl({
  anchor: BMAP_ANCHOR_BOTTOM_RIGHT,
  offset: new BMap.Size(29.5, 20),
  showAddressBar: true,
});

// 添加控件和比例尺
function addControls() {
  map.addControl(navigationControl);
  map.addControl(mapTypeControl);
  map.addControl(scaleControl);
  map.addControl(geolocationControl);
}
// 移除控件和比例尺
function deleteControls() {
  map.removeControl(navigationControl);
  map.removeControl(mapTypeControl);
  map.removeControl(scaleControl);
  map.removeControl(geolocationControl);
}
addControls();
预览