-
Notifications
You must be signed in to change notification settings - Fork 48
Expand file tree
/
Copy pathInfoBox.min.js
More file actions
1 lines (1 loc) · 8.63 KB
/
Copy pathInfoBox.min.js
File metadata and controls
1 lines (1 loc) · 8.63 KB
1
var BMapLib=window.BMapLib=BMapLib||{},INFOBOX_AT_TOP=1,INFOBOX_AT_RIGHT=2,INFOBOX_AT_BOTTOM=3,INFOBOX_AT_LEFT=4;!function(){var t,e,i=t=i||{version:"1.5.0"};i.guid="$BAIDU$",window[i.guid]=window[i.guid]||{},i.lang=i.lang||{},i.lang.isString=function(t){return"[object String]"==Object.prototype.toString.call(t)},i.lang.isFunction=function(t){return"[object Function]"==Object.prototype.toString.call(t)},i.lang.Event=function(t,e){this.type=t,this.returnValue=!0,this.target=e||null,this.currentTarget=null},i.object=i.object||{},i.extend=i.object.extend=function(t,e){for(var i in e)e.hasOwnProperty(i)&&(t[i]=e[i]);return t},i.event=i.event||{},i.event._listeners=i.event._listeners||[],i.dom=i.dom||{},i.dom._g=function(t){return i.lang.isString(t)?document.getElementById(t):t},i._g=i.dom._g,i.event.on=function(t,e,n){e=e.replace(/^on/i,""),t=i.dom._g(t);var o,s=function(e){n.call(t,e)},r=i.event._listeners,a=i.event._eventFilter,h=e;return e=e.toLowerCase(),a&&a[e]&&(h=(o=a[e](t,e,s)).type,s=o.listener),t.addEventListener?t.addEventListener(h,s,!1):t.attachEvent&&t.attachEvent("on"+h,s),r[r.length]=[t,e,n,s,h],t},i.on=i.event.on,i.event.un=function(t,e,n){t=i.dom._g(t),e=e.replace(/^on/i,"").toLowerCase();for(var o,s,r,a=i.event._listeners,h=a.length,_=!n;h--;)(o=a[h])[1]!==e||o[0]!==t||!_&&o[2]!==n||(s=o[4],r=o[3],t.removeEventListener?t.removeEventListener(s,r,!1):t.detachEvent&&t.detachEvent("on"+s,r),a.splice(h,1));return t},i.un=i.event.un,i.dom.g=function(t){return"string"==typeof t||t instanceof String?document.getElementById(t):t&&t.nodeName&&(1==t.nodeType||9==t.nodeType)?t:null},i.g=i.G=i.dom.g,i.dom._styleFixer=i.dom._styleFixer||{},i.dom._styleFilter=i.dom._styleFilter||[],i.dom._styleFilter.filter=function(t,e,n){for(var o,s=0,r=i.dom._styleFilter;o=r[s];s++)(o=o[n])&&(e=o(t,e));return e},i.string=i.string||{},i.string.toCamelCase=function(t){return t.indexOf("-")<0&&t.indexOf("_")<0?t:t.replace(/[-_][^-_]/g,function(t){return t.charAt(1).toUpperCase()})},i.dom.setStyle=function(t,e,n){var o,s=i.dom;return t=s.g(t),e=i.string.toCamelCase(e),(o=s._styleFilter)&&(n=o.filter(e,n,"set")),(o=s._styleFixer[e])&&o.set?o.set(t,n):t.style[o||e]=n,t},i.setStyle=i.dom.setStyle,i.dom.setStyles=function(t,e){for(var n in t=i.dom.g(t),e)i.dom.setStyle(t,n,e[n]);return t},i.setStyles=i.dom.setStyles,i.browser=i.browser||{},i.browser.ie=i.ie=/msie (\d+\.\d+)/i.test(navigator.userAgent)?document.documentMode||+RegExp.$1:void 0,i.dom._NAME_ATTRS=(e={cellpadding:"cellPadding",cellspacing:"cellSpacing",colspan:"colSpan",rowspan:"rowSpan",valign:"vAlign",usemap:"useMap",frameborder:"frameBorder"},i.browser.ie<8?(e.for="htmlFor",e.class="className"):(e.htmlFor="for",e.className="class"),e),i.dom.setAttr=function(t,e,n){return t=i.dom.g(t),"style"==e?t.style.cssText=n:(e=i.dom._NAME_ATTRS[e]||e,t.setAttribute(e,n)),t},i.setAttr=i.dom.setAttr,i.dom.setAttrs=function(t,e){for(var n in t=i.dom.g(t),e)i.dom.setAttr(t,n,e[n]);return t},i.setAttrs=i.dom.setAttrs,i.dom.create=function(t,e){var n=document.createElement(t),o=e||{};return i.dom.setAttrs(n,o)},t.undope=!0;var n=BMapLib.InfoBox=function(t,e,i){this._content=e||"",this._isOpen=!1,this._map=t,this._opts=i=i||{},this._opts.offset=i.offset||new BMap.Size(0,0),this._opts.boxClass=i.boxClass||"infoBox",this._opts.boxStyle=i.boxStyle||{},this._opts.closeIconMargin=i.closeIconMargin||"2px",this._opts.closeIconUrl=i.closeIconUrl||"close.png",this._opts.enableAutoPan=!!i.enableAutoPan,this._opts.align=i.align||INFOBOX_AT_TOP,this._opts.disableClose=!0===i.disableClose};n.prototype=new BMap.Overlay,n.prototype.initialize=function(t){var e=this,n=this._div=i.dom.create("div",{class:this._opts.boxClass});i.dom.setStyles(n,this._opts.boxStyle),n.style.position="absolute",this._setContent(this._content);var o=t.getPanes().floatPane;return o.style.width="auto",o.appendChild(n),this._getInfoBoxSize(),i.event.on(n,"onmousedown",function(t){e._stopBubble(t)}),i.event.on(n,"onmouseover",function(t){e._stopBubble(t)}),i.event.on(n,"click",function(t){e._stopBubble(t)}),i.event.on(n,"dblclick",function(t){e._stopBubble(t)}),n},n.prototype.draw=function(){this._isOpen&&this._adjustPosition(this._point)},n.prototype.open=function(t){var e,i=this;this._isOpen||(this._map.addOverlay(this),this._isOpen=!0,setTimeout(function(){i._dispatchEvent(i,"open",{point:i._point})},10)),t instanceof BMap.Point?(e=t,this._removeMarkerEvt()):t instanceof BMap.Marker&&(this._marker&&this._removeMarkerEvt(),e=t.getPosition(),this._marker=t,!this._markerDragend&&this._marker.addEventListener("dragend",this._markerDragend=function(t){i._point=t.point,i._adjustPosition(i._point),i._panBox(),i.show()}),!this._markerDragging&&this._marker.addEventListener("dragging",this._markerDragging=function(){i.hide(),i._point=i._marker.getPosition(),i._adjustPosition(i._point)})),this.show(),this._point=e,this._panBox(),this._adjustPosition(this._point)},n.prototype.close=function(){this._isOpen&&(this._map.removeOverlay(this),this._remove(),this._isOpen=!1,this._dispatchEvent(this,"close",{point:this._point}))},n.prototype.enableAutoPan=function(){this._opts.enableAutoPan=!0},n.prototype.disableAutoPan=function(){this._opts.enableAutoPan=!1},n.prototype.setContent=function(t){this._setContent(t),this._getInfoBoxSize(),this._adjustPosition(this._point)},n.prototype.setPosition=function(t){this._point=t,this._adjustPosition(t),this._removeMarkerEvt()},n.prototype.getPosition=function(){return this._point},n.prototype.getOffset=function(){return this._opts.offset},n.prototype._remove=function(){this.domElement&&this.domElement.parentNode&&(i.event.un(this._div.firstChild,"click",this._closeHandler()),this.domElement.parentNode.removeChild(this.domElement)),this.domElement=null,this._isOpen=!1,this.dispatchEvent("onremove")},i.object.extend(n.prototype,{_getCloseIcon:function(){return this._opts.disableClose?"<div></div>":"<img src='"+this._opts.closeIconUrl+"' align='right' style='position:absolute;right:0px;cursor:pointer;margin:"+this._opts.closeIconMargin+"'/>"},_setContent:function(t){if(this._div){var e=this._getCloseIcon();void 0===t.nodeType?this._div.innerHTML=e+t:(this._div.innerHTML=e,this._div.appendChild(t)),this._content=t,this._addEventToClose()}},_adjustPosition:function(t){var e=this._getPointPosition(t),i=this._marker&&this._marker.getIcon(),n=i&&(i.infoWindowAnchor||i.infoWindowOffset||{width:0,height:0});switch(this._opts.align){case INFOBOX_AT_TOP:this._marker?this._div.style.bottom=-(e.y-this._opts.offset.height-i.anchor.height+n.height)-this._marker.getOffset().height+2+"px":this._div.style.bottom=-(e.y-this._opts.offset.height)+"px";break;case INFOBOX_AT_BOTTOM:this._marker?this._div.style.top=e.y+this._opts.offset.height-i.anchor.height+n.height+this._marker.getOffset().height+"px":this._div.style.top=e.y+this._opts.offset.height+"px"}this._marker?this._div.style.left=e.x-i.anchor.width+this._marker.getOffset().width+n.width-this._boxWidth/2+this._opts.offset.width+"px":this._div.style.left=e.x-this._boxWidth/2+this._opts.offset.width+"px"},_getPointPosition:function(t){return this._pointPosition=this._map.pointToOverlayPixel(t),this._pointPosition},_getInfoBoxSize:function(){this._boxWidth=parseInt(this._div.offsetWidth,10),this._boxHeight=parseInt(this._div.offsetHeight,10)},_addEventToClose:function(){i.event.on(this._div.firstChild,"click",this._closeHandler()),this._hasBindEventClose=!0},_closeHandler:function(){var t=this;return function(e){t.close()}},_stopBubble:function(t){t&&t.stopPropagation?t.stopPropagation():window.event.cancelBubble=!0},_panBox:function(){if(this._opts.enableAutoPan){var t=parseInt(this._map.getContainer().offsetHeight,10),e=parseInt(this._map.getContainer().offsetWidth,10),i=this._boxHeight,n=this._boxWidth;if(!(i>=t||n>=e)){this._map.getBounds().containsPoint(this._point)||this._map.setCenter(this._point);var o,s,r,a=this._map.pointToPixel(this._point),h=n/2-a.x,_=n/2+a.x-e;if(this._marker)var l=this._marker.getIcon(),p=l&&(l.infoWindowAnchor||l.infoWindowOffset||{width:0,height:0});switch(this._opts.align){case INFOBOX_AT_TOP:var d=this._marker?l.anchor.height+this._marker.getOffset().height-p.height:0;o=i-a.y+this._opts.offset.height+d+2;break;case INFOBOX_AT_BOTTOM:d=this._marker?-l.anchor.height+p.height+this._marker.getOffset().height+this._opts.offset.height:0;s=i+a.y-t+d+4}panX=h>0?h:_>0?-_:0,r=o>0?o:s>0?-s:0,this._map.panBy(panX,r)}}},_removeMarkerEvt:function(){this._markerDragend&&this._marker.removeEventListener("dragend",this._markerDragend),this._markerDragging&&this._marker.removeEventListener("dragging",this._markerDragging),this._markerDragend=this._markerDragging=null},_dispatchEvent:function(t,e,n){0!=e.indexOf("on")&&(e="on"+e);var o=new i.lang.Event(e);if(n)for(var s in n)o[s]=n[s];t.dispatchEvent(o)}})}();