-
Notifications
You must be signed in to change notification settings - Fork 92
/
gDBox.pkg.min.js
1 lines (1 loc) · 35.4 KB
/
gDBox.pkg.min.js
1
!function(t,e){"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?module.exports=e():t.gDBox=e()}(this,function(){var s;s=!1,gClass=function(){},gClass.extend=function(t){var i=null;function e(){s||(i&&(this._superprototype=i.prototype),this.init.apply(this,arguments))}for(var n in this!==gClass&&(i=this),i&&(s=!0,(e.prototype=new i).constructor=e,s=!1),e.extend=arguments.callee,t)t.hasOwnProperty(n)&&(e.prototype[n]=i&&"function"==typeof t[n]&&"function"==typeof e.prototype[n]&&/\b_super\b/.test(t[n])?function(t,e){return function(){return this._super=i.prototype[t],e.apply(this,arguments)}}(n,t[n]):t[n]);return e};var t,v={};function g(t,e,i){var n=t.activeFeature,s=t.activePoint,o=n.points[s.relationNodesIndex[0]],r=n.points[s.relationNodesIndex[1]],a=Math.sqrt((o.x-r.x)*(o.x-r.x)+(o.y-r.y)*(o.y-r.y)),h=(o.y-r.y)/a,l=(o.x-r.x)/a;return 1===h&&0===l||-1===h&&0===l?{dltx:e,dlty:0}:0===h&&1===l||0===h&&-1===l?{dltx:0,dlty:i}:{dltx:0,dlty:0}}function m(t){var e=t.activeFeature,i=t.activePoint,n=e.points[i.relationNodesIndex[0]],s=e.points[i.index],o=Math.sqrt((n.x-s.x)*(n.x-s.x)+(n.y-s.y)*(n.y-s.y)),r=(n.y-s.y)/o,a=(n.x-s.x)/o;return 0===r&&1===a||0===r&&-1===a?{flag:"y"}:{flag:"x"}}function e(t,e,i){return e in t?Object.defineProperty(t,e,{value:i,enumerable:!0,configurable:!0,writable:!0}):t[e]=i,t}return v.config={version:"1.1.0"},v.Util={},v.Util.createDiv=function(t,e,i,n){var s=document.createElement("div");return s.id=t,s.style.width=e+"px",s.style.height=i+"px",n&&(s.style.position="absolute"),s.style.zIndex=1,s},v.Util.createCanvas=function(t,e,i,n){var s=document.createElement("canvas");return s.id=t,s.width=e,s.height=i,s.style.width=e+"px",s.style.height=i+"px",n&&(s.style.position="absolute"),s},v.Util.isInArray=function(t,e){for(var i in t)if(t[i]==e)return!0;return!1},v.Util.isObjInArray=function(t,e){for(var i in t)if(t[i].id==e.id)return alert("已被添加,请更换图层id"+e.id),!0;return!1},v.Util.setStyle=function(t,e){return t.fillStyle=e.fillColor,t.strokeStyle=e.strokeColor,t.lineWidth=e.lineWeight,t.globalAlpha=e.opacity,!0},v.Util.worldToScreen=function(t,e,i){var n=t.getCenter(),s=n.x,o=n.y,r=parseInt(t.w)/2,a=parseInt(t.h)/2,h=t.zoom/parseInt(t.w);return{x:parseFloat(r)+parseFloat((e-s)/h)+0,y:parseFloat(a)-parseFloat((i-o)/h)+0}},v.Util.screenToWorld=function(t,e,i){var n=t.getCenter(),s=n.x,o=n.y,r=parseInt(t.w)/2,a=parseInt(t.h)/2,h=t.zoom/parseInt(t.w);return{x:parseFloat(s)+parseFloat((e-r)*h),y:parseFloat(o)-parseFloat((i-a)*h)}},v.Util.addEvtHandler=function(t,e,i){t["on"+e]=i,"mousewheel"==e&&0==v.Util.getIEVersion()&&t.addEventListener("DOMMouseScroll",i,!1)},v.Util.removeEvtHandler=function(t,e){t["on"+e]=null},v.Util.getMouseXY=function(t,e){var i=0,n=0,s=e.srcElement?e.srcElement:e.target;if(1!=s.nodeType)return{x:i,y:n};if(document.attachEvent){o="medium"==v.Util.getEleStyle(s,"border-top-width")?0:v.Util.delpx(v.Util.getEleStyle(s,"border-top-width")),r="medium"==v.Util.getEleStyle(s,"border-left-width")?0:v.Util.delpx(v.Util.getEleStyle(s,"border-left-width"));i=e.layerX-r,n=e.layerY-o}else{for(;s&&s!=t;){var o="medium"==v.Util.getEleStyle(s,"border-top-width")?0:v.Util.delpx(v.Util.getEleStyle(s,"border-top-width")),r="medium"==v.Util.getEleStyle(s,"border-left-width")?0:v.Util.delpx(v.Util.getEleStyle(s,"border-left-width"));i+=s.offsetLeft+r,n+=s.offsetTop+o,s=s.offsetParent}i=e.offsetX+i+document.body.scrollLeft,n=e.offsetY+n+document.body.scrollTop}return{x:i,y:n}},v.Util.getMousePos=function(t){var e=t||window.event;return{x:e.screenX,y:e.screenY}},v.Util.getEleStyle=function(t,e){var i=e.split("-"),n=i[0];if(1<n.length)for(var s=1;s<i.length;s++)n+=i[s].substring(0,1).toUpperCase()+i[s].substring(1);else n=e;return t.currentStyle?t.currentStyle[n]:document.defaultView.getComputedStyle(t,!1)[n]},v.Util.delpx=function(t){return""==t?0:parseInt(t.substring(0,t.length-2))},v.Util.getRectPointsWithSAndE=function(t,e){var i=e.x,n=t.y,s=t.x,o=e.y;return[{x:t.x,y:t.y},{x:i,y:n},{x:e.x,y:e.y},{x:s,y:o}]},v.Util.pointInPoly=function(t,e){for(var i=!1,n=-1,s=e.length,o=s-1;++n<s;o=n)(e[n].y<=t.y&&t.y<e[o].y||e[o].y<=t.y&&t.y<e[n].y)&&t.x<(e[o].x-e[n].x)*(t.y-e[n].y)/(e[o].y-e[n].y)+e[n].x&&(i=!i);return i},v.Util.preventDefault=function(t){t.preventDefault?t.preventDefault():window.event.returnValue=!1},v.Util.stopPropagation=function(t){t.stopPropagation?t.stopPropagation():window.event.cancelBubble=!0},v.Util.getButton=function(t){if(t=t||window.event,+[1])return t.button;switch(t.button){case 0:case 1:case 3:case 5:case 7:return 0;case 2:case 6:return 2;case 4:return 1}},v.Util.createTextArea=function(t,e,i,n){var s=document.createElement("textarea");return s.id=t,s.style.width=e+"px",s.style.height=i+"px",s.style.resize="none",n&&(s.style.position="absolute"),s.style.zIndex=1,s},v.Util.colorRgb=function(t,e){var i=t.toLowerCase();if(i&&/^#([0-9a-fA-f]{3}|[0-9a-fA-f]{6})$/.test(i)){if(4===i.length){for(var n="#",s=1;s<4;s+=1)n+=i.slice(s,s+1).concat(i.slice(s,s+1));i=n}var o=[];for(s=1;s<7;s+=2)o.push(parseInt("0x"+i.slice(s,s+2)));return"RGBA("+o.join(",")+","+e+")"}return i},v.Util.getIEVersion=function(){var t=window.navigator.userAgent.toLowerCase();return/msie 8\.0/i.test(t)?8:/msie 7\.0/i.test(t)?7:/msie 6\.0/i.test(t)?6:0},v.Util.formatGeoPointsWithDlt=function(t,e,i,n){for(var s=e.length,o=t.getZoom()/t.getSize().w,r=i*o,a=n*o,h=[],l=0;l<s;l++){var u=e[l];h.push({x:u.x+r,y:u.y-a})}return h},v.Util.calNewPointsWithNodesIndexTmpPoint=function(t,e,i,n,s){for(var o=e.length,r=t.getZoom()/t.getSize().w,a=n*r,h=s*r,l=[],u=[],c=0;c<o;c++){var y=e[c],f=v.Util.worldToScreen(t,y.x,y.y);i.includes(c)?(l.push({x:y.x+a,y:y.y-h}),u.push({x:f.x+n,y:f.y+s})):(l.push({x:y.x,y:y.y}),u.push({x:f.x,y:f.y}))}return{points:l,sPoints:u}},v.Util.calNewPointsWithNodesIndexFormalPoint=function(t,e,i,n,s,o,r){for(var a=e.length,h=t.getZoom()/t.getSize().w,l=s*h,u=o*h,c=[],y=[],f=0;f<a;f++){var d=e[f],p=v.Util.worldToScreen(t,d.x,d.y),x=i.indexOf(f);"y"===r&&0===x||"x"===r&&1===x?(c.push({x:d.x,y:d.y-u}),y.push({x:p.x,y:p.y+o})):"y"===r&&1===x||"x"===r&&0===x?(c.push({x:d.x+l,y:d.y}),y.push({x:p.x+s,y:p.y})):f===n?(c.push({x:d.x+l,y:d.y-u}),y.push({x:p.x+s,y:p.y+o})):(c.push({x:d.x,y:d.y}),y.push({x:p.x,y:p.y}))}return{points:c,sPoints:y}},v.Util.getBounds=function(t){for(var e=t[0].x,i=t[0].y,n=t[0].x,s=t[0].y,o=1;o<t.length;o++)e>t[o].x&&(e=t[o].x),n<t[o].x&&(n=t[o].x),i>t[o].y&&(i=t[o].y),s<t[o].y&&(s=t[o].y);return[{x:e,y:s},{x:n,y:s},{x:n,y:i},{x:e,y:i}]},v.Graph={},v.Graph.drawPoint=function(t,e){t.beginPath(),t.arc(e.x,e.y,3,0,2*Math.PI,!0),t.closePath(),t.fill()},v.Graph.drawPoint_geo=function(t,e,i){var n=v.Util.worldToScreen(t,i.x,i.y);e.beginPath(),e.arc(n.x,n.y,3,0,2*Math.PI,!0),e.closePath(),e.fill()},v.Graph.drawPoints=function(t,e){for(var i=0;i<e.length;i++){var n={x:e[i].x,y:e[i].y};this.drawPoint(t,n)}},v.Graph.drawPoints_geo=function(t,e,i){for(var n=0;n<i.length;n++){var s=v.Util.worldToScreen(t,i[n].x,i[n].y);this.drawPoint(e,s)}},v.Graph.drawRect=function(t,e,i,n){t.strokeRect(e.x,e.y,i,n)},v.Graph.drawPolygon=function(t,e){var i=e.length;if(2<=i){t.beginPath(),t.moveTo(e[0].x,e[0].y);for(var n=1;n<i;n++)t.lineTo(e[n].x,e[n].y);t.closePath()}t.stroke()},v.Geometry=gClass.extend({init:function(t){this.name=t},getVertices:function(){},getBounds:function(){},calcBounds:function(){}}),v.Geometry.Point=gClass.extend({init:function(t,e){this.x=t,this.y=e,this.className="point"}}),v.Geometry.LineString=v.Geometry.extend({init:function(t){this.className="line",this.points=[];for(var e=0;e<t.length;e++){var i=t[e];i instanceof v.Geometry.Point?this.points.push(i):alert("初始化节点失败!")}},addPoint:function(t,e){/^\d+$/.test(e)?this.points.splice(e,0,t):this.points.push(t)},delPoint:function(t){this.points.splice(t,1)},removePoint:function(t){for(var e=0;e<this.points.length;e++)if(this.points[e]==t){this.points.splice(e,1);break}},getLength:function(){for(var t=this.points.length,e=0,i=0;i<t-1;i++){e+=Math.sqrt((this.points[i].x-this.points[i+1].x)*(this.points[i].x-this.points[i+1].x)+(this.points[i].y-this.points[i+1].y)*(this.points[i].y-this.points[i+1].y))}return e}}),v.Geometry.LinearRing=v.Geometry.LineString.extend({init:function(t){if(t.length<=2)alert("组成多边形节点个数不足!");else{this._super(t),this.className="polygon";var e=t[0];this.points.push(e)}},addPoint:function(t,e){this.points.splice(e,0,t)},delPoint:function(t){if(4!=this.points.length){if(this.points.splice(t,1),0==t){this.points.pop();var e=this.points[0];this.points.push(e)}}else alert("节点数低于3个,不能删除!")},getCenterPoint:function(){for(var t=this.points,e=t.length,i=0,n=0,s=0;s<e;s++)i+=t[s].x,n+=t[s].y;var o=i/e,r=n/e;return new v.Geometry.Point(o,r)},getArea:function(){for(var t=0,e=this.points,i=0;i<e.length;i++)t+=e[i].x*e[(i+1)%e.length].y-e[(i+1)%e.length].x*e[i].y;return parseInt(Math.abs(.5*t))}}),v.Geometry.RectRing=v.Geometry.LineString.extend({init:function(t){t.length<4?alert("组成矩形节点个数不足!"):(this._super(t),this.className="rect")},addPoint:function(t,e){this.points.splice(e,0,t)},delPoint:function(t){if(4!=this.points.length){if(this.points.splice(t,1),0==t){this.points.pop();var e=this.points[0];this.points.push(e)}}else alert("节点数低于3个,不能删除!")},getArea:function(){for(var t=0,e=this.points,i=0;i<e.length;i++)t+=e[i].x*e[(i+1)%e.length].y-e[(i+1)%e.length].x*e[i].y;return parseInt(Math.abs(.5*t))}}),v.Geometry.RadiusRing=v.Geometry.extend({init:function(t,e){this.radius=e,this.centerPoint=t,this.className="radius"},getArea:function(){return 6.28318*this.radius*this.radius}}),v.Feature=gClass.extend({init:function(){},getVertices:function(){return this.points},getBounds:function(){for(var t=this.getVertices(),e=t[0].x,i=t[0].y,n=t[0].x,s=t[0].y,o=1;o<t.length;o++)e>t[o].x&&(e=t[o].x),n<t[o].x&&(n=t[o].x),i>t[o].y&&(i=t[o].y),s<t[o].y&&(s=t[o].y);return[{x:e,y:s},{x:n,y:s},{x:n,y:i},{x:e,y:i}]},calcBounds:function(){}}),v.Feature.Polygon=v.Feature.extend({init:function(t,e,i,n){this.activeSatus=!1,this.hoverStatus=!1,this._show=!1,this.id=t,this.points=e,this.data=i||{},this.gStyle=n},onAdd:function(t){this._layerID=t.id,this._layer=t,this._show=!0,this.setEditVertices(),this.style=this.gStyle||t.featureStyle||new v.Style({}),this.hoveStyle=t.featureHoverStyle||new v.Style({strokeColor:"#FF0000",lineWeight:2}),this.activeStyle=t.featureActiveStyle||new v.Style({strokeColor:"#FF0000",lineWeight:2}),this.onDraw(t)},onRemove:function(t){},setEditVertices:function(){for(var t=this.points,e=t.length,i=this._layer.getMap(),n=[],s=0;s<e-1;s++){var o=t[s],r=t[s+1],a=-1<s-1?s-1:e-1,h=(t[a].y-r.y)/(t[a].x-r.x);n.push({point:o,sPoint:v.Util.worldToScreen(i,o.x,o.y),type:"formal",index:s,k:-1/h,relationNodesIndex:[a,s+1]});var l={x:(o.x+r.x)/2,y:(o.y+r.y)/2},u=(r.y-o.y)/(r.x-o.x);if(n.push({point:l,sPoint:v.Util.worldToScreen(i,l.x,l.y),type:"tmp",index:s,k:-1/u,relationNodesIndex:[s,s+1]}),s===e-2){var c=(t[0].y-o.y)/(t[0].x-o.x);n.push({point:r,sPoint:v.Util.worldToScreen(i,r.x,r.y),type:"formal",index:s+1,k:-1/c,relationNodesIndex:[s,0]});var y=t[0],f={x:(y.x+r.x)/2,y:(y.y+r.y)/2},d=(t[0].y-r.y)/(t[0].x-r.x);n.push({point:f,sPoint:v.Util.worldToScreen(i,f.x,f.y),type:"tmp",index:s,k:-1/d,relationNodesIndex:[s+1,0]})}}this._editPoints=n},catchPointWithPos:function(t){if(!this._show)return{flag:!1,point:null};for(var e=this._editPoints,i=this._layer.getMap(),n=v.Util.worldToScreen(i,t.x,t.y),s=e.length,o=0;o<s;o++){var r=e[o].sPoint,a=(n.x-r.x)*(n.x-r.x)+(n.y-r.y)*(n.y-r.y);if(Math.sqrt(a)<=10)return{flag:!0,point:e[o]}}return{flag:!1,point:null}},show:function(){this._show||(this._show=!0,this._layer.renew())},hide:function(){this._show&&(this._show=!1,this._layer.renew())},update:function(t){this.points=t.points||this.points,this.data=t.data||this.data,this.style=t.style||this.style,t.points&&this.setEditVertices(),this._layer.renew()},pointInFeature:function(t){return!(!v.Util.pointInPoly(t,this.points)||!this._show)},hover:function(t){this.hoverStatus||(this.hoveStyle=t||this.hoveStyle,this.hoverStatus=!0,this._layer.renew())},deHover:function(){this.hoverStatus&&(this.hoverStatus=!1,this._layer.renew())},active:function(t){this.activeSatus||(this.activeStyle=t||this.activeStyle,this.activeSatus=!0,this._layer.renew())},deActive:function(){this.activeSatus&&(this.activeSatus=!1,this._layer.renew())},getStyle:function(){return this.activeSatus?this.activeStyle:(this.hoverStatus,this.style)},onDraw:function(t){if(this._show){var e=t.getCtx(),i=this.getStyle();v.Util.setStyle(e,i),this.hoverStatus&&!this.activeSatus&&(e.lineWidth=i.lineWeight+1),i.lineDash?e.setLineDash([10,5]):e.setLineDash([]);var n=t.getMap();e.globalAlpha=1;var s=this.points.length;if(2<=s){e.beginPath();var o=v.Util.worldToScreen(t._map,this.points[0].x,this.points[0].y);e.moveTo(o.x,o.y);for(var r=1;r<s;r++)o=v.Util.worldToScreen(t._map,this.points[r].x,this.points[r].y),e.lineTo(o.x,o.y);e.closePath()}e.stroke(),t._opacity?e.globalAlpha=0:e.globalAlpha=this.style.opacity,e.fill(),this.activeSatus&&(e.globalAlpha=1,e.fillStyle="#FF0000",v.Graph.drawPoints_geo(n,e,this._editPoints.map(function(t){return t.point})))}}}),v.Marker=gClass.extend({init:function(t,e){this.id=t,this._img=new Image,this._img.src=e.src,this.src=e.src,this._img.style.position="absolute",this._img.style.zIndex=100,this.info=e},onAdd:function(t){var e=(this._layer=t).getMap(),i=this._container=t.getLayerContainer();this.x=this.info.x,this.y=this.info.y;var n=v.Util.worldToScreen(e,this.info.x,this.info.y);this._img.style.left=n.x+this.info.offset.x+"px",this._img.style.top=n.y+this.info.offset.y+"px",this._img.style.cursor="pointer",i.appendChild(this._img)},onRemove:function(){this._container.removeChild(this._img)},update:function(t){t.x&&(this.info.x=t.x),t.y&&(this.info.y=t.y),t.offset&&(this.info.offset=t.offset),this.renew()},regEvent:function(t,e){if("click"===t){var i=this;v.Util.addEvtHandler(this._img,"mousedown",function(t){v.Util.preventDefault(t),v.Util.stopPropagation(t)}),v.Util.addEvtHandler(this._img,"mouseup",function(t){0==v.Util.getButton(t)&&e.apply(i,arguments),v.Util.preventDefault(t),v.Util.stopPropagation(t)}),v.Util.addEvtHandler(this._img,"click",function(t){v.Util.preventDefault(t),v.Util.stopPropagation(t)})}},renew:function(){var t=this._layer.getMap(),e=v.Util.worldToScreen(t,this.info.x,this.info.y);this._img.style.left=e.x+this.info.offset.x+"px",this._img.style.top=e.y+this.info.offset.y+"px"},showInfo:function(){console.log("Hello ...")}}),v.Text=gClass.extend({init:function(t,e,i){this.id=t,this.startPoint=e.pos,this.offset=e.offset||{x:0,y:0},this.boxMaxWidth=e.width,this.wrap=e.wrap||!1,this.text=e.text,this.style=i||new v.Style({})},onAdd:function(t){var e=this.id;this._w=this.boxMaxWidth;var i=v.Util.createDiv(e,this._w,this._h,!0);i.style.borderWidth=0,i.style.width="initial",i.style.maxWidth=this._w+"px",this.wrap||(i.style.overflow="hidden",i.style.textOverflow="ellipsis",i.style.whiteSpace="nowrap"),this._textContainer=i,(this._container=t.getLayerContainer()).appendChild(this._textContainer),this._layer=t,this.onDraw(t)},update:function(t){t.pos&&(this.startPoint=t.pos),t.offset&&(this.offset=t.offset),this.renew()},onDraw:function(t){var e=v.Util.worldToScreen(t._map,this.startPoint.x,this.startPoint.y);e.x=e.x+this.offset.x,e.y=e.y+this.offset.y,this._textContainer.style.fontSize=this.style.fontSize+"px",this._textContainer.style.lineHeight=this.style.fontSize+"px",this._textContainer.style.fontFamily=this.style.fontFamily+",SimSun",this._textContainer.style.color=this.style.fontColor,this._textContainer.style.borderRadius="1px",this._textContainer.style.boxSizing="border-box",this._textContainer.style.padding="1px";var i=v.Util.colorRgb(this.style.bgColor,this.style.opacity||1);this._textContainer.style.background=i,this._textContainer.textContent=this.text,this._textContainer.style.left=e.x+"px",this._textContainer.style.top=e.y+"px",t._layerContainer.appendChild(this._textContainer)},setText:function(t){this.text=t,this.refresh()},setPosition:function(t,e){this.startPoint.x=t,this.startPoint.y=e},setSize:function(t){this._w=this.boxMaxWidth=t},onRemove:function(){this._container.removeChild(this._textContainer)},getContainer:function(){return this._textContainer},renew:function(){var t=this._layer;this.onDraw(t)},refresh:function(){this.renew()}}),v.Style=gClass.extend({init:function(t){this.oStyle="singleStyle",this.fillColor=t.fillColor?t.fillColor:"#00DD00",this.strokeColor=t.strokeColor?t.strokeColor:"#00DD00",this.lineWeight=t.lineWeight?t.lineWeight:1,this.borderStatus=!t.borderStatus||t.borderStatus,this.cirRadius=t.cirRadius?t.cirRadius:3,this.fillStatus=!t.fillStatus||t.fillStatus,this.vtxStatus=!!t.vtxStatus&&t.vtxStatus,this.vtxRadius=t.vtxRadius?t.vtxRadius:3,this.tlr=t.tlr?t.tlr:5,this.opacity=t.opacity?t.opacity:1,this.mappingValue=t.mappingValue?t.mappingValue:"default",this.fontSize=t.fontSize?t.fontSize:13,this.fontFamily=t.fontFamily?t.fontFamily:"KaiTi",this.fontColor=t.fontColor?t.fontColor:"#333333",this.bgColor=t.bgColor?t.bgColor:"#ffffff",this.lineDash=t.lineDash||!1}}),v.Style_Ex=gClass.extend({init:function(t,e){this.oStyle="multiStyles",this.styles=t,this.mappingField=e}}),v.Edit={},v.Edit.mouseDown=function(t,e){t.drawRectPoints=[];var i=v.Util.getMouseXY(t._container,e),n=v.Util.screenToWorld(t,i.x,i.y);switch(t.mode){case"drawRect":if(t.activeFeature)t.dragging=!0;else{t.resetLayerStatus("active");var s=new v.Geometry.Point(n.x,n.y);t.drawRectPoints.push(s)}}},v.Edit.mouseMove=function(t,e){var i=v.Util.getMouseXY(t._container,e),n=i.x-t.startX,s=i.y-t.startY;switch(t.mode){case"drawRect":t.overLayer.clear();var o=t.overLayer.getCtx();if(v.Util.setStyle(o,t.globalStyle),t.activeFeature&&t.dragging)if(v.Util.setStyle(o,new v.Style({strokeColor:"#FF0000",lineWeight:2})),t.overLayer.topzIndex(),t.activeFeature.show&&t.activeFeature.hide(),t.activePoint){var r=t.activePoint;if("tmp"===r.type){var a=g(t,n,s),h=v.Util.calNewPointsWithNodesIndexTmpPoint(t,t.activeFeature.points,r.relationNodesIndex,a.dltx,a.dlty);v.Graph.drawPolygon(o,h.sPoints),t.userGeometryEditing&&t.userGeometryEditing("rect",t.activeFeature,h.points)}else if("formal"===r.type){var l=m(t),u=v.Util.calNewPointsWithNodesIndexFormalPoint(t,t.activeFeature.points,r.relationNodesIndex,r.index,n,s,l.flag);v.Graph.drawPolygon(o,u.sPoints),t.userGeometryEditing&&t.userGeometryEditing("rect",t.activeFeature,u.points)}}else{var c=t.activeFeature.getBounds(),y=c[0],f=c[2],d=v.Util.worldToScreen(t,y.x,y.y),p=v.Util.worldToScreen(t,f.x,f.y);v.Graph.drawRect(o,{x:d.x+n,y:d.y+s},p.x-d.x,p.y-d.y);var x=v.Util.formatGeoPointsWithDlt(t,t.activeFeature.points,n,s);t.userGeometryEditing&&t.userGeometryEditing("rect",t.activeFeature,x)}else 0<t.drawRectPoints.length&&(t.overLayer.topzIndex(),v.Graph.drawRect(o,{x:t.startX,y:t.startY},n,s))}return!0},v.Edit.mouseUp=function(t,e){var i=v.Util.getMouseXY(t._container,e),n=v.Util.screenToWorld(t,i.x,i.y),s=i.x-t.startX,o=i.y-t.startY,r=!0;switch(t.mode){case"drawRect":if(t.overLayer.clear(),t.activeFeature&&t.dragging){var a=[],h=t.activePoint;if(h){if("tmp"===h.type){var l=g(t,s,o);a=v.Util.calNewPointsWithNodesIndexTmpPoint(t,t.activeFeature.points,h.relationNodesIndex,l.dltx,l.dlty).points}else if("formal"===h.type){var u=m(t);a=v.Util.calNewPointsWithNodesIndexFormalPoint(t,t.activeFeature.points,h.relationNodesIndex,h.index,s,o,u.flag).points}}else a=v.Util.formatGeoPointsWithDlt(t,t.activeFeature.points,s,o);r=!1,t.userGeometryEditDone&&t.userGeometryEditDone("rect",t.activeFeature,a),t.dragging=!1}else if(0<t.drawRectPoints.length){var c=t.drawRectPoints[0];t.drawRectPoints=[];var y=new v.Geometry.Point(n.x,n.y),f=v.Util.getRectPointsWithSAndE(c,y);1<Math.abs(f[0].x-f[2].x)&&1<Math.abs(f[0].y-f[2].y)?(r=!1,t.userGeometryDrawDone&&t.userGeometryDrawDone("rect",f)):console.log("invalid points data: 绘制矩形 —— 不是有效矩形框...")}}return r},v.Map=gClass.extend((e(t={init:function(t,e){this._options=e||{},this._initContainer(t),this._initProp(),this._initEvent(),this.overLayer=new v.Layer.Overlay("overlay"),this.mLayer=new v.Layer.Marker("markerLayer"),this.addLayer(this.overLayer),this.addLayer(this.mLayer),this.attachEvents()},attachEvents:function(){var e=this;e.events={on:function(t,n){switch(t){case"beforeMouseDown":e.userBeforeMouseDown=function(t){var e=n(t);return"boolean"!=typeof e||e};break;case"mouseDown":e.userMouseDown=function(t){var e=n(t);return"boolean"!=typeof e||e};break;case"beforeMouseMove":e.userBeforeMouseMove=function(t){n(t)};break;case"mouseMove":e.userMouseMove=function(t){n(t)};break;case"beforeMouseUp":e.userBeforeMouseUp=function(t){n(t)};break;case"mouseUp":e.userMouseUp=function(t){n(t)};break;case"geometryEditing":e.userGeometryEditing=function(t,e,i){n(t,e,i)};break;case"geometryEditDone":e.userGeometryEditDone=function(t,e,i){n(t,e,i)};break;case"geometryDrawDone":e.userGeometryDrawDone=function(t,e){n(t,e)};break;case"featureHover":e.userFetureHover=function(t){n(t)};break;case"featureSelected":e.userFetureSelected=function(t){n(t)};break;case"featureStatusReset":e.userFeatureStatusReset=function(t){n(t)}}}}},_initContainer:function(t){this._container=document.getElementById(t),this._container.innerHTML="",this.w=this._options.w||this._container.clientWidth,this.h=this._options.h||this._container.clientHeight,this._container.style.overflow="hidden"},getContainer:function(){return this._container},getSize:function(){return{w:this.w,h:this.h}},_initProp:function(){this.mode="pan",this.dragging=!1,this.oLayers=[],this.zoom=this._options.zoom||parseInt(1*this.w,10),this.cx=this._options.cx||0,this.cy=this._options.cy||0,this.startX=0,this.startY=0,this.startScrX=0,this.startSrcY=0,this.zoomScale=.025,this.zoomMax=this._options.zoomMax||1e9,this.zoomMin=this._options.zoomMin||0,this.drawRectPoints=[],this.activeFeature=null,this.activePoint=null},_initEvent:function(){var y=this,t=(document.documentElement,this._container);v.Util.addEvtHandler(t,"mousedown",function(t){var e=t||window.event;window.event||e.preventDefault();var i=v.Util.getMouseXY(y._container,e),n=v.Util.screenToWorld(y,i.x,i.y),s=v.Util.getMousePos(e);if(y.startX=i.x,y.startY=i.y,y.startScrX=s.x,y.startScrY=s.y,y.userBeforeMouseDown&&!y.userBeforeMouseDown(n))return;"pan"===y.mode?(y.resetLayerStatus("active"),function(t){y.dragging=!0;for(var e=y.getAllLayers(),i=0;i<e.length;i++)e[i].startLeft=v.Util.delpx(e[i]._layerContainer.style.left),e[i].startTop=v.Util.delpx(e[i]._layerContainer.style.top)}(),document.onmousemove=function(t){!function(t){v.Util.getMouseXY(y._container,t);var e=v.Util.getMousePos(t);if(y.dragging){var i=e.x-y.startScrX,n=e.y-y.startScrY,s=y.getAllLayers();if(0<Math.abs(i)||0<Math.abs(n))for(var o=0;o<s.length;o++)s[o].onDrag(i,n)}}(t)},document.onmouseup=function(t){document.onmousemove=null,document.onmouseup=null,function(t){v.Util.getMouseXY(y._container,t);var e=v.Util.getMousePos(t),i=e.x-y.startScrX,n=e.y-y.startScrY;if(0<Math.abs(i)||0<Math.abs(n)){var s=y.getScreenCenter(),o=s.x-i,r=s.y-n,a=v.Util.screenToWorld(y,o,r);y.setCenter(a.x,a.y);for(var h=y.getAllLayers(),l=h.length,u=0;u<l;u++)h[u].renew()}y.dragging=!1}(t)}):(o=e,v.Edit.mouseDown(y,o));var o;y.userMouseDown&&y.userMouseDown(n)}),v.Util.addEvtHandler(t,"mousemove",function(t){var e=v.Util.getMouseXY(y._container,t),i=v.Util.screenToWorld(y,e.x,e.y);y.dragging||y.handleDrawEditGeometryMouseMove(i);if(y.userBeforeMouseMove&&!y.userBeforeMouseMove(i))return;v.Edit.mouseMove(y,t),y.userMouseMove&&y.userMouseMove(i),y.dragging||y.setTargets(i,"hover")}),v.Util.addEvtHandler(t,"mouseup",function(t){var e=v.Util.getMouseXY(y._container,t),i=v.Util.screenToWorld(y,e.x,e.y);if(y.overLayer.resetzIndex(),y.userBeforeMouseUp&&!y.userBeforeMouseUp(i))return;var n=v.Edit.mouseUp(y,t);if(y.userMouseUp&&y.userMouseUp(i),!n)return;"drawRect"===y.mode&&y.setTargets(i,"selected")}),v.Util.addEvtHandler(t,"mousewheel",function(t){v.Util.preventDefault(t);var e=v.Util.getMouseXY(y._container,t),i=v.Util.screenToWorld(y,e.x,e.y);if("pan"===y.mode){var n=t.wheelDelta||-t.detail;if(0<n){if(y.zoom<=this.zoomMin)return;var s=(i.x-y.cx)*(1-y.zoomScale),o=(i.y-y.cy)*(1-y.zoomScale),r=i.x-s,a=i.y-o;y.setCenter(r,a),y.zoomIn(1)}else{if(y.zoom>=this.zoomMax)return;var h=(i.x-y.cx)/(1-y.zoomScale),l=(i.y-y.cy)/(1-y.zoomScale),u=i.x-h,c=i.y-l;y.setCenter(u,c),y.zoomOut(1)}}})},handleDrawEditGeometryMouseMove:function(s){var o=this;switch(o.mode){case"pan":o.setCursor("pointer");break;case"drawRect":case"drawPolygon":if(function(){for(var t=o.getAllLayers(),e=0;e<t.length;e++)if("featureLayer"===t[e].oClass){var i=t[e].catchFeaturePointWithPos(s,"active");if(i.length)return o.activeFeature=i[0].feature,o.activePoint=i[0].point,!0;var n=t[e].getFeaturesWithPos(s,"active");if(n.length)return o.activeFeature=n[0],!(o.activePoint=null)}return o.activeFeature=null,o.activePoint=null,!1}())if(o.activePoint){var t=o.activePoint.k;0<t&&t!==1/0?o.setCursor("nesw-resize"):0===t?o.setCursor("ew-resize"):t<0&&t!==-1/0?o.setCursor("nwse-resize"):o.setCursor("ns-resize")}else o.setCursor("move");else o.setCursor("crosshair")}},setTargets:function(t,e){for(var i=this.getAllLayers(),n=[],s=0;s<i.length;s++)n=n.concat(i[s].getFeaturesWithPos(t));if("selected"===e){if(!n.length)return void this.resetLayerStatus("active");n[0].active(),this.handleDrawEditGeometryMouseMove(t),this.userFetureSelected&&this.userFetureSelected(n[0])}else if("hover"===e){if(!n.length)return void this.resetLayerStatus("hover");n[0].hover(),this.userFetureHover&&this.userFetureHover(n[0])}return this},resetLayerStatus:function(t){for(var e=this.getAllLayers(),i=0;i<e.length;i++)"featureLayer"===e[i].oClass&&(e[i].resetFeatureStatus(t),t&&"active"===t&&this.userFeatureStatusReset&&this.userFeatureStatusReset())},addLayer:function(t){var e=this.oLayers;v.Util.isObjInArray(e,t)||(t.onAdd(this),e.push(t))},removeLayer:function(t){},getAllLayers:function(){return this.oLayers},getNewZoom:function(t,e){for(var i=e||6,n=this.zoom;0<i;)"zoomIn"===t?n-=n*this.zoomScale:n/=1-this.zoomScale,i--;return n},getZoom:function(){return this.zoom},setZoom:function(t){this.zoom=t},zoomIn:function(t){if(!(this.zoom<=this.zoomMin)){var e=this.getAllLayers(),i=this.getNewZoom("zoomIn",t);this.zoom=i;for(var n=0;n<e.length;n++)e[n].zoomIn()}},zoomOut:function(t){if(!(this.zoom>=this.zoomMax)){var e=this.getAllLayers(),i=this.getNewZoom("zoomOut",t);this.zoom=i;for(var n=0;n<e.length;n++)e[n].zoomOut()}},setMode:function(t,e){switch(this.mode=t){case"pan":this.resetLayerStatus()}this.globalStyle=e||new v.Style({})},setCursor:function(t){var e=this._container.style.cursor;e!==t&&(this.previousCursor=e,this._container.style.cursor=t)},resetCursor:function(){this.setCursor(this.previousCursor)},getMode:function(){return this.mode},setCenter:function(t,e){this.cx=t,this.cy=e},centerAndZoom:function(t,e){this.setCenter(t.x,t.y),this.setZoom(e);for(var i=this.getAllLayers(),n=0;n<i.length;n++)i[n].zoomIn()},getCenter:function(){return{x:this.cx,y:this.cy}},getScreenCenter:function(){return{x:this.w/2,y:this.h/2}}},"setCenter",function(t,e){this.cx=t,this.cy=e}),e(t,"resize",function(t,e){var i=this.zoom/this.w,n=t||this._container.clientWidth,s=e||this._container.clientHeight;this.zoom=i*n,this.w=n,this.h=s;for(var o=this.getAllLayers(),r=0;r<o.length;r++)o[r].resize()}),e(t,"destroy",function(){this._container.innerHTML="";var t=this._container;v.Util.removeEvtHandler(t,"mousedown"),v.Util.removeEvtHandler(t,"mousemove"),v.Util.removeEvtHandler(t,"mouseup"),v.Util.removeEvtHandler(t,"mousewheel")}),t)),v.Layer=gClass.extend({init:function(t,e){this.id=t,this.visible=!0,this.options={opacity:1,zIndex:0}},onAdd:function(t){this._map=t,this._container=t.getContainer();var e=t.getSize();this._initLayerContainer(this.id,e.w,e.h),this._initProp(t),this._initParams(t),this._container.appendChild(this._layerContainer),this.setzIndex(),this.setOpacity(this.options.opacity)},onRemove:function(t){},_initProp:function(t){},_initParams:function(t){},onDrag:function(t,e){this._layerContainer.style.left=this.startLeft+t+"px",this._layerContainer.style.top=this.startTop+e+"px"},zoomIn:function(){this.renew()},zoomOut:function(){this.renew()},zoomTo:function(){this.renew()},renew:function(){this._layerContainer.style.left="0px",this._layerContainer.style.top="0px"},getSize:function(){return{w:this._layerContainer.clientWidth,h:this._layerContainer.clientHeight}},getScreenCenter:function(){return{x:parseInt(this._layerContainer.clientWidth/2,10),y:parseInt(this._layerContainer.clientHeight/2,10)}},getMap:function(){return this._map},getLayerContainer:function(){return this._layerContainer},setzIndex:function(){isNaN(this.options.zIndex)||(this._layerContainer.style.zIndex=this.options.zIndex)},setOpacity:function(t){this.getLayerContainer().style.opacity=t},resize:function(){this._layerContainer.style.width=this._map.w+"px",this._layerContainer.style.height=this._map.h+"px"},getFeaturesWithPos:function(t){return[]},deSelect:function(){}}),v.Layer.Image=v.Layer.extend({init:function(t,e,i,n){this._super(t,n),this._src=e,this._size=i,this.oClass="imgLayer"},_initParams:function(t){},_initProp:function(t){this._super(),this._mapImg||(this._mapImg=new Image),this._mapImg.style.position="absolute",this._mapImg.src=this._src,this._mapImg.onmousedown=function(t){t.preventDefault()},this._layerContainer.appendChild(this._mapImg),this.renew()},_initLayerContainer:function(t,e,i){var n=v.Util.createDiv(t,e,i,!0);n.style.zIndex=2,this._layerContainer=n},onAdd:function(t){this._super(t)},zoomTo:function(){},renew:function(){this._super();var t=this._map.getSize(),e=this._map.zoom/t.w;this._mapImg.width=this._size.w/e;var i=v.Util.worldToScreen(this._map,-1*this._size.w/2,this._size.h/2);this._mapImg.style.left=i.x+"px",this._mapImg.style.top=i.y+"px"},resize:function(){this._super(),this.renew()},refresh:function(){}}),v.Layer.Feature=v.Layer.extend({init:function(t,e){e=e||{},this._super(t,e),this.featureStyle=e.style||new v.Style({}),this.featureHoverStyle=e.hoverStyle||new v.Style({strokeColor:"#FF0000",lineWeight:2}),this.featureActiveStyle=e.activeStyle||new v.Style({strokeColor:"#FF0000",lineWeight:2}),this._opacity=!!e.transparent&&e.transparent,this.oClass="featureLayer"},_initLayerContainer:function(t,e,i){var n=v.Util.createCanvas(t,e,i,!0);this._layerContainer=n,this._ctx=n.getContext("2d"),this._layerContainer.style.left="0px",this._layerContainer.style.top="0px"},_initProp:function(t){this._super()},onAdd:function(t){var e=(this._map=t).getSize(),i=this._map.getContainer();this._initLayerContainer(this.id,e.w,e.h),i.appendChild(this._layerContainer),this.setzIndex(),this.oFeatures=[]},addFeature:function(t){var e=this.getAllFeatures();v.Util.isInArray(e,t)||(e.push(t),t.onAdd(this))},getFeatureById:function(t){for(var e=this.getAllFeatures(),i=e.length-1;0<=i;i--)if(e[i].id===t)return e[i];return null},getFeaturesWithPos:function(t,e){for(var i=[],n=this.getAllFeatures(),s=n.length-1;0<=s;s--){var o=n[s],r=!0;e&&"active"===e&&(r=o.activeSatus),o.pointInFeature(t)&&r&&i.push(o)}return i},catchFeaturePointWithPos:function(t,e){for(var i=[],n=this.getAllFeatures(),s=n.length-1;0<=s;s--){var o=n[s],r=!0;e&&"active"===e&&(r=o.activeSatus);var a=o.catchPointWithPos(t);a.flag&&r&&i.push({feature:o,point:a.point})}return i},resetFeatureStatus:function(t){for(var e=this.getAllFeatures(),i=e.length-1;0<=i;i--)t&&"active"===t?e[i].activeSatus=!1:e[i].hoverStatus=(t&&"hover"===t||(e[i].activeSatus=!1),!1);this.renew()},getActiveFeatures:function(){for(var t=[],e=this.getAllFeatures(),i=e.length-1;0<=i;i--)e[i].activeSatus&&t.push(e[i]);return t},getHoverFeatures:function(){for(var t=[],e=this.getAllFeatures(),i=e.length-1;0<=i;i--)e[i].hoverStatus&&t.push(e[i]);return t},removeAllFeatures:function(){this.oFeatures=[],this.renew()},removeFeature:function(t){for(var e=[],i=0,n=0;i<this.oFeatures.length;i++)this.oFeatures[i]!==t?(e[n]=this.oFeatures[i],n++):t.onRemove(this);this.oFeatures=e,this.renew()},removeFeatureById:function(t){for(var e=[],i=0,n=0;i<this.oFeatures.length;i++)this.oFeatures[i].id!==t?(e[n]=this.oFeatures[i],n++):this.oFeatures[i].onRemove(this);this.oFeatures=e,this.renew()},draw:function(){for(var t=this.getAllFeatures(),e=0;e<t.length;e++)t[e].onDraw(this)},renew:function(){this._super(),this.clear(),this.draw()},resize:function(){this._super(),this._layerContainer.width=this._map.w,this._layerContainer.height=this._map.h,this.renew()},clear:function(){var t=this.getLayerContainer();this._ctx.clearRect(0,0,t.width,t.height)},getAllFeatures:function(){return this.oFeatures},getCtx:function(){return this._ctx}}),v.Layer.Overlay=v.Layer.Feature.extend({init:function(t,e){this._super(t,e),this.options=e||{opacity:1,zIndex:10},this.zIndexTopFlag=!1,this.oClass="overlayLayer"},setStyle:function(t){this.style=t},initStyle:function(){var t=this.getCtx();t.strokeStyle="green",t.fillStyle="green",this._layerContainer.style.left="0px",this._layerContainer.style.top="0px",t.gloablAlpha=.7},onAdd:function(t){this._super(t),this.initStyle()},resize:function(){this._super(),this._layerContainer.width=this._map.w,this._layerContainer.height=this._map.h,this.renew()},topzIndex:function(){this.zIndexTopFlag||(this._layerContainer.style.zIndex=9999,this.zIndexTopFlag=!0)},resetzIndex:function(){this.zIndexTopFlag&&(this._layerContainer.style.zIndex=this.options.zIndex,this.zIndexTopFlag=!1)}}),v.Layer.Marker=v.Layer.extend({init:function(t,e){this._super(t,e),this.options=e||{opacity:1,zIndex:20},this.id=t,this.oClass="markerLayer",this.oMarkers=[]},_initLayerContainer:function(t,e,i){var n=v.Util.createDiv(t,e,i,!0);this._layerContainer=n},addMarker:function(t){v.Util.isInArray(this.oMarkers,t)||(this.oMarkers.push(t),t.onAdd(this))},removeMarker:function(t){for(var e=[],i=0,n=0;i<this.oMarkers.length;i++)this.oMarkers[i]!=t?(e[n]=this.oMarkers[i],n++):this.oMarkers[i].onRemove(this);this.oMarkers=e,this.renew()},removeMarkerById:function(t){for(var e=[],i=0,n=0;i<this.oMarkers.length;i++)this.oMarkers[i].id!==t?(e[n]=this.oMarkers[i],n++):this.oMarkers[i].onRemove(this);this.oMarkers=e,this.renew()},getAllMarkers:function(){return this.oMarkers},getMarkerById:function(t){for(var e=0;e<this.oMarkers.length;e++)if(this.oMarkers[e].id===t)return this.oMarkers[e];return null},addMarkers:function(t){this.oMarkers;for(var e=0;e<t.length;e++)this.addMarker(t[e])},removeMarkers:function(t){for(var e=t,i=e.length,n=0;n<i;n++){var s=e[n];this.removeMarker(s)}},removeAllMarkers:function(){var t=this.oMarkers;this.removeMarkers(t)},renew:function(){this._super();for(var t=0;t<this.oMarkers.length;t++)this.oMarkers[t].renew()},resize:function(){this._super(),this.renew()}}),v.Layer.Text=v.Layer.extend({init:function(t,e){this._super(t,e),this.options=e||{opacity:1,zIndex:19},this.id=t,this.oClass="textLayer",this.oTexts=[]},_initLayerContainer:function(t,e,i){var n=v.Util.createDiv(t,e,i,!0);this._layerContainer=n},addText:function(t){v.Util.isInArray(this.oTexts,t)||(this.oTexts.push(t),t.onAdd(this))},removeText:function(t){for(var e=[],i=0,n=0;i<this.oTexts.length;i++)this.oTexts[i]!=t?(e[n]=this.oTexts[i],n++):this.oTexts[i].onRemove(this);this.oTexts=e,this.renew()},getTextById:function(t){for(var e=0;e<this.oTexts.length;e++)if(this.oTexts[e].id===t)return this.oTexts[e];return null},removeTextById:function(t){for(var e=[],i=0,n=0;i<this.oTexts.length;i++)this.oTexts[i].id!=t?(e[n]=this.oTexts[i],n++):this.oTexts[i].onRemove(this);this.oTexts=e,this.renew()},addTexts:function(t){this.oTexts;for(var e=0;e<t.length;e++)this.addText(t[e])},removeTexts:function(t){for(var e=t,i=e.length,n=0;n<i;n++){var s=e[n];this.removeText(s)}},getAllTexts:function(){return this.oTexts},removeAllTexts:function(){this._layerContainer.innerHTML="",this.oTexts=[],this.renew()},renew:function(){this._super();for(var t=0;t<this.oTexts.length;t++)this.oTexts[t].renew()},resize:function(){this._super(),this.renew()}}),v});