Repository navigation
Expand file tree
/
Copy pathMarkerTool.min.js
More file actions
1 lines (1 loc) · 5.31 KB
/
Copy pathMarkerTool.min.js
File metadata and controls
1 lines (1 loc) · 5.31 KB
1
var BMapLib=window.BMapLib=BMapLib||{};void 0===BMapLib._toolInUse&&(BMapLib._toolInUse=!1),function(){var t,e,n=(t=document.getElementsByTagName("script"),(e=document.currentScript?document.currentScript.src:t[t.length-1].src).substring(0,e.lastIndexOf("/")+1)),i=i||{guid:"$BAIDU$"};window[i.guid]={},i.extend=function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n]);return t},i.lang=i.lang||{},i.lang.guid=function(){return"TANGRAM__"+(window[i.guid]._counter++).toString(36)},window[i.guid]._counter=window[i.guid]._counter||1,window[i.guid]._instances=window[i.guid]._instances||{},i.lang.Class=function(t){this.guid=t||i.lang.guid(),window[i.guid]._instances[this.guid]=this},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.Class.prototype.toString=function(){return"[object "+(this._className||"Object")+"]"},i.lang.Class.prototype.dispose=function(){for(var t in delete window[i.guid]._instances[this.guid],this)i.lang.isFunction(this[t])||delete this[t];this.disposed=!0},i.lang.Event=function(t,e){this.type=t,this.returnValue=!0,this.target=e||null,this.currentTarget=null},i.lang.Class.prototype.addEventListener=function(t,e,n){if(i.lang.isFunction(e)){!this.__listeners&&(this.__listeners={});var o,s=this.__listeners;if("string"==typeof n&&n){if(/[^\w\-]/.test(n))throw"nonstandard key:"+n;e.hashCode=n,o=n}0!=t.indexOf("on")&&(t="on"+t),"object"!=typeof s[t]&&(s[t]={}),o=o||i.lang.guid(),e.hashCode=o,s[t][o]=e}},i.lang.Class.prototype.removeEventListener=function(t,e){if(i.lang.isFunction(e))e=e.hashCode;else if(!i.lang.isString(e))return;!this.__listeners&&(this.__listeners={}),0!=t.indexOf("on")&&(t="on"+t);var n=this.__listeners;n[t]&&n[t][e]&&delete n[t][e]},i.lang.Class.prototype.dispatchEvent=function(t,e){for(var n in i.lang.isString(t)&&(t=new i.lang.Event(t)),!this.__listeners&&(this.__listeners={}),e=e||{})t[n]=e[n];var o=this.__listeners,s=t.type;if(t.target=t.target||this,t.currentTarget=this,0!=s.indexOf("on")&&(s="on"+s),i.lang.isFunction(this[s])&&this[s].apply(this,arguments),"object"==typeof o[s])for(n in o[s])o[s][n].apply(this,arguments);return t.returnValue},i.lang.inherits=function(t,e,n){var i,o,s=t.prototype,r=new Function;for(i in r.prototype=e.prototype,o=t.prototype=new r,s)o[i]=s[i];t.prototype.constructor=t,t.superClass=e.prototype,"string"==typeof n&&(o._className=n)};var o=BMapLib.MarkerTool=function(t,e){i.lang.Class.call(this),this._map=t,this._opts={icon:o.SYS_ICONS[8],followText:"点击地图添加标注",autoClose:!0},i.extend(this._opts,e),this._isOpen=!1,this._opts.followText=this._checkStr(this._opts.followText),this._followMarker=null,this._followLabel=null};i.lang.inherits(o,i.lang.Class,"MarkerTool"),o.prototype.open=function(){return!!this._map&&(1==this._isOpen||!BMapLib._toolInUse&&(BMapLib._toolInUse=!0,this._isOpen=!0,this._binded||(this._bind(),this._binded=!0),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()),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(/?url=https%3A%2F%2Fgithub.com%2Fhuiyan-fe%2FBMap-JavaScript-library%2Fblob%2Fmaster%2Fsrc%2FMarkerTool%2F%26quot%3B%2Bo.CUR_IMG%2B%26quot%3B), default"),!0))},o.prototype.close=function(){this._isOpen&&(this._map.removeEventListener("mousemove",this._mouseMoveHandler),this._map.removeEventListener("click",this._clickHandler),this._followMarker.hide(),this._map.setDefaultCursor(this._preCursor),BMapLib._toolInUse=!1,this._isOpen=!1,this._binded=!1)},o.prototype.setIcon=function(t){t&&t instanceof BMap.Icon&&(this._opts.icon=t)},o.prototype.getIcon=function(){return this._opts.icon},o.prototype._checkStr=function(t){return t?t.replace(/</g,"<").replace(/>/g,">"):""},o.prototype._bind=function(){var t=this;t._isOpen&&(t._mouseMoveHandler=function(e){var n=e.point;t._followMarker.setIcon(t._opts.icon),t._followMarker.setPosition(n),t._followMarker.setLabel(t._followLabel),t._followMarker.show()},t._map.addEventListener("mousemove",t._mouseMoveHandler),t._clickHandler=function(e){var n=e.pixel,o=new BMap.Pixel(n.x-10,n.y-10),s=t._map.pixelToPoint(o),r=new BMap.Marker(s,{icon:t._opts.icon});t._map.addOverlay(r);var a=new i.lang.Event("onmarkend");a.marker=r,t.dispatchEvent(a),t._opts.autoClose&&t.close()},t._map.addEventListener("click",t._clickHandler))},o.CUR_IMG="http://api.map.baidu.com/library/MarkerTool/1.2/src/images/transparent.cur",o.ICON_IMG=n+"us_mk_icon.png";var s="4.0"===BMap.apiVersion,r=s?new BMap.Size(144,92):null;function a(t,e,n,i,a,l){var p={anchor:new BMap.Size(n,i),imageOffset:s?new BMap.Size(-a,-l):new BMap.Size(a,l)};return r&&(p.imageSize=r),new BMap.Icon(o.ICON_IMG,new BMap.Size(t,e),p)}o.SYS_ICONS=[a(21,21,6,21,0,0),a(21,21,6,21,-23,0),a(21,21,6,21,-46,0),a(21,21,6,21,-69,0),a(21,21,6,21,-92,0),a(21,21,6,21,-115,0),a(23,25,9,25,0,-21),a(23,25,9,25,-23,-21),a(23,25,9,25,-46,-21),a(23,25,9,25,-69,-21),a(23,25,9,25,-92,-21),a(23,25,9,25,-115,-21),a(21,21,1,21,0,-46),a(21,21,1,21,-23,-46),a(21,21,1,21,-46,-46),a(21,21,1,21,-69,-46),a(21,21,1,21,-92,-46),a(21,21,1,21,-115,-46),a(25,25,12,25,0,-67),a(25,25,12,25,-25,-67),a(24,25,12,25,-50,-67),a(25,25,12,25,-75,-67),a(25,25,12,25,-100,-67),a(19,25,9,25,-125,-67)]}();