var BMapGLLib=window.BMapGLLib=BMapGLLib||{};var BMAP_DRAWING_MARKER="marker",BMAP_DRAWING_POLYLINE="polyline",BMAP_DRAWING_CIRCLE="circle",BMAP_DRAWING_RECTANGLE="rectangle",BMAP_DRAWING_POLYGON="polygon";(function(){var d=d||{guid:"$BAIDU$"};(function(){window[d.guid]={};d.extend=function(n,l){for(var m in l){if(l.hasOwnProperty(m)){n[m]=l[m]}}return n};d.lang=d.lang||{};d.lang.guid=function(){return"TANGRAM__"+(window[d.guid]._counter++).toString(36)};window[d.guid]._counter=window[d.guid]._counter||1;window[d.guid]._instances=window[d.guid]._instances||{};d.lang.Class=function(l){this.guid=l||d.lang.guid();window[d.guid]._instances[this.guid]=this};window[d.guid]._instances=window[d.guid]._instances||{};d.lang.isString=function(l){return"[object String]"==Object.prototype.toString.call(l)};d.lang.isFunction=function(l){return"[object Function]"==Object.prototype.toString.call(l)};d.lang.Class.prototype.toString=function(){return"[object "+(this._className||"Object")+"]"};d.lang.Class.prototype.dispose=function(){delete window[d.guid]._instances[this.guid];for(var l in this){if(!d.lang.isFunction(this[l])){delete this[l]}}this.disposed=true};d.lang.Event=function(l,m){this.type=l;this.returnValue=true;this.target=m||null;this.currentTarget=null};d.lang.Class.prototype.addEventListener=function(o,n,m){if(!d.lang.isFunction(n)){return}!this.__listeners&&(this.__listeners={});var l=this.__listeners,p;if(typeof m=="string"&&m){if(/[^\w\-]/.test(m)){throw ("nonstandard key:"+m)}else{n.hashCode=m;p=m}}o.indexOf("on")!=0&&(o="on"+o);typeof l[o]!="object"&&(l[o]={});p=p||d.lang.guid();n.hashCode=p;l[o][p]=n};d.lang.Class.prototype.removeEventListener=function(n,m){if(d.lang.isFunction(m)){m=m.hashCode}else{if(!d.lang.isString(m)){return}}!this.__listeners&&(this.__listeners={});n.indexOf("on")!=0&&(n="on"+n);var l=this.__listeners;if(!l[n]){return}l[n][m]&&delete l[n][m]};d.lang.Class.prototype.dispatchEvent=function(o,l){if(d.lang.isString(o)){o=new d.lang.Event(o)}!this.__listeners&&(this.__listeners={});l=l||{};for(var n in l){o[n]=l[n]}var n,m=this.__listeners,q=o.type;o.target=o.target||this;o.currentTarget=this;q.indexOf("on")!=0&&(q="on"+q);d.lang.isFunction(this[q])&&this[q].apply(this,arguments);if(typeof m[q]=="object"){for(n in m[q]){m[q][n].apply(this,arguments)}}return o.returnValue};d.lang.inherits=function(r,p,o){var n,q,l=r.prototype,m=new Function();m.prototype=p.prototype;q=r.prototype=new m();for(n in l){q[n]=l[n]}r.prototype.constructor=r;r.superClass=p.prototype;if("string"==typeof o){q._className=o}};d.dom=d.dom||{};d._g=d.dom._g=function(l){if(d.lang.isString(l)){return document.getElementById(l)}return l};d.g=d.dom.g=function(l){if("string"==typeof l||l instanceof String){return document.getElementById(l)}else{if(l&&l.nodeName&&(l.nodeType==1||l.nodeType==9)){return l}}return null};d.insertHTML=d.dom.insertHTML=function(o,l,n){o=d.dom.g(o);var m,p;if(o.insertAdjacentHTML){o.insertAdjacentHTML(l,n)}else{m=o.ownerDocument.createRange();l=l.toUpperCase();if(l=="AFTERBEGIN"||l=="BEFOREEND"){m.selectNodeContents(o);m.collapse(l=="AFTERBEGIN")}else{p=l=="BEFOREBEGIN";m[p?"setStartBefore":"setEndAfter"](o);m.collapse(p)}m.insertNode(m.createContextualFragment(n))}return o};d.ac=d.dom.addClass=function(r,s){r=d.dom.g(r);var n=s.split(/\s+/),m=r.className,q=" "+m+" ",p=0,o=n.length;for(;p松开完成绘制",{position:H.point,offset:new BMapGL.Size(10,10)}); b.setStyle(E.labelOptions);D.addOverlay(b)};var z=function(K){var L=D.getViewport(p.getBounds());L.zoom-=1;D.setViewport(L);D.removeOverlay(b);var J=new BMapGL.Point(p.getBounds().getNorthEast().lng,x.lat);A.hide();n=new BMapGL.Marker(J);n.setIcon(y);n.enableDragging();u=new BMapGL.Polyline([x,J],v);var M=new BMapGL.Point((p.getBounds().getNorthEast().lng+x.lng)/2,x.lat);l=new j("circle",M,o,p,E);G=G.concat([n,u,l]);var H=null;if(E.limit){H=E.limit.area}var I={limit:H,type:"circle",point:J,overlay:p,overlays:G};r=new c(I,E);D.addOverlay(n);D.addOverlay(u);D.addOverlay(l);D.addOverlay(r);l.addEventListener("radiuschange",function(S){var N=S.radius;p.setRadius(N);var R=h(x,N,"east");var O=new BMapGL.Point(R.lng,x.lat);var Q=R.lng>x.lng?(p.getBounds().getNorthEast().lng+x.lng)/2:(p.getBounds().getSouthWest().lng+x.lng)/2;var P=new BMapGL.Point(Q,x.lat);n.setPosition(O);l.setInfo(P,N);r.setPosition(O,true);r.updateWindow();u.setPath([x,O])});n.addEventListener("dragging",function(R){var O=new BMapGL.Point(R.latLng.lng,x.lat);var Q=R.latLng.lng>x.lng?(p.getBounds().getNorthEast().lng+x.lng)/2:(p.getBounds().getSouthWest().lng+x.lng)/2;var N=R.latLng.lng>x.lng?true:false;var P=new BMapGL.Point(Q,x.lat);R.target.setPosition(O);l.setInfo(P,E._map.getDistance(x,R.latLng).toFixed(0));r.setPosition(O,N);u.setPath([x,O]);o=E._map.getDistance(x,R.latLng).toFixed(0);p.setRadius(E._map.getDistance(x,R.latLng))});n.addEventListener("dragend",function(N){r.updateWindow()});A.disableEdgeMove();A.removeEventListener("mousemove",t);A.removeEventListener("mousemove",C);d.un(document,"mouseup",z);E.close()};var C=function(H){d.preventDefault(H);d.stopBubble(H);if(E.controlButton=="right"&&H.button==1){return}if(x==null){B(H)}};var m=function(H){d.preventDefault(H);d.stopBubble(H);D.removeOverlay(b);b=new BMapGL.Label("按下确认中心点,拖拽确认半径",{position:H.point,offset:new BMapGL.Size(10,10)});b.setStyle(E.labelOptions);D.addOverlay(b)};var w=function(H){D.removeOverlay(n);D.removeOverlay(u);D.removeOverlay(l);D.removeOverlay(r)};var s=function(H){x=H.latLng;p.setCenter(H.latLng)};var F=function(H){x=H.latLng;z(H)};A.addEventListener("mousedown",C);A.addEventListener("mousemove",m)};i.prototype._bindPolylineOrPolygon=function(){var s=this,l=this._map,x=this._mask,u=[],r=null,o=null,p=null,m=false;function t(){var A=arguments[0];var B=0;var z=0;for(var y=0;y0){p=A[0].point;o.setPositionAt(r.length-1,A[0].point);return}}p=null;o.setPositionAt(r.length-1,z.point);l.removeOverlay(b);b=new BMapGL.Label("单击绘制下一个点,双击完成绘制",{position:z.point,offset:new BMapGL.Size(10,10)});b.setStyle(s.labelOptions);l.addOverlay(b)};var q=function(E){d.stopBubble(E);m=false;l.removeOverlay(b);x.disableEdgeMove();x.removeEventListener("mousedown",n);x.removeEventListener("mousemove",w);x.removeEventListener("mousemove",v);x.removeEventListener("dblclick",q);if(s.controlButton=="right"){u.push(E.point)}else{if(d.ie<=8){}else{u.pop()}}try{if(s._enableGpc&&window.gpcas&&"polygon"===s._drawingType){var G=new gpcas.geometry.PolyDefault();for(var B=0;B松开结束绘制",{position:z.point,offset:new BMapGL.Size(10,10)});b.setStyle(r.labelOptions);m.addOverlay(b)};var p=function(H){v.hide();var I=null;var C=[];var J=q(n,H.point);var G=[];var z=m.getViewport(J);z.zoom-=1;m.setViewport(z);m.removeOverlay(b);var y=r._map.getDistance(n,J[2]).toFixed(0);var K=r._map.getDistance(n,J[6]).toFixed(0);var x=new j("rectangle",J[0],{width:y,height:K},s,r);for(var E=0;E0?x:null;return Q};i.prototype.mc2ll=function(l){var n=this._map;var m=n.mercatorToLnglat(l.lng,l.lat);return new BMapGL.Point(m[0],m[1])};i.prototype.ll2mc=function(l){var n=this._map;var m=n.lnglatToMercator(l.lng,l.lat);return new BMapGL.Point(m[0],m[1])};function c(l,m){this.limit=l.limit;this.type=l.type;this.point=l.point;this.overlay=l.overlay;this.overlays=l.overlays;this.DrawingManager=m}c.prototype=new BMapGL.Overlay();c.prototype.dispatchEvent=d.lang.Class.prototype.dispatchEvent;c.prototype.addEventListener=d.lang.Class.prototype.addEventListener;c.prototype.removeEventListener=d.lang.Class.prototype.removeEventListener;c.prototype.initialize=function(p){var o=this;this._map=p;var l=(this.type==="polyline"?"长度":"面积");var n=(this.type==="polyline"?"万米":"万平方米");var q=this.div=document.createElement("div");q.className="operateWindow";var m='
'+l+"不超过"+this.limit/10000+n+"!
";q.innerHTML=m;this._map.getPanes().markerPane.appendChild(q);this.updateWindow();this._bind();return q};c.prototype._bind=function(){var n=this;var o=this._map;var l=this.overlay;var m=this.overlays;document.getElementById("confirmOperate").addEventListener("click",function(s){o.removeOverlay(n);if(n.type=="rectangle"){var r=n.DrawingManager._calculate(l,l.getPath())}else{if(n.type=="circle"){var r=n.DrawingManager._calculate(l,n.point)}else{if(n.type=="polygon"){var r=n.DrawingManager._calculate(l,(l.getPath()));n.DrawingManager.overlays.push(l);l.disableEditing()}else{if(n.type=="polyline"){var r=n.DrawingManager._calculate(l,(l.getPath()));n.DrawingManager.overlays.push(l);l.disableEditing()}}}}n.DrawingManager._dispatchOverlayComplete(l,r);for(var q=0;ql){document.getElementById("confirmOperate").style.display="none";document.getElementById("warnOperate").style.display="block"}else{document.getElementById("confirmOperate").style.display="block";document.getElementById("warnOperate").style.display="none"}};c.prototype.setPosition=function(m,l){this.point=m;var o=this._map,n=o.pointToOverlayPixel(this.point);if(l){this.div.classList.remove("operateLeft");this.div.style.left=n.x+15+"px"}else{this.div.classList.add("operateLeft");this.div.style.left=n.x-105+"px"}this.div.style.top=n.y-16+"px"};c.prototype.draw=function(){var m=this._map,l=m.pointToOverlayPixel(this.point);this.div.style.left=l.x+15+"px";this.div.style.top=l.y-16+"px"};function j(n,l,o,m,p){this.type=n;this.point=l;this.number=o;this.overlay=m;this.DrawingManager=p}j.prototype=new BMapGL.Overlay();j.prototype.dispatchEvent=d.lang.Class.prototype.dispatchEvent;j.prototype.addEventListener=d.lang.Class.prototype.addEventListener;j.prototype.removeEventListener=d.lang.Class.prototype.removeEventListener;j.prototype.initialize=function(n){var m=this;this._map=n;var o=this.div=document.createElement("div");o.className="screenshot";if(this.type=="circle"){var l='
'+this.number+'
'}else{if(this.type=="rectangle"){var l='
'+this.number.width+'
x
'+this.number.height+'
' }}o.innerHTML=l;this._map.getPanes().markerPane.appendChild(o);this._bind();return o};j.prototype._bind=function(){this.setNumber(this.number);if(this.type=="circle"){this.bindCircleEvent()}else{this.bindRectEvent()}};j.prototype.bindCircleEvent=function(){var m=this;var l=document.getElementById("screenshotNum");var n=document.getElementById("circleInput");l.addEventListener("click",function(o){var p=l.innerText;l.style.display="none";n.value=p;n.style.display="inline-block";n.focus()});n.addEventListener("click",function(o){n.focus()});n.addEventListener("keydown",function(p){if(p.keyCode===13){var q=n.value;n.style.display="none";l.style.display="inline-block";l.innerText=q;var o={radius:q,overlay:m.overlay};m._dispatchRadiusChange(o)}});n.addEventListener("blur",function(p){var q=n.value;n.style.display="none";l.style.display="inline-block";l.innerText=q;var o={radius:q,overlay:m.overlay};m._dispatchRadiusChange(o)})};j.prototype.bindRectEvent=function(){var n=this;var m=document.getElementById("rectWidth");var p=document.getElementById("rectWidthInput");var l=document.getElementById("rectHeight");var o=document.getElementById("rectHeightInput");p.value=m.innerText;o.value=l.innerText;m.addEventListener("click",function(q){var r=m.innerText;m.style.display="none";p.value=r;p.style.display="inline-block";p.focus()});l.addEventListener("click",function(q){var r=l.innerText;l.style.display="none";o.value=r;o.style.display="inline-block";o.focus()});p.addEventListener("click",function(q){p.focus()});o.addEventListener("click",function(q){o.focus()});p.addEventListener("keydown",function(t){if(t.keyCode===13){var r=p.value;var s=o.value;p.style.display="none";o.style.display="none";m.style.display="inline-block";l.style.display="inline-block";m.innerText=r;l.innerText=s;var q={width:r,height:s,overlay:n.overlay};n._dispatchRectWHChange(q)}});o.addEventListener("keydown",function(t){if(t.keyCode===13){var r=p.value;var s=o.value;p.style.display="none";o.style.display="none";m.style.display="inline-block";l.style.display="inline-block";m.innerText=r;l.innerText=s;var q={width:r,height:s,overlay:n.overlay};n._dispatchRectWHChange(q)}})};j.prototype.setInfo=function(l,m){this.setNumber(m);this.setPosition(l)};j.prototype.setNumber=function(l){if(this.type=="circle"){document.getElementById("screenshotNum").textContent=l}else{document.getElementById("rectWidth").textContent=l.width;document.getElementById("rectHeight").textContent=l.height}};j.prototype.setPosition=function(l){this.point=l;var o=this._map,n=this.type,m=o.pointToOverlayPixel(this.point);if(n=="circle"){this.div.style.left=m.x-30+"px";this.div.style.top=m.y-40+"px"}else{if(n=="rectangle"){this.div.style.left=m.x+"px";this.div.style.top=m.y-45+"px"}}};j.prototype.draw=function(){var n=this._map,m=this.type,l=n.pointToOverlayPixel(this.point);if(m=="circle"){this.div.style.left=l.x-30+"px";this.div.style.top=l.y-40+"px"}else{if(m=="rectangle"){this.div.style.left=l.x+"px";this.div.style.top=l.y-45+"px"}}};j.prototype._dispatchRadiusChange=function(l){this.dispatchEvent("radiuschange",l)};j.prototype._dispatchRectWHChange=function(l){this.dispatchEvent("rectwhchange",l)};function g(){this._enableEdgeMove=false}g.prototype=new BMapGL.Overlay();g.prototype.dispatchEvent=d.lang.Class.prototype.dispatchEvent;g.prototype.addEventListener=d.lang.Class.prototype.addEventListener;g.prototype.removeEventListener=d.lang.Class.prototype.removeEventListener;g.prototype.initialize=function(n){var m=this;this._map=n;var o=this.container=document.createElement("div");var l=this._map.getSize();o.style.cssText="position:absolute;background:transparent;cursor:crosshair;width:"+l.width+"px;height:"+l.height+"px";this._map.addEventListener("resize",function(p){m._adjustSize(p.size)});this._map.getPanes().floatPane.appendChild(o);this._bind();return o};g.prototype.draw=function(){var n=this._map,l=n.pixelToPoint(new BMapGL.Pixel(0,0)),m=n.pointToOverlayPixel(l);this.container.style.left=m.x+"px";this.container.style.top=m.y+"px"};g.prototype.enableEdgeMove=function(){this._enableEdgeMove=true};g.prototype.disableEdgeMove=function(){clearInterval(this._edgeMoveTimer);this._enableEdgeMove=false};g.prototype._bind=function(){var q=this,l=this._map,m=this.container,r=null,s=null;var p=function(u){return{x:u.clientX,y:u.clientY}};var o=function(w){var v=w.type;w=d.getEvent(w);point=q.getDrawPoint(w);var x=function(y){w.point=point;q.dispatchEvent(w)};if(v=="mousedown"){r=p(w)}var u=p(w);if(v=="click"){if(Math.abs(u.x-r.x)<5&&Math.abs(u.y-r.y)<5){if(!s||!(Math.abs(u.x-s.x)<5&&Math.abs(u.y-s.y)<5)){x("click");s=p(w)}else{s=null}}}else{x(v)}};var t=["click","mousedown","mousemove","mouseup","dblclick"],n=t.length;while(n--){d.on(m,t[n],o)}d.on(m,"mousemove",function(u){if(q._enableEdgeMove){q.mousemoveAction(u)}})};g.prototype.mousemoveAction=function(s){function l(x){var w=x.clientX,v=x.clientY;if(x.changedTouches){w=x.changedTouches[0].clientX;v=x.changedTouches[0].clientY}return new BMapGL.Pixel(w,v) }var m=this._map,t=this,n=m.pointToPixel(this.getDrawPoint(s)),p=l(s),q=p.x-n.x,o=p.y-n.y;n=new BMapGL.Pixel((p.x-q),(p.y-o));this._draggingMovePixel=n;var u=m.pixelToPoint(n),r={pixel:n,point:u};this._panByX=this._panByY=0;if(n.x<=20||n.x>=m.width-20||n.y<=50||n.y>=m.height-10){if(n.x<=20){this._panByX=8}else{if(n.x>=m.width-20){this._panByX=-8}}if(n.y<=50){this._panByY=8}else{if(n.y>=m.height-10){this._panByY=-8}}if(!this._edgeMoveTimer){this._edgeMoveTimer=setInterval(function(){m.panBy(t._panByX,t._panByY,{noAnimation:true})},30)}}else{if(this._edgeMoveTimer){clearInterval(this._edgeMoveTimer);this._edgeMoveTimer=null}}};g.prototype._adjustSize=function(l){this.container.style.width=l.width+"px";this.container.style.height=l.height+"px"};g.prototype.getDrawPoint=function(q){var p=this._map,o=d.getTarget(q),m=q.offsetX||q.layerX||0,r=q.offsetY||q.layerY||0;if(o.nodeType!=1){o=o.parentNode}while(o&&o!=p.getContainer()){if(!(o.clientWidth==0&&o.clientHeight==0&&o.offsetParent&&o.offsetParent.nodeName=="TD")){m+=o.offsetLeft||0;r+=o.offsetTop||0}o=o.offsetParent}var n=new BMapGL.Pixel(m,r);var l=p.pixelToPoint(n);return l};function f(m,l){this.drawingManager=m;l=this.drawingToolOptions=l||{};this._opts={};this.defaultAnchor=BMAP_ANCHOR_TOP_LEFT;this.defaultOffset=new BMapGL.Size(10,10);this.defaultDrawingModes=[BMAP_DRAWING_MARKER,BMAP_DRAWING_CIRCLE,BMAP_DRAWING_POLYLINE,BMAP_DRAWING_POLYGON,BMAP_DRAWING_RECTANGLE];if(l.drawingModes){this.drawingModes=l.drawingModes}else{this.drawingModes=this.defaultDrawingModes}if(l.hasCustomStyle){if(l.anchor){this.setAnchor(l.anchor)}if(l.offset){this.setOffset(l.offset)}}}f.prototype=new BMapGL.Control();f.prototype.initialize=function(p){var m=this.container=document.createElement("div");m.className="BMapGLLib_Drawing";var l=this.panel=document.createElement("div");l.className="BMapGLLib_Drawing_panel";if(this.drawingToolOptions&&this.drawingToolOptions.hasCustomStyle&&this.drawingToolOptions.scale){this._setScale(this.drawingToolOptions.scale)}m.appendChild(l);var n=this._generalHtml();l.appendChild(n);var o=this.tip=document.createElement("div");o.className="BMapGLLib_tip";o.innerHTML='

';if(this.drawingToolOptions.enableTips===true){l.appendChild(o)}this._bind(l);if(this.drawingToolOptions.customContainer){d.g(this.drawingToolOptions.customContainer).appendChild(m)}else{p.getContainer().appendChild(m)}return m};f.prototype._generalHtml=function(r){var q=this;var m={};m.hander="拖动地图";m[BMAP_DRAWING_MARKER]="画点";m[BMAP_DRAWING_CIRCLE]="圆形工具";m[BMAP_DRAWING_POLYLINE]="画折线";m[BMAP_DRAWING_POLYGON]="多边形工具";m[BMAP_DRAWING_RECTANGLE]="矩形工具";var s=function(u,t){var v=document.createElement("a");v.className=u;v.href="javascript:void(0)";v.setAttribute("drawingType",t);v.setAttribute("onfocus","this.blur()");v.addEventListener("mouseenter",function(x){var w=x.target.getAttribute("drawingType");var y=m[w];if(w==="hander"){q.tip.children[0].innerText=y;q.tip.children[1].innerText="使用鼠标拖动地图"}else{q.tip.className+=" "+w;q.tip.children[0].innerText=y;q.tip.children[1].innerText="使用"+y+"选出目标区域"}q.tip.style.display="block"});v.addEventListener("mouseleave",function(y){var w=y.target.getAttribute("drawingType");var x=" "+q.tip.className.replace(/[\t\r\n]/g,"")+" ";while(x.indexOf(" "+w+" ")>=0){x=x.replace(" "+w+" "," ")}q.tip.className=x.replace(/^\s+|\s+$/g,"");q.tip.style.display="none"});return v};var n=document.createDocumentFragment();for(var o=0,l=this.drawingModes.length;o