var map; var maptype; var centerPoint; var zoom; var divtop; var _xx; var _yy; //页面加载 function pageLoad(name, x, y, id){ initMap(); QueryPRJ(name, x, y, id); } function initMap(){ map = new BMap.Map("container"); var opts1 = {type: BMAP_NAVIGATION_CONTROL_SMALL}; map.addControl(new BMap.NavigationControl(opts1)); //缩放条 map.centerAndZoom(new BMap.Point(120.010951, 30.356294), 16); //杭州中心点位置 map.enableScrollWheelZoom(); //开启滚轮事件 map.enableAutoResize(); var menu = new BMap.ContextMenu(); var txtMenuItem = [ { text:'放大', callback:function(){map.zoomIn()} }, { text:'缩小', callback:function(){map.zoomOut()} } ]; for(var i=0; i < txtMenuItem.length; i++){ menu.addItem(new BMap.MenuItem(txtMenuItem[i].text,txtMenuItem[i].callback,100)); } map.addContextMenu(menu); //判断是否是360浏览器,top值样式有区别 if(window.external&&window.external.twGetRunPath){ var r=external.twGetRunPath(); if(r&&r.toLowerCase().indexOf("360")>-1){ divtop = "5"; } }else{ divtop = "5"; } } //初始化楼盘 function QueryPRJ(name, x, y, id){ if(name != undefined && name != '' && name != null){ _xx = x; _yy = y; var myCompOverlay = new ComplexCustomOverlay(new BMap.Point(_xx,_yy), name, name, id); map.addOverlay(myCompOverlay); setTimeout(movetoo,1000); } } function movetoo(point){ map.centerAndZoom(new BMap.Point(_xx, _yy), 16); } //缩放到最大级别 function zoom(x,y){ if(map.getZoom()<16){ map.setZoom(16); } } // 自定义楼盘标签 function ComplexCustomOverlay(point, text, mouseoverText,prjid){ this._point = point; this._text = text; this._overText = mouseoverText; this._textLength = this._text.length*13; this._overTextLength = this._overText.length*13; this._prjid = prjid; this._imgstr = ""; } ComplexCustomOverlay.prototype = new BMap.Overlay(); ComplexCustomOverlay.prototype.initialize = function(map){ this._map = map; var div = this._div = document.createElement("div"); div.id = this._prjid; div.style.position = "absolute"; div.style.zIndex = BMap.Overlay.getZIndex(this._point.lat); var divhidden = this._divhidden = document.createElement("div"); divhidden.innerHTML = this._point.lng+","+this._point.lat; divhidden.style.display = "none"; div.appendChild(divhidden); this._imgstr = "l"; var textlength = this._textLength; var overtextLength = this._overTextLength; var divleft= this._divleft = document.createElement("div"); divleft.style.background = "url(/webty/images/"+ this._imgstr+"_left.png)"; divleft.style.position = "absolute"; divleft.style.width = "5px"; divleft.style.height = "28px"; divleft.style.left = "0px"; divleft.onmouseover = null; divleft.onmouseout = null; div.appendChild(divleft); var divmiddle= this._divmiddle = document.createElement("div"); divmiddle.style.background = "url(/webty/images/"+ this._imgstr+"_middle.png)"; divmiddle.style.position = "absolute"; divmiddle.style.width = textlength+"px"; divmiddle.style.height = "28px"; divmiddle.style.left = "5px"; divmiddle.onmouseover = null; divmiddle.onmouseout = null; div.appendChild(divmiddle); var divmiddletext = this._divmiddletext = document.createElement("div"); divmiddletext.style.position = "absolute"; divmiddletext.style.width = textlength+"px"; divmiddletext.style.height = "28px"; divmiddletext.style.left = "7px"; divmiddletext.style.top =divtop+"px"; //divmiddletext.style.top = "3px"; //divmiddletext.style.top = "-7px"; divmiddletext.innerHTML ="

"+this._text+"

"; divmiddletext.onmouseover = null; divmiddletext.onmouseout = null; div.appendChild(divmiddletext); var divright = this._divright = document.createElement("div"); divright.style.background = "url(/webty/images/"+ this._imgstr+"_right.png)"; divright.style.position = "absolute"; divright.style.width = "5px"; divright.style.height = "28px"; divright.style.left = textlength+5+"px"; divright.onmouseover = null; divright.onmouseout = null; div.appendChild(divright); var divjt = this._divjt = document.createElement("div"); divjt.style.background = "url(/webty/images/"+ this._imgstr+"_jt.png)"; divjt.style.position = "absolute"; divjt.style.width = "25px"; divjt.style.height = "17px"; divjt.style.left = "0px"; divjt.style.top = "23px"; divjt.onmouseover = null; divjt.onmouseout = null; div.appendChild(divjt); var that = this; div.onmouseover = function(){ div.style.cursor="pointer"; that._divleft.style.background = "url(/webty/images/z_left.png)"; that._divmiddle.style.background = "url(/webty/images/z_middle.png)"; that._divright.style.background = "url(/webty/images/z_right.png)"; that._divjt.style.background = "url(/webty/images/z_jt.png)"; that._divmiddle.style.width = that._overTextLength+"px"; that._divright.style.left = that._overTextLength+5+"px"; that._divmiddletext.style.width = that._overTextLength+"px"; var p = document.getElementById("p"+that._prjid); p.innerText = that._overText; } div.onmouseout = function(){ that._divleft.style.background = "url(/webty/images/"+that._imgstr+"_left.png)"; that._divmiddle.style.background = "url(/webty/images/"+that._imgstr+"_middle.png)"; that._divright.style.background = "url(/webty/images/"+that._imgstr+"_right.png)"; that._divjt.style.background = "url(/webty/images/"+that._imgstr+"_jt.png)"; that._divmiddle.style.width = that._textLength+"px"; that._divright.style.left = that._textLength+5+"px"; that._divmiddletext.style.width = that._textLength+"px"; var p = document.getElementById("p"+that._prjid); p.innerText = that._text; } div.onclick = function(){ window.open("/newhouse/property_"+sid+"_"+this.id+"_info.htm"); } map.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._divleft.style.left) + "px"; this._div.style.top = pixel.y - 30 + "px"; }