setViewport 函数
//初始化
var myMap = new BMap.Map("container");
myMap.addControl(new BMap.NavigationControl());
myMap.enableScrollWheelZoom(); //启用滚轮放大缩小,默认禁用
myMap.enableContinuousZoom();
var gspinfo = <?php echo json_encode($map_info);?>; //将php数组通过json方式传给js
//可以转化gps坐标
myMap.centerAndZoom(new BMap.Point(lat_point, lng_point), leva);
var mapWforGPS = new BMapLib.MapWrapper(myMap, BMapLib.COORD_TYPE_GPS);
//================================
function ComplexCustomOverlay(point, text, mouseoverText){
this._point = point;
this._text = text;
this._overText = mouseoverText;
}
ComplexCustomOverlay.prototype = new BMap.Overlay();
ComplexCustomOverlay.prototype.initialize = function(map){
this._map = map;
var divm = this._div = document.createElement("div");
divm.style.position = "absolute";
divm.style.zIndex = BMap.Overlay.getZIndex(this._point.lat);
divm.style.backgroundColor = "#EE5D5B";
divm.style.border = "1px solid #BC3B3A";
divm.style.color = "white";
divm.style.height = "18px";
divm.style.padding = "2px";
divm.style.lineHeight = "18px";
divm.style.whiteSpace = "nowrap";
divm.style.MozUserSelect = "none";
divm.style.fontSize = "12px"
var span = this._span = document.createElement("span");
divm.appendChild(span);
span.appendChild(document.createTextNode(this._text));
var that = this;
var arrow = this._arrow = document.createElement("div");
arrow.style.background = "url(http://map.baidu.com/fwmap/upload/r/map/fwmap/static/house/images/label.png) no-repeat";
arrow.style.position = "absolute";
arrow.style.width = "11px";
arrow.style.height = "10px";
arrow.style.top = "22px";
arrow.style.left = "10px";
arrow.style.overflow = "hidden";
divm.appendChild(arrow);
divm.onmouseover = function(){
this.style.backgroundColor = "#6BADCA";
this.style.borderColor = "#0000ff";
this.getElementsByTagName("span")[0].innerHTML = that._overText;
arrow.style.backgroundPosition = "0px -20px";
}
divm.onmouseout = function(){
this.style.backgroundColor = "#EE5D5B";
this.style.borderColor = "#BC3B3A";
this.getElementsByTagName("span")[0].innerHTML = that._text;
arrow.style.backgroundPosition = "0px 0px";
}
myMap.getPanes().labelPane.appendChild(divm);
return divm;
}
ComplexCustomOverlay.prototype.draw = function(){
var map = this._map;
var pixel = map.pointToOverlayPixel(this._point);
this._div.style.left = pixel.x - parseInt(this._arrow.style.left) + "px";
this._div.style.top = pixel.y - 30 + "px";
}
//==============================
points = Array();
for (var i = 0; i < gl_; i++) {
//添加gps坐标mkr
//var gpsMkr = new BMap.Marker(new BMap.Point(/*GPS坐标*/gspinfo[i].lat ,gspinfo[i].lng));
//myMap.centerAndZoom(gpsMkr, leva);
//mapWforGPS.addOverlay(gpsMkr);
// var marker = new BMap.Marker(gpsMkr);
//var labelgps = new BMap.Label(gspinfo[i].drugname,{offset:new BMap.Size(20,-10)});
//gpsMkr.setLabel(labelgps);
points[i]= new BMap.Point(gspinfo[i].lat,gspinfo[i].lng);
//===========================
var txt = gspinfo[i].drugname, mouseoverTxt =gspinfo[i].asi+' '+txt;
//添加自定义标签
var myCompOverlay = new ComplexCustomOverlay(new BMap.Point(gspinfo[i].lat,gspinfo[i].lng)," "+gspinfo[i].asi+" ",mouseoverTxt);
myMap.addOverlay(myCompOverlay);
//points[$i]=new BMap.Point(gspinfo[i].lat,gspinfo[i].lng);
}
myMap.setViewport(points); //调用setViewport 设置视野
//points = [new BMap.Point(gspinfo[i].lat,gspinfo[i].lng),new BMap.Point(gspinfo[i].lat,gspinfo[i].lng),new BMap.Point(gspinfo[i].lat,gspinfo[i].lng) ]
/
转载于:https://my.oschina.net/startphp/blog/192904