@maplat/transform 0.4.1 → 0.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +224 -224
- package/README.ja.md +340 -170
- package/README.md +341 -171
- package/dist/index.d.ts +218 -1
- package/dist/maplat_transform.js +756 -459
- package/dist/maplat_transform.umd.js +1 -1
- package/package.json +3 -1
- package/src/compiled-state.ts +213 -211
- package/src/constants.ts +8 -0
- package/src/coord-utils.ts +27 -0
- package/src/edgeutils.ts +47 -47
- package/src/geometry.ts +240 -247
- package/src/index.ts +38 -398
- package/src/map-transform.ts +473 -0
- package/src/transform.ts +338 -0
- package/src/triangulation.ts +170 -179
- package/src/types.ts +162 -122
- package/src/viewpoint.ts +104 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(P,k){typeof exports=="object"&&typeof module<"u"?k(exports):typeof define=="function"&&define.amd?define(["exports"],k):(P=typeof globalThis<"u"?globalThis:P||self,k(P.maplat_transform={}))})(this,(function(P){"use strict";var Xt=Object.defineProperty;var Wt=(P,k,R)=>k in P?Xt(P,k,{enumerable:!0,configurable:!0,writable:!0,value:R}):P[k]=R;var x=(P,k,R)=>Wt(P,typeof k!="symbol"?k+"":k,R);function k(t,e,r={}){const n={type:"Feature"};return(r.id===0||r.id)&&(n.id=r.id),r.bbox&&(n.bbox=r.bbox),n.properties=e||{},n.geometry=t,n}function R(t,e,r={}){if(!t)throw new Error("coordinates is required");if(!Array.isArray(t))throw new Error("coordinates must be an Array");if(t.length<2)throw new Error("coordinates must be at least 2 numbers long");if(!J(t[0])||!J(t[1]))throw new Error("coordinates must contain numbers");return k({type:"Point",coordinates:t},e,r)}function G(t,e,r={}){for(const c of t){if(c.length<4)throw new Error("Each LinearRing of a Polygon must have 4 or more Positions.");if(c[c.length-1].length!==c[0].length)throw new Error("First and last Position are not equivalent.");for(let i=0;i<c[c.length-1].length;i++)if(c[c.length-1][i]!==c[0][i])throw new Error("First and last Position are not equivalent.")}return k({type:"Polygon",coordinates:t},e,r)}function W(t,e={}){const r={type:"FeatureCollection"};return e.id&&(r.id=e.id),e.bbox&&(r.bbox=e.bbox),r.features=t,r}function J(t){return!isNaN(t)&&t!==null&&!Array.isArray(t)}function at(t){if(!t)throw new Error("coord is required");if(!Array.isArray(t)){if(t.type==="Feature"&&t.geometry!==null&&t.geometry.type==="Point")return[...t.geometry.coordinates];if(t.type==="Point")return[...t.coordinates]}if(Array.isArray(t)&&t.length>=2&&!Array.isArray(t[0])&&!Array.isArray(t[1]))return[...t];throw new Error("coord must be GeoJSON Point or an Array of numbers")}function K(t){if(Array.isArray(t))return t;if(t.type==="Feature"){if(t.geometry!==null)return t.geometry.coordinates}else if(t.coordinates)return t.coordinates;throw new Error("coords must be GeoJSON Feature, Geometry Object or an Array")}function ct(t){return t.type==="Feature"?t.geometry:t}const F=11102230246251565e-32,S=134217729,ut=(3+8*F)*F;function $(t,e,r,n,c){let i,f,g,h,l=e[0],y=n[0],o=0,u=0;y>l==y>-l?(i=l,l=e[++o]):(i=y,y=n[++u]);let b=0;if(o<t&&u<r)for(y>l==y>-l?(f=l+i,g=i-(f-l),l=e[++o]):(f=y+i,g=i-(f-y),y=n[++u]),i=f,g!==0&&(c[b++]=g);o<t&&u<r;)y>l==y>-l?(f=i+l,h=f-i,g=i-(f-h)+(l-h),l=e[++o]):(f=i+y,h=f-i,g=i-(f-h)+(y-h),y=n[++u]),i=f,g!==0&&(c[b++]=g);for(;o<t;)f=i+l,h=f-i,g=i-(f-h)+(l-h),l=e[++o],i=f,g!==0&&(c[b++]=g);for(;u<r;)f=i+y,h=f-i,g=i-(f-h)+(y-h),y=n[++u],i=f,g!==0&&(c[b++]=g);return(i!==0||b===0)&&(c[b++]=i),b}function ft(t,e){let r=e[0];for(let n=1;n<t;n++)r+=e[n];return r}function Y(t){return new Float64Array(t)}const dt=(3+16*F)*F,ht=(2+12*F)*F,gt=(9+64*F)*F*F,V=Y(4),Q=Y(8),H=Y(12),Z=Y(16),T=Y(4);function lt(t,e,r,n,c,i,f){let g,h,l,y,o,u,b,p,d,a,s,m,v,M,_,w,A,O;const I=t-c,N=r-c,B=e-i,C=n-i;M=I*C,u=S*I,b=u-(u-I),p=I-b,u=S*C,d=u-(u-C),a=C-d,_=p*a-(M-b*d-p*d-b*a),w=B*N,u=S*B,b=u-(u-B),p=B-b,u=S*N,d=u-(u-N),a=N-d,A=p*a-(w-b*d-p*d-b*a),s=_-A,o=_-s,V[0]=_-(s+o)+(o-A),m=M+s,o=m-M,v=M-(m-o)+(s-o),s=v-w,o=v-s,V[1]=v-(s+o)+(o-w),O=m+s,o=O-m,V[2]=m-(O-o)+(s-o),V[3]=O;let X=ft(4,V),L=ht*f;if(X>=L||-X>=L||(o=t-I,g=t-(I+o)+(o-c),o=r-N,l=r-(N+o)+(o-c),o=e-B,h=e-(B+o)+(o-i),o=n-C,y=n-(C+o)+(o-i),g===0&&h===0&&l===0&&y===0)||(L=gt*f+ut*Math.abs(X),X+=I*y+C*g-(B*l+N*h),X>=L||-X>=L))return X;M=g*C,u=S*g,b=u-(u-g),p=g-b,u=S*C,d=u-(u-C),a=C-d,_=p*a-(M-b*d-p*d-b*a),w=h*N,u=S*h,b=u-(u-h),p=h-b,u=S*N,d=u-(u-N),a=N-d,A=p*a-(w-b*d-p*d-b*a),s=_-A,o=_-s,T[0]=_-(s+o)+(o-A),m=M+s,o=m-M,v=M-(m-o)+(s-o),s=v-w,o=v-s,T[1]=v-(s+o)+(o-w),O=m+s,o=O-m,T[2]=m-(O-o)+(s-o),T[3]=O;const Rt=$(4,V,4,T,Q);M=I*y,u=S*I,b=u-(u-I),p=I-b,u=S*y,d=u-(u-y),a=y-d,_=p*a-(M-b*d-p*d-b*a),w=B*l,u=S*B,b=u-(u-B),p=B-b,u=S*l,d=u-(u-l),a=l-d,A=p*a-(w-b*d-p*d-b*a),s=_-A,o=_-s,T[0]=_-(s+o)+(o-A),m=M+s,o=m-M,v=M-(m-o)+(s-o),s=v-w,o=v-s,T[1]=v-(s+o)+(o-w),O=m+s,o=O-m,T[2]=m-(O-o)+(s-o),T[3]=O;const Ut=$(Rt,Q,4,T,H);M=g*y,u=S*g,b=u-(u-g),p=g-b,u=S*y,d=u-(u-y),a=y-d,_=p*a-(M-b*d-p*d-b*a),w=h*l,u=S*h,b=u-(u-h),p=h-b,u=S*l,d=u-(u-l),a=l-d,A=p*a-(w-b*d-p*d-b*a),s=_-A,o=_-s,T[0]=_-(s+o)+(o-A),m=M+s,o=m-M,v=M-(m-o)+(s-o),s=v-w,o=v-s,T[1]=v-(s+o)+(o-w),O=m+s,o=O-m,T[2]=m-(O-o)+(s-o),T[3]=O;const Ft=$(Ut,H,4,T,Z);return Z[Ft-1]}function yt(t,e,r,n,c,i){const f=(e-i)*(r-c),g=(t-c)*(n-i),h=f-g,l=Math.abs(f+g);return Math.abs(h)>=dt*l?h:-lt(t,e,r,n,c,i,l)}function bt(t,e){var r,n,c=0,i,f,g,h,l,y,o,u=t[0],b=t[1],p=e.length;for(r=0;r<p;r++){n=0;var d=e[r],a=d.length-1;if(y=d[0],y[0]!==d[a][0]&&y[1]!==d[a][1])throw new Error("First and last coordinates in a ring must be the same");for(f=y[0]-u,g=y[1]-b,n;n<a;n++){if(o=d[n+1],h=o[0]-u,l=o[1]-b,g===0&&l===0){if(h<=0&&f>=0||f<=0&&h>=0)return 0}else if(l>=0&&g<=0||l<=0&&g>=0){if(i=yt(f,h,g,l,0,0),i===0)return 0;(i>0&&l>0&&g<=0||i<0&&l<=0&&g>0)&&c++}y=o,g=l,f=h}}return c%2!==0}function D(t,e,r={}){if(!t)throw new Error("point is required");if(!e)throw new Error("polygon is required");const n=at(t),c=ct(e),i=c.type,f=e.bbox;let g=c.coordinates;if(f&&mt(n,f)===!1)return!1;i==="Polygon"&&(g=[g]);let h=!1;for(var l=0;l<g.length;++l){const y=bt(n,g[l]);if(y===0)return!r.ignoreBoundary;y&&(h=!0)}return h}function mt(t,e){return e[0]<=t[0]&&e[1]<=t[1]&&e[2]>=t[0]&&e[3]>=t[1]}function tt(t,e){for(let r=0;r<e.features.length;r++)if(D(t,e.features[r]))return e.features[r]}function et(t,e,r){const n=e.geometry.coordinates[0][0],c=e.geometry.coordinates[0][1],i=e.geometry.coordinates[0][2],f=t.geometry.coordinates,g=e.properties.a.geom,h=e.properties.b.geom,l=e.properties.c.geom,y=[c[0]-n[0],c[1]-n[1]],o=[i[0]-n[0],i[1]-n[1]],u=[f[0]-n[0],f[1]-n[1]],b=[h[0]-g[0],h[1]-g[1]],p=[l[0]-g[0],l[1]-g[1]];let d=(o[1]*u[0]-o[0]*u[1])/(y[0]*o[1]-y[1]*o[0]),a=(y[0]*u[1]-y[1]*u[0])/(y[0]*o[1]-y[1]*o[0]);if(r){const s=r[e.properties.a.index],m=r[e.properties.b.index],v=r[e.properties.c.index];let M;if(d<0||a<0||1-d-a<0){const _=d/(d+a),w=a/(d+a);M=d/m/(_/m+w/v),a=a/v/(_/m+w/v)}else M=d/m/(d/m+a/v+(1-d-a)/s),a=a/v/(d/m+a/v+(1-d-a)/s);d=M}return[d*b[0]+a*p[0]+g[0],d*b[1]+a*p[1]+g[1]]}function wt(t,e,r,n){const c=t.geometry.coordinates,i=r.geometry.coordinates,f=Math.atan2(c[0]-i[0],c[1]-i[1]),g=xt(f,e[0]);if(g===void 0)throw new Error("Unable to determine vertex index");const h=e[1][g];return et(t,h.features[0],n)}function rt(t,e,r,n,c,i,f,g){let h;if(f&&(h=tt(t,W([f]))),!h){if(r){const l=t.geometry.coordinates,y=r.gridNum,o=r.xOrigin,u=r.yOrigin,b=r.xUnit,p=r.yUnit,d=r.gridCache,a=U(l[0],o,b,y),s=U(l[1],u,p,y),m=d[a]?d[a][s]?d[a][s]:[]:[];e=W(m.map(v=>e.features[v]))}h=tt(t,e)}return g&&g(h),h?et(t,h,i):wt(t,n,c,i)}function U(t,e,r,n){let c=Math.floor((t-e)/r);return c>=n&&(c=n-1),c}function xt(t,e){let r=nt(t-e[0]),n=Math.PI*2,c;for(let i=0;i<e.length;i++){const f=(i+1)%e.length,g=nt(t-e[f]),h=Math.min(Math.abs(r),Math.abs(g));r*g<=0&&h<n&&(n=h,c=i),r=g}return c}function nt(t,e=!1){const r=e?function(n){return!(n>=0&&n<Math.PI*2)}:function(n){return!(n>-1*Math.PI&&n<=Math.PI)};for(;r(t);)t=t+2*Math.PI*(t>0?-1:1);return t}function it(t,e){return e&&e>=2.00703||Array.isArray(t[0])?t:t.map(r=>[r.illstNodes,r.mercNodes,r.startEnd])}function pt(t){const e=t.features;for(let r=0;r<e.length;r++){const n=e[r];`${n.properties.a.index}`.substring(0,1)==="b"&&`${n.properties.b.index}`.substring(0,1)==="b"?e[r]={geometry:{type:"Polygon",coordinates:[[n.geometry.coordinates[0][2],n.geometry.coordinates[0][0],n.geometry.coordinates[0][1],n.geometry.coordinates[0][2]]]},properties:{a:{geom:n.properties.c.geom,index:n.properties.c.index},b:{geom:n.properties.a.geom,index:n.properties.a.index},c:{geom:n.properties.b.geom,index:n.properties.b.index}},type:"Feature"}:`${n.properties.c.index}`.substring(0,1)==="b"&&`${n.properties.a.index}`.substring(0,1)==="b"&&(e[r]={geometry:{type:"Polygon",coordinates:[[n.geometry.coordinates[0][1],n.geometry.coordinates[0][2],n.geometry.coordinates[0][0],n.geometry.coordinates[0][1]]]},properties:{a:{geom:n.properties.b.geom,index:n.properties.b.index},b:{geom:n.properties.c.geom,index:n.properties.c.index},c:{geom:n.properties.a.geom,index:n.properties.a.index}},type:"Feature"})}return t}function vt(t){const e=["a","b","c","a"].map(i=>t.properties[i].geom),r=t.geometry.coordinates[0],n=t.properties,c={a:{geom:r[0],index:n.a.index},b:{geom:r[1],index:n.b.index},c:{geom:r[2],index:n.c.index}};return G([e],c)}function Mt(t){const e=[0,1,2,0].map(n=>t[n][0][0]),r={a:{geom:t[0][0][1],index:t[0][1]},b:{geom:t[1][0][1],index:t[1][1]},c:{geom:t[2][0][1],index:t[2][1]}};return G([e],r)}function q(t,e,r,n,c,i=!1,f){const g=t.map(h=>{(!f||f<2.00703)&&(h=st(h));const l=isFinite(h)?e[h]:h==="c"?n:h==="b0"?c[0]:h==="b1"?c[1]:h==="b2"?c[2]:h==="b3"?c[3]:(function(){const y=h.match(/e(\d+)/);if(y){const o=parseInt(y[1]);return r[o]}throw"Bad index value for indexesToTri"})();return i?[[l[1],l[0]],h]:[[l[0],l[1]],h]});return Mt(g)}function st(t){return typeof t=="number"?t:t.replace(/^(c|e|b)(?:ent|dgeNode|box)(\d+)?$/,"$1$2")}const z=2.00703;function At(t){return!!(t.version||!t.tins&&t.points&&t.tins_points)}function _t(t){return{points:t.points,pointsWeightBuffer:Pt(t),strictStatus:St(t),verticesParams:Ot(t),centroid:Tt(t),edges:it(t.edges||[]),edgeNodes:t.edgeNodes||[],tins:kt(t),kinks:It(t.kinks_points),yaxisMode:t.yaxisMode??"invert",strictMode:t.strictMode??"auto",vertexMode:t.vertexMode,bounds:t.bounds,boundsPolygon:t.boundsPolygon,wh:t.wh,xy:t.bounds?t.xy:[0,0]}}function Et(t){const e=Nt(t),r=e.tins;return{compiled:e,tins:r,points:Bt(r),strictStatus:e.strict_status,pointsWeightBuffer:e.weight_buffer,verticesParams:e.vertices_params,centroid:e.centroid,kinks:e.kinks}}function Pt(t){return!t.version||t.version<z?["forw","bakw"].reduce((e,r)=>{const n=t.weight_buffer[r];return n&&(e[r]=Object.keys(n).reduce((c,i)=>{const f=st(i);return c[f]=n[i],c},{})),e},{}):t.weight_buffer}function St(t){return t.strict_status?t.strict_status:t.kinks_points?"strict_error":t.tins_points.length===2?"loose":"strict"}function Ot(t){const e={forw:[t.vertices_params[0]],bakw:[t.vertices_params[1]]};return e.forw[1]=ot(t,!1),e.bakw[1]=ot(t,!0),e}function ot(t,e){return[0,1,2,3].map(r=>{const n=(r+1)%4,c=q(["c",`b${r}`,`b${n}`],t.points,t.edgeNodes||[],t.centroid_point,t.vertices_points,e,z);return W([c])})}function Tt(t){return{forw:R(t.centroid_point[0],{target:{geom:t.centroid_point[1],index:"c"}}),bakw:R(t.centroid_point[1],{target:{geom:t.centroid_point[0],index:"c"}})}}function kt(t){const e=t.tins_points.length===1?0:1;return{forw:W(t.tins_points[0].map(r=>q(r,t.points,t.edgeNodes||[],t.centroid_point,t.vertices_points,!1,t.version))),bakw:W(t.tins_points[e].map(r=>q(r,t.points,t.edgeNodes||[],t.centroid_point,t.vertices_points,!0,t.version)))}}function It(t){if(t)return{bakw:W(t.map(e=>R(e)))}}function Nt(t){return JSON.parse(JSON.stringify(t).replace('"cent"','"c"').replace(/"bbox(\d+)"/g,'"b$1"'))}function Bt(t){const e=[],r=t.forw.features;for(let n=0;n<r.length;n++){const c=r[n];["a","b","c"].map((i,f)=>{const g=c.geometry.coordinates[0][f],h=c.properties[i].geom,l=c.properties[i].index;typeof l=="number"&&(e[l]=[g,h])})}return e}const Ct=z,E=class E{constructor(){x(this,"points",[]);x(this,"pointsWeightBuffer");x(this,"strict_status");x(this,"vertices_params");x(this,"centroid");x(this,"edgeNodes");x(this,"edges");x(this,"tins");x(this,"kinks");x(this,"yaxisMode",E.YAXIS_INVERT);x(this,"strictMode",E.MODE_AUTO);x(this,"vertexMode",E.VERTEX_PLAIN);x(this,"bounds");x(this,"boundsPolygon");x(this,"wh");x(this,"xy");x(this,"indexedTins");x(this,"stateFull",!1);x(this,"stateTriangle");x(this,"stateBackward");x(this,"priority");x(this,"importance");x(this,"xyBounds");x(this,"mercBounds")}setCompiled(e){if(At(e)){this.applyModernState(_t(e));return}this.applyLegacyState(Et(e))}applyModernState(e){this.points=e.points,this.pointsWeightBuffer=e.pointsWeightBuffer,this.strict_status=e.strictStatus,this.vertices_params=e.verticesParams,this.centroid=e.centroid,this.edges=e.edges,this.edgeNodes=e.edgeNodes||[],this.tins=e.tins,this.addIndexedTin(),this.kinks=e.kinks,this.yaxisMode=e.yaxisMode??E.YAXIS_INVERT,this.vertexMode=e.vertexMode??E.VERTEX_PLAIN,this.strictMode=e.strictMode??E.MODE_AUTO,e.bounds?(this.bounds=e.bounds,this.boundsPolygon=e.boundsPolygon,this.xy=e.xy,this.wh=e.wh):(this.bounds=void 0,this.boundsPolygon=void 0,this.xy=e.xy??[0,0],e.wh&&(this.wh=e.wh))}applyLegacyState(e){this.tins=e.tins,this.addIndexedTin(),this.strict_status=e.strictStatus,this.pointsWeightBuffer=e.pointsWeightBuffer,this.vertices_params=e.verticesParams,this.centroid=e.centroid,this.kinks=e.kinks,this.points=e.points}addIndexedTin(){const e=this.tins,r=e.forw,n=e.bakw,c=Math.ceil(Math.sqrt(r.features.length));if(c<3){this.indexedTins=void 0;return}let i=[],f=[];const g=r.features.map(d=>{let a=[];return K(d)[0].map(s=>{i.length===0?i=[Array.from(s),Array.from(s)]:(s[0]<i[0][0]&&(i[0][0]=s[0]),s[0]>i[1][0]&&(i[1][0]=s[0]),s[1]<i[0][1]&&(i[0][1]=s[1]),s[1]>i[1][1]&&(i[1][1]=s[1])),a.length===0?a=[Array.from(s),Array.from(s)]:(s[0]<a[0][0]&&(a[0][0]=s[0]),s[0]>a[1][0]&&(a[1][0]=s[0]),s[1]<a[0][1]&&(a[0][1]=s[1]),s[1]>a[1][1]&&(a[1][1]=s[1]))}),a}),h=(i[1][0]-i[0][0])/c,l=(i[1][1]-i[0][1])/c,y=g.reduce((d,a,s)=>{const m=U(a[0][0],i[0][0],h,c),v=U(a[1][0],i[0][0],h,c),M=U(a[0][1],i[0][1],l,c),_=U(a[1][1],i[0][1],l,c);for(let w=m;w<=v;w++){d[w]||(d[w]=[]);for(let A=M;A<=_;A++)d[w][A]||(d[w][A]=[]),d[w][A].push(s)}return d},[]),o=n.features.map(d=>{let a=[];return K(d)[0].map(s=>{f.length===0?f=[Array.from(s),Array.from(s)]:(s[0]<f[0][0]&&(f[0][0]=s[0]),s[0]>f[1][0]&&(f[1][0]=s[0]),s[1]<f[0][1]&&(f[0][1]=s[1]),s[1]>f[1][1]&&(f[1][1]=s[1])),a.length===0?a=[Array.from(s),Array.from(s)]:(s[0]<a[0][0]&&(a[0][0]=s[0]),s[0]>a[1][0]&&(a[1][0]=s[0]),s[1]<a[0][1]&&(a[0][1]=s[1]),s[1]>a[1][1]&&(a[1][1]=s[1]))}),a}),u=(f[1][0]-f[0][0])/c,b=(f[1][1]-f[0][1])/c,p=o.reduce((d,a,s)=>{const m=U(a[0][0],f[0][0],u,c),v=U(a[1][0],f[0][0],u,c),M=U(a[0][1],f[0][1],b,c),_=U(a[1][1],f[0][1],b,c);for(let w=m;w<=v;w++){d[w]||(d[w]=[]);for(let A=M;A<=_;A++)d[w][A]||(d[w][A]=[]),d[w][A].push(s)}return d},[]);this.indexedTins={forw:{gridNum:c,xOrigin:i[0][0],yOrigin:i[0][1],xUnit:h,yUnit:l,gridCache:y},bakw:{gridNum:c,xOrigin:f[0][0],yOrigin:f[0][1],xUnit:u,yUnit:b,gridCache:p}}}transform(e,r,n){if(r&&this.strict_status==E.STATUS_ERROR)throw'Backward transform is not allowed if strict_status == "strict_error"';this.yaxisMode==E.YAXIS_FOLLOW&&r&&(e=[e[0],-1*e[1]]);const c=R(e);if(this.bounds&&!r&&!n&&!D(c,this.boundsPolygon))return!1;const i=r?this.tins.bakw:this.tins.forw,f=r?this.indexedTins.bakw:this.indexedTins.forw,g=r?this.vertices_params.bakw:this.vertices_params.forw,h=r?this.centroid.bakw:this.centroid.forw,l=r?this.pointsWeightBuffer.bakw:this.pointsWeightBuffer.forw;let y,o;this.stateFull&&(this.stateBackward==r?y=this.stateTriangle:(this.stateBackward=r,this.stateTriangle=void 0),o=b=>{this.stateTriangle=b});let u=rt(c,i,f,g,h,l,y,o);if(this.bounds&&r&&!n){const b=R(u);if(!D(b,this.boundsPolygon))return!1}else this.yaxisMode==E.YAXIS_FOLLOW&&!r&&(u=[u[0],-1*u[1]]);return u}};x(E,"VERTEX_PLAIN","plain"),x(E,"VERTEX_BIRDEYE","birdeye"),x(E,"MODE_STRICT","strict"),x(E,"MODE_AUTO","auto"),x(E,"MODE_LOOSE","loose"),x(E,"STATUS_STRICT","strict"),x(E,"STATUS_ERROR","strict_error"),x(E,"STATUS_LOOSE","loose"),x(E,"YAXIS_FOLLOW","follow"),x(E,"YAXIS_INVERT","invert");let j=E;P.Transform=j,P.counterTri=vt,P.format_version=Ct,P.normalizeEdges=it,P.rotateVerticesTriangle=pt,P.transformArr=rt,Object.defineProperty(P,Symbol.toStringTag,{value:"Module"})}));
|
|
1
|
+
(function(T,B){typeof exports=="object"&&typeof module<"u"?B(exports):typeof define=="function"&&define.amd?define(["exports"],B):(T=typeof globalThis<"u"?globalThis:T||self,B(T.maplat_transform={}))})(this,(function(T){"use strict";var Gt=Object.defineProperty;var Zt=(T,B,O)=>B in T?Gt(T,B,{enumerable:!0,configurable:!0,writable:!0,value:O}):T[B]=O;var x=(T,B,O)=>Zt(T,typeof B!="symbol"?B+"":B,O);function B(e,t,r={}){const n={type:"Feature"};return(r.id===0||r.id)&&(n.id=r.id),r.bbox&&(n.bbox=r.bbox),n.properties=t||{},n.geometry=e,n}function O(e,t,r={}){if(!e)throw new Error("coordinates is required");if(!Array.isArray(e))throw new Error("coordinates must be an Array");if(e.length<2)throw new Error("coordinates must be at least 2 numbers long");if(!nt(e[0])||!nt(e[1]))throw new Error("coordinates must contain numbers");return B({type:"Point",coordinates:e},t,r)}function q(e,t,r={}){for(const s of e){if(s.length<4)throw new Error("Each LinearRing of a Polygon must have 4 or more Positions.");if(s[s.length-1].length!==s[0].length)throw new Error("First and last Position are not equivalent.");for(let i=0;i<s[s.length-1].length;i++)if(s[s.length-1][i]!==s[0][i])throw new Error("First and last Position are not equivalent.")}return B({type:"Polygon",coordinates:e},t,r)}function U(e,t={}){const r={type:"FeatureCollection"};return t.id&&(r.id=t.id),t.bbox&&(r.bbox=t.bbox),r.features=e,r}function nt(e){return!isNaN(e)&&e!==null&&!Array.isArray(e)}function gt(e){if(!e)throw new Error("coord is required");if(!Array.isArray(e)){if(e.type==="Feature"&&e.geometry!==null&&e.geometry.type==="Point")return[...e.geometry.coordinates];if(e.type==="Point")return[...e.coordinates]}if(Array.isArray(e)&&e.length>=2&&!Array.isArray(e[0])&&!Array.isArray(e[1]))return[...e];throw new Error("coord must be GeoJSON Point or an Array of numbers")}function st(e){if(Array.isArray(e))return e;if(e.type==="Feature"){if(e.geometry!==null)return e.geometry.coordinates}else if(e.coordinates)return e.coordinates;throw new Error("coords must be GeoJSON Feature, Geometry Object or an Array")}function bt(e){return e.type==="Feature"?e.geometry:e}const V=11102230246251565e-32,S=134217729,pt=(3+8*V)*V;function G(e,t,r,n,s){let i,o,u,l,f=t[0],m=n[0],a=0,d=0;m>f==m>-f?(i=f,f=t[++a]):(i=m,m=n[++d]);let g=0;if(a<e&&d<r)for(m>f==m>-f?(o=f+i,u=i-(o-f),f=t[++a]):(o=m+i,u=i-(o-m),m=n[++d]),i=o,u!==0&&(s[g++]=u);a<e&&d<r;)m>f==m>-f?(o=i+f,l=o-i,u=i-(o-l)+(f-l),f=t[++a]):(o=i+m,l=o-i,u=i-(o-l)+(m-l),m=n[++d]),i=o,u!==0&&(s[g++]=u);for(;a<e;)o=i+f,l=o-i,u=i-(o-l)+(f-l),f=t[++a],i=o,u!==0&&(s[g++]=u);for(;d<r;)o=i+m,l=o-i,u=i-(o-l)+(m-l),m=n[++d],i=o,u!==0&&(s[g++]=u);return(i!==0||g===0)&&(s[g++]=i),g}function wt(e,t){let r=t[0];for(let n=1;n<e;n++)r+=t[n];return r}function Y(e){return new Float64Array(e)}const xt=(3+16*V)*V,Mt=(2+12*V)*V,_t=(9+64*V)*V*V,F=Y(4),ot=Y(8),it=Y(12),at=Y(16),I=Y(4);function Tt(e,t,r,n,s,i,o){let u,l,f,m,a,d,g,b,y,h,c,p,M,_,E,w,v,C;const R=e-s,X=r-s,k=t-i,N=n-i;_=R*N,d=S*R,g=d-(d-R),b=R-g,d=S*N,y=d-(d-N),h=N-y,E=b*h-(_-g*y-b*y-g*h),w=k*X,d=S*k,g=d-(d-k),b=k-g,d=S*X,y=d-(d-X),h=X-y,v=b*h-(w-g*y-b*y-g*h),c=E-v,a=E-c,F[0]=E-(c+a)+(a-v),p=_+c,a=p-_,M=_-(p-a)+(c-a),c=M-w,a=M-c,F[1]=M-(c+a)+(a-w),C=p+c,a=C-p,F[2]=p-(C-a)+(c-a),F[3]=C;let L=wt(4,F),z=Mt*o;if(L>=z||-L>=z||(a=e-R,u=e-(R+a)+(a-s),a=r-X,f=r-(X+a)+(a-s),a=t-k,l=t-(k+a)+(a-i),a=n-N,m=n-(N+a)+(a-i),u===0&&l===0&&f===0&&m===0)||(z=_t*o+pt*Math.abs(L),L+=R*m+N*u-(k*f+X*l),L>=z||-L>=z))return L;_=u*N,d=S*u,g=d-(d-u),b=u-g,d=S*N,y=d-(d-N),h=N-y,E=b*h-(_-g*y-b*y-g*h),w=l*X,d=S*l,g=d-(d-l),b=l-g,d=S*X,y=d-(d-X),h=X-y,v=b*h-(w-g*y-b*y-g*h),c=E-v,a=E-c,I[0]=E-(c+a)+(a-v),p=_+c,a=p-_,M=_-(p-a)+(c-a),c=M-w,a=M-c,I[1]=M-(c+a)+(a-w),C=p+c,a=C-p,I[2]=p-(C-a)+(c-a),I[3]=C;const zt=G(4,F,4,I,ot);_=R*m,d=S*R,g=d-(d-R),b=R-g,d=S*m,y=d-(d-m),h=m-y,E=b*h-(_-g*y-b*y-g*h),w=k*f,d=S*k,g=d-(d-k),b=k-g,d=S*f,y=d-(d-f),h=f-y,v=b*h-(w-g*y-b*y-g*h),c=E-v,a=E-c,I[0]=E-(c+a)+(a-v),p=_+c,a=p-_,M=_-(p-a)+(c-a),c=M-w,a=M-c,I[1]=M-(c+a)+(a-w),C=p+c,a=C-p,I[2]=p-(C-a)+(c-a),I[3]=C;const qt=G(zt,ot,4,I,it);_=u*m,d=S*u,g=d-(d-u),b=u-g,d=S*m,y=d-(d-m),h=m-y,E=b*h-(_-g*y-b*y-g*h),w=l*f,d=S*l,g=d-(d-l),b=l-g,d=S*f,y=d-(d-f),h=f-y,v=b*h-(w-g*y-b*y-g*h),c=E-v,a=E-c,I[0]=E-(c+a)+(a-v),p=_+c,a=p-_,M=_-(p-a)+(c-a),c=M-w,a=M-c,I[1]=M-(c+a)+(a-w),C=p+c,a=C-p,I[2]=p-(C-a)+(c-a),I[3]=C;const jt=G(qt,it,4,I,at);return at[jt-1]}function vt(e,t,r,n,s,i){const o=(t-i)*(r-s),u=(e-s)*(n-i),l=o-u,f=Math.abs(o+u);return Math.abs(l)>=xt*f?l:-Tt(e,t,r,n,s,i,f)}function Et(e,t){var r,n,s=0,i,o,u,l,f,m,a,d=e[0],g=e[1],b=t.length;for(r=0;r<b;r++){n=0;var y=t[r],h=y.length-1;if(m=y[0],m[0]!==y[h][0]&&m[1]!==y[h][1])throw new Error("First and last coordinates in a ring must be the same");for(o=m[0]-d,u=m[1]-g,n;n<h;n++){if(a=y[n+1],l=a[0]-d,f=a[1]-g,u===0&&f===0){if(l<=0&&o>=0||o<=0&&l>=0)return 0}else if(f>=0&&u<=0||f<=0&&u>=0){if(i=vt(o,l,u,f,0,0),i===0)return 0;(i>0&&f>0&&u<=0||i<0&&f<=0&&u>0)&&s++}m=a,u=f,o=l}}return s%2!==0}function D(e,t,r={}){if(!e)throw new Error("point is required");if(!t)throw new Error("polygon is required");const n=gt(e),s=bt(t),i=s.type,o=t.bbox;let u=s.coordinates;if(o&&At(n,o)===!1)return!1;i==="Polygon"&&(u=[u]);let l=!1;for(var f=0;f<u.length;++f){const m=Et(n,u[f]);if(m===0)return!r.ignoreBoundary;m&&(l=!0)}return l}function At(e,t){return t[0]<=e[0]&&t[1]<=e[1]&&t[2]>=e[0]&&t[3]>=e[1]}function Z(e,t){for(let r=0;r<t.features.length;r++)if(D(e,t.features[r]))return t.features[r]}function ct(e,t,r){const n=t.geometry.coordinates[0][0],s=t.geometry.coordinates[0][1],i=t.geometry.coordinates[0][2],o=e.geometry.coordinates,u=t.properties.a.geom,l=t.properties.b.geom,f=t.properties.c.geom,m=[s[0]-n[0],s[1]-n[1]],a=[i[0]-n[0],i[1]-n[1]],d=[o[0]-n[0],o[1]-n[1]],g=[l[0]-u[0],l[1]-u[1]],b=[f[0]-u[0],f[1]-u[1]];let y=(a[1]*d[0]-a[0]*d[1])/(m[0]*a[1]-m[1]*a[0]),h=(m[0]*d[1]-m[1]*d[0])/(m[0]*a[1]-m[1]*a[0]);if(r){const c=r[t.properties.a.index],p=r[t.properties.b.index],M=r[t.properties.c.index];let _;if(y<0||h<0||1-y-h<0){const E=y/(y+h),w=h/(y+h);_=y/p/(E/p+w/M),h=h/M/(E/p+w/M)}else _=y/p/(y/p+h/M+(1-y-h)/c),h=h/M/(y/p+h/M+(1-y-h)/c);y=_}return[y*g[0]+h*b[0]+u[0],y*g[1]+h*b[1]+u[1]]}function St(e,t,r,n){const s=e.geometry.coordinates,i=r.geometry.coordinates,o=Math.atan2(s[0]-i[0],s[1]-i[1]),u=Ct(o,t[0]);if(u===void 0)throw new Error("Unable to determine vertex index");const l=t[1][u];return ct(e,l.features[0],n)}function ut(e,t,r,n,s,i,o,u){let l;if(o&&(l=Z(e,U([o]))),!l)if(r){const f=e.geometry.coordinates,m=r.gridNum,a=r.xOrigin,d=r.yOrigin,g=r.xUnit,b=r.yUnit,y=r.gridCache,h=W(f[0],a,g,m),c=W(f[1],d,b,m),p=y[h]?y[h][c]?y[h][c]:[]:[],M=U(p.map(_=>t.features[_]));l=Z(e,M)}else l=Z(e,t);return u&&u(l),l?ct(e,l,i):St(e,n,s,i)}function W(e,t,r,n){let s=Math.floor((e-t)/r);return s<0&&(s=0),s>=n&&(s=n-1),s}function Ct(e,t){let r=ft(e-t[0]),n=Math.PI*2,s;for(let i=0;i<t.length;i++){const o=(i+1)%t.length,u=ft(e-t[o]),l=Math.min(Math.abs(r),Math.abs(u));r*u<=0&&l<n&&(n=l,s=i),r=u}return s}function ft(e,t=!1){const r=2*Math.PI,n=e-Math.floor(e/r)*r;return t?n:n>Math.PI?n-r:n}function It(e){const t=e.features;for(let r=0;r<t.length;r++){const n=t[r];`${n.properties.a.index}`.substring(0,1)==="b"&&`${n.properties.b.index}`.substring(0,1)==="b"?t[r]={geometry:{type:"Polygon",coordinates:[[n.geometry.coordinates[0][2],n.geometry.coordinates[0][0],n.geometry.coordinates[0][1],n.geometry.coordinates[0][2]]]},properties:{a:{geom:n.properties.c.geom,index:n.properties.c.index},b:{geom:n.properties.a.geom,index:n.properties.a.index},c:{geom:n.properties.b.geom,index:n.properties.b.index}},type:"Feature"}:`${n.properties.c.index}`.substring(0,1)==="b"&&`${n.properties.a.index}`.substring(0,1)==="b"&&(t[r]={geometry:{type:"Polygon",coordinates:[[n.geometry.coordinates[0][1],n.geometry.coordinates[0][2],n.geometry.coordinates[0][0],n.geometry.coordinates[0][1]]]},properties:{a:{geom:n.properties.b.geom,index:n.properties.b.index},b:{geom:n.properties.c.geom,index:n.properties.c.index},c:{geom:n.properties.a.geom,index:n.properties.a.index}},type:"Feature"})}return e}function Bt(e){const t=["a","b","c","a"].map(i=>e.properties[i].geom),r=e.geometry.coordinates[0],n=e.properties,s={a:{geom:r[0],index:n.a.index},b:{geom:r[1],index:n.b.index},c:{geom:r[2],index:n.c.index}};return q([t],s)}function Ot(e){const t=[0,1,2,0].map(n=>e[n][0][0]),r={a:{geom:e[0][0][1],index:e[0][1]},b:{geom:e[1][0][1],index:e[1][1]},c:{geom:e[2][0][1],index:e[2][1]}};return q([t],r)}function J(e,t,r,n,s,i=!1,o){const u=e.map(l=>{(!o||o<2.00703)&&(l=ht(l));const f=isFinite(l)?t[l]:l==="c"?n:(function(){const m=l.match(/^b(\d+)$/);if(m)return s[parseInt(m[1])];const a=l.match(/^e(\d+)$/);if(a)return r[parseInt(a[1])];throw new Error("Bad index value for indexesToTri")})();return i?[[f[1],f[0]],l]:[[f[0],f[1]],l]});return Ot(u)}function ht(e){return typeof e=="number"?e:e.replace(/^(c|e|b)(?:ent|dgeNode|box)(\d+)?$/,"$1$2")}function dt(e,t){return t&&t>=2.00703||Array.isArray(e[0])?e:e.map(r=>[r.illstNodes,r.mercNodes,r.startEnd])}const K=2.00703;function Pt(e){return!!(e.version!==void 0||!e.tins&&e.points&&e.tins_points)}function Rt(e){return{points:e.points,pointsWeightBuffer:kt(e),strictStatus:Nt(e),verticesParams:Wt(e),centroid:Vt(e),edges:dt(e.edges||[]),edgeNodes:e.edgeNodes||[],tins:Lt(e),kinks:Ut(e.kinks_points),yaxisMode:e.yaxisMode??"invert",strictMode:e.strictMode??"auto",vertexMode:e.vertexMode,bounds:e.bounds,boundsPolygon:e.boundsPolygon,wh:e.wh,xy:e.xy??[0,0]}}function Xt(e){const t=Ft(e),r=t.tins;return{compiled:t,tins:r,points:Dt(r),strictStatus:t.strict_status,pointsWeightBuffer:t.weight_buffer,verticesParams:t.vertices_params,centroid:t.centroid,kinks:t.kinks}}function kt(e){return!e.version||e.version<K?["forw","bakw"].reduce((t,r)=>{const n=e.weight_buffer[r];return n&&(t[r]=Object.keys(n).reduce((s,i)=>{const o=ht(i);return s[o]=n[i],s},{})),t},{}):e.weight_buffer}function Nt(e){return e.strict_status?e.strict_status:e.kinks_points?"strict_error":e.tins_points.length===2?"loose":"strict"}function Wt(e){const t={forw:[e.vertices_params[0]],bakw:[e.vertices_params[1]]};return t.forw[1]=lt(e,!1),t.bakw[1]=lt(e,!0),t}function lt(e,t){const r=e.vertices_points.length;return Array.from({length:r},(n,s)=>{const i=(s+1)%r,o=J(["c",`b${s}`,`b${i}`],e.points,e.edgeNodes||[],e.centroid_point,e.vertices_points,t,K);return U([o])})}function Vt(e){return{forw:O(e.centroid_point[0],{target:{geom:e.centroid_point[1],index:"c"}}),bakw:O(e.centroid_point[1],{target:{geom:e.centroid_point[0],index:"c"}})}}function Lt(e){const t=e.tins_points.length===1?0:1;return{forw:U(e.tins_points[0].map(r=>J(r,e.points,e.edgeNodes||[],e.centroid_point,e.vertices_points,!1,e.version))),bakw:U(e.tins_points[t].map(r=>J(r,e.points,e.edgeNodes||[],e.centroid_point,e.vertices_points,!0,e.version)))}}function Ut(e){if(e)return{bakw:U(e.map(t=>O(t)))}}function Ft(e){return JSON.parse(JSON.stringify(e).replace('"cent"','"c"').replace(/"bbox(\d+)"/g,'"b$1"'))}function Dt(e){const t=[],r=e.forw.features;for(let n=0;n<r.length;n++){const s=r[n];["a","b","c"].forEach((i,o)=>{const u=s.geometry.coordinates[0][o],l=s.properties[i].geom,f=s.properties[i].index;typeof f=="number"&&(t[f]=[u,l])})}return t}const Yt=K,A=class A{constructor(){x(this,"points",[]);x(this,"pointsWeightBuffer");x(this,"strict_status");x(this,"vertices_params");x(this,"centroid");x(this,"edgeNodes");x(this,"edges");x(this,"tins");x(this,"kinks");x(this,"yaxisMode",A.YAXIS_INVERT);x(this,"strictMode",A.MODE_AUTO);x(this,"vertexMode",A.VERTEX_PLAIN);x(this,"bounds");x(this,"boundsPolygon");x(this,"wh");x(this,"xy");x(this,"indexedTins");x(this,"stateFull",!1);x(this,"stateTriangle");x(this,"stateBackward");x(this,"priority");x(this,"importance");x(this,"xyBounds");x(this,"mercBounds")}setCompiled(t){if(Pt(t)){this.applyModernState(Rt(t));return}this.applyLegacyState(Xt(t))}applyModernState(t){this.points=t.points,this.pointsWeightBuffer=t.pointsWeightBuffer,this.strict_status=t.strictStatus,this.vertices_params=t.verticesParams,this.centroid=t.centroid,this.edges=t.edges,this.edgeNodes=t.edgeNodes||[],this.tins=t.tins,this.addIndexedTin(),this.kinks=t.kinks,this.yaxisMode=t.yaxisMode??A.YAXIS_INVERT,this.vertexMode=t.vertexMode??A.VERTEX_PLAIN,this.strictMode=t.strictMode??A.MODE_AUTO,t.bounds?(this.bounds=t.bounds,this.boundsPolygon=t.boundsPolygon,this.xy=t.xy,this.wh=t.wh):(this.bounds=void 0,this.boundsPolygon=void 0,this.xy=t.xy??[0,0],t.wh&&(this.wh=t.wh))}applyLegacyState(t){this.tins=t.tins,this.addIndexedTin(),this.strict_status=t.strictStatus,this.pointsWeightBuffer=t.pointsWeightBuffer,this.vertices_params=t.verticesParams,this.centroid=t.centroid,this.kinks=t.kinks,this.points=t.points}addIndexedTin(){const t=this.tins,r=t.forw,n=t.bakw,s=Math.ceil(Math.sqrt(r.features.length));if(s<3){this.indexedTins=void 0;return}let i=[],o=[];const u=r.features.map(y=>{let h=[];return st(y)[0].map(c=>{i.length===0?i=[Array.from(c),Array.from(c)]:(c[0]<i[0][0]&&(i[0][0]=c[0]),c[0]>i[1][0]&&(i[1][0]=c[0]),c[1]<i[0][1]&&(i[0][1]=c[1]),c[1]>i[1][1]&&(i[1][1]=c[1])),h.length===0?h=[Array.from(c),Array.from(c)]:(c[0]<h[0][0]&&(h[0][0]=c[0]),c[0]>h[1][0]&&(h[1][0]=c[0]),c[1]<h[0][1]&&(h[0][1]=c[1]),c[1]>h[1][1]&&(h[1][1]=c[1]))}),h}),l=(i[1][0]-i[0][0])/s,f=(i[1][1]-i[0][1])/s,m=u.reduce((y,h,c)=>{const p=W(h[0][0],i[0][0],l,s),M=W(h[1][0],i[0][0],l,s),_=W(h[0][1],i[0][1],f,s),E=W(h[1][1],i[0][1],f,s);for(let w=p;w<=M;w++){y[w]||(y[w]=[]);for(let v=_;v<=E;v++)y[w][v]||(y[w][v]=[]),y[w][v].push(c)}return y},[]),a=n.features.map(y=>{let h=[];return st(y)[0].map(c=>{o.length===0?o=[Array.from(c),Array.from(c)]:(c[0]<o[0][0]&&(o[0][0]=c[0]),c[0]>o[1][0]&&(o[1][0]=c[0]),c[1]<o[0][1]&&(o[0][1]=c[1]),c[1]>o[1][1]&&(o[1][1]=c[1])),h.length===0?h=[Array.from(c),Array.from(c)]:(c[0]<h[0][0]&&(h[0][0]=c[0]),c[0]>h[1][0]&&(h[1][0]=c[0]),c[1]<h[0][1]&&(h[0][1]=c[1]),c[1]>h[1][1]&&(h[1][1]=c[1]))}),h}),d=(o[1][0]-o[0][0])/s,g=(o[1][1]-o[0][1])/s,b=a.reduce((y,h,c)=>{const p=W(h[0][0],o[0][0],d,s),M=W(h[1][0],o[0][0],d,s),_=W(h[0][1],o[0][1],g,s),E=W(h[1][1],o[0][1],g,s);for(let w=p;w<=M;w++){y[w]||(y[w]=[]);for(let v=_;v<=E;v++)y[w][v]||(y[w][v]=[]),y[w][v].push(c)}return y},[]);this.indexedTins={forw:{gridNum:s,xOrigin:i[0][0],yOrigin:i[0][1],xUnit:l,yUnit:f,gridCache:m},bakw:{gridNum:s,xOrigin:o[0][0],yOrigin:o[0][1],xUnit:d,yUnit:g,gridCache:b}}}transform(t,r,n){if(!this.tins)throw new Error("setCompiled() must be called before transform()");if(r&&this.strict_status==A.STATUS_ERROR)throw new Error('Backward transform is not allowed if strict_status == "strict_error"');this.yaxisMode==A.YAXIS_FOLLOW&&r&&(t=[t[0],-1*t[1]]);const s=O(t);if(this.bounds&&!r&&!n&&!D(s,this.boundsPolygon))return!1;const i=r?this.tins.bakw:this.tins.forw,o=r?this.indexedTins.bakw:this.indexedTins.forw,u=r?this.vertices_params.bakw:this.vertices_params.forw,l=r?this.centroid.bakw:this.centroid.forw,f=r?this.pointsWeightBuffer.bakw:this.pointsWeightBuffer.forw;let m,a;this.stateFull&&(this.stateBackward==r?m=this.stateTriangle:(this.stateBackward=r,this.stateTriangle=void 0),a=g=>{this.stateTriangle=g});let d=ut(s,i,o,u,l,f,m,a);if(this.bounds&&r&&!n){const g=O(d);if(!D(g,this.boundsPolygon))return!1}else this.yaxisMode==A.YAXIS_FOLLOW&&!r&&(d=[d[0],-1*d[1]]);return d}};x(A,"VERTEX_PLAIN","plain"),x(A,"VERTEX_BIRDEYE","birdeye"),x(A,"MODE_STRICT","strict"),x(A,"MODE_AUTO","auto"),x(A,"MODE_LOOSE","loose"),x(A,"STATUS_STRICT","strict"),x(A,"STATUS_ERROR","strict_error"),x(A,"STATUS_LOOSE","loose"),x(A,"YAXIS_FOLLOW","follow"),x(A,"YAXIS_INVERT","invert");let $=A;const P=20037508342789244e-9,yt=[[0,0],[0,1],[1,0],[0,-1],[-1,0]];function Q(e,t){return Math.floor(Math.min(e[0],e[1])/4)*P/128/Math.pow(2,t)}function mt(e,t){const r=[];for(let n=0;n<e.length;n++){const s=e[n],i=s[0]*Math.cos(t)-s[1]*Math.sin(t),o=s[0]*Math.sin(t)+s[1]*Math.cos(t);r.push([i,o])}return r}function H(e,t,r,n){const s=Q(n,t);return mt(yt,r).map(u=>[u[0]*s+e[0],u[1]*s+e[1]])}function tt(e,t){const r=e[0],s=e.slice(1,5).map(g=>[g[0]-r[0],g[1]-r[1]]),i=[[0,1],[1,0],[0,-1],[-1,0]];let o=0,u=0,l=0;for(let g=0;g<4;g++){const b=s[g],y=i[g],h=Math.sqrt(Math.pow(b[0],2)+Math.pow(b[1],2));o+=h;const c=b[0]*y[1]-b[1]*y[0],p=Math.acos((b[0]*y[0]+b[1]*y[1])/h),M=c>0?-1*p:p;u+=Math.cos(M),l+=Math.sin(M)}const f=o/4,m=Math.atan2(l,u),a=Math.floor(Math.min(t[0],t[1])/4),d=Math.log(a*P/128/f)/Math.log(2);return{center:r,zoom:d,rotation:m}}function j(e,t){const r=e[0]*(2*P)/t-P,n=-1*(e[1]*(2*P)/t-P);return[r,n]}function et(e,t){const r=(e[0]+P)*t/(2*P),n=(-e[1]+P)*t/(2*P);return[r,n]}const rt=256;class $t{constructor(){x(this,"mainTin",null);x(this,"subTins",[]);x(this,"_maxxy",0)}setMapData(t){const r=new $;if(r.setCompiled(t.compiled),this.mainTin=r,t.maxZoom!==void 0)this._maxxy=Math.pow(2,t.maxZoom)*rt;else if(t.compiled.wh){const n=Math.max(t.compiled.wh[0],t.compiled.wh[1]),s=Math.ceil(Math.log2(n/rt));this._maxxy=Math.pow(2,s)*rt}if(this.subTins=[],t.sub_maps)for(const n of t.sub_maps){const s=new $;s.setCompiled(n.compiled);const i=n.bounds??n.compiled.bounds;if(!i)throw new Error("SubMapData must have bounds or compiled.bounds to create xyBounds polygon");const o=[...i,i[0]],u=o.map(l=>{const f=s.transform(l,!1);if(!f)throw new Error("Failed to transform sub-map bounds to mercator");return f});this.subTins.push({tin:s,priority:n.priority,importance:n.importance,xyBounds:q([o]),mercBounds:q([u])})}}xy2Merc(t){const r=this.xy2MercWithLayer(t);return r?r[1]:!1}merc2Xy(t){const r=this.merc2XyWithLayer(t),n=r[0]||r[1];return n?n[1]:!1}xy2MercWithLayer(t){this._assertMapData();const r=this._getTinsSortedByPriority();for(let n=0;n<r.length;n++){const{index:s,isMain:i}=r[n];if(i||D(O(t),this.subTins[s-1].xyBounds)){const o=this._transformByIndex(t,s,!1);if(o===!1)continue;return[s,o]}}return!1}merc2XyWithLayer(t){return this._assertMapData(),this._getAllTinsWithIndex().map(({index:o,tin:u,isMain:l})=>{const f=this._transformByIndex(t,o,!0);return f===!1?[u,o]:l||D(O(f),this.subTins[o-1].xyBounds)?[u,o,f]:[u,o]}).sort((o,u)=>{const l=o[0].priority??0,f=u[0].priority??0;return l<f?1:-1}).reduce((o,u,l,f)=>{const m=u[0],a=u[1],d=u[2];if(!d)return o;for(let g=0;g<l;g++){const b=f[g][1],y=b===0;if(f[g][2]&&(y||D(O(d),this.subTins[b-1].xyBounds)))if(o.length){const h=!o[0],c=h?o[1][2]:o[0][2],p=m.importance??0,M=c.importance??0;return h?p<M?o:[void 0,[a,d,m]]:[...o.filter(w=>w!==void 0),[a,d,m]].sort((w,v)=>(w[2].importance??0)<(v[2].importance??0)?1:-1).slice(0,2)}else return[[a,d,m]]}return!o.length||!o[0]?[[a,d,m]]:(o.push([a,d,m]),o.sort((g,b)=>{const y=g[2].importance??0,h=b[2].importance??0;return y<h?1:-1}).filter((g,b)=>b<2))},[]).map(o=>{if(o)return[o[0],o[1]]})}mercs2SysCoords(t){this._assertMapData();const r=this.merc2XyWithLayer(t[0]);let n=!1;return r.map((s,i)=>{if(!s){n=!0;return}const o=s[0],u=s[1];return i!==0&&!n?[this.xy2SysCoordInternal(u)]:t.map((f,m)=>m===0?u:this._transformByIndex(f,o,!0)).map(f=>this.xy2SysCoordInternal(f))})}viewpoint2Mercs(t,r){this._assertMapData(),this._assertMaxxy();const s=H(t.center,t.zoom,t.rotation,r).map(f=>et(f,this._maxxy)),i=this.xy2MercWithLayer(s[0]);if(!i)throw new Error("viewpoint2Mercs: center point is out of bounds");const o=i[0],u=i[1];return s.map((f,m)=>{if(m===0)return u;const a=this._transformByIndex(f,o,!1);if(a===!1)throw new Error(`viewpoint2Mercs: point ${m} is out of bounds`);return a})}mercs2Viewpoint(t,r){this._assertMapData(),this._assertMaxxy();const n=this.merc2XyWithLayer(t[0]),s=n[0]||n[1];if(!s)throw new Error("mercs2Viewpoint: center point is out of bounds");const i=s[0],o=s[1],l=t.map((f,m)=>{if(m===0)return o;const a=this._transformByIndex(f,i,!0);if(a===!1)throw new Error(`mercs2Viewpoint: point ${m} is out of bounds`);return a}).map(f=>j(f,this._maxxy));return tt(l,r)}static zoom2Radius(t,r){return Q(t,r)}static mercViewpoint2Mercs(t,r,n,s){return H(t,r,n,s)}static mercs2MercViewpoint(t,r){return tt(t,r)}static xy2SysCoord(t,r){return j(t,r)}static sysCoord2Xy(t,r){return et(t,r)}_assertMapData(){if(!this.mainTin)throw new Error("setMapData() must be called before transformation")}_assertMaxxy(){if(this._maxxy===0)throw new Error("MapData.maxZoom or compiled.wh must be set for viewpoint conversion (xy2SysCoord / sysCoord2Xy)")}getLayerTransform(t){if(t===0)return this.mainTin;const r=this.subTins[t-1];return r?r.tin:null}get layerCount(){return 1+this.subTins.length}get maxxy(){return this._maxxy}_getTinsSortedByPriority(){return this._getAllTinsWithIndex().sort((r,n)=>{const s=r.tin.priority??0,i=n.tin.priority??0;return s<i?1:-1})}_getAllTinsWithIndex(){const t=[{index:0,tin:this.mainTin,isMain:!0}];return this.subTins.forEach((r,n)=>{r.tin.priority=r.priority,r.tin.importance=r.importance,t.push({index:n+1,tin:r.tin,isMain:!1})}),t}_transformByIndex(t,r,n){if(r===0)return this.mainTin.transform(t,n);const s=this.subTins[r-1];return s?s.tin.transform(t,n,!0):!1}xy2SysCoordInternal(t){return j(t,this._maxxy)}}T.MERC_CROSSMATRIX=yt,T.MERC_MAX=P,T.MapTransform=$t,T.Transform=$,T.counterTri=Bt,T.format_version=Yt,T.mercViewpoint2Mercs=H,T.mercs2MercViewpoint=tt,T.normalizeEdges=dt,T.rotateMatrix=mt,T.rotateVerticesTriangle=It,T.sysCoord2Xy=et,T.transformArr=ut,T.xy2SysCoord=j,T.zoom2Radius=Q,Object.defineProperty(T,Symbol.toStringTag,{value:"Module"})}));
|
package/package.json
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
7
|
-
"version": "0.
|
|
7
|
+
"version": "0.5.1",
|
|
8
8
|
"description": "A JavaScript library that performs coordinate transformation between two plane coordinate systems using transformation definitions generated by Maplat.",
|
|
9
9
|
"type": "module",
|
|
10
10
|
"engines": {
|
|
@@ -46,6 +46,7 @@
|
|
|
46
46
|
],
|
|
47
47
|
"devDependencies": {
|
|
48
48
|
"@eslint/js": "^9.39.2",
|
|
49
|
+
"@maplat/tin": "^0.14.0",
|
|
49
50
|
"@types/geojson": "^7946.0.16",
|
|
50
51
|
"@types/node": "^24.10.4",
|
|
51
52
|
"@typescript-eslint/eslint-plugin": "^8.50.1",
|
|
@@ -66,6 +67,7 @@
|
|
|
66
67
|
"@turf/turf": "^7.3.1"
|
|
67
68
|
},
|
|
68
69
|
"scripts": {
|
|
70
|
+
"generate:submaps": "node scripts/generate-submaps-compiled.mjs",
|
|
69
71
|
"dev": "vite --host",
|
|
70
72
|
"build": "pnpm run typecheck && cross-env BUILD_MODE=package vite build",
|
|
71
73
|
"typecheck": "tsc --noEmit --allowImportingTsExtensions",
|
package/src/compiled-state.ts
CHANGED
|
@@ -1,211 +1,213 @@
|
|
|
1
|
-
import { featureCollection, point } from "@turf/turf";
|
|
2
|
-
import type { Position } from "geojson";
|
|
3
|
-
import { normalizeEdges } from "./edgeutils.ts";
|
|
4
|
-
import { indexesToTri, normalizeNodeKey } from "./triangulation.ts";
|
|
5
|
-
import type { PropertyTriKey } from "./geometry.ts";
|
|
6
|
-
import type {
|
|
7
|
-
BiDirectionKey,
|
|
8
|
-
Compiled,
|
|
9
|
-
CompiledLegacy,
|
|
10
|
-
LegacyStatePayload,
|
|
11
|
-
ModernStatePayload,
|
|
12
|
-
PointSet,
|
|
13
|
-
StrictStatus,
|
|
14
|
-
TinsBD,
|
|
15
|
-
VerticesParamsBD,
|
|
16
|
-
WeightBufferBD
|
|
17
|
-
} from "./types.ts";
|
|
18
|
-
import type { WeightBuffer } from "./geometry.ts";
|
|
19
|
-
|
|
20
|
-
export const FORMAT_VERSION = 2.00703;
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
const
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
if (compiled.
|
|
98
|
-
if (compiled.
|
|
99
|
-
return "
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
params.
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
compiled.
|
|
120
|
-
compiled.
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
compiled.
|
|
155
|
-
compiled.
|
|
156
|
-
|
|
157
|
-
compiled.
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
compiled.
|
|
168
|
-
compiled.
|
|
169
|
-
|
|
170
|
-
compiled.
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
const
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
}
|
|
1
|
+
import { featureCollection, point } from "@turf/turf";
|
|
2
|
+
import type { Position } from "geojson";
|
|
3
|
+
import { normalizeEdges } from "./edgeutils.ts";
|
|
4
|
+
import { indexesToTri, normalizeNodeKey } from "./triangulation.ts";
|
|
5
|
+
import type { PropertyTriKey } from "./geometry.ts";
|
|
6
|
+
import type {
|
|
7
|
+
BiDirectionKey,
|
|
8
|
+
Compiled,
|
|
9
|
+
CompiledLegacy,
|
|
10
|
+
LegacyStatePayload,
|
|
11
|
+
ModernStatePayload,
|
|
12
|
+
PointSet,
|
|
13
|
+
StrictStatus,
|
|
14
|
+
TinsBD,
|
|
15
|
+
VerticesParamsBD,
|
|
16
|
+
WeightBufferBD
|
|
17
|
+
} from "./types.ts";
|
|
18
|
+
import type { WeightBuffer } from "./geometry.ts";
|
|
19
|
+
|
|
20
|
+
export const FORMAT_VERSION = 2.00703;
|
|
21
|
+
export const FORMAT_VERSION_V3 = 3;
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Type guard for discriminating modern compiled payloads.
|
|
25
|
+
*/
|
|
26
|
+
export function isModernCompiled(
|
|
27
|
+
compiled: Compiled | CompiledLegacy
|
|
28
|
+
): compiled is Compiled {
|
|
29
|
+
return Boolean(
|
|
30
|
+
compiled.version !== undefined ||
|
|
31
|
+
(!(compiled as CompiledLegacy).tins && compiled.points && compiled.tins_points)
|
|
32
|
+
);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Restore the in-memory state produced by modern compiled payloads.
|
|
37
|
+
*/
|
|
38
|
+
export function restoreModernState(compiled: Compiled): ModernStatePayload {
|
|
39
|
+
return {
|
|
40
|
+
points: compiled.points,
|
|
41
|
+
pointsWeightBuffer: normalizeWeightBuffer(compiled),
|
|
42
|
+
strictStatus: deriveStrictStatus(compiled),
|
|
43
|
+
verticesParams: buildVerticesParams(compiled),
|
|
44
|
+
centroid: buildCentroid(compiled),
|
|
45
|
+
edges: normalizeEdges(compiled.edges || []),
|
|
46
|
+
edgeNodes: compiled.edgeNodes || [],
|
|
47
|
+
tins: buildTins(compiled),
|
|
48
|
+
kinks: buildKinks(compiled.kinks_points),
|
|
49
|
+
yaxisMode: compiled.yaxisMode ?? "invert",
|
|
50
|
+
strictMode: compiled.strictMode ?? "auto",
|
|
51
|
+
vertexMode: compiled.vertexMode,
|
|
52
|
+
bounds: compiled.bounds,
|
|
53
|
+
boundsPolygon: compiled.boundsPolygon,
|
|
54
|
+
wh: compiled.wh,
|
|
55
|
+
xy: compiled.xy ?? [0, 0]
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Restore the in-memory state produced by the legacy payloads.
|
|
61
|
+
*/
|
|
62
|
+
export function restoreLegacyState(
|
|
63
|
+
rawCompiled: CompiledLegacy
|
|
64
|
+
): LegacyStatePayload {
|
|
65
|
+
const normalized = normalizeLegacyStructure(rawCompiled);
|
|
66
|
+
const tins = normalized.tins!;
|
|
67
|
+
return {
|
|
68
|
+
compiled: normalized,
|
|
69
|
+
tins,
|
|
70
|
+
points: rebuildLegacyPoints(tins),
|
|
71
|
+
strictStatus: normalized.strict_status,
|
|
72
|
+
pointsWeightBuffer: normalized.weight_buffer,
|
|
73
|
+
verticesParams: normalized.vertices_params as VerticesParamsBD,
|
|
74
|
+
centroid: normalized.centroid,
|
|
75
|
+
kinks: normalized.kinks
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
function normalizeWeightBuffer(compiled: Compiled): WeightBufferBD {
|
|
80
|
+
if (!compiled.version || compiled.version < FORMAT_VERSION) {
|
|
81
|
+
return (["forw", "bakw"] as BiDirectionKey[]).reduce((bd, forb) => {
|
|
82
|
+
const base = compiled.weight_buffer[forb];
|
|
83
|
+
if (base) {
|
|
84
|
+
bd[forb] = Object.keys(base).reduce((buffer, key) => {
|
|
85
|
+
const normKey = normalizeNodeKey(key);
|
|
86
|
+
buffer[normKey] = base[key];
|
|
87
|
+
return buffer;
|
|
88
|
+
}, {} as WeightBuffer);
|
|
89
|
+
}
|
|
90
|
+
return bd;
|
|
91
|
+
}, {} as WeightBufferBD);
|
|
92
|
+
}
|
|
93
|
+
return compiled.weight_buffer;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
function deriveStrictStatus(compiled: Compiled): StrictStatus {
|
|
97
|
+
if (compiled.strict_status) return compiled.strict_status;
|
|
98
|
+
if (compiled.kinks_points) return "strict_error";
|
|
99
|
+
if (compiled.tins_points.length === 2) return "loose";
|
|
100
|
+
return "strict";
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
function buildVerticesParams(compiled: Compiled): VerticesParamsBD {
|
|
104
|
+
const params: VerticesParamsBD = {
|
|
105
|
+
forw: [compiled.vertices_params[0]],
|
|
106
|
+
bakw: [compiled.vertices_params[1]]
|
|
107
|
+
};
|
|
108
|
+
params.forw![1] = buildVertexTins(compiled, false);
|
|
109
|
+
params.bakw![1] = buildVertexTins(compiled, true);
|
|
110
|
+
return params;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
function buildVertexTins(compiled: Compiled, bakw: boolean) {
|
|
114
|
+
const N = compiled.vertices_points.length;
|
|
115
|
+
return Array.from({ length: N }, (_, idx) => {
|
|
116
|
+
const idxNxt = (idx + 1) % N;
|
|
117
|
+
const tri = indexesToTri(
|
|
118
|
+
["c", `b${idx}`, `b${idxNxt}`],
|
|
119
|
+
compiled.points,
|
|
120
|
+
compiled.edgeNodes || [],
|
|
121
|
+
compiled.centroid_point,
|
|
122
|
+
compiled.vertices_points,
|
|
123
|
+
bakw,
|
|
124
|
+
FORMAT_VERSION
|
|
125
|
+
);
|
|
126
|
+
return featureCollection([tri]);
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
function buildCentroid(compiled: Compiled) {
|
|
131
|
+
return {
|
|
132
|
+
forw: point(compiled.centroid_point[0], {
|
|
133
|
+
target: {
|
|
134
|
+
geom: compiled.centroid_point[1],
|
|
135
|
+
index: "c"
|
|
136
|
+
}
|
|
137
|
+
}),
|
|
138
|
+
bakw: point(compiled.centroid_point[1], {
|
|
139
|
+
target: {
|
|
140
|
+
geom: compiled.centroid_point[0],
|
|
141
|
+
index: "c"
|
|
142
|
+
}
|
|
143
|
+
})
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
function buildTins(compiled: Compiled) {
|
|
148
|
+
const bakwIndex = compiled.tins_points.length === 1 ? 0 : 1;
|
|
149
|
+
return {
|
|
150
|
+
forw: featureCollection(
|
|
151
|
+
compiled.tins_points[0].map(idxes =>
|
|
152
|
+
indexesToTri(
|
|
153
|
+
idxes,
|
|
154
|
+
compiled.points,
|
|
155
|
+
compiled.edgeNodes || [],
|
|
156
|
+
compiled.centroid_point,
|
|
157
|
+
compiled.vertices_points,
|
|
158
|
+
false,
|
|
159
|
+
compiled.version
|
|
160
|
+
)
|
|
161
|
+
)
|
|
162
|
+
),
|
|
163
|
+
bakw: featureCollection(
|
|
164
|
+
compiled.tins_points[bakwIndex].map(idxes =>
|
|
165
|
+
indexesToTri(
|
|
166
|
+
idxes,
|
|
167
|
+
compiled.points,
|
|
168
|
+
compiled.edgeNodes || [],
|
|
169
|
+
compiled.centroid_point,
|
|
170
|
+
compiled.vertices_points,
|
|
171
|
+
true,
|
|
172
|
+
compiled.version
|
|
173
|
+
)
|
|
174
|
+
)
|
|
175
|
+
)
|
|
176
|
+
};
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
function buildKinks(kinksPoints?: Position[]) {
|
|
180
|
+
if (!kinksPoints) return undefined;
|
|
181
|
+
return {
|
|
182
|
+
bakw: featureCollection(
|
|
183
|
+
kinksPoints.map((coord: Position) => point(coord))
|
|
184
|
+
)
|
|
185
|
+
};
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
function normalizeLegacyStructure(
|
|
189
|
+
compiled: CompiledLegacy
|
|
190
|
+
): CompiledLegacy {
|
|
191
|
+
return JSON.parse(
|
|
192
|
+
JSON.stringify(compiled)
|
|
193
|
+
.replace('"cent"', '"c"')
|
|
194
|
+
.replace(/"bbox(\d+)"/g, '"b$1"')
|
|
195
|
+
);
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
function rebuildLegacyPoints(tins: TinsBD): PointSet[] {
|
|
199
|
+
const points: PointSet[] = [];
|
|
200
|
+
const features = tins.forw!.features;
|
|
201
|
+
for (let i = 0; i < features.length; i++) {
|
|
202
|
+
const tri = features[i];
|
|
203
|
+
(["a", "b", "c"] as PropertyTriKey[]).forEach((key, idx) => {
|
|
204
|
+
const forw = tri.geometry!.coordinates[0][idx];
|
|
205
|
+
const bakw = tri.properties![key].geom;
|
|
206
|
+
const pIdx = tri.properties![key].index;
|
|
207
|
+
if (typeof pIdx === "number") {
|
|
208
|
+
points[pIdx] = [forw, bakw];
|
|
209
|
+
}
|
|
210
|
+
});
|
|
211
|
+
}
|
|
212
|
+
return points;
|
|
213
|
+
}
|
package/src/constants.ts
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { MERC_MAX } from "./constants.ts";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* ピクセル座標をシステム座標(EPSG:3857相当)に変換する
|
|
5
|
+
*
|
|
6
|
+
* @param xy - ピクセル座標 [x, y]
|
|
7
|
+
* @param maxxy - 最大座標値(2^maxZoom * 256)
|
|
8
|
+
* @returns システム座標 [x, y]
|
|
9
|
+
*/
|
|
10
|
+
export function xy2SysCoord(xy: number[], maxxy: number): number[] {
|
|
11
|
+
const sysCoordX = (xy[0] * (2 * MERC_MAX)) / maxxy - MERC_MAX;
|
|
12
|
+
const sysCoordY = -1 * ((xy[1] * (2 * MERC_MAX)) / maxxy - MERC_MAX);
|
|
13
|
+
return [sysCoordX, sysCoordY];
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* システム座標(EPSG:3857相当)をピクセル座標に変換する
|
|
18
|
+
*
|
|
19
|
+
* @param sysCoord - システム座標 [x, y]
|
|
20
|
+
* @param maxxy - 最大座標値(2^maxZoom * 256)
|
|
21
|
+
* @returns ピクセル座標 [x, y]
|
|
22
|
+
*/
|
|
23
|
+
export function sysCoord2Xy(sysCoord: number[], maxxy: number): number[] {
|
|
24
|
+
const x = ((sysCoord[0] + MERC_MAX) * maxxy) / (2 * MERC_MAX);
|
|
25
|
+
const y = ((-sysCoord[1] + MERC_MAX) * maxxy) / (2 * MERC_MAX);
|
|
26
|
+
return [x, y];
|
|
27
|
+
}
|