10 lines
698 KiB
JavaScript
10 lines
698 KiB
JavaScript
|
|
var t=1e-6,e="undefined"!=typeof Float32Array?Float32Array:Array;function r(){var t=new e(4);return e!=Float32Array&&(t[1]=0,t[2]=0),t[0]=1,t[3]=1,t}function n(t,e){var r=e[0],n=e[1],i=e[2],s=e[3],a=r*s-i*n;return a?(t[0]=s*(a=1/a),t[1]=-n*a,t[2]=-i*a,t[3]=r*a,t):null}function i(t,e,r){var n=e[0],i=e[1],s=e[2],a=e[3],o=Math.sin(r),l=Math.cos(r);return t[0]=n*l+s*o,t[1]=i*l+a*o,t[2]=n*-o+s*l,t[3]=i*-o+a*l,t}function s(){var t=new e(9);return e!=Float32Array&&(t[1]=0,t[2]=0,t[3]=0,t[5]=0,t[6]=0,t[7]=0),t[0]=1,t[4]=1,t[8]=1,t}function a(t,e){return t[0]=e[0],t[1]=e[1],t[2]=e[2],t[3]=e[4],t[4]=e[5],t[5]=e[6],t[6]=e[8],t[7]=e[9],t[8]=e[10],t}function o(t,e){var r=e[0],n=e[1],i=e[2],s=e[3],a=e[4],o=e[5],l=e[6],u=e[7],c=e[8],h=c*a-o*u,p=-c*s+o*l,d=u*s-a*l,f=r*h+n*p+i*d;return f?(t[0]=h*(f=1/f),t[1]=(-c*n+i*u)*f,t[2]=(o*n-i*a)*f,t[3]=p*f,t[4]=(c*r-i*l)*f,t[5]=(-o*r+i*s)*f,t[6]=d*f,t[7]=(-u*r+n*l)*f,t[8]=(a*r-n*s)*f,t):null}function l(t,e){var r=e[0],n=e[1],i=e[2],s=e[3],a=e[4],o=e[5],l=e[6],u=e[7],c=e[8];return t[0]=a*c-o*u,t[1]=i*u-n*c,t[2]=n*o-i*a,t[3]=o*l-s*c,t[4]=r*c-i*l,t[5]=i*s-r*o,t[6]=s*u-a*l,t[7]=n*l-r*u,t[8]=r*a-n*s,t}function u(t,e,r){var n=e[0],i=e[1],s=e[2],a=e[3],o=e[4],l=e[5],u=e[6],c=e[7],h=e[8],p=r[0],d=r[1],f=r[2],m=r[3],y=r[4],g=r[5],x=r[6],v=r[7],b=r[8];return t[0]=p*n+d*a+f*u,t[1]=p*i+d*o+f*c,t[2]=p*s+d*l+f*h,t[3]=m*n+y*a+g*u,t[4]=m*i+y*o+g*c,t[5]=m*s+y*l+g*h,t[6]=x*n+v*a+b*u,t[7]=x*i+v*o+b*c,t[8]=x*s+v*l+b*h,t}function c(t,e){var r=Math.sin(e),n=Math.cos(e);return t[0]=n,t[1]=r,t[2]=0,t[3]=-r,t[4]=n,t[5]=0,t[6]=0,t[7]=0,t[8]=1,t}function h(){var t=new e(16);return e!=Float32Array&&(t[1]=0,t[2]=0,t[3]=0,t[4]=0,t[6]=0,t[7]=0,t[8]=0,t[9]=0,t[11]=0,t[12]=0,t[13]=0,t[14]=0),t[0]=1,t[5]=1,t[10]=1,t[15]=1,t}function p(t){var r=new e(16);return r[0]=t[0],r[1]=t[1],r[2]=t[2],r[3]=t[3],r[4]=t[4],r[5]=t[5],r[6]=t[6],r[7]=t[7],r[8]=t[8],r[9]=t[9],r[10]=t[10],r[11]=t[11],r[12]=t[12],r[13]=t[13],r[14]=t[14],r[15]=t[15],r}function d(t,r,n,i,s,a,o,l,u,c,h,p,d,f,m,y){var g=new e(16);return g[0]=t,g[1]=r,g[2]=n,g[3]=i,g[4]=s,g[5]=a,g[6]=o,g[7]=l,g[8]=u,g[9]=c,g[10]=h,g[11]=p,g[12]=d,g[13]=f,g[14]=m,g[15]=y,g}function f(t){return t[0]=1,t[1]=0,t[2]=0,t[3]=0,t[4]=0,t[5]=1,t[6]=0,t[7]=0,t[8]=0,t[9]=0,t[10]=1,t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,t}function m(t,e){if(t===e){var r=e[1],n=e[2],i=e[3],s=e[6],a=e[7],o=e[11];t[1]=e[4],t[2]=e[8],t[3]=e[12],t[4]=r,t[6]=e[9],t[7]=e[13],t[8]=n,t[9]=s,t[11]=e[14],t[12]=i,t[13]=a,t[14]=o}else t[0]=e[0],t[1]=e[4],t[2]=e[8],t[3]=e[12],t[4]=e[1],t[5]=e[5],t[6]=e[9],t[7]=e[13],t[8]=e[2],t[9]=e[6],t[10]=e[10],t[11]=e[14],t[12]=e[3],t[13]=e[7],t[14]=e[11],t[15]=e[15];return t}function y(t,e){var r=e[0],n=e[1],i=e[2],s=e[3],a=e[4],o=e[5],l=e[6],u=e[7],c=e[8],h=e[9],p=e[10],d=e[11],f=e[12],m=e[13],y=e[14],g=e[15],x=r*o-n*a,v=r*l-i*a,b=r*u-s*a,w=n*l-i*o,_=n*u-s*o,A=i*u-s*l,I=c*m-h*f,M=c*y-p*f,S=c*g-d*f,P=h*y-p*m,k=h*g-d*m,B=p*g-d*y,z=x*B-v*k+b*P+w*S-_*M+A*I;return z?(t[0]=(o*B-l*k+u*P)*(z=1/z),t[1]=(i*k-n*B-s*P)*z,t[2]=(m*A-y*_+g*w)*z,t[3]=(p*_-h*A-d*w)*z,t[4]=(l*S-a*B-u*M)*z,t[5]=(r*B-i*S+s*M)*z,t[6]=(y*b-f*A-g*v)*z,t[7]=(c*A-p*b+d*v)*z,t[8]=(a*k-o*S+u*I)*z,t[9]=(n*S-r*k-s*I)*z,t[10]=(f*_-m*b+g*x)*z,t[11]=(h*b-c*_-d*x)*z,t[12]=(o*M-a*P-l*I)*z,t[13]=(r*P-n*M+i*I)*z,t[14]=(m*v-f*w-y*x)*z,t[15]=(c*w-h*v+p*x)*z,t):null}function g(t,e,r){var n=e[0],i=e[1],s=e[2],a=e[3],o=e[4],l=e[5],u=e[6],c=e[7],h=e[8],p=e[9],d=e[10],f=e[11],m=e[12],y=e[13],g=e[14],x=e[15],v=r[0],b=r[1],w=r[2],_=r[3];return t[0]=v*n+b*o+w*h+_*m,t[1]=v*i+b*l+w*p+_*y,t[2]=v*s+b*u+w*d+_*g,t[3]=v*a+b*c+w*f+_*x,t[4]=(v=r[4])*n+(b=r[5])*o+(w=r[6])*h+(_=r[7])*m,t[5]=v*i+b*l+w*p+_*y,t[6]=v*s+b*u+w*d+_*g,t[7]=v*a+b*c+w*f+_*x,t[8]=(v=r[8])*n+(b=r[9])*o+(w=r[10])*h+(_=r[11])*m,t[9]=v*i+b*l+w*p+_*y,t[10]=v*s+b*u+w*d+_*g,t[11]=v*a+b*c+w*f+_*x,t[12]=(v=r[12])*n+(b=r[13])*o+(w=r[14])*h+(_=r[15])*m,t[13]=v*i+b*l+w*p+_*y,t[14]=v*s+b*u+w*d+_*g,t[15]=v*a+b*c+w*f+_*x,t}function x(t,e,r){var n,i,s,a,o,l,u,c,h,p,d,f,m=r[0],y=r[1],g=r[2];return e===t?(t[12]=e[0]*m+e[4]*y+e[8]*g+e[12],t[13]=e[1]*m+e[5]*y+e[9]*g+e[13],t[14]=e[2]*m+e[6]*y+e[10]*g+e[14],t[15
|
||
|
|
/**
|
||
|
|
* martinez v0.7.4
|
||
|
|
* Martinez polygon clipping algorithm, does boolean operation on polygons (multipolygons, polygons with holes etc): intersection, union, difference, xor
|
||
|
|
*
|
||
|
|
* @author Alex Milevski <info@w8r.name>
|
||
|
|
* @license MIT
|
||
|
|
* @preserve
|
||
|
|
*/function qd(t,e,r,n){const i=[],s=0===n?(t,e,r,n,i,s)=>{t.push(new $t(s,r+(s-e)/(n-e)*(i-r)))}:(t,e,r,n,i,s)=>{t.push(new $t(e+(s-r)/(i-r)*(n-e),s))};for(const a of t){const t=[];for(const i of a){if(i.length<=2)continue;const a=[];for(let t=0;t<i.length-1;t++){const o=i[t].x,l=i[t].y,u=i[t+1].x,c=i[t+1].y,h=0===n?o:l,p=0===n?u:c;h<e?p>e&&s(a,o,l,u,c,e):h>r?p<r&&s(a,o,l,u,c,r):a.push(i[t]),p<e&&h>=e&&s(a,o,l,u,c,e),p>r&&h<=r&&s(a,o,l,u,c,r)}let o=i[i.length-1];const l=0===n?o.x:o.y;l>=e&&l<=r&&a.push(o),a.length&&(o=a[a.length-1],a[0].x===o.x&&a[0].y===o.y||a.push(a[0]),t.push(a))}t.length&&i.push(t)}return i}function Hd(t,e){const r=Zd(t),n=Zd([e]),i=Gd.intersection(r,n);return null==i?[]:Wd(i)}function Xd(t,e){const r=65536;let n=Zd(t,r);const i=[];for(;e.valid();e.next()){const[t,n]=e.get(),s=t.x*r,a=t.y*r,o=n.x*r,l=n.y*r,u=o-s,c=l-a,h=Math.hypot(u,c);if(0===h)continue;const p=Math.trunc(c/h*3),d=-Math.trunc(u/h*3);i.push([[[s,a],[o,l],[o+p,l+d],[s+p,a+d],[s,a]]])}return i.length>0&&(n=Gd.diff(n,i)),Wd(n,1/r)}function Zd(t,e=1){return[t.map((t=>t.map((t=>[t.x*e,t.y*e]))))]}function Wd(t,e=1){return t.map((t=>t.map(((t,r)=>{const n=t.map((t=>new $t(t[0]*e,t[1]*e).round()));return r>0&&n.reverse(),n}))))}class Yd{constructor(t,e){this.layoutVertexArray=new _l,this.indexArray=new $l,this.lineIndexArray=new Ll,this.triangleSegments=new bu,this.lineSegments=new bu,this.programConfigurations=new Yu(t.layers,{zoom:t.zoom,lut:t.lut}),this.uploaded=!1,e&&(this.elevatedLayoutVertexArray=new Ml)}update(t,e,r,n,i,s,a,o){this.programConfigurations.updatePaintArrays(t,e,i,r,n,s,a,o)}isEmpty(){return 0===this.layoutVertexArray.length}needsUpload(){return this.programConfigurations.needsUpload}upload(t){this.uploaded||(this.layoutVertexBuffer=t.createVertexBuffer(this.layoutVertexArray,nd.members),this.indexBuffer=t.createIndexBuffer(this.indexArray),this.lineIndexBuffer=t.createIndexBuffer(this.lineIndexArray),this.elevatedLayoutVertexArray&&this.elevatedLayoutVertexArray.length>0&&(this.elevatedLayoutVertexBuffer=t.createVertexBuffer(this.elevatedLayoutVertexArray,id.members))),this.programConfigurations.upload(t),this.uploaded=!0}destroy(){this.layoutVertexBuffer&&(this.elevatedLayoutVertexBuffer&&this.elevatedLayoutVertexBuffer.destroy(),this.layoutVertexBuffer.destroy(),this.indexBuffer.destroy(),this.lineIndexBuffer.destroy(),this.programConfigurations.destroy(),this.triangleSegments.destroy(),this.lineSegments.destroy())}populatePaintArrays(t,e,r,n,i,s,a){this.programConfigurations.populatePaintArrays(this.layoutVertexArray.length,t,e,r,n,i,s,void 0,a)}}class Kd{constructor(t){this.zoom=t.zoom,this.pixelRatio=t.pixelRatio,this.overscaling=t.overscaling,this.layers=t.layers,this.layerIds=this.layers.map((t=>t.fqid)),this.index=t.index,this.hasPattern=!1,this.patternFeatures=[],this.lut=t.lut,this.bufferData=new Yd(t,!1),this.elevationBufferData=new Yd(t,!0),this.stateDependentLayerIds=this.layers.filter((t=>t.isStateDependent())).map((t=>t.id)),this.projection=t.projection,this.elevationMode=this.layers[0].layout.get("fill-elevation-reference"),this.sourceLayerIndex=t.sourceLayerIndex,this.worldview=t.worldview,this.hasAppearances=null}updateFootprints(t,e){}updateAppearances(t,e,r,n){}populate(t,e,r,n){this.hasPattern=Dd("fill",this.layers,this.pixelRatio,e);const i=this.layers[0].layout.get("fill-sort-key"),s=[];for(const{feature:a,id:o,index:l,sourceLayerIndex:u}of t){const t=this.layers[0]._featureFilter.needGeometry,c=Nc(a,t);if(!this.layers[0]._featureFilter.filter(new Po(this.zoom,{worldview:this.worldview,activeFloors:e.activeFloors}),c,r))continue;const h=i?i.evaluate(c,{},r,e.availableImages):void 0,p={id:o,properties:a.properties,type:a.type,sourceLayerIndex:u,index:l,geometry:t?c.geometry:Uc(a,r,n),patterns:{},sortKey:h};s.push(p)}i&&s.sort(((t,e)=>t.sortKey-e.sortKey));for(const n of s){const{geometry:i,index:s,sourceLayerIndex:a}=n;if(this.hasPattern){const t=Rd("fill",this.layers,n,this.zoom,this.pixelRatio,e);this.patternFeatures.push(t)}else this.addFeature(n,i,s,r,{},e.availableImages,e.brightness,e.elevat
|