Repository navigation
Expand file tree
/
Copy pathGeoUtils.min.js
More file actions
1 lines (1 loc) · 3.87 KB
/
Copy pathGeoUtils.min.js
File metadata and controls
1 lines (1 loc) · 3.87 KB
1
var BMapLib=window.BMapLib=BMapLib||{};!function(){var t=6370996.81,a=BMapLib.GeoUtils=function(){};function n(t,a,n){return null!=a&&(t=Math.max(t,a)),null!=n&&(t=Math.min(t,n)),t}function l(t,a,n){for(;t>n;)t-=n-a;for(;t<a;)t+=n-a;return t}a.isPointInRect=function(t,a){if(!(t instanceof BMap.Point&&a instanceof BMap.Bounds))return!1;var n=a.getSouthWest(),l=a.getNorthEast();return t.lng>=n.lng&&t.lng<=l.lng&&t.lat>=n.lat&&t.lat<=l.lat},a.isPointInCircle=function(t,n){if(!(t instanceof BMap.Point&&n instanceof BMap.Circle))return!1;var l=n.getCenter(),e=n.getRadius();return a.getDistance(t,l)<=e},a.isPointOnPolyline=function(t,a){if(!(t instanceof BMap.Point&&a instanceof BMap.Polyline))return!1;var n=a.getBounds();if(!this.isPointInRect(t,n))return!1;for(var l=a.getPath(),e=0;e<l.length-1;e++){var i=l[e],r=l[e+1];if(t.lng>=Math.min(i.lng,r.lng)&&t.lng<=Math.max(i.lng,r.lng)&&t.lat>=Math.min(i.lat,r.lat)&&t.lat<=Math.max(i.lat,r.lat)){var o=(i.lng-t.lng)*(r.lat-t.lat)-(r.lng-t.lng)*(i.lat-t.lat);if(o<2e-10&&o>-2e-10)return!0}}return!1},a.isPointInPolygon=function(t,a){if(!(t instanceof BMap.Point&&a instanceof BMap.Polygon))return!1;var n=a.getBounds();if(!this.isPointInRect(t,n))return!1;var l,e,i=a.getPath(),r=i.length,o=!0,M=0,g=t;l=i[0];for(var h=1;h<=r;++h){if(g.equals(l))return o;if(e=i[h%r],g.lat<Math.min(l.lat,e.lat)||g.lat>Math.max(l.lat,e.lat))l=e;else{if(g.lat>Math.min(l.lat,e.lat)&&g.lat<Math.max(l.lat,e.lat)){if(g.lng<=Math.max(l.lng,e.lng)){if(l.lat==e.lat&&g.lng>=Math.min(l.lng,e.lng))return o;if(l.lng==e.lng){if(l.lng==g.lng)return o;++M}else{var s=(g.lat-l.lat)*(e.lng-l.lng)/(e.lat-l.lat)+l.lng;if(Math.abs(g.lng-s)<2e-10)return o;g.lng<s&&++M}}}else if(g.lat==e.lat&&g.lng<=e.lng){var f=i[(h+1)%r];g.lat>=Math.min(l.lat,f.lat)&&g.lat<=Math.max(l.lat,f.lat)?++M:M+=2}l=e}}return M%2!=0},a.degreeToRad=function(t){return Math.PI*t/180},a.radToDegree=function(t){return 180*t/Math.PI},a.getDistance=function(e,i){return e instanceof BMap.Point&&i instanceof BMap.Point?(e.lng=l(e.lng,-180,180),e.lat=n(e.lat,-74,74),i.lng=l(i.lng,-180,180),i.lat=n(i.lat,-74,74),r=a.degreeToRad(e.lng),M=a.degreeToRad(e.lat),o=a.degreeToRad(i.lng),g=a.degreeToRad(i.lat),t*Math.acos(Math.sin(M)*Math.sin(g)+Math.cos(M)*Math.cos(g)*Math.cos(o-r))):0;var r,o,M,g},a.getPolylineDistance=function(t){if(t instanceof BMap.Polyline||t instanceof Array){var n;if((n=t instanceof BMap.Polyline?t.getPath():t).length<2)return 0;for(var l=0,e=0;e<n.length-1;e++){var i=n[e],r=n[e+1];l+=a.getDistance(i,r)}return l}return 0},a.getPolygonArea=function(a){if(!(a instanceof BMap.Polygon||a instanceof Array))return 0;var n;if((n=a instanceof BMap.Polygon?a.getPath():a).length>3&&n[0].equals(n[n.length-1])&&(n=n.slice(0,n.length-1)),n.length<3)return 0;for(var l,e,i=0,r=0,o=0,M=0,g=0,h=0,s=0,f=0,c=0,P=0,u=0,I=0,B=0,v=0,p=0,d=0,m=0,y=0,R=0,x=0,T=0,b=0,D=0,q=0,L=0,A=0,C=0,w=0,E=t,G=n.length,N=0;N<G;N++)0==N?(i=n[G-1].lng*Math.PI/180,r=n[G-1].lat*Math.PI/180,o=n[0].lng*Math.PI/180,M=n[0].lat*Math.PI/180,g=n[1].lng*Math.PI/180,h=n[1].lat*Math.PI/180):N==G-1?(i=n[G-2].lng*Math.PI/180,r=n[G-2].lat*Math.PI/180,o=n[G-1].lng*Math.PI/180,M=n[G-1].lat*Math.PI/180,g=n[0].lng*Math.PI/180,h=n[0].lat*Math.PI/180):(i=n[N-1].lng*Math.PI/180,r=n[N-1].lat*Math.PI/180,o=n[N].lng*Math.PI/180,M=n[N].lat*Math.PI/180,g=n[N+1].lng*Math.PI/180,h=n[N+1].lat*Math.PI/180),s=Math.cos(M)*Math.cos(o),f=Math.cos(M)*Math.sin(o),c=Math.sin(M),P=Math.cos(r)*Math.cos(i),u=Math.cos(r)*Math.sin(i),I=Math.sin(r),(q=((T=(m=(s*s+f*f+c*c)/(s*(B=Math.cos(h)*Math.cos(g))+f*(v=Math.cos(h)*Math.sin(g))+c*(p=Math.sin(h))))*B-s)*(y=(d=(s*s+f*f+c*c)/(s*P+f*u+c*I))*P-s)+(b=m*v-f)*(R=d*u-f)+(D=m*p-c)*(x=d*I-c))/(Math.sqrt(T*T+b*b+D*D)*Math.sqrt(y*y+R*R+x*x)))<-1&&(q=-1),q=Math.acos(q),(0!=s?(b*x-D*R)/s:0!=f?(0-(T*x-D*y))/f:(T*R-b*y)/c)>0?(L+=q,w++):(A+=q,C++);return l=L+(2*Math.PI*C-A),e=2*Math.PI*w-L+A,((L>A?l-(G-2)*Math.PI<1?l:e:e-(G-2)*Math.PI<1?e:l)-(G-2)*Math.PI)*E*E}}();