素材牛VIP会员
百度地图 infobox
 你***擦  分类:JavaScript  人气:1061  回帖:1  发布于6年前 收藏

使用百度地图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()
 标签:javascript

讨论这个帖子(1)垃圾回帖将一律封号处理……

Lv5 码农
许***焱 Web前端工程师 6年前#1
 文明上网,理性发言!   😉 阿里云幸运券,戳我领取