使用百度地图infobox 在自定义覆盖物下时总是有以下报错:
自定义覆盖物代码:
function myOverlay(point, text) {
this._point = point;
this._text = text;
}
myOverlay.prototype = new BMap.Overlay();
myOverlay.prototype.initialize = function(map) {
this._map = map;
var div = this._div = document.createElement("div");
div.style.position = "absolute";
div.style.zIndex = BMap.Overlay.getZIndex(this._point.lat);
div.style.background = "red";
div.style.width = "23px";
div.style.height = "30px";
div.style.lineHeight = "26px";
div.style.textAlign = "center";
div.style.fontSize = "12px";
div.style.color = "#fff";
div.style.borderRadius = "50%";
div.style.zIndex = '999';
// div.setAttribute('id', i + 's');
div.style.cursor = 'pointer';
var span = this._span = document.createElement("span");
div.appendChild(span);
span.appendChild(document.createTextNode(this._text));
var that = this;
var _index = BMap.Overlay.getZIndex(this._point.lat);
map.getPanes().labelPane.appendChild(div);
// div.onmouseover = function() { // this.style.background = "url('./images/icon/positionH.png') no-repeat"; // this.style.zIndex = "99"; // }; // div.onmouseout = function() { // this.style.background = "url('./images/icon/position.png') no-repeat"; // this.style.zIndex = _index; // };
return div;
};
myOverlay.prototype.draw = function() {
var map = this._map;
var p = map.pointToOverlayPixel(this._point);
this._div.style.left = p.x - 10 + "px";
this._div.style.top = p.y - 30 + "px";
};
var myaddOverlay = new myOverlay(poi);
map.addOverlay(myaddOverlay);
infoBox.open(myaddOverlay); // myCompOverlay.enableDragging()