BDMarkerTool.min.js 7.3 KB

1
  1. var BMapLib=window.BMapLib=BMapLib||{};if(typeof BMapLib._toolInUse=="undefined"){BMapLib._toolInUse=false}(function(){var r=r||{guid:"$BAIDU$"};(function(){window[r.guid]={};r.extend=function(e,n){for(var i in n){if(n.hasOwnProperty(i)){e[i]=n[i]}}return e};r.lang=r.lang||{};r.lang.guid=function(){return"TANGRAM__"+(window[r.guid]._counter++).toString(36)};window[r.guid]._counter=window[r.guid]._counter||1;window[r.guid]._instances=window[r.guid]._instances||{};r.lang.Class=function(e){this.guid=e||r.lang.guid();window[r.guid]._instances[this.guid]=this};r.lang.isString=function(e){return"[object String]"==Object.prototype.toString.call(e)};r.lang.isFunction=function(e){return"[object Function]"==Object.prototype.toString.call(e)};r.lang.Class.prototype.toString=function(){return"[object "+(this._className||"Object")+"]"};r.lang.Class.prototype.dispose=function(){delete window[r.guid]._instances[this.guid];for(var e in this){if(!r.lang.isFunction(this[e])){delete this[e]}}this.disposed=true};r.lang.Event=function(e,n){this.type=e;this.returnValue=true;this.target=n||null;this.currentTarget=null};r.lang.Class.prototype.addEventListener=function(e,n,i){if(!r.lang.isFunction(n)){return}!this.__listeners&&(this.__listeners={});var t=this.__listeners,a;if(typeof i=="string"&&i){if(/[^\w\-]/.test(i)){throw"nonstandard key:"+i}else{n.hashCode=i;a=i}}e.indexOf("on")!=0&&(e="on"+e);typeof t[e]!="object"&&(t[e]={});a=a||r.lang.guid();n.hashCode=a;t[e][a]=n};r.lang.Class.prototype.removeEventListener=function(e,n){if(r.lang.isFunction(n)){n=n.hashCode}else if(!r.lang.isString(n)){return}!this.__listeners&&(this.__listeners={});e.indexOf("on")!=0&&(e="on"+e);var i=this.__listeners;if(!i[e]){return}i[e][n]&&delete i[e][n]};r.lang.Class.prototype.dispatchEvent=function(e,n){if(r.lang.isString(e)){e=new r.lang.Event(e)}!this.__listeners&&(this.__listeners={});n=n||{};for(var i in n){e[i]=n[i]}var i,t=this.__listeners,a=e.type;e.target=e.target||this;e.currentTarget=this;a.indexOf("on")!=0&&(a="on"+a);r.lang.isFunction(this[a])&&this[a].apply(this,arguments);if(typeof t[a]=="object"){for(i in t[a]){t[a][i].apply(this,arguments)}}return e.returnValue};r.lang.inherits=function(e,n,i){var t,a,o=e.prototype,s=new Function;s.prototype=n.prototype;a=e.prototype=new s;for(t in o){a[t]=o[t]}e.prototype.constructor=e;e.superClass=n.prototype;if("string"==typeof i){a._className=i}}})();var i=BMapLib.MarkerTool=function(e,n){r.lang.Class.call(this);this._map=e;this._opts={icon:i.SYS_ICONS[8],followText:"点击地图添加工作场所",autoClose:true};r.extend(this._opts,n);this._isOpen=false;this._opts.followText=this._checkStr(this._opts.followText);this._followMarker=null;this._followLabel=null};r.lang.inherits(i,r.lang.Class,"MarkerTool");i.prototype.open=function(){if(!this._map){return false}if(this._isOpen==true){return true}if(BMapLib._toolInUse){return false}BMapLib._toolInUse=true;this._isOpen=true;if(!this._binded){this._bind();this._binded=true}if(!this._followMarker){this._followMarker=new BMap.Marker(this._map.getCenter(),{offset:new BMap.Size(-10,-10)});this._map.addOverlay(this._followMarker);this._followMarker.setZIndex(1e3);this._followMarker.hide()}if(!this._followLabel){this._followLabel=new BMap.Label(this._opts.followText,{offset:new BMap.Size(20,0)})}this._preCursor=this._map.getDefaultCursor();this._map.setDefaultCursor("url("+i.CUR_IMG+"), default");return true};i.prototype.close=function(){if(!this._isOpen){return}this._map.removeEventListener("mousemove",this._mouseMoveHandler);this._map.removeEventListener("click",this._clickHandler);this._followMarker.hide();this._map.setDefaultCursor(this._preCursor);BMapLib._toolInUse=false;this._isOpen=false;this._binded=false};i.prototype.setIcon=function(e){if(!e||!(e instanceof BMap.Icon)){return}this._opts.icon=e};i.prototype.getIcon=function(){return this._opts.icon};i.prototype._checkStr=function(e){if(!e){return""}return e.replace(/</g,"&lt;").replace(/>/g,"&gt;")};i.prototype._bind=function(){var s=this;if(!s._isOpen){return}s._mouseMoveHandler=function(e){var n=e.point;s._followMarker.setIcon(s._opts.icon);s._followMarker.setPosition(n);s._followMarker.setLabel(s._followLabel);s._followMarker.show()};s._map.addEventListener("mousemove",s._mouseMoveHandler);s._clickHandler=function(e){var n=e.pixel;var i=new BMap.Pixel(n.x-10,n.y-10);var t=s._map.pixelToPoint(i);var a=new BMap.Marker(t,{icon:s._opts.icon,enableDragging:true});s._map.addOverlay(a);var o=new r.lang.Event("onmarkend");o.marker=a;s.dispatchEvent(o);if(s._opts.autoClose){s.close()}};s._map.addEventListener("click",s._clickHandler)};i.CUR_IMG="/x_component_Attendance/$AddressExplorer/default/icon/transparent.cur";i.ICON_IMG="/x_component_Attendance/$AddressExplorer/default/icon/us_mk_icon.png";i.SYS_ICONS=[new BMap.Icon(i.ICON_IMG,new BMap.Size(21,21),{anchor:new BMap.Size(6,21),imageOffset:new BMap.Size(0,0)}),new BMap.Icon(i.ICON_IMG,new BMap.Size(21,21),{anchor:new BMap.Size(6,21),imageOffset:new BMap.Size(-23,0)}),new BMap.Icon(i.ICON_IMG,new BMap.Size(21,21),{anchor:new BMap.Size(6,21),imageOffset:new BMap.Size(-46,0)}),new BMap.Icon(i.ICON_IMG,new BMap.Size(21,21),{anchor:new BMap.Size(6,21),imageOffset:new BMap.Size(-69,0)}),new BMap.Icon(i.ICON_IMG,new BMap.Size(21,21),{anchor:new BMap.Size(6,21),imageOffset:new BMap.Size(-92,0)}),new BMap.Icon(i.ICON_IMG,new BMap.Size(21,21),{anchor:new BMap.Size(6,21),imageOffset:new BMap.Size(-115,0)}),new BMap.Icon(i.ICON_IMG,new BMap.Size(23,25),{anchor:new BMap.Size(9,25),imageOffset:new BMap.Size(0,-21)}),new BMap.Icon(i.ICON_IMG,new BMap.Size(23,25),{anchor:new BMap.Size(9,25),imageOffset:new BMap.Size(-23,-21)}),new BMap.Icon(i.ICON_IMG,new BMap.Size(23,25),{anchor:new BMap.Size(9,25),imageOffset:new BMap.Size(-46,-21)}),new BMap.Icon(i.ICON_IMG,new BMap.Size(23,25),{anchor:new BMap.Size(9,25),imageOffset:new BMap.Size(-69,-21)}),new BMap.Icon(i.ICON_IMG,new BMap.Size(23,25),{anchor:new BMap.Size(9,25),imageOffset:new BMap.Size(-92,-21)}),new BMap.Icon(i.ICON_IMG,new BMap.Size(23,25),{anchor:new BMap.Size(9,25),imageOffset:new BMap.Size(-115,-21)}),new BMap.Icon(i.ICON_IMG,new BMap.Size(21,21),{anchor:new BMap.Size(1,21),imageOffset:new BMap.Size(0,-46)}),new BMap.Icon(i.ICON_IMG,new BMap.Size(21,21),{anchor:new BMap.Size(1,21),imageOffset:new BMap.Size(-23,-46)}),new BMap.Icon(i.ICON_IMG,new BMap.Size(21,21),{anchor:new BMap.Size(1,21),imageOffset:new BMap.Size(-46,-46)}),new BMap.Icon(i.ICON_IMG,new BMap.Size(21,21),{anchor:new BMap.Size(1,21),imageOffset:new BMap.Size(-69,-46)}),new BMap.Icon(i.ICON_IMG,new BMap.Size(21,21),{anchor:new BMap.Size(1,21),imageOffset:new BMap.Size(-92,-46)}),new BMap.Icon(i.ICON_IMG,new BMap.Size(21,21),{anchor:new BMap.Size(1,21),imageOffset:new BMap.Size(-115,-46)}),new BMap.Icon(i.ICON_IMG,new BMap.Size(25,25),{anchor:new BMap.Size(12,25),imageOffset:new BMap.Size(0,-67)}),new BMap.Icon(i.ICON_IMG,new BMap.Size(25,25),{anchor:new BMap.Size(12,25),imageOffset:new BMap.Size(-25,-67)}),new BMap.Icon(i.ICON_IMG,new BMap.Size(24,25),{anchor:new BMap.Size(12,25),imageOffset:new BMap.Size(-50,-67)}),new BMap.Icon(i.ICON_IMG,new BMap.Size(25,25),{anchor:new BMap.Size(12,25),imageOffset:new BMap.Size(-75,-67)}),new BMap.Icon(i.ICON_IMG,new BMap.Size(25,25),{anchor:new BMap.Size(12,25),imageOffset:new BMap.Size(-100,-67)}),new BMap.Icon(i.ICON_IMG,new BMap.Size(19,25),{anchor:new BMap.Size(9,25),imageOffset:new BMap.Size(-125,-67)})]})();