博客列表 >百度地图自定义覆盖物

百度地图自定义覆盖物

dxp2tq的博客
dxp2tq的博客原创
2017年11月24日 14:51:441718浏览

// 复杂的自定义图片覆盖物
function ComplexCustomOverlay(point){
   this._point = point;    
}
ComplexCustomOverlay.prototype = new BMap.Overlay();
ComplexCustomOverlay.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.border = "2px solid #fff";
   div.style.height = "48px";
   div.style.width = "48px";
   div.style.lineHeight = "18px";
   div.style.whiteSpace = "nowrap";
   div.style.MozUserSelect = "none";
   div.style.fontSize = "12px";
   var arrow = this._arrow = document.createElement("img");
   arrow.src = case_pic;
   arrow.style.width = "48px";
   arrow.style.height = "48px";
   arrow.style.top = "22px";
   arrow.style.left = "10px";
   div.appendChild(arrow);

   var that = this;
   var arrow = this._arrow = document.createElement("div");
   arrow.style.background = "url(/tpl/default/theme/new201607/images/officed_label3.png) no-repeat";
   arrow.style.position = "absolute";
   arrow.style.width = "48px";
   arrow.style.height = "48px";
   arrow.style.top = "50px";
   arrow.style.left = "12px";
   arrow.style.overflow = "hidden";
   div.appendChild(arrow);
   pro_map_new.getPanes().labelPane.appendChild(div);
   return div;
}
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";
}
//添加监听事件(必有)
ComplexCustomOverlay.prototype.addEventListener = function(event,fun){
   this._div['on'+event] = fun;
}
var myCompOverlay = new ComplexCustomOverlay(pro_point_new);
pro_map_new.addOverlay(myCompOverlay);

声明:本文内容转载自脚本之家,由网友自发贡献,版权归原作者所有,如您发现涉嫌抄袭侵权,请联系admin@php.cn 核实处理。
全部评论
文明上网理性发言,请遵守新闻评论服务协议