qa-prevention-gwj-vue/static/map/cesium91/CesiumUnminified/Workers/GisTools.js

2 lines
2.9 KiB
JavaScript
Raw Permalink Normal View History

2023-12-17 15:30:40 +08:00
define((function(){"use strict";class t{static pointDistToLine(t,e,r,n,s,i){let l=((t-r)*(s-r)+(e-n)*(i-n))/((r-s)*(r-s)+(n-i)*(n-i)),a=r+l*(s-r),u=n+l*(i-n);return Math.sqrt((t-a)*(t-a)+(e-u)*(e-u))}static isPointOnSegment(e,r,n,s,i,l){if(e-5>n&&e+5>i||e+5<n&&e-5<i)return 0;if(r-5>s&&r+5>l||r+5<s&&r-5<l)return 0;return t.pointDistToLine(e,r,n,s,i,l)<5?1:0}static pointInLine(e,r,n){let s=[];Array.isArray(n[0])?s=n:s.push(n);for(var i=0;i<s.length;i++){let n=s[i],a=n.length/2;for(var l=0;l<a-1;l++){let s;s=l+1;let i=n[2*l],a=n[2*l+1],u=n[2*s],o=n[2*s+1];if(1==t.isPointOnSegment(e,r,i,a,u,o))return 1}}return 0}static pointInPolygon(t,e,r){let n=0,s=[];Array.isArray(r[0])?s=r:s.push(r);for(var i=0;i<s.length;i++){let r=s[i];for(var l=0,a=r.length/2,u=a-1;l<a;u=l,l++){let s=r[2*l],i=r[2*l+1],a=r[2*u],o=r[2*u+1];if(s===t&&i===e||a===t&&o===e)return 1;if(i<e&&o>=e||i>=e&&o<e){let r=s+(e-i)*(a-s)/(o-i);if(r===t)return 1;r>t&&(n=!n)}}}return n?1:0}static lineIntersects(t,e,r,n,s,i,l,a){var u,o,h,c,f=[null,null];return 0===(u=(a-i)*(r-t)-(l-s)*(n-e))?null!==f[0]&&null!==f[1]&&f:(c=(r-t)*(o=e-i)-(n-e)*(h=t-s),o=((l-s)*o-(a-i)*h)/u,h=c/u,f[0]=t+o*(r-t),f[1]=e+o*(n-e),h>0&&h<1&&f)}static polyWith(e,r){let n,s,i,l,a,u,o,h,c=e.length/2,f=r.length/2;for(let p=0;p<c;p++){p!=c-1?(s=e[2*p],i=e[2*p+1],l=e[2*p+2],n=e[2*p+3]):(s=e[2*p],i=e[2*p+1],l=e[0],n=e[1]);for(let e=0;e<f;e++)if(e!=f-1?(u=r[2*e],o=r[2*e+1],h=r[2*e+2],a=r[2*e+3]):(u=r[2*e],o=r[2*e+1],h=r[0],a=r[1]),0!=t.lineIntersects(s,i,l,n,u,o,h,a))return 1}let p=r[0],g=r[1];return t.pointInPolygon(p,g,e)?2:3}static boxToPolyArr(t,e,r,n){let s=[];return s.push(t),s.push(e),s.push(t),s.push(n),s.push(r),s.push(n),s.push(r),s.push(e),s.push(t),s.push(e),s}static getExtensionPoint(t,e,r){let n=e[0]-t[0],s=e[1]-t[1],i=e[0],l=e[1];if(0==n)l=s>0?e[1]+r:e[1]-r;else{let t=Math.sqrt(r*r/(s/n*(s/n)+1));n<0&&(t=-t),i=e[0]+t,l=e[1]+s/n*t}return[i,l]}static lineOffset(e,r){let n=[],s=[];return e.forEach((function(i,l){if(l!==e.length-1){let a=t.processSegment(i,e[l+1],r);if(n.push(a),l>0){let r=n[l-1],i=t.lineIntersects(a[0][0],a[0][1],a[1][0],a[1][1],r[0][0],r[0][1],r[1][0],r[1][1]);!1!==i&&(r[1]=i,a[0]=i),s.push(r[0]),l===e.length-2&&(s.push(a[0]),s.push(a[1]))}2===e.length&&(s.push(a[0]),s.push(a[1]))}})),s}static processSegment(t,e,r){let n=t[0],s=e[0],i=Math.sqrt((n[0]-s[0])*(n[0]-s[0])+(n[1]-s[1])*(n[1]-s[1])),l=n[0]+r*(s[1]-n[1])/i,a=s[0]+r*(s[1]-n[1])/i,u=n[1]+r*(n[0]-s[0])/i,o=s[1]+r*(n[0]-s[0])/i;return[[[l,u],t[1]],[[a,o],e[1]]]}static isInBox(t,e){return t[0]>=e[0]&&t[1]>=e[1]&&t[2]<=e[2]&&t[3]<=e[3]}static Utf8ArrayToStr(t){var e,r,n,s,i,l;for(e="",n=t.length,r=0;r<n;)switch((s=t[r++])>>4){case 0:case 1:case 2:case 3:case 4:case 5:case 6:case 7:e+=String.fromCharCode(s);break;case 12:case 13:i=t[r++],e+=String.fromCharCode((31&s)<<6|63&i);break;case 14:i=t[r++],l=t[r++],e+=String.fromCharCode((15&s)<<12|(63&i)<<6|(63&l)<<0)}return e}}return t}));