osmgl 0.31.85 → 0.31.86
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/README.md +26 -1
- package/dist/chunk-75GAN2RE.js +2 -0
- package/dist/{chunk-UTCX6F2H.js.map → chunk-75GAN2RE.js.map} +1 -1
- package/dist/chunk-C4FIKFZ5.js +3 -0
- package/dist/chunk-C4FIKFZ5.js.map +1 -0
- package/dist/chunk-JLFNXD5I.js +4754 -0
- package/dist/chunk-JLFNXD5I.js.map +1 -0
- package/dist/chunk-RJYVR2JE.js +3 -0
- package/dist/chunk-RJYVR2JE.js.map +1 -0
- package/dist/core.js +1 -1
- package/dist/ld-roads.d.ts +8378 -0
- package/dist/ld-roads.js +7 -0
- package/dist/ld-roads.js.map +1 -0
- package/dist/nav.js +1 -1
- package/dist/navigram.js +1 -1
- package/dist/osmgl.js +1 -1
- package/package.json +11 -5
- package/dist/chunk-FFBTYNPV.js +0 -4754
- package/dist/chunk-FFBTYNPV.js.map +0 -1
- package/dist/chunk-NRKJQUT2.js +0 -3
- package/dist/chunk-NRKJQUT2.js.map +0 -1
- package/dist/chunk-UTCX6F2H.js +0 -2
package/dist/ld-roads.js
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import {Wf}from'./chunk-JLFNXD5I.js';import'./chunk-PDRUPAYQ.js';import {Sa as Sa$1,ub}from'./chunk-RJYVR2JE.js';import {De,fd,wd}from'./chunk-OCA36U5D.js';var oe={OsmGL:Wf},Ma={getElementById:()=>null};if(!oe.OsmGL)throw Ma.getElementById("city-stats").innerHTML='<b style="color:#c0322b">Движок не загрузился.</b> Рядом со страницей должен лежать собранный <code>dist/osmgl.global.js</code>: соберите его (<code>npm run build</code>) или откройте страницу через демо-сервер (<code>npm run demo</code>).',new Error("[city] нет window.OsmGL");function Xo(y={}){let M={source:"shanghai","source-layer":"geojson"},A={background:"#cdc7b8",levelHeight:8,light:{ambient:.6,sun:.8,azimuth:150,altitude:50},layers:[{id:"water",type:"fill",...M,filter:["==","kind","water"],paint:{color:"#8fb3c7",material:"water",materialScale:30,materialSpeed:.6}},{id:"green",type:"fill",...M,filter:["==","kind","green"],paint:{color:"#bdd3b0"}},{id:"tunnel-bed",type:"surface",...M,filter:["==","kind","tunnel-bed"],minzoom:14,elevation:-0.03,bevel:0,bevelDrop:0,weld:0,paint:{color:"#a49e91",opacity:.7,sideShade:0}},{id:"tunnel-edge",type:"line",...M,filter:["==","kind","tunnel-edge"],minzoom:14,maxzoom:17.5,paint:{color:"#8d887c",elevation:-0.02,material:"flat",widthMeters:{stops:[[14,1.2],[17,.6]]},dashMeters:[2.5,2.5],opacity:.7}},{id:"road-bed",type:"surface",...M,filter:["==","kind","roadway"],elevation:.28,bevel:.14,bevelDrop:.1,weld:0,deck:1.4,paint:{color:"#43454b",sideColor:"#cbc7bd",sideShade:.18,sideLight:.35}},{id:"walkway",type:"surface",...M,filter:["==","kind","footway"],elevation:.34,bevel:.1,bevelDrop:.08,weld:0,deck:.4,paint:{color:"#8f8f96",sideColor:"#cbc7bd",sideShade:.18,sideLight:.35}},{id:"mark-centre",type:"line",...M,filter:["==","kind","mark-centre"],minzoom:15,paint:{color:"#e9c65a",elevation:.3,material:"flat",widthMeters:{stops:[[15,1.1],[17,.5],[19,.15]]}}},{id:"mark-lane",type:"line",...M,filter:["==","kind","mark-lane"],minzoom:15.5,paint:{color:"#e7eae8",elevation:.3,material:"flat",widthMeters:{stops:[[15.5,.8],[17,.4],[19,.15]]},dashMeters:[3,5]}},{id:"mark-arrow",type:"surface",...M,filter:["==","kind","mark-arrow"],minzoom:16.5,elevation:.32,bevel:0,bevelDrop:0,weld:0,paint:{color:"#eef1ef",sideShade:0}},{id:"mark-stop",type:"line",...M,filter:["==","kind","mark-stop"],minzoom:16,paint:{color:"#e7eae8",elevation:.31,material:"flat",widthMeters:.4}},{id:"mark-zebra",type:"line",...M,filter:["==","kind","mark-zebra"],minzoom:16,paint:{color:"#eef1ef",elevation:.31,material:"flat",widthMeters:.45}},{id:"mark-edge",type:"line",...M,filter:["==","kind","mark-edge"],minzoom:15.5,paint:{color:"#e7eae8",elevation:.3,material:"flat",widthMeters:{stops:[[15.5,.8],[17,.4],[19,.2]]}}},{id:"mark-lane-solid",type:"line",...M,filter:["==","kind","mark-lane-solid"],minzoom:15.5,paint:{color:"#e7eae8",elevation:.3,material:"flat",widthMeters:{stops:[[15.5,.8],[17,.4],[19,.15]]}}},{id:"mark-centre-dashed",type:"line",...M,filter:["==","kind","mark-centre-dashed"],minzoom:15,paint:{color:"#e9c65a",elevation:.3,material:"flat",widthMeters:{stops:[[15,1.1],[17,.5],[19,.15]]},dashMeters:[3,5]}},{id:"mark-bus",type:"line",...M,filter:["==","kind","mark-bus"],minzoom:15.5,paint:{color:"#e9c65a",elevation:.3,material:"flat",widthMeters:{stops:[[15.5,.8],[17,.4],[19,.2]]}}},{id:"mark-bus-dashed",type:"line",...M,filter:["==","kind","mark-bus-dashed"],minzoom:15.5,paint:{color:"#e9c65a",elevation:.3,material:"flat",widthMeters:{stops:[[15.5,.8],[17,.4],[19,.2]]},dashMeters:[3,5]}},{id:"mark-wide",type:"line",...M,filter:["==","kind","mark-wide"],minzoom:15.5,paint:{color:"#e7eae8",elevation:.3,material:"flat",widthMeters:{stops:[[15.5,1],[17,.6],[19,.4]]}}},{id:"mark-temp",type:"line",...M,filter:["==","kind","mark-temp"],minzoom:15.5,paint:{color:"#f08a24",elevation:.31,material:"flat",widthMeters:{stops:[[15.5,.8],[17,.4],[19,.15]]}}},{id:"mark-hatch",type:"line",...M,filter:["==","kind","mark-hatch"],minzoom:16,paint:{color:"#e7eae8",elevation:.3,material:"flat",widthMeters:{stops:[[16,.5],[17,.35],[19,.3]]}}},{id:"mark-yield",type:"surface",...M,filter:["==","kind","mark-yield"],minzoom:16.5,elevation:.32,bevel:0,bevelDrop:0,weld:0,paint:{color:"#eef1ef",sideShade:0}},{id:"mark-text",type:"surface",...M,filter:["==","kind","mark-text"],minzoom:16.5,elevation:.32,bevel:0,bevelDrop:0,weld:0,paint:{color:"#d9dcda",sideShade:0}},...[["white","#eef1ef"],["yellow","#e9c65a"],["red","#d2524e"],["green","#4a9d77"],["blue","#4a86c8"],["orange","#f08a24"],["brown","#8c5a3c"],["grey","#9aa0a0"]].map(([P,O])=>({id:`mark-fill-${P}`,type:"surface",...M,filter:["==","kind",`mark-fill-${P}`],minzoom:16,elevation:.29,bevel:0,bevelDrop:0,weld:0,paint:{color:O,sideShade:0}})),{id:"graph-edge-left",type:"line",...M,filter:["==","kind","__off__"],paint:{color:"#19a34a",elevation:.62,material:"flat",widthMeters:.3}},{id:"graph-edge-right",type:"line",...M,filter:["==","kind","__off__"],paint:{color:"#c24fd0",elevation:.62,material:"flat",widthMeters:.3}},{id:"graph-axis",type:"line",...M,filter:["==","kind","__off__"],paint:{color:"#1b6ef3",elevation:.64,material:"flat",widthMeters:.35}},{id:"graph-node-end",type:"surface",...M,filter:["==","kind","__off__"],elevation:.62,bevel:0,bevelDrop:0,weld:0,paint:{color:"#3a7be0",sideShade:0}},{id:"graph-node-joint",type:"surface",...M,filter:["==","kind","__off__"],elevation:.64,bevel:0,bevelDrop:0,weld:0,paint:{color:"#e8a33a",sideShade:0}},{id:"graph-node-crossing",type:"surface",...M,filter:["==","kind","__off__"],elevation:.66,bevel:0,bevelDrop:0,weld:0,paint:{color:"#e0443a",sideShade:0}},{id:"buildings",type:"fill-extrusion",...M,filter:["==","kind","building"],paint:{color:"#cfd3d6",roofColor:"#c4c8cc",windowColor:"#8fa6bb",windowFrameColor:"#dfe3e6",tintVariation:.09,facadeDetail:1,floorHeight:3.4,ice:.3,plinthShade:.16}}]};return y.variant==="pascal"?ba(A):A}function ba(y){let A=.16999999999999998,O="#f3f1df",F="#e8c447",W=(Y,Mt)=>({...Y,depthTest:true,paint:{...Y.paint,elevation:.02,...Mt}}),J=Y=>({stops:[[15,Math.max(Y*5,.6)],[17,Math.max(Y*2.5,.3)],[19,Y]]}),H={source:"shanghai","source-layer":"geojson"},$=[];for(let Y of y.layers){if(typeof Y.id=="string"&&Y.id.startsWith("mark-fill-")){$.push({...Y,elevation:.02+.005,base:.02});continue}switch(Y.id){case "road-bed":$.push({...Y,filter:["==","kind","__mesh__"]}),$.push({id:"kerb-joint",type:"line",...H,filter:["==","kind","kerb-joint"],minzoom:18,depthTest:true,paint:{color:"#8f8c85",elevation:A,material:"flat",widthMeters:.24,dashMeters:[.03,.97]}});break;case "walkway":$.push({...Y,elevation:.02+.08,paint:{...Y.paint,color:"#b9b7b0",sideColor:"#a9a7a0"}});break;case "mark-centre":case "mark-centre-dashed":$.push(W(Y,{color:F,widthMeters:J(.12)}));break;case "mark-lane":case "mark-bus-dashed":$.push(W(Y,{color:Y.id==="mark-lane"?O:F,widthMeters:J(.12)}));break;case "mark-wide":$.push(W(Y,{color:O,widthMeters:J(.4)}));break;case "mark-temp":$.push(W(Y,{widthMeters:J(.12)}));break;case "mark-edge":$.push(W(Y,{color:O,widthMeters:J(.15)}));break;case "mark-lane-solid":case "mark-bus":case "mark-hatch":case "mark-stop":case "mark-zebra":$.push(W(Y,{color:Y.id==="mark-bus"?F:O}));break;case "mark-arrow":case "mark-yield":case "mark-text":$.push({...Y,elevation:.02+.01,base:.02,paint:{...Y.paint,color:Y.id==="mark-text"?"#dcdbd0":O},filter:["all",Y.filter,["!has","baked"]]});break;default:$.push(Y);}}return {...y,background:"#b4bdc8",light:{...y.light,ambient:.62,sun:.85},layers:$}}function Un(y){return typeof y!="string"||!/^#[0-9a-fA-F]{6}$/.test(y)?null:[1,3,5].map(M=>parseInt(y.slice(M,M+2),16)/255)}var Wo={tj:{lane:[3,9],centre:[3,9],approach:[6,2],dotted:[.5,.5],wide:[1,3],noPark:[1,1],edge:[3,9],gap:.15,approachM:50,approachStyle:"approach",busFill:"red",bikeFill:"green",tramFill:"grey",variableFill:"blue",gaugeM:1.524,zigzag:[4,1],bay:{parallel:[6,2.5],perp:[5,2.5],angle:[5,2.5]}},cn:{lane:[2,4],centre:[4,6],approach:[6,2],dotted:[2,2],wide:[3,3],noPark:[1,1],edge:[2,4],gap:.15,approachM:30,approachStyle:"solid",busFill:"brown",bikeFill:"green",tramFill:"grey",variableFill:"blue",gaugeM:1.435,zigzag:[3,1],bay:{parallel:[6,2.5],perp:[5.3,2.5],angle:[5.3,2.5]}}};function ka(y,M={}){let A=M.variant==="pascal",P=y.filter(t=>t.properties.kind==="road"&&t.geometry.type==="LineString"),O=y.filter(t=>t.properties.kind==="walkway"&&t.geometry.type==="LineString");if(!P.length)return [];let F=P[0].geometry.coordinates[0][1],W=111320,J=111320*Math.cos(F*Math.PI/180),H=([t,e])=>[t*J,e*W],$=(t,e)=>[t/J,e/W],Y=t=>{let e=t.layer??0;return e!==0?e:t.tunnel?-1:t.bridge?1:0},Mt=t=>{let e=t.profile;if(!e||typeof e!="object")return null;let n=m=>Array.isArray(m)?m.filter(_=>_&&typeof _.fromM=="number"&&typeof _.toM=="number"&&typeof _.style=="string"&&_.toM>_.fromM).map(_=>({b:typeof _.b=="number"?_.b:-1,from:_.fromM,to:_.toM,style:_.style,temp:_.temp===true})):[],s=m=>Array.isArray(m)?m.filter(_=>_&&typeof _.fromM=="number"&&typeof _.toM=="number"&&_.toM>_.fromM).map(_=>({from:_.fromM,to:_.toM})):[],o=m=>m&&typeof m=="object"?{on:m.on!==false,color:typeof m.color=="string"?m.color:null,spans:s(m.spans)}:null,a=m=>{if(!m||!Array.isArray(m.lanes)||!m.lanes.length)return null;let _=m.lanes.map(G=>({use:typeof G?.use=="string"?G.use:"car",width:typeof G?.widthM=="number"&&G.widthM>0?G.widthM:3.5,turns:Array.isArray(G?.turns)?G.turns.filter(Z=>typeof Z=="string"):[],fill:o(G?.fill),variable:G?.variable===true})),v=_.map((G,Z)=>Z===0?"none":"dashed").concat("none");for(let G=0;G<v.length;G++)typeof m.dividers?.[G]=="string"&&(v[G]=m.dividers[G]);let z=m.arrows!==false,N=typeof m.arrowGapM=="number"&&m.arrowGapM>=0?m.arrowGapM:14,q=n(m.spans).filter(G=>G.b>=0&&G.b<=_.length);return {lanes:_,dividers:v,sum:_.reduce((G,Z)=>G+Z.width,0),arrows:z,arrowGap:N,spans:q}},r=a(e.forward);if(!r)return null;let l=a(e.backward),i=l?{divider:typeof e.median?.divider=="string"?e.median.divider:"solid",width:typeof e.median?.widthM=="number"&&e.median.widthM>0?e.median.widthM:0,paint:e.median?.color==="white"?"white":"yellow",spans:n(e.median?.spans)}:{divider:"none",width:0,paint:"yellow",spans:[]},f=m=>({on:!!m?.on,offset:typeof m?.offsetM=="number"&&m.offsetM>=0?Math.min(2,m.offsetM):.3,spans:n(m?.spans)}),h=e.edges&&typeof e.edges=="object"?{left:f(e.edges.left),right:f(e.edges.right)}:null,c=(m,_,v,z)=>typeof m=="number"&&Number.isFinite(m)?Math.min(v,Math.max(_,m)):z,u=m=>{if(!m||typeof m!="object")return null;let _=["gutter","lawn","aryk"].includes(m.verge)?m.verge:null;return {on:m.on!==false,kind:typeof m.kind=="string"?m.kind:"concrete",height:c(m.heightM,0,1,.15),width:c(m.widthM,.05,.8,.15),color:Un(m.color)??Un("#a9a9a4"),stripe:Un(m.stripe),stripeM:c(m.stripeM,.2,5,1),joint:c(m.jointM,0,6,1),grain:m.kind==="granite"?.09:Un(m.stripe)?.02:.04,verge:_,vergeM:_?c(m.vergeM,.2,6,.5):0,lowerAtCrossings:m.lowerAtCrossings!==false,lowered:Array.isArray(m.lowered)?m.lowered.filter(v=>v&&typeof v.from=="number"&&typeof v.to=="number").map(v=>[Math.min(v.from,v.to),Math.max(v.from,v.to)]):[]}},d=e.kerbs&&typeof e.kerbs=="object"&&(u(e.kerbs.left)||u(e.kerbs.right))?{left:u(e.kerbs.left)??u({}),right:u(e.kerbs.right)??u({})}:null,g=r.sum+(l?l.sum+i.width:0),w=l?(l.sum-r.sum)/2:0,p=Wo[e.preset]?e.preset:"tj",S=m=>typeof m=="number"&&Number.isFinite(m)&&m>0?Math.min(300,m):0,L=e.approach&&typeof e.approach=="object"?{start:S(e.approach.start),end:S(e.approach.end)}:{start:0,end:0},b=m=>m&&typeof m=="object"&&typeof m.fromM=="number"&&typeof m.toM=="number"&&m.toM>m.fromM?{side:m.side==="left"?"left":"right",from:Math.min(m.fromM,m.toM),to:Math.max(m.fromM,m.toM)}:null,x=(Array.isArray(e.zigzags)?e.zigzags:[]).map(m=>{let _=b(m);return _&&{..._,step:typeof m.stepM=="number"&&m.stepM>0?m.stepM:null,amp:typeof m.amplitudeM=="number"&&m.amplitudeM>0?m.amplitudeM:null}}).filter(Boolean),I=(Array.isArray(e.parking)?e.parking:[]).map(m=>{let _=b(m);return _&&{..._,layout:m.layout==="perp"||m.layout==="angle"?m.layout:"parallel",bayL:typeof m.bayLM=="number"&&m.bayLM>0?m.bayLM:null,bayW:typeof m.bayWM=="number"&&m.bayWM>0?m.bayWM:null}}).filter(Boolean),R=typeof t.arrowObjects=="string"?t.arrowObjects:null,T=typeof t.stopObjects=="string"?t.stopObjects:null,k=typeof t.zebraObjects=="string"?t.zebraObjects:null;return {forward:r,backward:l,median:i,width:g,centre:w,edges:h,kerbs:d,preset:p,approach:L,zigzags:x,parking:I,arrowObjects:R,stopObjects:T,zebraObjects:k}},X=8,_t=1,Ht=Math.cos(35*Math.PI/180),Nt=t=>{let e=t.profile,n=s=>Array.isArray(s?.lanes)?s.lanes.reduce((o,a)=>o+(typeof a?.widthM=="number"&&a.widthM>0?a.widthM:3.5),0):0;if(e&&typeof e=="object"&&Array.isArray(e.forward?.lanes)&&e.forward.lanes.length){let s=n(e.forward),o=n(e.backward),a=typeof e.median?.widthM=="number"&&e.median.widthM>0?e.median.widthM:0,r=s+(o>0?o+a:0);if(r>0)return r}return t.width??8},ie=(t,e)=>{let n=1/0;for(let s=1;s<e.length;s++){let[o,a]=e[s-1],[r,l]=e[s],i=r-o,f=l-a,h=i*i+f*f,c=h>0?Math.max(0,Math.min(1,((t[0]-o)*i+(t[1]-a)*f)/h)):0;n=Math.min(n,Math.hypot(o+i*c-t[0],a+f*c-t[1]));}return n},Ft=t=>{let e=t[1],n=0;for(let r=1;r<t.length&&(n+=Math.hypot(t[r][0]-t[r-1][0],t[r][1]-t[r-1][1]),e=t[r],!(n>=2));r++);let s=t[0][0]-e[0],o=t[0][1]-e[1],a=Math.hypot(s,o);return a>1e-6?[s/a,o/a]:null},Gt=(t,e,n)=>{for(let a of [e,[...e].reverse()]){if(Math.hypot(a[0][0]-t[0],a[0][1]-t[1])>_t)continue;let r=Ft(a);return !!r&&-(r[0]*n[0]+r[1]*n[1])>=Ht}let s=1/0,o=null;for(let a=1;a<e.length;a++){let r=ie(t,[e[a-1],e[a]]),l=e[a][0]-e[a-1][0],i=e[a][1]-e[a-1][1],f=Math.hypot(l,i);r<s&&f>1e-6&&(s=r,o=[l/f,i/f]);}return !!o&&Math.abs(o[0]*n[0]+o[1]*n[1])>=Ht},te=t=>{let e=a=>a==="start"||a==="end"||a==="both";if(!t.some(a=>e(a.properties.open)))return t;let n=t.map(a=>a.geometry.coordinates.map(H)),s=[],o=[];return t.forEach((a,r)=>{let l=a.properties.open;if(!e(l)||n[r].length<2){s.push(a);return}let i={start:l!=="end",end:l!=="start"},f=Y(a.properties);for(let d of ["start","end"]){if(!i[d])continue;let g=d==="start"?n[r]:[...n[r]].reverse(),w=g[0],p=[];if(t.forEach((I,R)=>{R!==r&&n[R].length>=2&&Y(I.properties)===f&&ie(w,n[R])<=_t&&p.push(R);}),!p.length)continue;i[d]=false;let S=Ft(g);if(!S||p.some(I=>Gt(w,n[I],S)))continue;let L=Math.max(...p.map(I=>Nt(t[I].properties)/2+.9))+X,b=a.geometry.coordinates,x=d==="start"?b[0]:b[b.length-1];o.push({type:"Feature",geometry:{type:"LineString",coordinates:[[x[0],x[1]],$(w[0]+S[0]*L,w[1]+S[1]*L)]},properties:{...a.properties,open:"end"}});}let h=i.start&&i.end?"both":i.start?"start":i.end?"end":null;if(h===l){s.push(a);return}let{open:c,...u}=a.properties;s.push({...a,properties:h?{...u,open:h}:u});}),o.length||s.some((a,r)=>a!==t[r])?[...s,...o]:t},Oe=new Map;for(let t of P)t.properties.profile&&typeof t.properties.profile=="object"&&Oe.set(t.properties.profile,t.geometry.coordinates.flatMap(H));let Ie=.6,ye=1,Se=t=>t.look==="asphalt"||t.look==="ribbon"?t.look:null,he=(t,e)=>{let{tunnel:n,bridge:s,...o}=t;return {...o,layer:e}},Ne=t=>{if(!t.some(a=>Se(a.properties)))return t;let e=t.map(a=>a.geometry.coordinates.map(H)),n=t.map(a=>Y(a.properties)),s=t.map((a,r)=>{let l=Se(a.properties);return l==="ribbon"&&n[r]>=0?-1:l==="asphalt"&&n[r]<0?0:n[r]}),o=[];return t.forEach((a,r)=>{if(s[r]===n[r]){o.push(a);return}if(s[r]<0){o.push({...a,properties:he(a.properties,s[r])});return}let l=e[r],i=[0];for(let k=1;k<l.length;k++)i.push(i[k-1]+Math.hypot(l[k][0]-l[k-1][0],l[k][1]-l[k-1][1]));let f=i[i.length-1],h=Nt(a.properties)/2+.45+Re,c=[];t.forEach((k,m)=>{if(m===r||s[m]!==0||n[m]<=n[r]||e[m].length<2)return;let _=Nt(k.properties)/2+.45+Re,v=e[m];for(let z=1;z<l.length;z++){let[N,q]=l[z-1],[G,Z]=l[z],at=G-N,mt=Z-q,vt=Math.hypot(at,mt);if(!(vt<1e-6))for(let wt=1;wt<v.length;wt++){let[C,rt]=v[wt-1],[kt,At]=v[wt],gt=kt-C,bt=At-rt,lt=Math.hypot(gt,bt);if(lt<1e-6)continue;let xt=at*bt-mt*gt;if(Math.abs(xt)<1e-9)continue;let Yt=((C-N)*bt-(rt-q)*gt)/xt,Ct=((C-N)*mt-(rt-q)*at)/xt;if(Yt<0||Yt>1||Ct<0||Ct>1)continue;let Vt=i[z-1]+Yt*vt;if(Vt<.5||Vt>f-.5)continue;let Dt=Math.max(.2,Math.abs(xt)/(vt*lt)),ht=Math.sqrt(Math.max(0,1-Dt*Dt)),Ot=_/Dt+h*ht/Dt+Ie;c.push([Vt-Ot,Vt+Ot]);}}});let u=(k,m)=>{let _=1/0;for(let v=1;v<m.length;v++){let[z,N]=m[v-1],[q,G]=m[v],Z=q-z,at=G-N,mt=Z*Z+at*at,vt=mt>0?Math.max(0,Math.min(1,((k[0]-z)*Z+(k[1]-N)*at)/mt)):0;_=Math.min(_,Math.hypot(k[0]-(z+Z*vt),k[1]-(N+at*vt)));}return _},d=k=>{let m=1;for(;m<i.length-1&&i[m]<k;)m++;let _=i[m]-i[m-1],v=_>0?Math.max(0,Math.min(1,(k-i[m-1])/_)):0;return [l[m-1][0]+(l[m][0]-l[m-1][0])*v,l[m-1][1]+(l[m][1]-l[m-1][1])*v]},g=[l[0],l[l.length-1]],w=[];if(t.forEach((k,m)=>{if(m===r||s[m]!==0||n[m]<=n[r]||e[m].length<2)return;let _=Nt(k.properties)/2,v=_+h+Ie,z=g.map((N,q)=>u(N,e[m])<.5?q===0?0:f:null).filter(N=>N!==null);w.push({pts:e[m],half:_,reach:v,joinedAt:z});}),w.length){let m=null;for(let _=0;_<=f+1e-9;_+=.5){let v=d(_),z=d(Math.max(0,_-.25)),N=d(Math.min(f,_+.25)),q=Math.hypot(N[0]-z[0],N[1]-z[1])||1,G=-(N[1]-z[1])/q,Z=(N[0]-z[0])/q,at=w.filter(vt=>!vt.joinedAt.some(wt=>Math.abs(_-wt)<vt.reach)&&u(v,vt.pts)<vt.half+h),mt=at.length>0;for(let vt=-h;mt&&vt<=h+1e-9;vt+=.5){let wt=[v[0]+G*vt,v[1]+Z*vt];mt=at.some(C=>u(wt,C.pts)<C.half);}mt&&m===null&&(m=_),!mt&&m!==null&&(c.push([m,_-.5]),m=null);}m!==null&&c.push([m,f+Ie]);}let p=a.properties;if(!c.length){o.push({...a,properties:he(p,0)});return}c.sort((k,m)=>k[0]-m[0]);let S=[];for(let k of c){let m=S[S.length-1];m&&k[0]<=m[1]?m[1]=Math.max(m[1],k[1]):S.push([k[0],k[1]]);}let L=[],b=0;for(let[k,m]of S)k>b&&L.push([b,k]),b=Math.max(b,m);b<f&&L.push([b,f]);let x=k=>{let m=1;for(;m<i.length-1&&i[m]<k;)m++;let _=i[m]-i[m-1],v=_>0?Math.max(0,Math.min(1,(k-i[m-1])/_)):0;return $(l[m-1][0]+(l[m][0]-l[m-1][0])*v,l[m-1][1]+(l[m][1]-l[m-1][1])*v)},I=p.open,R=I==="start"||I==="both",T=I==="end"||I==="both";for(let[k,m]of L){if(m-k<ye)continue;let _=[x(k)];for(let Z=1;Z<l.length-1;Z++)i[Z]>k&&i[Z]<m&&_.push(a.geometry.coordinates[Z]);_.push(x(m));let v=k>0?false:R,z=m<f?false:T,{open:N,...q}=he(p,0),G=v&&z?"both":v?"start":z?"end":null;o.push({...a,geometry:{type:"LineString",coordinates:_},properties:G?{...q,open:G}:q});}}),o},Re=.3,De=te(Ne(P)),be=oe.OsmGL.roundRings(De.map(t=>{let e={pts:t.geometry.coordinates.flatMap(H),width:t.properties.width??8,level:Y(t.properties),oneway:!!t.properties.oneway,lanes:t.properties.lanes??0,cls:t.properties.cls??""},n={};for(let o of ["arrowObjects","stopObjects","zebraObjects"])typeof t.properties[o]=="string"&&(n[o]=t.properties[o]);Object.keys(n).length&&(e.objFlags=n);let s=t.properties.profile?Mt(t.properties):null;return s?(s.wayLine=Oe.get(t.properties.profile)??e.pts,{...e,width:s.width,lanes:s.forward.lanes.length+(s.backward?s.backward.lanes.length:0),oneway:!s.backward,profile:s}):e}),400),ze=oe.OsmGL.buildRoadGraph(be,{smooth:.9,maxSmooth:20}),Qe=oe.OsmGL.roadHeights(ze,{levelHeight:8,maxGrade:.06}),ct=[];ze.chains.forEach((t,e)=>{for(let n of t.axes)ct[n]=e;});let nt=(t,e,n)=>{let s=ct[t];if(s===void 0)return 0;let o=ze.chains[s].pts,a=1/0,r=0,l=0;for(let i=0;i+3<o.length;i+=2){let f=o[i+2]-o[i],h=o[i+3]-o[i+1],c=Math.hypot(f,h),u=c>0?Math.max(0,Math.min(1,((e-o[i])*f+(n-o[i+1])*h)/(c*c))):0,d=Math.hypot(o[i]+f*u-e,o[i+1]+h*u-n);d<a&&(a=d,r=l+u*c),l+=c;}return Qe.at(s,r)},Tt=5,yt=oe.OsmGL.snapRoadEnds(be,2,(t,e,n,s,o)=>{let a=be[t].pts,r=e?a[0]:a[a.length-2],l=e?a[1]:a[a.length-1],i=nt(t,r,l),f=nt(n,s,o);return Math.abs(i-f)<.5?true:i<.5&&f<Tt}),tt=oe.OsmGL.buildRoadGraph(yt,{smooth:.9,maxSmooth:20,miter:true}),me=[];for(let t of Array.isArray(M.restrictions)?M.restrictions:[]){if(!Array.isArray(t?.via)||!Array.isArray(t?.from)||!Array.isArray(t?.to))continue;let[e,n]=H(t.via),[s,o]=H(t.from),[a,r]=H(t.to);me.push({x:e,y:n,from:Math.atan2(n-o,e-s),to:Math.atan2(r-n,a-e),only:t.only===true});}let ae=me.length?oe.OsmGL.turnRules(tt,me):null,we=ae?{turnAllowed:ae}:{},It=t=>{let e=[];for(let r=0;r+1<t.length;r+=2)e.push($(t[r],t[r+1]));let[n,s]=e[0],[o,a]=e[e.length-1];return (n!==o||s!==a)&&e.push([n,s]),e},mn=8,tn=.06,se=oe.OsmGL.roadHeights(tt,{levelHeight:mn,maxGrade:tn,clearance:5});oe.cityGraph=tt,oe.cityToDegrees=$;let Jr={node:()=>0,at:()=>0,length:t=>se.length(t),flat:()=>true,grade:()=>0};oe.cityRoadMeshBuild=({kerb:t=true,flat:e=false}={})=>{let n=performance.now(),s=oe.OsmGL.roadMesh(tt,e?Jr:se,{widthExtra:.9,kerbRadius:7,elevation:.28,deck:1.4,kerbWidth:t?.3:0,skip:o=>tt.chains[o].level<0});return s.ms=performance.now()-n,s.toDegrees=$,s};let gn=oe.OsmGL.roadSurfaces(tt,{widthExtra:.9,cornerRadius:7,edges:true,fillet:8,trim:true,merge:true,mergeClasses:true,apart:t=>t.chain!==void 0?!se.flat(t.chain):(t.nodes??[]).some(e=>se.node(e)>.05)}),Yn=[];for(let t of gn){t.edges&&t.chain!==void 0&&(Yn[t.chain]=t.edges.centre);for(let e of t.sourceEdges??[])Yn[e.chain]=e.edges.centre;}let Mn=t=>Yn[t]??tt.chains[t]?.pts,Ae=A?.5:.6,Ue=[];De.forEach((t,e)=>{let n=t.properties.open;if(n!=="start"&&n!=="end"&&n!=="both")return;let s=t.geometry.coordinates;for(let[o,a]of [["start",0],["end",s.length-1]]){if(n!==o&&n!=="both")continue;let[r,l]=H(s[a]),i=-1,f=1.5;if(tt.nodes.forEach((x,I)=>{if(x.degree!==1)return;let R=Math.hypot(x.x-r,x.y-l);R<f&&(f=R,i=I);}),i<0)continue;let h=tt.chains.findIndex(x=>x.head===i||x.tail===i);if(h<0||tt.chains[h].level<0)continue;let c=Mn(h);if(!c||c.length<4)continue;let u=tt.chains[h].head===i,d=[];for(let x=0;x+1<c.length;x+=2)d.push([c[x],c[x+1]]);u||d.reverse();let g={x:d[0][0],y:d[0][1]},w={x:d[1][0],y:d[1][1]};for(let x=1,I=0;x<d.length&&(I+=Math.hypot(d[x][0]-d[x-1][0],d[x][1]-d[x-1][1]),w={x:d[x][0],y:d[x][1]},!(I>=2));x++);let p=g.x-w.x,S=g.y-w.y,L=Math.hypot(p,S);if(!(L>1e-6))continue;let b=be[e]?.width??8;Ue.push({x:g.x,y:g.y,ux:p/L,uy:S/L,hw:b/2+.9,chain:h,h:se.at(h,u?0:se.length(h))});}});let _e=(t,e,n)=>{let s=e-t.x,o=n-t.y,a=s*t.ux+o*t.uy,r=-s*t.uy+o*t.ux;return {a,b:r,zone:Math.abs(r)<t.hw+1&&a>-1&&a<t.hw+3}},fo=t=>{if(!Ue.length)return t;let e=[];for(let n of t){let s=n.properties?.kind??"";if(n.geometry?.type!=="LineString"||!(s.startsWith("mark-")||s==="kerb-joint")){e.push(n);continue}let o=[n.geometry.coordinates.map(H)],a=false;for(let r of Ue){if(!o.some(i=>i.some(([f,h])=>_e(r,f,h).zone)))continue;a=true;let l=[];for(let i of o){let f=[];for(let h=0;h<i.length;h++){let c=_e(r,i[h][0],i[h][1]),u=c.zone&&c.a>Ae;if(h>0){let d=_e(r,i[h-1][0],i[h-1][1]),g=d.zone&&d.a>Ae;if(u!==g&&(c.zone||d.zone)){let w=(Ae-d.a)/(c.a-d.a);w>=0&&w<=1&&f.push([i[h-1][0]+(i[h][0]-i[h-1][0])*w,i[h-1][1]+(i[h][1]-i[h-1][1])*w]);}}u?(f.length>=2&&l.push(f),f=[]):f.push(i[h]);}f.length>=2&&l.push(f);}for(let i of l)for(let f of [false,true]){let h=f?0:i.length-1,c=f?1:i.length-2,u=_e(r,i[h][0],i[h][1]);if(!u.zone||Math.abs(u.b)>r.hw||u.a<-3||u.a>Ae-.01)continue;let d=i[h][0]-i[c][0],g=i[h][1]-i[c][1],w=Math.hypot(d,g);if(!(w>1e-6)||(d*r.ux+g*r.uy)/w<.95)continue;let p=[i[h][0]+r.ux*(Ae-u.a),i[h][1]+r.uy*(Ae-u.a)];f?i.unshift(p):i.push(p);}o=l;}if(!a){e.push(n);continue}for(let r of o){let l=0;for(let i=1;i<r.length;i++)l+=Math.hypot(r[i][0]-r[i-1][0],r[i][1]-r[i-1][1]);l<.3||e.push({...n,geometry:{type:"LineString",coordinates:r.map(([i,f])=>$(i,f))}});}}return e},Qr=t=>{let e=[];if(!Ue.length)return {outer:t,cuts:e};let n=t;for(let s of Ue){let o=n.length/2,a=[];for(let g=0;g<o;g++){let w=_e(s,n[2*g],n[2*g+1]);a.push(w.zone&&w.a>1e-6);}if(!a.some(Boolean)||a.every(Boolean))continue;let r=-1;for(let g=0;g<o;g++)if(a[g]&&!a[(g-1+o)%o]){r=g;break}if(r<0)continue;let l=0;for(;l<o&&a[(r+l)%o];)l++;let i=(g,w)=>{let p=_e(s,n[2*g],n[2*g+1]),S=_e(s,n[2*w],n[2*w+1]),L=p.a===S.a?0:-p.a/(S.a-p.a);return [n[2*g]+(n[2*w]-n[2*g])*L,n[2*g+1]+(n[2*w+1]-n[2*g+1])*L]},f=(r-1+o)%o,h=(r+l)%o,c=i(f,r),u=i((r+l-1)%o,h),d=[];for(let g=0;g<o-l;g++){let w=(h+g)%o;d.push(n[2*w],n[2*w+1]);}d.push(...c,...u),n=d,e.push({e:s,p1:c,p2:u});}return {outer:n,cuts:e}},ti=8,Hn=(t,e=0,n=1/0)=>{let s=Mn(t);if(!s||s.length<4)return null;let o=[],a=(l,i,f)=>{if(f<e||f>n)return;let[h,c]=$(l,i);o.push(h.toFixed(7)+","+c.toFixed(7)+","+se.at(t,f).toFixed(2));};a(s[0],s[1],0);let r=0;for(let l=2;l+1<s.length;l+=2){let i=Math.hypot(s[l]-s[l-2],s[l+1]-s[l-1]),f=Math.max(1,Math.ceil(i/ti));for(let h=1;h<=f;h++){let c=h/f;a(s[l-2]+(s[l]-s[l-2])*c,s[l-1]+(s[l+1]-s[l-1])*c,r+i*c);}r+=i;}return o.length>=2?o.join(";"):null},rs=40,Wn=[];for(let t=0;t<tt.chains.length;t++)for(let e of [tt.chains[t].head,tt.chains[t].tail])e!==void 0&&(Wn[e]=Wn[e]||[]).push(t);let is=(t,e)=>{let n=new Set(e===void 0?[]:[e]),s=[],o=false;for(let a of t??[])for(let r of Wn[a]??[]){if(n.has(r))continue;n.add(r),se.grade(r)>=1e-4&&(o=true);let l=se.length(r),i=tt.chains[r].head===a?Hn(r,0,rs):Hn(r,Math.max(0,l-rs),1/0);i&&s.push(i);}return {parts:s,sloped:o}},ho=[],as=t=>{if(t===void 0)return;if(t in ho)return ho[t];let e=tt.chains[t],n=is(e?[e.head,e.tail]:[],t),s=hs([t]),o=se.at(t,0),a=s.parts.some(f=>f.split(";").some(h=>Math.abs(+h.split(",")[2]-o)>.05)),l=se.grade(t)>=1e-4||n.sloped||s.differs||a?Hn(t):null,i=l?[l,...n.parts,...s.parts].join("|"):void 0;return ho[t]=i,i},ei=t=>{if(!t||!t.length)return;let e=is(t),n=new Set;for(let r of t)for(let l of Wn[r]??[])n.add(l);let s=hs([...n]),o=Math.max(...t.map(r=>se.node(r))),a=s.parts.some(r=>r.split(";").some(l=>Math.abs(+l.split(",")[2]-o)>.05));return (e.sloped||s.differs||a)&&e.parts.length?[...e.parts,...s.parts].join("|"):void 0},uo=t=>{let e=as(t);if(e)return {liftPath:e};let n=t!==void 0?se.at(t,0):0;return n>.01?{lift:+n.toFixed(2)}:{}},ge=30,cs=10,en=new Map,ni=(t,e)=>Math.floor(t/ge)+","+Math.floor(e/ge),ls=(t,e,n,s)=>{let o=ni(e,n),a=en.get(o);a?a.push(t,e,n,s):en.set(o,[t,e,n,s]);};for(let t=0;t<tt.chains.length;t++){let e=Mn(t);if(!e||e.length<4)continue;let n=0;ls(t,e[0],e[1],0);for(let s=2;s+1<e.length;s+=2){let o=Math.hypot(e[s]-e[s-2],e[s+1]-e[s-1]),a=Math.max(1,Math.ceil(o/cs));for(let r=1;r<=a;r++){let l=r/a;ls(t,e[s-2]+(e[s]-e[s-2])*l,e[s-1]+(e[s+1]-e[s-1])*l,n+o*l);}n+=o;}}let oi=1,fs=15,po=new Map,hs=t=>{let e=[...t].sort((l,i)=>l-i).join(",");if(po.has(e))return po.get(e);let n=new Set(t),s=new Map;for(let l of t){let i=tt.chains[l],f=Mn(l);if(!i||!f||f.length<4)continue;let h=0;for(let c=2;c+1<f.length;c+=2){let u=Math.hypot(f[c]-f[c-2],f[c+1]-f[c-1]),d=Math.max(1,Math.ceil(u/cs));for(let g=0;g<d;g++){let w=g/d,p=f[c-2]+(f[c]-f[c-2])*w,S=f[c-1]+(f[c+1]-f[c-1])*w,L=se.at(l,h+u*w),b=Math.floor(p/ge),x=Math.floor(S/ge);for(let I=-1;I<=1;I++)for(let R=-1;R<=1;R++){let T=en.get(b+R+","+(x+I));if(T)for(let k=0;k<T.length;k+=4){let m=T[k];if(n.has(m))continue;let _=tt.chains[m];if(_.level!==i.level)continue;let v=(i.width+_.width)/2+1;if((p-T[k+1])**2+(S-T[k+2])**2>v*v||Math.abs(se.at(m,T[k+3])-L)>=oi)continue;let z=s.get(m)??[];z.push(T[k+3]-fs,T[k+3]+fs),s.set(m,z);}}}h+=u;}}let o=[],a=false;for(let[l,i]of s){let f=[];for(let c=0;c<i.length;c+=2)f.push([i[c],i[c+1]]);f.sort((c,u)=>c[0]-u[0]);let h=[];for(let c of f){let u=h[h.length-1];u&&c[0]<=u[1]?u[1]=Math.max(u[1],c[1]):h.push([...c]);}for(let[c,u]of h){let d=Hn(l,Math.max(0,c),u);d&&o.push(d);}se.grade(l)>=1e-4&&(a=true);}let r={parts:o,differs:a};return po.set(e,r),r},si=(t,e)=>{let n=ge*ge*4,s=0,o=Math.floor(t/ge),a=Math.floor(e/ge);for(let r=-1;r<=1;r++)for(let l=-1;l<=1;l++){let i=en.get(o+l+","+(a+r));if(i)for(let f=0;f<i.length;f+=4){let h=(t-i[f+1])**2+(e-i[f+2])**2;h<n&&(n=h,s=se.at(i[f],i[f+3]));}}return s},fn=(t,e)=>{let n=si(t,e);return n>.01?{lift:+n.toFixed(2)}:{}},bn=[];for(let t of gn){if(t.level<0){if(bn.push({type:"Feature",properties:{kind:"tunnel-bed",cls:t.cls,width:t.width},geometry:{type:"Polygon",coordinates:[It(t.outer),...t.holes.map(It)]}}),t.edges)for(let i of [t.edges.left,t.edges.right]){let f=[];for(let h=0;h+1<i.length;h+=2)f.push($(i[h],i[h+1]));f.length>=2&&bn.push({type:"Feature",properties:{kind:"tunnel-edge",cls:t.cls},geometry:{type:"LineString",coordinates:f}});}continue}let e={kind:"roadway",cls:t.cls,layer:t.level,width:t.width},n=t.chain,s=as(n),o=t.nodes&&t.nodes.length?Math.max(...t.nodes.map(i=>se.node(i))):void 0,a=s?void 0:ei(t.nodes),r=s||a?{...e,liftPath:s||a}:{...e,lift:n!==void 0?se.at(n,0):o!==void 0?Math.max(o,Math.max(0,t.level)*mn):Math.max(0,t.level)*mn},l=A?{outer:t.outer,cuts:[]}:Qr(t.outer);bn.push({type:"Feature",properties:r,geometry:{type:"Polygon",coordinates:[It(l.outer),...t.holes.map(It)]}});for(let{e:i,p1:f,p2:h}of l.cuts){let c=r.lift??i.h,u=[...f,...h,h[0]+i.ux*Ae,h[1]+i.uy*Ae,f[0]+i.ux*Ae,f[1]+i.uy*Ae];for(let d of [1e-4,2e-4])bn.push({type:"Feature",properties:{...e,open:true,lift:c+d},geometry:{type:"Polygon",coordinates:[It(u)]}});}}let us=O.map(t=>({pts:t.geometry.coordinates.flatMap(H),width:t.properties.width??3,level:t.properties.layer??0,cls:t.properties.cls??""})),ri=t=>{let e=tt.chains,n=0;for(let i of e)n=Math.max(n,(i.width+.9)/2);let s=Math.max(20,n+8),o=new Map;for(let i of e){let f=i.pts;for(let h=0;h+3<f.length;h+=2){let c=Math.floor(Math.min(f[h],f[h+2])/s),u=Math.floor(Math.max(f[h],f[h+2])/s),d=Math.floor(Math.min(f[h+1],f[h+3])/s),g=Math.floor(Math.max(f[h+1],f[h+3])/s);for(let w=c;w<=u;w++)for(let p=d;p<=g;p++){let S=w*1e7+p,L=o.get(S);L?L.push(i,h):o.set(S,[i,h]);}}}let a=(i,f,h)=>{let c=0,u=Math.floor(i/s),d=Math.floor(f/s);for(let g=d-1;g<=d+1;g++)for(let w=u-1;w<=u+1;w++){let p=o.get(w*1e7+g);if(p)for(let S=0;S<p.length;S+=2){let L=p[S],b=p[S+1],x=L.pts,I=(L.width+.9)/2+h,R=x[b+2]-x[b],T=x[b+3]-x[b+1],k=R*R+T*T,m=k>0?Math.max(0,Math.min(1,((i-x[b])*R+(f-x[b+1])*T)/k)):0,_=Math.hypot(i-(x[b]+R*m),f-(x[b+1]+T*m));_<I&&(c=Math.max(c,I-_));}}return c},r=.5,l=(i,f,h)=>{let c=R=>f?i.length-2-R*2:R*2,u=0;for(;i.length/2-u>=2&&a(i[c(u)],i[c(u)+1],h)>.2;)u++;if(u===0)return true;if(i.length/2-u<2)return false;let d=c(u),g=c(u-1),w=i[d],p=i[d+1],S=i[g],L=i[g+1],b=Math.hypot(S-w,L-p),x=w,I=p;for(let R=r;R<b;R+=r){let T=w+(S-w)*R/b,k=p+(L-p)*R/b;if(a(T,k,h)>.2)break;x=T,I=k;}return f?(i.length=d+2,i.push(x,I)):i.splice(0,d,x,I),true};return t.map(i=>{let f=i.pts.slice(),h=(i.width+.3)/2;return !l(f,false,h)||!l(f,true,h)?null:f.length>=4?{...i,pts:f}:null}).filter(Boolean)},ds=us.length?ri(us):[],Kn=ds.length?oe.OsmGL.buildRoadGraph(ds):null,ps=Kn?oe.OsmGL.roadSurfaces(Kn,{widthExtra:.3,cornerRadius:5,taper:5,edges:true}):[],ii=ps.map(t=>({type:"Feature",properties:{kind:"footway",cls:t.cls,layer:t.level},geometry:{type:"Polygon",coordinates:[It(t.outer),...t.holes.map(It)]}})),ys=(t,e,n)=>{let s=[];for(let a=0;a<t.nodes.length;a++){let r=t.nodes[a];if(!r.rays.length)continue;let l=0;for(let c of r.rays)l=Math.max(l,c.width);let i=r.crossing?"crossing":r.degree===1?"end":"joint",f=Math.max(l*e[i],1),h=[];for(let c=0;c<=20;c++){let u=c/20*Math.PI*2;h.push($(r.x+Math.cos(u)*f,r.y+Math.sin(u)*f));}s.push({type:"Feature",properties:{kind:"node-"+i,degree:r.degree},geometry:{type:"Polygon",coordinates:[h]}});}let o=[];for(let a of n){a.edges&&o.push({cls:a.cls,edges:a.edges});for(let r of a.sourceEdges??[])o.push({cls:a.cls,edges:r.edges});}for(let a of o){if(!a.edges)continue;let r=(l,i)=>{let f=[];for(let h=0;h+1<l.length;h+=2)f.push($(l[h],l[h+1]));f.length>=2&&s.push({type:"Feature",properties:{kind:i,cls:a.cls},geometry:{type:"LineString",coordinates:f}});};r(a.edges.centre,"axis"),r(a.edges.left,"edge-left"),r(a.edges.right,"edge-right");}return s},ai=[...ys(tt,{crossing:.34,joint:.18,end:.14},gn),...Kn?ys(Kn,{crossing:.5,joint:.3,end:.22},ps):[]],ci=25*Math.PI/180,yo=50,Xn=1<<21,ms=(t,e)=>(Math.floor(t/yo)+Xn)*(Xn*2)+(Math.floor(e/yo)+Xn),mo=new Map,gs=[],Pn=[],Ms=[];for(let t=0;t<tt.chains.length;t++){let e=tt.chains[t];gs[t]=(e.width+.9)/2;let n=new Float64Array(e.pts.length/2),s=0;for(let o=0;o+3<e.pts.length;o+=2){n[o/2]=s;let a=e.pts[o+2]-e.pts[o],r=e.pts[o+3]-e.pts[o+1],l=Math.hypot(a,r);s+=l;let i=Math.max(1,Math.ceil(l/(yo/2))),f=-1;for(let h=0;h<=i;h++){let c=h/i,u=ms(e.pts[o]+a*c,e.pts[o+1]+r*c);if(u===f)continue;f=u;let d=mo.get(u);d||mo.set(u,d=[]),d.push(t,o);}}n[n.length-1]=s,Pn[t]=s,Ms[t]=n;}let go=new Map,On=[],In=[],$n=[],bs=[],ks=[],xs=[],ws=[],As=[],Mo=0,bo=(t,e)=>{Mo=0,go.clear();let n=ms(t,e);for(let s=-1;s<=1;s++)for(let o=-1;o<=1;o++){let a=mo.get(n+o*(Xn*2)+s);if(a)for(let r=0;r<a.length;r+=2){let l=a[r],i=a[r+1],f=tt.chains[l].pts,h=f[i+2]-f[i],c=f[i+3]-f[i+1],u=h*h+c*c,d=u>0?Math.max(0,Math.min(1,((t-f[i])*h+(e-f[i+1])*c)/u)):0,g=f[i]+h*d,w=f[i+1]+c*d,p=Math.hypot(t-g,e-w),S=go.get(l);if(S===void 0)S=Mo++,On[S]=l,go.set(l,S);else if(In[S]<=p)continue;In[S]=p,$n[S]=Math.atan2(c,h),bs[S]=Ms[l][i/2]+Math.sqrt(u)*d,ks[S]=g,xs[S]=w,ws[S]=h,As[S]=c;}}return Mo},Rn=t=>{let e=new Map;return {add(n,s,o){let a=Math.floor(n/t)+","+Math.floor(s/t),r=e.get(a);r||e.set(a,r=[]),r.push(o);},near(n,s){let o=[],a=Math.floor(n/t),r=Math.floor(s/t);for(let l=-1;l<=1;l++)for(let i=-1;i<=1;i++){let f=e.get(a+i+","+(r+l));if(f)for(let h of f)o.push(h);}return o}}},nn=25,li=16,fi=globalThis.process?.env?.NEAR_AXIS_CHECK==="1",vs=new WeakMap,hi=t=>{let e=vs.get(t);if(e&&e.n===t.length)return e;let n=(t.length>>1)-1,s=new Float64Array(n+1),o=new Float64Array(Math.max(0,n)),a=0;for(let l=0;l<n;l++){let i=l*2,f=Math.hypot(t[i+2]-t[i],t[i+3]-t[i+1]);s[l]=a,o[l]=f,a+=f;}s[n]=a;let r=new Map;for(let l=0;l<n;l++){let i=l*2,f=Math.floor(Math.min(t[i],t[i+2])/nn),h=Math.floor(Math.max(t[i],t[i+2])/nn),c=Math.floor(Math.min(t[i+1],t[i+3])/nn),u=Math.floor(Math.max(t[i+1],t[i+3])/nn);for(let d=f;d<=h;d++)for(let g=c;g<=u;g++){let w=d*1e7+g,p=r.get(w);p?p.push(l):r.set(w,[l]);}}return e={n:t.length,done:s,len:o,total:a,cells:r},vs.set(t,e),e},ko=(t,e,n)=>{let s=1/0,o=0,a=0,r=0;for(let l=0;l+3<t.length;l+=2){let i=t[l+2]-t[l],f=t[l+3]-t[l+1],h=Math.hypot(i,f),c=i*i+f*f,u=c>0?Math.max(0,Math.min(1,((e-t[l])*i+(n-t[l+1])*f)/c)):0,d=Math.hypot(e-(t[l]+i*u),n-(t[l+1]+f*u));d<s&&(s=d,o=Math.atan2(f,i),a=r+h*u),r+=h;}return {d:s,ang:o,at:a,total:r}},le=(t,e,n)=>{if((t.length>>1)-1<=li)return ko(t,e,n);let s=hi(t),o=Math.floor(e/nn),a=Math.floor(n/nn),r=1/0,l=-1,i=0,f=new Set;for(let g=0;g<=8;g++){for(let w=o-g;w<=o+g;w++)for(let p=a-g;p<=a+g;p++){if(g&&w!==o-g&&w!==o+g&&p!==a-g&&p!==a+g)continue;let S=s.cells.get(w*1e7+p);if(S)for(let L of S){if(f.has(L))continue;f.add(L);let b=L*2,x=t[b+2]-t[b],I=t[b+3]-t[b+1],R=x*x+I*I,T=R>0?Math.max(0,Math.min(1,((e-t[b])*x+(n-t[b+1])*I)/R)):0,k=Math.hypot(e-(t[b]+x*T),n-(t[b+1]+I*T));(k<r||k===r&&L<l)&&(r=k,l=L,i=T);}}if(l>=0&&r<g*nn)break}if(l<0||r>=8*nn)return ko(t,e,n);let h=l*2,c=t[h+2]-t[h],u=t[h+3]-t[h+1],d={d:r,ang:Math.atan2(u,c),at:s.done[l]+s.len[l]*i,total:s.total};if(fi){let g=ko(t,e,n);if(g.d!==d.d||g.ang!==d.ang||g.at!==d.at||g.total!==d.total)throw new Error(`nearAxis: индекс разошёлся с перебором ${JSON.stringify(g)} ≠ ${JSON.stringify(d)}`)}return d},ui=(t,e)=>{let n=tt.chains[t],s=tt.chains[e];return n.width!==s.width?n.width>s.width:n.lanes!==s.lanes?n.lanes>s.lanes:Pn[t]!==Pn[e]?Pn[t]>Pn[e]:t<e},xo=(t,e,n,s)=>{let o=bo(t,e);if(!o)return false;let a=Ss.get(n),r=null;for(let l=0;l<o;l++)if(On[l]===a){r=$n[l];break}r===null&&(r=le(n.pts,t,e).ang);for(let l=0;l<o;l++){let i=On[l];if(i===a||tt.chains[i].level!==n.level||In[l]>gs[i])continue;let h=Math.abs($n[l]-r)%Math.PI;if(h>Math.PI/2&&(h=Math.PI-h),h>=ci||!s&&ui(i,a))return true}return false},Fe=4,wo=1.05,di=gn.map(t=>{let e=1/0,n=1/0,s=-1/0,o=-1/0;for(let a=0;a+1<t.outer.length;a+=2){let r=t.outer[a],l=t.outer[a+1];r<e&&(e=r),r>s&&(s=r),l<n&&(n=l),l>o&&(o=l);}return [e,n,s,o]}),Ao=(t,e,n)=>{let s=false,o=t.length/2;for(let a=0,r=o-1;a<o;r=a++){let l=t[a*2],i=t[a*2+1],f=t[r*2],h=t[r*2+1];i>n!=h>n&&e<(f-l)*(n-i)/(h-i)+l&&(s=!s);}return s},pi=(t,e)=>{for(let n=0;n<gn.length;n++){let[s,o,a,r]=di[n];if(t<s||t>a||e<o||e>r)continue;let l=gn[n];if(!(l.level<0)&&Ao(l.outer,t,e)&&!(l.holes??[]).some(i=>Ao(i,t,e)))return true}return false},Ls=(t,e,n,s)=>{let o=n-t,a=s-e,r=Math.hypot(o,a);if(r<1.5)return [];let l=o/r,i=a/r,f=i,h=-l,c=[],u=Math.max(Math.floor((r-.6)/wo),2),d=(u-1)*wo,g=(t+n)/2,w=(e+s)/2;for(let p=0;p<u;p++){let S=-d/2+p*wo,L=g+l*S,b=w+i*S;pi(L,b)&&c.push({type:"Feature",properties:{kind:"mark-zebra",...fn(L,b)},geometry:{type:"LineString",coordinates:[$(L-f*Fe/2,b-h*Fe/2),$(L+f*Fe/2,b+h*Fe/2)]}});}return c},Ss=new Map(tt.chains.map((t,e)=>[t,e])),$e=new Map,vo=t=>{let e=Mn(t);if(!e||e.length<4)return null;let n=tt.chains[t].pts;if(Math.hypot(e[0]-n[0],e[1]-n[1])>Math.hypot(e[0]-n[n.length-2],e[1]-n[n.length-1])){let s=[];for(let o=e.length-2;o>=0;o-=2)s.push(e[o],e[o+1]);e=s;}return e},Lo=new Map;tt.chains.forEach((t,e)=>{if(t.level<0)return;let n=t.axes.filter(o=>yt[o]&&yt[o].pts&&yt[o].pts.length>=4);if(!n.some(o=>yt[o].objFlags))return;let s=vo(e);s&&Lo.set(e,{base:s,members:n.map(o=>{let a=yt[o].pts,r=le(s,a[0],a[1]).at<=le(s,a[a.length-2],a[a.length-1]).at;return {flags:yt[o].objFlags||null,src:a,same:r}})});}),tt.chains.forEach((t,e)=>{if(t.level<0)return;let n=t.axes.find(i=>yt[i]&&yt[i].profile);if(n===void 0)return;let s=vo(e);if(!s)return;let o=i=>le(s,i[0],i[1]).at<=le(s,i[i.length-2],i[i.length-1]).at,a=yt[n].pts,r=o(a),l=t.axes.filter(i=>yt[i]&&yt[i].profile&&yt[i].pts&&yt[i].pts.length>=4).map(i=>({profile:yt[i].profile,src:yt[i].pts,same:i===n?r:o(yt[i].pts)}));$e.set(e,{profile:yt[n].profile,same:r,base:s,src:a,members:l});});let _s=(t,e,n,s,o=$e)=>{let a=o.get(t);if(!a)return null;if(a.members.length<2)return a.members[0]||a;if(n===void 0||s===void 0){let i=a.base,f=e===tt.chains[t].tail;n=f?i[i.length-2]:i[0],s=f?i[i.length-1]:i[1];}let r=null,l=1/0;for(let i of a.members){let f=le(i.src,n,s).d;f<l&&(l=f,r=i);}return r},Es=(t,e,n)=>{let s=n||$e.get(t);return s?e===tt.chains[t].tail===s.same?"forward":"backward":null},Ps=(t,e,n,s,o)=>{let a=_s(t,e,n,s);if(!a||!a.src||a.src.length<4)return null;let r=le(a.src,n,s);if(!(r.d<=o)||!(r.at>0)||!(r.at<r.total))return null;let l=e==null?null:Es(t,e,a);return {ldAtM:Math.round(r.at*100)/100,...l?{ldDir:l}:{}}},So=(t,e,n,s,o)=>{let a=_s(t,e,s,o,Lo),r=a&&a.flags&&a.flags[n];return r?r==="both"||r===Es(t,e,a):false},yi=(t,e,n,s)=>{let o=[],a=null,r=bo(t,e);for(let i=0;i<r;i++){let f=tt.chains[On[i]],h={d:In[i],dx:ws[i],dy:As[i],width:f.width,x:ks[i],y:xs[i],chain:f,at:bs[i]};(!a||h.d<a.d)&&(a=h),h.d<=f.width/2+2&&o.push(h);}if(n===void 0||!o.length)return a;let l=null;for(let i of o){let f=Math.hypot(i.dx,i.dy)||1,h=Math.abs(i.dx/f*n+i.dy/f*s);(!l||h<l.along)&&(l={...i,along:h});}return l},Os=t=>{let e=tt.chains[t.chain];for(let n=-1;n<=1;n+=.5)if(xo(t.x+t.dirX*t.half*n,t.y+t.dirY*t.half*n,e,true))return true;return false},Is=1+Fe/2+.6,mi=25,hn=t=>{let e=0;for(let n=0;n+3<t.length;n+=2)e+=Math.hypot(t[n+2]-t[n],t[n+3]-t[n+1]);return e},Ge=(t,e)=>{let n=e;for(let s=0;s+3<t.length;s+=2){let o=t[s+2]-t[s],a=t[s+3]-t[s+1],r=Math.hypot(o,a);if(r>=n||s+5>=t.length){let l=r>0?Math.max(0,Math.min(1,n/r)):0;return {x:t[s]+o*l,y:t[s+1]+a*l,dx:o/(r||1),dy:a/(r||1)}}n-=r;}return null},gi=(t,e)=>{let n=t.pts,s=n.length/2;if(s<2)return null;let o=hn(n),a=tt.clearanceAt(t.head,Math.atan2(n[3]-n[1],n[2]-n[0]),t.level,t.axes),r=tt.clearanceAt(t.tail,Math.atan2(n[s*2-3]-n[s*2-1],n[s*2-4]-n[s*2-2]),t.level,t.axes),l=null;if(a>0&&(l={s:a+Is,node:t.head}),r>0){let f=o-(r+Is);(!l||Math.abs(f-e)<Math.abs(l.s-e))&&(l={s:f,node:t.tail});}if(!l||l.s<0||l.s>o||Math.abs(l.s-e)>mi)return null;let i=Ge(n,l.s);return i&&{...i,node:l.node,s:l.s,total:o}},_o=6,Eo=[];for(let t of y){if(!t.properties.marked)continue;let e=t.properties.kind;if(e!=="crossing-line"&&e!=="crossing-node")continue;let n,s,o,a;if(e==="crossing-line"&&t.geometry.type==="LineString"){let f=t.geometry.coordinates,[h,c]=H(f[0]),[u,d]=H(f[f.length-1]),g=Math.hypot(u-h,d-c);if(g<1.5)continue;n=(h+u)/2,s=(c+d)/2,o=(u-h)/g,a=(d-c)/g;}else if(e==="crossing-node"&&t.geometry.type==="Point"){let[f,h]=H(t.geometry.coordinates);n=f,s=h,o=null;}else continue;let r=yi(n,s,o===null?void 0:o,a);if(!r||r.d>r.width)continue;let l=Math.hypot(r.dx,r.dy)||1;if(o!==null&&Math.abs(o*(r.dx/l)+a*(r.dy/l))>.7)continue;o=-r.dy/l,a=r.dx/l;let i=gi(r.chain,r.at);i&&(r.x=i.x,r.y=i.y,o=-i.dy,a=i.dx),Eo.push({x:r.x,y:r.y,dirX:o,dirY:a,half:r.width/2,fromLine:e==="crossing-line",chain:Ss.get(r.chain),node:i?i.node:null,at:i?i.s:r.at,runX:i?i.dx:r.dx/l,runY:i?i.dy:r.dy/l,flip:i?i.node===r.chain.tail:false,total:i?i.total:0});}Eo.sort((t,e)=>Number(e.fromLine)-Number(t.fromLine));let ke=[],Rs=Rn(_o);for(let t of Eo){let e=false;for(let n of Rs.near(t.x,t.y))if(Math.hypot(t.x-n.x,t.y-n.y)<_o){e=true;break}e||(ke.push(t),Rs.add(t.x,t.y,t));}let Mi=30,bi=4,zs=60,Po=Math.cos(25*Math.PI/180),ki=(t,e)=>{for(let n of t.of){if(Math.abs(n.runX*e.runX+n.runY*e.runY)<Po)continue;let s=e.x-n.x,o=e.y-n.y,a=Math.abs(s*n.runX+o*n.runY),r=Math.abs(s*n.dirX+o*n.dirY);if(!(a>Mi||r>zs||r<bi))return true}return false},un=[],Oo=Rn(zs);for(let t of ke){let e=null;for(let o of new Set(Oo.near(t.x,t.y)))if(ki(o,t)){e=o;break}if(!e){let o={x:t.x,y:t.y,dirX:t.dirX,dirY:t.dirY,runX:t.runX,runY:t.runY,of:[t]};un.push(o),Oo.add(t.x,t.y,o);continue}e.of.push(t),Oo.add(t.x,t.y,e);let n=e.runX*t.runX+e.runY*t.runY<0?-1:1,s=e.of.length;e.x+=(t.x-e.x)/s,e.y+=(t.y-e.y)/s,e.dirX+=(t.dirX*n-e.dirX)/s,e.dirY+=(t.dirY*n-e.dirY)/s,e.runX+=(t.runX*n-e.runX)/s,e.runY+=(t.runY*n-e.runY)/s;}let Fs=(t,e,n,s)=>{for(let o of t.of){let a=o.runX*e+o.runY*n;if(Math.abs(a)<.2)continue;let r=s/a;o.x+=o.runX*r,o.y+=o.runY*r,o.node!==null&&(o.at+=r);}t.x+=e*s,t.y+=n*s;},Ts=30,xi=6;for(let t of un){let e=Math.hypot(t.runX,t.runY)||1,n=t.runX/e,s=t.runY/e;for(let l of t.of){let i=l.runX*n+l.runY*s;if(Math.abs(i)<.2)continue;let f=((t.x-l.x)*n+(t.y-l.y)*s)/i;l.x+=l.runX*f,l.y+=l.runY*f,l.node!==null&&(l.at+=f);}let o=0;for(let l of t.of){if(l.node===null)continue;let i=l.flip?-1:1;o+=l.runX*i*n+l.runY*i*s;}if(!o||(t.outX=n*Math.sign(o),t.outY=s*Math.sign(o),!t.of.some(Os)))continue;let a=o>0?1:-1,r=0;for(let l=1;l<=Ts;l++)Fs(t,n,s,a),t.of.some(Os)&&(r=l);Fs(t,n,s,a*(r+xi-Ts));}let wi=70,Ai=14;for(let t of un){let e=tt.chains[t.of[0].chain],n=Math.hypot(t.dirX,t.dirY)||1,s=t.dirX/n,o=t.dirY/n,a=Math.hypot(t.runX,t.runY)||1,r=t.runX/a,l=t.runY/a,i=new Set(t.of.map(h=>h.chain)),f=new Map;for(let h of [-1,1]){let c=0;for(let u=1;u<=wi;u++){let d=t.x+s*u*h,g=t.y+o*u*h,w=false,p=bo(d,g);for(let S=0;S<p;S++){let L=On[S],b={d:In[S],ang:$n[S]},x=tt.chains[L];if(x.level!==e.level||b.d>x.width/2||(w=true,i.has(L)||x.cls==="service"||x.width<6)||Math.abs(Math.cos(b.ang)*r+Math.sin(b.ang)*l)<Po)continue;let I=f.get(L);(!I||b.d<I.d)&&f.set(L,{d:b.d,x:d,y:g});}if(c=w?0:c+1,c>=Ai)break}}for(let[h,c]of f){let u=tt.chains[h];t.of.push({x:c.x,y:c.y,dirX:s,dirY:o,half:u.width/2,chain:h,node:null,at:0,total:0,flip:false,fromLine:false,runX:r,runY:l});}}let Ns=70,vi=5;for(let t of un)t.span=t.of.reduce((e,n)=>e+n.half*2,0),t.low=Math.min(...t.of.map(e=>e.chain));let Li=(t,e)=>t.of.length!==e.of.length?t.of.length>e.of.length:Math.abs(t.span-e.span)>.5?t.span>e.span:t.low<e.low,Si=(t,e)=>{if(Math.abs(t.runX*e.runX+t.runY*e.runY)<Po||t.outX===void 0||e.outX===void 0||t.outX*e.outX+t.outY*e.outY<=0)return false;let n=e.x-t.x,s=e.y-t.y;return Math.abs(n*t.runX+s*t.runY)>Ns?false:Math.abs(n*t.dirX+s*t.dirY)<=(t.span+e.span)/2+vi},zn=new Set,Ds=Rn(Ns);for(let t of un)Ds.add(t.x,t.y,t);for(let t of un)if(!zn.has(t)){for(let e of Ds.near(t.x,t.y))if(!(e===t||zn.has(e))&&Si(t,e)){if(Li(e,t)){zn.add(t);break}zn.add(e);}}let Bs=new Map,js=[];for(let t of un)if(!zn.has(t))for(let e of t.of)js.push(e),e.node!==null&&Bs.set(e.chain+":"+e.node,e.flip?e.total-e.at:e.at);ke.length=0,ke.push(...js);let Io=[];for(let t of ke)Io.some(e=>Math.hypot(t.x-e.x,t.y-e.y)<_o)||Io.push(t);ke.length=0,ke.push(...Io);let _i=(t=>{let e=t.map(n=>({...n}));for(let n=true;n;){n=false;for(let s=0;s<e.length&&!n;s++)for(let o=s+1;o<e.length;o++){let a=e[s],r=e[o];if(Math.hypot(r.x-a.x,r.y-a.y)>a.half+r.half+Fe+2||Math.abs(a.dirX*r.dirX+a.dirY*r.dirY)<.97)continue;let l=r.x-a.x,i=r.y-a.y,f=l*a.dirX+i*a.dirY,h=-l*a.dirY+i*a.dirX;if(Math.abs(h)>Fe)continue;let c=Math.min(-a.half,f-r.half),u=Math.max(a.half,f+r.half);if(f-r.half>a.half+1.5||f+r.half<-a.half-1.5)continue;let d=(c+u)/2,g=h*r.half/(a.half+r.half);e[s]={...a,x:a.x+a.dirX*d-a.dirY*g,y:a.y+a.dirY*d+a.dirX*g,half:(u-c)/2},e.splice(o,1),n=true;break}}return e})(ke);ke.length=0,ke.push(..._i);let Ro=[];for(let t of ke){if(t.node!==null&&t.node!==void 0&&So(t.chain,t.node,"zebraObjects",t.x,t.y))continue;let e=Ps(t.chain,t.node,t.x,t.y,t.half+1);for(let n of Ls(t.x-t.dirX*t.half,t.y-t.dirY*t.half,t.x+t.dirX*t.half,t.y+t.dirY*t.half))Ro.push(e?{...n,properties:{...n.properties,...e}}:n);}let zo=[];for(let t of ke)zo.push([t.x,t.y,t.half+Fe]);let Cs=oe.OsmGL.laneGuides(tt,{...we,blocked:(t,e)=>{for(let[n,s,o]of zo)if(Math.hypot(t-n,e-s)<o+3)return true;return false}}),Fn=Cs.map(t=>({type:"Feature",properties:{kind:"mark-arrow",cls:t.cls,layer:t.level,...uo(t.chain)},geometry:{type:"Polygon",coordinates:[It(t.pts)]}})),Fo=tt.chains.filter(t=>t.head===t.tail&&t.pts.length>=8),Us=(t,e)=>{for(let n of Fo){let s=(n.width+.9)/2,o=n.pts;for(let a=0;a+3<o.length;a+=2){let r=o[a+2]-o[a],l=o[a+3]-o[a+1],i=r*r+l*l,f=i>0?Math.max(0,Math.min(1,((t-o[a])*r+(e-o[a+1])*l)/i)):0;if(Math.hypot(t-(o[a]+r*f),e-(o[a+1]+l*f))<s)return true}}return false},Gs=oe.OsmGL.roadMarkings(tt,{...we,throughStop:false,zebra:false,axes:Yn,keepOut:(t,e,n)=>(Fo.includes(n)?false:Us(t,e))||xo(t,e,n),crossingAt:(t,e,n)=>Bs.get(e+":"+n)??null,minPiece:40}).filter(t=>t.kind!=="edge"),Ye=Gs.filter(t=>t.kind==="stop"&&t.pts.length===4),Ei=Gs.filter(t=>!(t.kind==="stop"&&t.pts.length===4)),Ys=t=>{let e=tt.chains[t.chain];if(!e)return null;let n=Mn(t.chain);return !n||n.length<4?null:le(n,(t.pts[0]+t.pts[2])/2,(t.pts[1]+t.pts[3])/2).at<hn(n)/2?e.head:e.tail};[...Lo.values()].some(t=>t.members.some(e=>e.flags&&e.flags.stopObjects))&&(Ye=Ye.filter(t=>{let e=Ys(t);if(e===null)return true;let n=t.pts.length>=4?(t.pts[0]+t.pts[t.pts.length-2])/2:void 0,s=t.pts.length>=4?(t.pts[1]+t.pts[t.pts.length-1])/2:void 0;return !So(t.chain,e,"stopObjects",n,s)}));let Hs=t=>{let e=t.slice();for(let n=true;n;){n=false;for(let s=0;s<e.length&&!n;s++)for(let o=s+1;o<e.length;o++){let a=e[s].pts,r=e[o].pts,l=a[2]-a[0],i=a[3]-a[1],f=Math.hypot(l,i)||1,h=l/f,c=i/f,u=r[2]-r[0],d=r[3]-r[1],g=Math.hypot(u,d)||1;if(Math.abs((h*u+c*d)/g)<.97)continue;let w=(r[0]-a[0])*h+(r[1]-a[1])*c,p=(r[2]-a[0])*h+(r[3]-a[1])*c,S=-(r[0]-a[0])*c+(r[1]-a[1])*h,L=-(r[2]-a[0])*c+(r[3]-a[1])*h;if(Math.abs(S)>1.2||Math.abs(L)>1.2)continue;let b=Math.min(w,p),x=Math.max(w,p);if(b>f+1||x<-1)continue;let I=Math.min(0,b),R=Math.max(f,x),T=(S+L)/4,k=a[0]-c*T,m=a[1]+h*T;e[s]={...e[s],pts:[k+h*I,m+c*I,k+h*R,m+c*R]},e.splice(o,1),n=true;break}}return e};Ye=Hs(Ye);let Ws=1,Ks=Rn(40);for(let t of ke)Ks.add(t.x,t.y,t);Ye=Ye.map(t=>{let[e,n,s,o]=t.pts,a=(e+s)/2,r=(n+o)/2,l=s-e,i=o-n,f=Math.hypot(l,i)||1,h=null,c=12;for(let k of Ks.near(a,r)){if(Math.abs((l*k.dirX+i*k.dirY)/f)<.9)continue;let m=a-k.x,_=r-k.y,v=m*k.dirX+_*k.dirY;if(Math.abs(v)>k.half+2)continue;let z=Math.abs(-m*k.dirY+_*k.dirX);z<c&&(c=z,h=k);}if(!h)return t;let u=h,d=-u.dirY,g=u.dirX,w=Math.sign((a-u.x)*d+(r-u.y)*g)||1,p=u.node!==null&&u.node!==void 0?tt.nodes[u.node]:null;if(p){let k=(p.x-u.x)*d+(p.y-u.y)*g;Math.abs(k)>.5&&(w=-Math.sign(k));}let S=w*(Fe/2+Ws),L=(e-u.x)*u.dirX+(n-u.y)*u.dirY,b=(s-u.x)*u.dirX+(o-u.y)*u.dirY,x=Math.max(-u.half,Math.min(L,b)),I=Math.min(u.half,Math.max(L,b));if(I-x<1)return t;let R=u.x+d*S,T=u.y+g*S;return {...t,pts:[R+u.dirX*x,T+u.dirY*x,R+u.dirX*I,T+u.dirY*I],atZebra:true}}),Ye=Hs(Ye);let Pi=ke.map(t=>({x:t.x,y:t.y,ux:t.dirX,uy:t.dirY,hu:t.half+.3,hv:Fe/2+Ws+.4})),kn=Rn(40);for(let t of Pi)kn.add(t.x,t.y,t);let Vn=(t,e,n)=>{let s=e-t.x,o=n-t.y;return Math.abs(s*t.ux+o*t.uy)<=t.hu&&Math.abs(-s*t.uy+o*t.ux)<=t.hv},Oi=t=>{let e=[];for(let o=0;o+3<t.length;o+=2){let a=t[o],r=t[o+1],l=t[o+2],i=t[o+3],f=Math.max(1,Math.ceil(Math.hypot(l-a,i-r)/.25));for(let h=0;h<f;h++)e.push(a+(l-a)*h/f,r+(i-r)*h/f);}e.push(t[t.length-2],t[t.length-1]);let n=[],s=[];for(let o=0;o<e.length;o+=2){let a=e[o],r=e[o+1];kn.near(a,r).some(i=>Vn(i,a,r))?(s.length>=4&&n.push(s),s=[]):s.push(a,r);}return s.length>=4&&n.push(s),n},dn=[];for(let t of Ei){if(t.kind!=="lane"&&t.kind!=="centre"){dn.push(t);continue}if(![0,t.pts.length-2,(t.pts.length>>2)*2].some(n=>kn.near(t.pts[n],t.pts[n+1]).length>0)){dn.push(t);continue}for(let n of Oi(t.pts)){let s=[n[0],n[1]];for(let o=2;o+2<n.length;o+=2)o/2%8===0&&s.push(n[o],n[o+1]);s.push(n[n.length-2],n[n.length-1]),Math.hypot(s[s.length-2]-s[0],s[s.length-1]-s[1])>.8&&dn.push({...t,pts:s});}}let ue=[],on=t=>{let e=[];for(let n=0;n+1<t.length;n+=2)e.push($(t[n],t[n+1]));return e},Xs=(t,e,n)=>{let s=Ge(t,e);return s?[s.x+s.dy*n,s.y-s.dx*n]:null},Ii=(t,e,n,s)=>{let o=[],a=(f,h)=>{let c=o.length;c&&Math.abs(o[c-2]-f)<1e-6&&Math.abs(o[c-1]-h)<1e-6||o.push(f,h);},r=0;for(let f=0;f+3<t.length;f+=2){let h=t[f],c=t[f+1],u=t[f+2],d=t[f+3],g=Math.hypot(u-h,d-c);if(g>0&&r+g>=n&&r<=s){let w=Math.max(0,(n-r)/g),p=Math.min(1,(s-r)/g);a(h+(u-h)*w,c+(d-c)*w),a(h+(u-h)*p,c+(d-c)*p);}r+=g;}let l=o.length/2;if(l<2)return null;let i=[];for(let f=0;f<l;f++){let h=0,c=0,u=0,d=0;for(let[p,S]of [[f-1,f],[f,f+1]]){if(p<0||S>=l)continue;let L=o[S*2]-o[p*2],b=o[S*2+1]-o[p*2+1],x=Math.hypot(L,b);x!==0&&(h+=b/x,c+=-L/x,u=b/x,d=-L/x);}let g=Math.hypot(h,c);if(g<1e-9)continue;h/=g,c/=g;let w=1/Math.max(.5,h*u+c*d);i.push(o[f*2]+h*e*w,o[f*2+1]+c*e*w);}return i.length>=4?i:null},Ri=(t,e,n=.8)=>{let s=[];for(let i=0;i+3<t.length;i+=2){let f=t[i],h=t[i+1],c=t[i+2],u=t[i+3],d=Math.max(1,Math.ceil(Math.hypot(c-f,u-h)/.25));for(let g=0;g<d;g++)s.push(f+(c-f)*g/d,h+(u-h)*g/d);}s.push(t[t.length-2],t[t.length-1]);let o=Fo.includes(e),a=[],r=[],l=()=>{if(r.length>=4){let i=[r[0],r[1]];for(let f=2;f+2<r.length;f+=2)f/2%8===0&&i.push(r[f],r[f+1]);i.push(r[r.length-2],r[r.length-1]),Math.hypot(i[i.length-2]-i[0],i[i.length-1]-i[1])>n&&a.push(i);}r=[];};for(let i=0;i<s.length;i+=2){let f=s[i],h=s[i+1];kn.near(f,h).some(u=>Vn(u,f,h))||!o&&Us(f,h)||xo(f,h,e)?l():r.push(f,h);}return l(),a},$s={white:"mark-lane-solid",yellow:"mark-centre",bus:"mark-bus",edge:"mark-edge"},zi=(t,e,n,s=false)=>{let o=$s[e]??$s.white,a=e==="yellow"?n.centre:e==="edge"?n.edge:n.lane,r=n.gap,l;switch(t){case "dashed":l=[[0,o,a]];break;case "solid":l=[[0,o,null]];break;case "approach":l=[[0,o,n.approach]];break;case "dotted":l=[[0,o,n.dotted]];break;case "wide-dashed":l=[[0,"mark-wide",n.wide]];break;case "double-solid":l=[[-r,o,null],[r,o,null]];break;case "double-dashed":l=[[-r,o,n.approach],[r,o,n.approach]];break;case "solid-dashed":l=[[-r,o,null],[r,o,a]];break;case "dashed-solid":l=[[-r,o,a],[r,o,null]];break;case "no-stop":l=[[0,"mark-centre",null]];break;case "no-park":l=[[0,"mark-centre",n.noPark]];break;default:l=[];}return s?l.map(([i,,f])=>[i,"mark-temp",f]):l},Fi=(t,e,n,s=false)=>{if(!(e>t))return [];if(!n)return [[t,e]];let[o,a]=n,r=o+a;if(!(o>0)||!(r>0))return [[t,e]];let l=[];if(s){for(let i=e;i>t;i-=r)l.push([Math.max(t,i-o),i]);l.reverse();}else for(let i=t;i<e;i+=r)l.push([i,Math.min(e,i+o)]);return l.filter(([i,f])=>f-i>.05)},To=(t,e,n,s,o,a=[],r="approach")=>{let l=e.map(c=>{let u=n(c.from),d=n(c.to);return {a:Math.min(u,d),b:Math.max(u,d),style:c.style,temp:c.temp}}),i=new Set([s,o]);for(let c of l)i.add(c.a),i.add(c.b);for(let[c,u]of a)i.add(c),i.add(u);let f=[...i].filter(c=>c>=s&&c<=o).sort((c,u)=>c-u),h=[];for(let c=0;c+1<f.length;c++){let u=f[c],d=f[c+1];if(d-u<1e-6)continue;let g=(u+d)/2,w=t,p=false;for(let L of l)g>=L.a&&g<=L.b&&(w=L.style,p=L.temp);w==="dashed"&&a.some(([L,b])=>g>=L&&g<=b)&&(w=r);let S=h[h.length-1];S&&S.style===w&&S.temp===p&&Math.abs(S.b-u)<1e-6?S.b=d:h.push({a:u,b:d,style:w,temp:p});}return h},Ti=5,Ni=.3,Vs={tj:[5,7.5],cn:[4.5,9]},Di=["motorway","trunk"],qs=(t,e)=>{let n=Vs[t]??Vs.tj;return Di.includes(e)?n[1]:n[0]},Zs=t=>{let e=s=>t.includes(s),n=[];return e("left")&&n.push(e("straight")?"straight-left":"left"),e("right")&&n.push(e("straight")?"straight-right":"right"),e("straight")&&!e("left")&&!e("right")&&n.push("straight"),e("uturn")&&n.push("u-turn"),n},Js=(t,e,n,s,o,a,r=Ti)=>{let l=[];for(let d of t)for(let g of oe.OsmGL.laneArrow(d,{length:r}))l.push(g.map((w,p)=>p%2===1?-w:w));if(!l.length)return;let i=1/0,f=-1/0;for(let d of l)for(let g=1;g<d.length;g+=2)d[g]<i&&(i=d[g]),d[g]>f&&(f=d[g]);let h=o-2*Ni,c=f>i&&h>0?Math.min(1,h/(f-i)):1,u=(i+f)/2;for(let d of l){let g=d.map((w,p)=>p%2===1?w-u:w);ue.push({type:"Feature",properties:{...a},geometry:{type:"Polygon",coordinates:[It(oe.OsmGL.placeMarking(g,s,e,n,c,c))]}});}},Qs=(t,e,n,s,o)=>It(oe.OsmGL.placeMarking([-s/2,-o/2,s/2,-o/2,s/2,o/2,-s/2,o/2],n,t,e,1,1)),Bi=(t,e)=>{for(let[n,s,o]of zo)if(Math.hypot(t-n,e-s)<o+3)return true;return false},Tn=new Set;for(let[t,{profile:e,same:n,base:s}]of $e){let o=tt.chains[t],a=o.pts,r=a.length/2,l=hn(s),i=uo(t),f={cls:o.cls,layer:o.level,src:"profile"},h=Math.atan2(a[3]-a[1],a[2]-a[0]),c=Math.atan2(a[r*2-3]-a[r*2-1],a[r*2-4]-a[r*2-2]),u=0,d=l;tt.nodes[o.head]?.crossing&&(u=tt.clearanceAt(o.head,h,o.level,o.axes)+1),tt.nodes[o.tail]?.crossing&&(d=l-tt.clearanceAt(o.tail,c,o.level,o.axes)-1);for(let C of Ye){if(C.chain!==t)continue;let rt=le(s,(C.pts[0]+C.pts[2])/2,(C.pts[1]+C.pts[3])/2).at;rt<l/2?u=Math.max(u,rt+.6):d=Math.min(d,rt-.6);}let g=C=>n?C:-C,w=Wo[e.preset]??Wo.tj,p=e.wayLine&&e.wayLine.length>=4?e.wayLine:s,S=hn(p),L=le(p,s[0],s[1]).at,b=le(p,s[s.length-2],s[s.length-1]).at,x=Math.min(L,b),I=Math.max(L,b),R=C=>{if(C<=x+1e-6)return L<=b?0:l;if(C>=I-1e-6)return L<=b?l:0;let rt=Ge(p,C);return rt?le(s,rt.x,rt.y).at:0},T=C=>C<S/2?e.approach.start:e.approach.end,k=tt.nodes[o.head]?.crossing&&T(L)>0?[u,Math.min(d,u+T(L))]:null,m=tt.nodes[o.tail]?.crossing&&T(b)>0?[Math.max(u,d-T(b)),d]:null,_=(C,rt)=>Xs(s,C,g(rt)),v=C=>(C==="left"?-1:1)*(e.width/2),z=C=>C>=x-1e-6&&C<=I+1e-6,N=C=>Math.min(d,Math.max(u,R(C))),q=C=>{let rt=C.length?C:[{from:0,to:S}],kt=[];for(let At of rt){let gt=R(At.from),bt=R(At.to),lt=Math.max(u,Math.min(gt,bt)),xt=Math.min(d,Math.max(gt,bt));xt-lt>.5&&kt.push([lt,xt]);}return kt},G=2,Z=(C,rt,kt,At)=>{let gt=Math.max(1,Math.ceil((rt-C)/G)),bt=[],lt=[];for(let xt=0;xt<=gt;xt++){let Yt=C+(rt-C)*xt/gt,Ct=_(Yt,kt),Vt=_(Yt,At);if(!Ct||!Vt)return null;bt.push(Ct[0],Ct[1]),lt.push(Vt[0],Vt[1]);}for(let xt=lt.length-2;xt>=0;xt-=2)bt.push(lt[xt],lt[xt+1]);return bt},at=(C,rt,kt)=>{let At=Math.max(1,Math.ceil((rt-C)/G)),gt=[];for(let bt=0;bt<=At;bt++){let lt=_(C+(rt-C)*bt/At,kt);if(!lt)return null;gt.push(lt[0],lt[1]);}return gt},mt=(C,rt,kt,At,gt=(lt,xt)=>lt+xt,bt=null)=>{if(!(d-u<2))for(let lt of rt){if(bt&&!bt(lt))continue;let xt=zi(lt.style,kt,w,lt.temp),Yt=lt.b>=d-1e-6&<.a>u+1e-6;xt.forEach(([Ct,Vt,Dt],ht)=>{for(let Ot of [].concat(gt(C,Ct,ht,xt.length)))for(let[Zt,Wt]of Fi(lt.a,lt.b,Dt,Yt)){let Kt=Ii(s,g(Ot),Zt,Wt);if(Kt)for(let qt of Ri(Kt,o,Dt?.3:.8))ue.push({type:"Feature",properties:{kind:Vt,...f,...At,style:lt.style,...lt.temp?{temp:true}:{},...i},geometry:{type:"LineString",coordinates:on(qt)}});}});}};if(e.backward){let C=e.median.width,rt=[k,m].filter(Boolean),kt=To(e.median.divider,e.median.spans,R,u,d,rt,w.approachStyle),At=C>=.5?(gt,bt,lt,xt)=>xt===1?[gt-C/2,gt+C/2]:lt===0?gt-C/2:gt+C/2:(gt,bt)=>gt+bt;mt(e.centre,kt,e.median.paint,{divider:e.median.divider},At);}let vt={};if(e.edges)for(let[C,rt]of [["left",-1],["right",1]]){let kt=e.edges[C],At=To(kt.on?"solid":"none",kt.spans,R,u,d);if(vt[C]=At,!A)mt(rt*(e.width/2-kt.offset-.1),At,"edge",{side:C});else {let gt=e.kerbs?.[C],bt=gt?(gt.on?gt.width:0)+(gt.verge==="gutter"?gt.vergeM:0):.3;mt(rt*(e.width/2-bt-kt.offset-.075),At,"edge",{side:C},void 0,lt=>lt.style!=="solid"||lt.temp);}}$e.get(t).edgeRuns=vt;let wt=[{spec:e.forward,sign:1,name:"forward",from:e.backward?e.centre+e.median.width/2:-e.width/2}];e.backward&&wt.push({spec:e.backward,sign:-1,name:"backward",from:-e.centre+e.median.width/2});for(let C of wt){let{lanes:rt,dividers:kt}=C.spec,At=[C.from];for(let ht of rt)At.push(At[At.length-1]+ht.width);let gt=ht=>C.sign*ht,bt=C.sign>0===n?1:-1,lt=[bt>0?m:k].filter(Boolean);for(let ht=1;ht<rt.length;ht++){let Ot=rt[ht-1].use==="bus"||rt[ht].use==="bus"?"bus":"white",Zt=To(kt[ht],C.spec.spans.filter(Wt=>Wt.b===ht),R,u,d,lt,w.approachStyle);mt(At[ht],Zt,Ot,{divider:kt[ht],direction:C.name},(Wt,Kt)=>gt(Wt+Kt));}let xt=(ht,Ot)=>Xs(s,ht,g(gt(Ot))),Yt=ht=>{let Ot=Ge(s,ht);return Ot?Math.atan2(Ot.dy*bt,Ot.dx*bt):0};rt.forEach((ht,Ot)=>{let Zt=(At[Ot]+At[Ot+1])/2,Wt=ht.variable?w.variableFill:ht.use==="bus"?w.busFill:ht.use==="bike"?w.bikeFill:ht.use==="tram"?w.tramFill:null;if(ht.fill?ht.fill.on:!!Wt){let qt=ht.fill?.color??Wt??"white",Jt=ht.use==="tram",ve=Jt?w.gaugeM:ht.width,pe=gt(Zt-ve/2),Te=gt(Zt+ve/2),Ve={...f,direction:C.name,lane:Ot,mark:Jt?"tram":"lane-fill"};for(let[so,E]of q(ht.fill?.spans??[])){let U=Z(so,E,pe,Te);if(U&&ue.push({type:"Feature",properties:{kind:`mark-fill-${qt}`,...Ve,...i},geometry:{type:"Polygon",coordinates:[It(U)]}}),!!Jt)for(let j of [pe,Te]){let B=at(so,E,j);B&&ue.push({type:"Feature",properties:{kind:"mark-lane-solid",...Ve,rail:true,...i},geometry:{type:"LineString",coordinates:on(B)}});}}}if(ht.use==="bus"&&d-u>12){let qt=(u+d)/2,Jt=xt(qt,Zt);Jt&&ue.push({type:"Feature",properties:{kind:"mark-text",text:"公交专用",...f,direction:C.name,lane:Ot,...i},geometry:{type:"Polygon",coordinates:[Qs(Jt[0],Jt[1],Yt(qt),5,Math.max(.5,Math.min(2.5,ht.width-.8)))]}});}if(ht.use==="hatched")for(let qt=u;qt+ht.width<=d;qt+=4){let Jt=xt(qt,At[Ot]+.15),ve=xt(qt+ht.width,At[Ot+1]-.15);if(!Jt||!ve)continue;let pe=(Jt[0]+ve[0])/2,Te=(Jt[1]+ve[1])/2;kn.near(pe,Te).some(Ve=>Vn(Ve,pe,Te))||ue.push({type:"Feature",properties:{kind:"mark-hatch",...f,direction:C.name,lane:Ot,...i},geometry:{type:"LineString",coordinates:on([Jt[0],Jt[1],ve[0],ve[1]])}});}});let Ct=bt>0?o.tail:o.head;if(!C.spec.arrows){tt.nodes[Ct]?.crossing&&Tn.add(t+":"+Ct);continue}if(So(t,Ct,"arrowObjects")){tt.nodes[Ct]?.crossing&&Tn.add(t+":"+Ct);continue}if(!rt.some(ht=>ht.turns.length)||!tt.nodes[Ct]?.crossing)continue;Tn.add(t+":"+Ct);let Vt=tt.clearanceAt(Ct,bt>0?c:h,o.level,o.axes);if(Vt<=0)continue;let Dt=null;for(let ht=0;ht<3;ht++){let Ot=Vt+C.spec.arrowGap+ht*7,Zt=bt>0?l-Ot:Ot;if(Zt<0||Zt>l)break;let Wt=Ge(s,Zt);if(Wt&&!Bi(Wt.x,Wt.y)){Dt=Zt;break}}Dt!==null&&rt.forEach((ht,Ot)=>{let Zt=Zs(ht.turns);if(!Zt.length)return;let Wt=xt(Dt,(At[Ot]+At[Ot+1])/2);Wt&&Js(Zt,Wt[0],Wt[1],Yt(Dt),ht.width,{kind:"mark-arrow",...f,turns:ht.turns.join(","),direction:C.name,lane:Ot,...i},qs(e.preset,o.cls));});}for(let C of e.zigzags){let rt=C.step??w.zigzag[0],kt=C.amp??w.zigzag[1],At=v(C.side),gt=C.side==="left"?1:-1,bt=Math.max(.5,rt)/2,lt=[],xt=()=>{lt.length>=4&&ue.push({type:"Feature",properties:{kind:"mark-bus",...f,mark:"zigzag",side:C.side,...i},geometry:{type:"LineString",coordinates:on(lt)}}),lt=[];};for(let Yt=0;Yt<4e3;Yt++){let Ct=Math.min(C.to,C.from+Yt*bt),Vt=R(Ct),Dt=z(Ct)&&Vt>=u-1e-6&&Vt<=d+1e-6?_(N(Ct),At+(Yt%2?gt*kt:0)):null;if(Dt?lt.push(Dt[0],Dt[1]):xt(),Ct>=C.to)break}xt();}for(let C of e.parking){let[rt,kt]=w.bay[C.layout]??w.bay.parallel,At=C.bayL??rt,gt=C.bayW??kt,bt=C.layout==="parallel"?At:C.layout==="perp"?gt:gt*Math.SQRT2;if(!(bt>0))continue;let lt=v(C.side),Yt=(C.side==="left"?1:-1)*(C.layout==="parallel"?gt:C.layout==="perp"?At:At*Math.SQRT1_2),Ct=C.layout==="angle"?At*Math.SQRT1_2:0,Vt=Math.min(200,Math.floor((C.to-C.from)/bt+1e-6));for(let Dt=0;Dt<Vt;Dt++){let ht=C.from+Dt*bt,Ot=ht+bt,Zt=(ht+Ot)/2;if(!z(Zt))continue;let Wt=R(Zt);if(!(Wt>u&&Wt<d))continue;let Kt=[],qt=true;for(let[Jt,ve]of [[ht,lt],[Ot,lt],[Ot+Ct,lt+Yt],[ht+Ct,lt+Yt]]){let pe=_(N(Jt),ve);if(!pe){qt=false;break}Kt.push(pe[0],pe[1]);}qt&&(Kt.push(Kt[0],Kt[1]),ue.push({type:"Feature",properties:{kind:"mark-lane-solid",...f,mark:"parking",side:C.side,layout:C.layout,bay:Dt,...i},geometry:{type:"LineString",coordinates:on(Kt)}}));}}}if($e.size){let t=dn.filter(e=>!((e.kind==="lane"||e.kind==="centre")&&$e.has(e.chain)));dn.length=0,dn.push(...t);}if(Tn.size){let t=Fn.filter((e,n)=>{let s=Cs[n];if(!$e.has(s.chain))return true;let o=tt.chains[s.chain];return !Tn.has(s.chain+":"+(s.at<hn(o.pts)/2?o.head:o.tail))});Fn.length=0,Fn.push(...t);}let tr=[];for(let t of y){let e=t.properties;if(e.kind!=="ld-object"||t.geometry?.type!=="Point")continue;let[n,s]=H(t.geometry.coordinates),o=e.profile?Mt(e):null,a=o?o.width:typeof e.hostWidth=="number"&&e.hostWidth>0?e.hostWidth:8,r=o?!o.backward:!!e.hostOneway,l=o?o.centre:0,i=o?o.median.width:0,f=e.direction==="backward",h=(e.headingDeg??0)*Math.PI/180,c=(e.heading??0)*Math.PI/180+h,u=Math.cos(c)*(f?-1:1),d=Math.sin(c)*(f?-1:1),g=Math.sin(c),w=-Math.cos(c),p=Math.atan2(d,u),S=typeof e.offsetM=="number"?e.offsetM:0,L=n+g*S,b=s+w*S,x=e.params&&typeof e.params=="object"?e.params:{},I={ldObject:e.key??null},R=r?[-a/2,a/2]:f?[-a/2,l-i/2]:[l+i/2,a/2],T=3.5;if(o){let k=[{spec:o.forward,sign:1,from:o.backward?l+i/2:-a/2}];o.backward&&k.push({spec:o.backward,sign:-1,from:-l+i/2});for(let m of k){let _=m.from;for(let v of m.spec.lanes){let z=m.sign*_,N=m.sign*(_+v.width);S>=Math.min(z,N)&&S<=Math.max(z,N)&&(T=v.width),_+=v.width;}}}switch(e.object){case "stop-line":{ue.push({type:"Feature",properties:{kind:"mark-stop",...I,...fn(n,s)},geometry:{type:"LineString",coordinates:[$(n+g*R[0],s+w*R[0]),$(n+g*R[1],s+w*R[1])]}});break}case "crosswalk":{tr.push([n,s,typeof x.depthM=="number"&&x.depthM>0?x.depthM:Fe]);for(let k of Ls(n-g*(a/2),s-w*(a/2),n+g*(a/2),s+w*(a/2)))ue.push({...k,properties:{...k.properties,...I}});break}case "lane-arrow":{let k=Array.isArray(x.turns)?x.turns:["straight"],m=T;if(o&&Number.isInteger(x.lane)&&x.lane>=0){let _=f?o.backward:o.forward;_&&_.lanes[x.lane]&&(m=_.lanes[x.lane].width);}Js(Zs(k),L,b,p,m,{kind:"mark-arrow",turns:k.join(","),...Number.isInteger(x.lane)?{lane:x.lane}:{},direction:e.direction==="backward"?"backward":"forward",...I,...fn(L,b)},qs(o?o.preset:"tj",typeof e.hostCls=="string"?e.hostCls:""));break}case "yield-line":{let k=R[1]-R[0],m=Math.max(1,Math.floor(k/1.2)),_=k/m;for(let v=0;v<m;v++){let z=R[0]+_*(v+.5),N=n+g*z,q=s+w*z,G=[N+u*.35-g*.3,q+d*.35-w*.3,N+u*.35+g*.3,q+d*.35+w*.3,N-u*.35,q-d*.35];ue.push({type:"Feature",properties:{kind:"mark-yield",...I,...fn(N,q)},geometry:{type:"Polygon",coordinates:[It(G)]}});}break}case "hatch":{let k=typeof x.lengthM=="number"&&x.lengthM>0?x.lengthM:15,m=typeof x.widthM=="number"&&x.widthM>0?x.widthM:3,_=fn(L,b),v=(N,q)=>[L+u*N+g*q,b+d*N+w*q],z=[...v(-k/2,-m/2),...v(k/2,-m/2),...v(k/2,m/2),...v(-k/2,m/2),...v(-k/2,-m/2)];ue.push({type:"Feature",properties:{kind:"mark-lane-solid",...I,..._},geometry:{type:"LineString",coordinates:on(z)}});for(let N=-k/2-m;N<k/2;N+=2){let q=Math.max(N,-k/2),G=Math.min(N+m,k/2);if(G-q<.3)continue;let Z=-m/2+(q-N),at=-m/2+(G-N);ue.push({type:"Feature",properties:{kind:"mark-hatch",...I,..._},geometry:{type:"LineString",coordinates:on([...v(q,Z),...v(G,at)])}});}break}case "text":{let k=typeof x.lengthM=="number"&&x.lengthM>0?x.lengthM:4,m=typeof x.widthM=="number"&&x.widthM>0?x.widthM:Math.max(.5,Math.min(2.5,T-.6));ue.push({type:"Feature",properties:{kind:"mark-text",text:typeof x.text=="string"?x.text:"",...I,...fn(L,b)},geometry:{type:"Polygon",coordinates:[Qs(L,b,p,k,m)]}});break}}}let er=.075,nr=600,ji={white:"mark-hatch",yellow:"mark-bus",orange:"mark-temp"},Ci={white:"mark-lane-solid",yellow:"mark-bus",orange:"mark-temp"},or=(t,e,n,s,o)=>{let a=s-e,r=o-n,l=[0,1],i=t.length/2;for(let h=0,c=i-1;h<i;c=h++){let u=t[c*2],d=t[c*2+1],g=t[h*2],w=t[h*2+1],p=g-u,S=w-d,L=a*S-r*p;if(Math.abs(L)<1e-12)continue;let b=((u-e)*S-(d-n)*p)/L,x=((u-e)*r-(d-n)*a)/L;b>0&&b<1&&x>=0&&x<=1&&l.push(b);}l.sort((h,c)=>h-c);let f=[];for(let h=0;h+1<l.length;h++){let c=l[h],u=l[h+1];if(u-c<1e-9)continue;let d=(c+u)/2;Ao(t,e+a*d,n+r*d)&&(Math.hypot(a*(u-c),r*(u-c))<.3||f.push([e+a*c,n+r*c,e+a*u,n+r*u]));}return f},qn=(t,e,n,s,o)=>{let a=n?"mark-temp":(o?Ci:ji)[e];if(a){ue.push({type:"Feature",properties:{kind:a,ldArea:s.ldArea,...s.props},geometry:{type:"LineString",coordinates:on(t)}});return}for(let r=0;r+3<t.length;r+=2){let l=t[r],i=t[r+1],f=t[r+2],h=t[r+3],c=Math.hypot(f-l,h-i);if(!(c>0))continue;let u=(h-i)/c*er,d=-(f-l)/c*er;ue.push({type:"Feature",properties:{kind:`mark-fill-${e}`,ldArea:s.ldArea,...s.props},geometry:{type:"Polygon",coordinates:[It([l+u,i+d,f+u,h+d,f-u,h-d,l-u,i-d])]}});}},Ui=1,Gi=1,Yi=(t,e,n)=>{let s=[],o=e,a=true,r=a?[t[0],t[1]]:[];for(let l=0;l+3<t.length;l+=2){let i=t[l],f=t[l+1],h=t[l+2],c=t[l+3],u=Math.hypot(h-i,c-f);if(!(u>0))continue;let d=(h-i)/u,g=(c-f)/u;for(;u>o;)i+=d*o,f+=g*o,u-=o,a?(r.push(i,f),r.length>=4&&s.push(r)):r=[i,f],a=!a,o=a?e:n;o-=u,a&&r.push(h,c);}return a&&r.length>=4&&s.push(r),s};for(let t of y){let e=t.properties;if(e.kind!=="ld-area"||t.geometry?.type!=="Polygon")continue;let n=t.geometry.coordinates&&t.geometry.coordinates[0];if(!Array.isArray(n)||n.length<4)continue;let s=[];for(let p of n){let[S,L]=H(p);s.push(S,L);}if(s.length>=4&&Math.abs(s[0]-s[s.length-2])<1e-9&&Math.abs(s[1]-s[s.length-1])<1e-9&&(s.length-=2),s.length<6)continue;let o=1/0,a=1/0,r=-1/0,l=-1/0;for(let p=0;p<s.length;p+=2)s[p]<o&&(o=s[p]),s[p]>r&&(r=s[p]),s[p+1]<a&&(a=s[p+1]),s[p+1]>l&&(l=s[p+1]);let i=(o+r)/2,f=(a+l)/2,h=e.temp===true,c=h?"orange":typeof e.color=="string"?e.color:"white",u=typeof e.pattern=="string"?e.pattern:"diag",d=Number.isFinite(e.stepM)&&e.stepM>=.2?e.stepM:2,g=(Number.isFinite(e.angleDeg)?e.angleDeg:45)*Math.PI/180,w={ldArea:e.key??null,props:fn(i,f)};if(u!=="none")if(u==="solid")ue.push({type:"Feature",properties:{kind:`mark-fill-${c}`,ldArea:w.ldArea,...w.props},geometry:{type:"Polygon",coordinates:[It(s)]}});else {let p=Math.hypot(r-o,l-a)/2+1,S=L=>{let b=Math.cos(L),x=Math.sin(L),I=-x,R=b,T=1/0,k=-1/0;for(let v=0;v<s.length;v+=2){let z=(s[v]-i)*I+(s[v+1]-f)*R;z<T&&(T=z),z>k&&(k=z);}let m=Math.ceil(T/d)*d,_=0;for(let v=m;v<=k&&_<nr;v+=d,_++){let z=i+I*v,N=f+R*v;for(let[q,G,Z,at]of or(s,z-b*p,N-x*p,z+b*p,N+x*p))qn([q,G,Z,at],c,h,w,false);}};if(u==="chevron"){let L=Math.cos(g),b=Math.sin(g),x=-b,I=L,R=1/0,T=-1/0,k=1/0,m=-1/0;for(let N=0;N<s.length;N+=2){let q=(s[N]-i)*L+(s[N+1]-f)*b,G=(s[N]-i)*x+(s[N+1]-f)*I;q<R&&(R=q),q>T&&(T=q),G<k&&(k=G),G>m&&(m=G);}let _=Math.max(.5,(m-k)/2),v=(N,q)=>[i+L*N+x*q,f+b*N+I*q],z=0;for(let N=Math.ceil(R/d)*d;N<=T+_&&z<nr;N+=d,z++){let q=v(N,(k+m)/2),G=v(N-_,k),Z=v(N-_,m);for(let at of [G,Z])for(let[mt,vt,wt,C]of or(s,q[0],q[1],at[0],at[1]))qn([mt,vt,wt,C],c,h,w,false);}}else S(g),u==="grid"&&S(g+Math.PI/2);}if(e.outline!==false){let p=[...s,s[0],s[1]];if(e.dash===true)for(let S of Yi(p,Ui,Gi))qn(S,c,h,w,true);else qn(p,c,h,w,true);}}let sr=.015,Hi=1,Wi=A?.9:.45,Ki=A?.02:.28,sn=new Map,Zn=new Map($e);tt.chains.forEach((t,e)=>{if(t.level>=0||Zn.has(e))return;let n=t.axes.find(r=>yt[r]&&yt[r].profile&&(yt[r].profile.kerbs||yt[r].profile.edges)&&yt[r].pts&&yt[r].pts.length>=4);if(n===void 0)return;let s=vo(e);if(!s)return;let o=yt[n].pts,a=le(s,o[0],o[1]).at<=le(s,o[o.length-2],o[o.length-1]).at;Zn.set(e,{profile:yt[n].profile,same:a,base:s,src:o,members:[]});});for(let[t,e]of Zn){let n=e.profile.kerbs;if(!n)continue;let s=tt.chains[t],o=s.pts,a=o.length/2,r=hn(e.base),l=0,i=r;tt.nodes[s.head]?.crossing&&(l=tt.clearanceAt(s.head,Math.atan2(o[3]-o[1],o[2]-o[0]),s.level,s.axes)),tt.nodes[s.tail]?.crossing&&(i=r-tt.clearanceAt(s.tail,Math.atan2(o[a*2-3]-o[a*2-1],o[a*2-4]-o[a*2-2]),s.level,s.axes));let f=hn(e.src),h=u=>{let d=n[u],g=[],w=(S,L,b)=>{let x=le(e.base,S,L);x.d<=e.profile.width/2+1&&x.at>0&&x.at<r&&g.push([x.at-b/2,x.at+b/2]);};if(d.lowerAtCrossings){for(let S of ke)w(S.x,S.y,Fe);for(let[S,L,b]of tr)w(S,L,b);}for(let[S,L]of d.lowered){let b=Ge(e.src,S*f),x=Ge(e.src,L*f);if(!b||!x)continue;let I=le(e.base,b.x,b.y).at,R=le(e.base,x.x,x.y).at;g.push([Math.min(I,R),Math.max(I,R)]);}let p=d.on?d.height:0;return S=>{let L=p;for(let[b,x]of g){let I=S<b?b-S:S>x?S-x:0,R=Math.min(p,sr+(p-sr)*Math.min(1,I/Hi));R<L&&(L=R);}return L}},c=u=>u==="right"===e.same?1:-1;sn.set(t,{...e,chain:t,total:r,s0:l,s1:i,kerbs:n,sign:c,heightAt:{left:h("left"),right:h("right")}});}let Jn=(t,e)=>{if(!sn.size)return null;let n=1/0,s=-1,o=Math.floor(t/ge),a=Math.floor(e/ge);for(let c=-1;c<=1;c++)for(let u=-1;u<=1;u++){let d=en.get(o+u+","+(a+c));if(d)for(let g=0;g<d.length;g+=4){let w=(t-d[g+1])**2+(e-d[g+2])**2;w<n&&(n=w,s=d[g]);}}let r=sn.get(s);if(!r)return null;let l=le(r.base,t,e),i=Ge(r.base,l.at);if(!i)return null;let h=Math.cos(l.ang)*(e-i.y)-Math.sin(l.ang)*(t-i.x)>0===r.same?"left":"right";return {kc:r,side:h,k:r.kerbs[h],at:l.at}},de={pos:[],nrm:[],part:[],hgt:[],paint:[],idx:[]},Xi=(t,e,n,s,o,a,r,l,i,f)=>(de.pos.push(t,e,n),de.nrm.push(s,o,a),de.part.push(r),de.hgt.push(l),de.paint.push(i[0],i[1],i[2],i[3],i[4],i[5],f,i[7],i[8],i[9]),de.part.length-1),$i=t=>[...t.color,...t.stripe??t.color,0,t.stripe?t.stripeM:0,t.joint,t.grain],Qn=(t,e)=>{let n=Un(t);return [...n,...n,0,0,0,e]},xn=(t,e,n,s,o,a,r,l)=>{if(o-s<.3)return;let i=Math.max(1,Math.ceil((o-s)/.5)),f=[];for(let d=0;d<=i;d++){let g=s+(o-s)*d/i,w=Ge(t.base,g);if(!w)return;let p=w.dy,S=-w.dx;f.push({s:g,nx:p,ny:S,dx:w.dx,dy:w.dy,a:[w.x+p*e,w.y+S*e],b:[w.x+p*n,w.y+S*n],zb:a(g),zt:r(g),h:se.at(t.chain,g)});}let h=n>e?1:-1,c=(d,g,w,p,S,L,b)=>Xi(d[0],d[1],g,w,p,S,L,b.h,l,b.s),u=d=>de.idx.push(d[0],d[1],d[2],d[0],d[2],d[3]);for(let d=0;d<i;d++){let g=f[d],w=f[d+1];if(u([c(g.a,g.zt,0,0,1,3,g),c(w.a,w.zt,0,0,1,3,w),c(w.b,w.zt,0,0,1,3,w),c(g.b,g.zt,0,0,1,3,g)]),!(g.zt-g.zb<.002&&w.zt-w.zb<.002))for(let[p,S]of [["a",-h],["b",h]]){let L=g.nx*S,b=g.ny*S;u([c(g[p],g.zt,L,b,0,4,g),c(w[p],w.zt,L,b,0,4,w),c(w[p],w.zb,L,b,0,4,w),c(g[p],g.zb,L,b,0,4,g)]);}}for(let[d,g]of [[f[0],-1],[f[f.length-1],1]]){if(d.zt-d.zb<.002)continue;let w=d.dx*g,p=d.dy*g;u([c(d.a,d.zt,w,p,0,4,d),c(d.b,d.zt,w,p,0,4,d),c(d.b,d.zb,w,p,0,4,d),c(d.a,d.zb,w,p,0,4,d)]);}};for(let t of sn.values()){if(t.s1-t.s0<1)continue;let e=o=>se.at(t.chain,o),n=o=>e(o)+Ki,s=t.profile.width/2+Wi;for(let o of ["left","right"]){let a=t.kerbs[o],r=t.sign(o),l=t.heightAt[o],i=a.on?a.width:0;if(!A&&a.on&&xn(t,r*(s-i),r*s,t.s0,t.s1,h=>n(h)-.12,h=>n(h)+l(h),$i(a)),!a.verge)continue;if(a.verge==="gutter"){let h=c=>n(c)+.004;xn(t,r*(s-i-a.vergeM),r*(s-i),t.s0,t.s1,h,h,Qn("#8a8984",.05));continue}if([t.s0,t.s1,(t.s0+t.s1)/2].some(h=>e(h)>.5))continue;let f=h=>c=>e(c)+h;if(a.verge==="lawn")xn(t,r*s,r*(s+a.vergeM),t.s0,t.s1,f(.01),f(.01),Qn("#6e8b4a",.14));else {let c=Qn("#9e9c95",.05);xn(t,r*s,r*(s+.1),t.s0,t.s1,f(0),f(.06),c),xn(t,r*(s+.1),r*(s+.1+a.vergeM),t.s0,t.s1,f(.005),f(.005),Qn("#5c6b5a",.02)),xn(t,r*(s+.1+a.vergeM),r*(s+2*.1+a.vergeM),t.s0,t.s1,f(0),f(.06),c);}}}let No=null;if(de.idx.length){let t=de.part.length,e=new Float64Array(t*2);for(let n=0;n<t;n++){let[s,o]=$(de.pos[3*n],de.pos[3*n+1]);e[2*n]=s,e[2*n+1]=o;}No={lonlat:e,z:Float32Array.from({length:t},(n,s)=>de.pos[3*s+2]),normals:Float32Array.from(de.nrm),part:Uint8Array.from(de.part),height:Float32Array.from(de.hgt),indices:Uint32Array.from(de.idx),kerbPaint:Float32Array.from(de.paint)};}let Vi=[...dn,...Ye].map(t=>{let e=[];for(let s=0;s+1<t.pts.length;s+=2)e.push($(t.pts[s],t.pts[s+1]));let n=t.kind==="stop"&&t.pts.length===4?Ps(t.chain,Ys(t),(t.pts[0]+t.pts[2])/2,(t.pts[1]+t.pts[3])/2,Math.hypot(t.pts[2]-t.pts[0],t.pts[3]-t.pts[1])/2+1):null;return {type:"Feature",properties:{kind:"mark-"+t.kind,cls:t.cls,layer:t.level,...uo(t.chain),...n},geometry:{type:"LineString",coordinates:e}}}),Me=.3,Nn=.15,ee=.02,qi=()=>{let t=[];tt.chains.forEach((h,c)=>{for(let u of h.axes)t[u]=c;});let e=(h,c,u)=>{let d=t[h];if(d===void 0)return 0;let g=tt.chains[d].pts,w=1/0,p=0,S=0;for(let L=0;L+3<g.length;L+=2){let b=g[L+2]-g[L],x=g[L+3]-g[L+1],I=Math.hypot(b,x),R=I>0?Math.max(0,Math.min(1,((c-g[L])*b+(u-g[L+1])*x)/(I*I))):0,T=Math.hypot(g[L]+b*R-c,g[L+1]+x*R-u);T<w&&(w=T,p=S+R*I),S+=I;}return se.at(d,p)},n=50,s=new Map;yt.forEach((h,c)=>{for(let u=0;u+3<h.pts.length;u+=2){let d=Math.floor(Math.min(h.pts[u],h.pts[u+2])/n),g=Math.floor(Math.max(h.pts[u],h.pts[u+2])/n),w=Math.floor(Math.min(h.pts[u+1],h.pts[u+3])/n),p=Math.floor(Math.max(h.pts[u+1],h.pts[u+3])/n);for(let S=d;S<=g;S++)for(let L=w;L<=p;L++){let b=S*1e7+L,x=s.get(b);x?x.push(c,u):s.set(b,[c,u]);}}});let o=yt.map(()=>[]),a=new Set;for(let h of s.values())for(let c=0;c<h.length;c+=2)for(let u=c+2;u<h.length;u+=2){let d=h[c],g=h[c+1],w=h[u],p=h[u+1];if(d===w)continue;let S=d<w?d+":"+g+":"+w+":"+p:w+":"+p+":"+d+":"+g;if(a.has(S))continue;a.add(S);let L=yt[d],b=yt[w];if(L.level!==b.level)continue;let x=L.pts[g],I=L.pts[g+1],R=L.pts[g+2]-x,T=L.pts[g+3]-I,k=b.pts[p],m=b.pts[p+1],_=b.pts[p+2]-k,v=b.pts[p+3]-m,z=R*v-T*_;if(Math.abs(z)<1e-9)continue;let N=((k-x)*v-(m-I)*_)/z,q=((k-x)*T-(m-I)*R)/z;if(N<=1e-6||N>=1-1e-6||q<=1e-6||q>=1-1e-6)continue;let G=x+R*N,Z=I+T*N;Math.abs(e(d,G,Z)-e(w,G,Z))>.5||(o[d].push([g,N,G,Z]),o[w].push([p,q,G,Z]));}let r=new Map;yt.forEach((h,c)=>{let u=h.pts.length/2;for(let d=0;d<u;d++){let g=Math.round(h.pts[2*d]*100)+","+Math.round(h.pts[2*d+1]*100),w=r.get(g);w?w.push(c,d):r.set(g,[c,d]);}});for(let h of r.values()){if(h.length<4)continue;let c=new Set;for(let u=0;u<h.length;u+=2)c.add(h[u]);if(!(c.size<2))for(let u=0;u<h.length;u+=2){let d=h[u],g=h[u+1],w=yt[d].pts.length/2;if(g===0||g===w-1)continue;let p=yt[d].pts[2*g],S=yt[d].pts[2*g+1];[...c].filter(b=>b!==d).some(b=>yt[b].level===yt[d].level&&Math.abs(e(b,p,S)-e(d,p,S))<=.5)&&o[d].push([2*g,0,p,S]);}}if(!o.some(h=>h.length))return {graph:tt,heights:se};let l=[];yt.forEach((h,c)=>{let u=o[c];if(!u.length){l.push(h);return}u.sort((w,p)=>w[0]-p[0]||w[1]-p[1]);let d=[h.pts[0],h.pts[1]],g=0;for(let w=0;w+3<h.pts.length;w+=2){for(;g<u.length&&u[g][0]===w;)u[g][1]>0&&d.push(u[g][2],u[g][3]),d.length>=4&&l.push({...h,pts:d}),d=[u[g][2],u[g][3]],g++;d.push(h.pts[w+2],h.pts[w+3]);}l.push({...h,pts:d});});let i=oe.OsmGL.buildRoadGraph(l.filter(h=>h.pts.length>=4),{smooth:.9,maxSmooth:20,miter:true}),f=oe.OsmGL.roadHeights(i,{levelHeight:mn,maxGrade:tn,clearance:5});return {graph:i,heights:f}},wn=null,Zi={motorway:12,trunk:12,primary:11,secondary:9,tertiary:8,residential:6,unclassified:6,living_street:4,service:4,track:4},rr=(t,e)=>Zi[t.chains[e]?.cls]??7,Ji=()=>{wn=qi();let t=wn.graph,e=oe.OsmGL.ROAD_MESH_RADIUS_BY_CORNER?(n,s)=>Math.min(rr(t,n),rr(t,s)):7;return Qi(wn.graph,wn.heights,{widthExtra:.9,kerbRadius:e,elevation:ee,deck:1.4,kerbWidth:Me,kerbHeight:Nn,fillGap:1.5,outline:true,skip:n=>wn.graph.chains[n].level<0})},Qi=(...t)=>oe.OsmGL.roadMesh(...t),ta=t=>{let a=[],{positions:r,part:l,indices:i}=t,f=E=>Math.round(r[3*E]*1e3)+","+Math.round(r[3*E+1]*1e3),h=new Map,c=[],u=new Int32Array(r.length/3);for(let E=0;E<r.length/3;E++){let U=f(E),j=h.get(U);j===void 0&&(j=c.length/3,h.set(U,j),c.push(r[3*E],r[3*E+1],r[3*E+2])),u[E]=j;}let d=new Map;for(let E=0;E+2<i.length;E+=3){let U=i[E],j=i[E+1],B=i[E+2];if(l[U]!==0||l[j]!==0||l[B]!==0)continue;let D=u[U],K=u[j],V=u[B];if(D===K||K===V||D===V)continue;let ot=(c[3*K]-c[3*D])*(c[3*V+1]-c[3*D+1])-(c[3*V]-c[3*D])*(c[3*K+1]-c[3*D+1])>0?[D,K,V]:[D,V,K];for(let Q=0;Q<3;Q++){let it=ot[Q],ut=ot[(Q+1)%3],Lt=it<ut?it+":"+ut:ut+":"+it,pt=d.get(Lt);pt?pt.n++:d.set(Lt,{u:it,w:ut,n:1});}}let g=4,w=new Map,p=[];for(let E=0;E+2<i.length;E+=3){let U=i[E],j=i[E+1],B=i[E+2];if(l[U]!==0||l[j]!==0||l[B]!==0)continue;let D=p.length;p.push(U,j,B);let K=Math.min(r[3*U],r[3*j],r[3*B]),V=Math.max(r[3*U],r[3*j],r[3*B]),st=Math.min(r[3*U+1],r[3*j+1],r[3*B+1]),ot=Math.max(r[3*U+1],r[3*j+1],r[3*B+1]);for(let Q=Math.floor(K/g);Q<=Math.floor(V/g);Q++)for(let it=Math.floor(st/g);it<=Math.floor(ot/g);it++){let ut=Q*1e7+it,Lt=w.get(ut);Lt?Lt.push(D):w.set(ut,[D]);}}let S=(E,U,j)=>{let B=null;for(let D of w.get(Math.floor(E/g)*1e7+Math.floor(U/g))??[]){let K=p[D],V=p[D+1],st=p[D+2],ot=r[3*K],Q=r[3*K+1],it=r[3*V],ut=r[3*V+1],Lt=r[3*st],pt=r[3*st+1],Rt=(ut-pt)*(ot-Lt)+(Lt-it)*(Q-pt);if(Math.abs(Rt)<1e-12)continue;let Bt=((ut-pt)*(E-Lt)+(Lt-it)*(U-pt))/Rt,dt=((pt-Q)*(E-Lt)+(ot-Lt)*(U-pt))/Rt,St=1-Bt-dt;if(Bt<-1e-6||dt<-1e-6||St<-1e-6)continue;let Pt=Bt*r[3*K+2]+dt*r[3*V+2]+St*r[3*st+2];(B===null||Math.abs(Pt-j)<Math.abs(B-j))&&(B=Pt);}return B},L=new Map;for(let E of d.values()){if(E.n!==1)continue;let U=c[3*E.u],j=c[3*E.u+1],B=c[3*E.w],D=c[3*E.w+1],K=Math.hypot(B-U,D-j)||1,V=(D-j)/K,st=-(B-U)/K,ot=(c[3*E.u+2]+c[3*E.w+2])/2,Q=S((U+B)/2+V*.03,(j+D)/2+st*.03,ot);if(Q!==null&&Math.abs(Q-ot)<.3)continue;let it=L.get(E.u);it?it.push(E.w):L.set(E.u,[E.w]);}let b=[],x=E=>{let U=L.get(E);return !U||!U.length?-1:U.pop()},I=new Set;for(let[E,U]of L)U.length&&I.add(E);let R=new Set;for(let E of L.values())for(let U of E)R.add(U);let T=E=>{let U=[E],j=E;for(;;){let B=x(j);if(B<0||(U.push(B),j=B,B===E))break}U.length>=2&&b.push(U);};for(let E of I)R.has(E)||T(E);for(let E of L.keys())for(;(L.get(E)??[]).length;)T(E);let k=.6,m=E=>[c[3*E],c[3*E+1]],_=(E,U)=>{let j=U?E[E.length-2]:E[0],B=U?E[E.length-1]:E[1],[D,K]=m(j),[V,st]=m(B),ot=Math.hypot(V-D,st-K)||1;return [(V-D)/ot,(st-K)/ot]};for(let E=true;E;){E=false;let U=b.map((B,D)=>D).filter(B=>b[B]&&b[B][0]!==b[B][b[B].length-1]),j=new Map;for(let B of U){let[D,K]=m(b[B][0]),V=Math.floor(D/k)*1e7+Math.floor(K/k),st=j.get(V);st?st.push(B):j.set(V,[B]);}for(let B of U){let D=b[B];if(!D)continue;let[K,V]=m(D[D.length-1]),st=_(D,true),ot=-1,Q=k,it=Math.floor(K/k),ut=Math.floor(V/k);for(let Bt=ut-1;Bt<=ut+1;Bt++)for(let dt=it-1;dt<=it+1;dt++)for(let St of j.get(dt*1e7+Bt)??[]){if(St===B||!b[St])continue;let[Pt,ce]=m(b[St][0]),re=Math.hypot(Pt-K,ce-V),Qt=_(b[St],false);re<Q&&st[0]*Qt[0]+st[1]*Qt[1]>.7&&(Q=re,ot=St);}if(ot<0)continue;let Lt=D[D.length-1],pt=b[ot][0],Rt=c.length/3;c.push((c[3*Lt]+c[3*pt])/2,(c[3*Lt+1]+c[3*pt+1])/2,(c[3*Lt+2]+c[3*pt+2])/2),b[B]=D.slice(0,-1).concat([Rt],b[ot].slice(1)),b[ot]=null,E=true;}for(let B=b.length-1;B>=0;B--)b[B]||b.splice(B,1);for(let B=0;B<b.length;B++){let D=b[B];if(D[0]===D[D.length-1]||D.length<4)continue;let[K,V]=m(D[0]),[st,ot]=m(D[D.length-1]);Math.hypot(K-st,V-ot)<k&&D.push(D[0]);}}let v=.2,z=Math.cos(45*Math.PI/180);for(let E of b)for(let U=true;U;){U=false;for(let j=1;j+1<E.length&&E.length>3;j++){let B=E[j-1],D=E[j],K=E[j+1],V=c[3*D]-c[3*B],st=c[3*D+1]-c[3*B+1],ot=c[3*K]-c[3*D],Q=c[3*K+1]-c[3*D+1],it=Math.hypot(V,st),ut=Math.hypot(ot,Q);Math.min(it,ut)>v||it>1e-9&&ut>1e-9&&(V*ot+st*Q)/(it*ut)>z||(E.splice(j,1),U=true,j--);}}let N=[];{let E=[];for(let D=0;D<b.length;D++)b[D][0]!==b[D][b[D].length-1]&&E.push(D);let U=new Map;for(let D of E){let[K,V]=m(b[D][0]),st=Math.floor(K/k)*1e7+Math.floor(V/k),ot=U.get(st);ot?ot.push(D):U.set(st,[D]);}let j=new Set,B=(D,K)=>{let V=b[D],[st,ot]=m(V[V.length-1]),Q=-1,it=k,ut=Math.floor(st/k),Lt=Math.floor(ot/k);for(let pt=Lt-1;pt<=Lt+1;pt++)for(let Rt=ut-1;Rt<=ut+1;Rt++)for(let Bt of U.get(Rt*1e7+pt)??[]){if(j.has(Bt)||Bt!==K[0]&&K.includes(Bt))continue;let[dt,St]=m(b[Bt][0]),Pt=Math.hypot(dt-st,St-ot);Pt<it&&(it=Pt,Q=Bt);}return Q};for(let D of E){if(j.has(D))continue;let K=[D],V=0,st=false;for(let it=D;K.length<8&&V<40;){let ut=b[it];for(let pt=0;pt+1<ut.length;pt++)V+=Math.hypot(c[3*ut[pt+1]]-c[3*ut[pt]],c[3*ut[pt+1]+1]-c[3*ut[pt]+1]);let Lt=B(it,K);if(Lt<0)break;if(Lt===D){st=true;break}K.push(Lt),it=Lt;}if(!st||K.length<2)continue;let ot=K.flatMap(it=>b[it]).map(it=>[c[3*it],c[3*it+1],c[3*it+2]]),Q=0;for(let it=0;it<ot.length;it++){let ut=ot[it],Lt=ot[(it+1)%ot.length];Q+=ut[0]*Lt[1]-Lt[0]*ut[1];}if(Q/=2,Q<0&&(-Q/V<.5||-Q<4)){N.push(ot);for(let it of K)j.add(it);}}if(j.size){let D=b.filter((K,V)=>!j.has(V));b.length=0,b.push(...D);}}let q=[];for(let E of b){if(E.length>3&&E[0]===E[E.length-1]){let j=0,B=0;for(let D=0;D+1<E.length;D++){let K=E[D],V=E[D+1];j+=c[3*K]*c[3*V+1]-c[3*V]*c[3*K+1],B+=Math.hypot(c[3*V]-c[3*K],c[3*V+1]-c[3*K+1]);}if(j/=2,j<0&&(-j/B<.5||-j<4)){N.push(E.slice(0,-1).map(D=>[c[3*D],c[3*D+1],c[3*D+2]]));continue}}else {let j=0;for(let B=0;B+1<E.length;B++){let D=E[B],K=E[B+1];j+=Math.hypot(c[3*K]-c[3*D],c[3*K+1]-c[3*D+1]);}if(j<3)continue}q.push(E);}b.length=0,b.push(...q);let G=.75,Z=100*Math.PI/180,at=1,mt=[],vt=[],wt=[],C=(E,U,j,B,D,K)=>{let V=j-E,st=B-U,ot=D-j,Q=K-B;return Math.PI+Math.atan2(V*Q-st*ot,V*ot+st*Q)},rt=E=>{let U=[0];for(let j=0;j+1<E.length;j++)U.push(U[j]+Math.hypot(c[3*E[j+1]]-c[3*E[j]],c[3*E[j+1]+1]-c[3*E[j]+1]));return U},kt=(E,U,j)=>{let B=1;for(;B<U.length-1&&U[B]<j;)B++;let D=U[B]-U[B-1],K=D>0?Math.max(0,Math.min(1,(j-U[B-1])/D)):0,V=E[B-1],st=E[B];return {x:c[3*V]+(c[3*st]-c[3*V])*K,y:c[3*V+1]+(c[3*st+1]-c[3*V+1])*K,z:c[3*V+2]+(c[3*st+2]-c[3*V+2])*K,seg:B}},At=1.2,gt=(E,U)=>{let j=1/0,B=-1,D=Math.floor(E/ge),K=Math.floor(U/ge);for(let V=-1;V<=1;V++)for(let st=-1;st<=1;st++){let ot=en.get(D+st+","+(K+V));if(ot)for(let Q=0;Q<ot.length;Q+=4){let it=(E-ot[Q+1])**2+(U-ot[Q+2])**2;it<j&&(j=it,B=ot[Q]);}}return B},bt=(E,U)=>Ue.some(j=>{let B=_e(j,E,U);return B.zone&&B.a>-3});for(let E=true,U=0;E&&U<50;U++){E=false;for(let j=0;j<b.length&&!E;j++){let B=b[j];if(B.length<2||B[0]===B[B.length-1])continue;let D=B[B.length-1],K=B[Math.max(0,B.length-3)];for(let V=0;V<b.length&&!E;V++){let st=b[V];if(st.length<2||st[0]===st[st.length-1])continue;let ot=st[0],Q=st[Math.min(st.length-1,2)];if(Math.hypot(c[3*ot]-c[3*D],c[3*ot+1]-c[3*D+1])>At||Math.abs(c[3*ot+2]-c[3*D+2])>.3||bt(c[3*D],c[3*D+1]))continue;let ut=(c[3*D]+c[3*ot])/2,Lt=(c[3*D+1]+c[3*ot+1])/2;C(c[3*K],c[3*K+1],ut,Lt,c[3*Q],c[3*Q+1])<Z&&(j===V?b[j]=[...B,B[0]]:(b[j]=[...B,...st],b.splice(V,1)),E=true);}}}for(let E=0;E<b.length;E++)for(let U=0;U<8;U++){let j=b[E],B=j.length>3&&j[0]===j[j.length-1],D=B?j.slice(0,-1):j.slice(),K=D.length;if(K<4)break;let V=B?[...D,...D,...D]:D,st=rt(V),ot=null;for(let jt=B?K:0;jt<(B?2*K:K);jt++){let $t=st[jt];if($t-at<0||$t+at>st[st.length-1])continue;let Ke=kt(V,st,$t-at),ln=kt(V,st,$t+at),Xe=V[jt];if(bt(c[3*Xe],c[3*Xe+1])||mt.some(An=>Math.hypot(c[3*Xe]-An.c[0],c[3*Xe+1]-An.c[1])<An.R+at+.5))continue;let Je=C(Ke.x,Ke.y,c[3*Xe],c[3*Xe+1],ln.x,ln.y);Je<Z&&(!ot||Je<ot.g)&&(ot={k:jt%K,g:Je});}if(!ot)break;let Q,it;if(B){let jt=Math.floor(K/2),$t=(ot.k-jt+K)%K;Q=[...D.slice($t),...D.slice(0,$t)],it=jt;}else Q=D,it=ot.k;let ut=rt(Q),Lt=Q[it],pt=c[3*Lt],Rt=c[3*Lt+1],Bt=c[3*Lt+2],dt=G/Math.tan(Math.max(.001,ot.g/2)),St=Math.min(ut[it],ut[ut.length-1]-ut[it])-.05;if(St<.3)break;dt=Math.min(dt,St);let Pt=kt(Q,ut,ut[it]-dt),ce=kt(Q,ut,ut[it]+dt);{let jt=kt(Q,ut,Math.max(0,ut[it]-Math.max(dt,2))),$t=kt(Q,ut,Math.min(ut[ut.length-1],ut[it]+Math.max(dt,2)));if(gt(jt.x,jt.y)===gt($t.x,$t.y)){mt.push({c:[pt,Rt],R:0,skip:true});continue}}let re=Pt.x-pt,Qt=Pt.y-Rt,He=ce.x-pt,qe=ce.y-Rt,rn=Math.hypot(re,Qt),pn=Math.hypot(He,qe);if(rn<.2||pn<.2)break;re/=rn,Qt/=rn,He/=pn,qe/=pn;let an=Math.acos(Math.max(-1,Math.min(1,re*He+Qt*qe)));if(!(an>.01&&an<Z+.3))break;let Be=Math.min(rn,pn),We=Be*Math.tan(an/2);if(We<.6){mt.push({c:[pt,Rt],R:0,skip:true});continue}let et=re+He,ft=Qt+qe,Et=Math.hypot(et,ft)||1;et/=Et,ft/=Et;let zt=pt+et*We/Math.sin(an/2),Ut=Rt+ft*We/Math.sin(an/2),Xt=[pt+re*Be,Rt+Qt*Be],ne=[pt+He*Be,Rt+qe*Be];if(S(zt,Ut,Bt)!==null||S(zt+et*(We+.8),Ut+ft*(We+.8),Bt)!==null){mt.push({c:[pt,Rt],R:0,skip:true});continue}let xe=Math.atan2(Xt[1]-Ut,Xt[0]-zt),Pe=Math.atan2(ne[1]-Ut,ne[0]-zt)-xe;for(;Pe>Math.PI;)Pe-=2*Math.PI;for(;Pe<-Math.PI;)Pe+=2*Math.PI;let je=Math.max(4,Math.ceil(Math.abs(Pe)/(Math.PI/16))),fe=[];for(let jt=0;jt<=je;jt++){let $t=xe+Pe*jt/je;fe.push([zt+We*Math.cos($t),Ut+We*Math.sin($t)]);}let Ce=(jt,$t,Ke)=>{let ln=c.length/3;return c.push(jt,$t,Ke),ln},jo=Pt.z,Co=ce.z,jn=(jo+Co)/2,fr=Q.slice(0,Pt.seg),hr=Q.slice(ce.seg),cn=[Ce(Pt.x,Pt.y,jo)];Math.hypot(Xt[0]-Pt.x,Xt[1]-Pt.y)>.01&&cn.push(Ce(Xt[0],Xt[1],jo));for(let jt=1;jt<fe.length-1;jt++)cn.push(Ce(fe[jt][0],fe[jt][1],jn));Math.hypot(ne[0]-ce.x,ne[1]-ce.y)>.01&&cn.push(Ce(ne[0],ne[1],Co)),cn.push(Ce(ce.x,ce.y,Co));let Uo=[...fr,...cn,...hr];if(b[E]=B?[...Uo,Uo[0]]:Uo,jn-ee>.5){let $t=[cn[0],...fr.slice().reverse()],Ke=[cn[cn.length-1],...hr],ln=rt($t),Xe=rt(Ke),Je=[],An=false;for(let vn=0;vn<=Math.min(ln[ln.length-1],Xe[Xe.length-1],150);vn+=1){let Ln=kt($t,ln,vn),Le=kt(Ke,Xe,vn);if(Math.hypot(Ln.x-Le.x,Ln.y-Le.y)>25)break;if(Je.push([Ln,Le]),Ln.z-ee<.3&&Le.z-ee<.3){An=true;break}}if(An&&Je.length>=3){let vn=[...Je.slice().reverse().map(([Le])=>[Le.x,Le.y]),...fe,...Je.map(([,Le])=>[Le.x,Le.y])],Ln=[[zt,Ut,jn-ee],...Je.map(([Le,Ho])=>[(Le.x+Ho.x)/2,(Le.y+Ho.y)/2,Math.max(0,(Le.z+Ho.z)/2-ee)])];wt.push({ring:vn,path:Ln});}}let ga=(jt,$t)=>S(jt,$t,Bt)!==null,Go=(jt,$t)=>{for(let Ke=0;Ke<6;Ke++){if(ga($t[0],$t[1]))return $t;$t=[(jt[0]+$t[0])/2,(jt[1]+$t[1])/2];}return jt},ur=Math.min(1.5,dt),Ze=Go([pt,Rt],[pt-et*ur,Rt-ft*ur]),ro=Go(Ze,[Ze[0]+ft*1.2,Ze[1]-et*1.2]),io=Go(Ze,[Ze[0]-ft*1.2,Ze[1]+et*1.2]),Yo=Math.hypot(ro[0]-Xt[0],ro[1]-Xt[1])<Math.hypot(io[0]-Xt[0],io[1]-Xt[1])?[ro,...fe,io]:[io,...fe,ro],ao=([jt,$t])=>S(jt,$t,jn)??jn;mt.push({b:[pt,Rt,Bt],q1:Xt,q2:ne,c:[zt,Ut],R:We,arc:fe,far:Ze,fan:Yo,arcZ:fe.map(ao),fanZ:Yo.map(ao),farZ:ao(Ze)});let dr=[Ze,...Yo];vt.push({pts:[...dr,dr[0]].map(jt=>[jt[0],jt[1],ao(jt)-ee-.03])});}let lt=4,xt=new Map,Yt=(E,U)=>Math.floor(E/lt)*1e7+Math.floor(U/lt),Ct=b.map(E=>{let U=[0];for(let j=0;j+1<E.length;j++){let B=E[j],D=E[j+1];U.push(U[j]+Math.hypot(c[3*D]-c[3*B],c[3*D+1]-c[3*B+1]));}return U});b.forEach((E,U)=>{for(let j=0;j+1<E.length;j++){let B=E[j],D=E[j+1],K=[c[3*B],c[3*B+1],c[3*D],c[3*D+1],U,j,c[3*B+2],c[3*D+2]],V=Math.max(1,Math.ceil(Math.hypot(K[2]-K[0],K[3]-K[1])/lt)),st=NaN;for(let ot=0;ot<=V;ot++){let Q=Yt(K[0]+(K[2]-K[0])*ot/V,K[1]+(K[3]-K[1])*ot/V);if(Q===st)continue;st=Q;let it=xt.get(Q);it?it.push(K):xt.set(Q,[K]);}}});let Vt=(E,U,j,B,D,K,V=null,st=null,ot=null)=>{let Q=Math.floor(E/lt),it=Math.floor(U/lt);for(let ut=it-1;ut<=it+1;ut++)for(let Lt=Q-1;Lt<=Q+1;Lt++)for(let pt of xt.get(Lt*1e7+ut)??[]){if(pt[4]===B){let Pt=Ct[B],ce=Pt[Pt.length-1],re=Math.abs(Pt[pt[5]]-Pt[D]);if(Math.min(re,ce-re)<=K)continue}let Rt=pt[2]-pt[0],Bt=pt[3]-pt[1],dt=Rt*Rt+Bt*Bt;if(V!==null&&dt>0){let Pt=Math.sqrt(dt);if(V*(-Bt/Pt)+st*(Rt/Pt)>-0.3)continue}let St=dt>0?Math.max(0,Math.min(1,((E-pt[0])*Rt+(U-pt[1])*Bt)/dt)):0;if(!(ot!==null&&Math.abs(pt[6]+(pt[7]-pt[6])*St-ot)>.5)&&Math.hypot(pt[0]+Rt*St-E,pt[1]+Bt*St-U)<j)return true}return false},Dt=(E,U)=>!kn.near(E,U).some(j=>Vn(j,E,U)),ht=(E,U)=>{let[j,B]=$(E,U);return [+j.toFixed(8),+B.toFixed(8)]},Ot=E=>E.every(U=>Math.abs(U[2]-E[0][2])<=.02)?{lift:+E[0][2].toFixed(2)}:{liftPath:E.map(([U,j,B])=>{let[D,K]=ht(U,j);return D+","+K+","+B.toFixed(2)}).join(";")},Zt=(E,U)=>{let j=1/0,B=0,D=Math.floor(E/ge),K=Math.floor(U/ge);for(let V=-1;V<=1;V++)for(let st=-1;st<=1;st++){let ot=en.get(D+st+","+(K+V));if(ot)for(let Q=0;Q<ot.length;Q+=4){let it=(E-ot[Q+1])**2+(U-ot[Q+2])**2;it<j&&(j=it,B=tt.chains[ot[Q]].level);}}return B},Wt=new Map;for(let[E,U]of Zn)U.profile.edges&&Wt.set(E,U);let Kt=(E,U)=>{let j=1/0,B=-1,D=Math.floor(E/ge),K=Math.floor(U/ge);for(let Rt=-1;Rt<=1;Rt++)for(let Bt=-1;Bt<=1;Bt++){let dt=en.get(D+Bt+","+(K+Rt));if(dt)for(let St=0;St<dt.length;St+=4){let Pt=(E-dt[St+1])**2+(U-dt[St+2])**2;Pt<j&&(j=Pt,B=dt[St]);}}let V=Wt.get(B);if(!V)return null;let st=le(V.base,E,U),ot=Ge(V.base,st.at);if(!ot)return null;let it=Math.cos(st.ang)*(U-ot.y)-Math.sin(st.ang)*(E-ot.x)>0===V.same?"left":"right",ut=V.profile.edges[it],pt=V.edgeRuns?.[it]?.find(Rt=>st.at>=Rt.a&&st.at<=Rt.b);return pt?{...ut,on:pt.style==="solid"&&!pt.temp}:ut},qt=[],Jt=[];b.forEach((E,U)=>{let j=E.length>3&&E[0]===E[E.length-1],B=j?E.slice(0,-1):E,D=[],K=[],V=[],st=[],ot=j?B.length:B.length-1;for(let et=0;et<ot;et++){let ft=B[et],Et=B[(et+1)%B.length],zt=c[3*ft],Ut=c[3*ft+1],Xt=c[3*ft+2],ne=c[3*Et],xe=c[3*Et+1],Pe=c[3*Et+2],je=Math.max(1,Math.ceil(Math.hypot(ne-zt,xe-Ut)/1));for(let fe=0;fe<je;fe++)D.push(zt+(ne-zt)*fe/je),K.push(Ut+(xe-Ut)*fe/je),V.push(Xt+(Pe-Xt)*fe/je),st.push(et);}if(!j){let et=B[B.length-1];D.push(c[3*et]),K.push(c[3*et+1]),V.push(c[3*et+2]),st.push(ot-1);}let Q=D.length;if(Q<2)return;let it=j?Q:Q-1,ut=new Float64Array(Q),Lt=new Float64Array(Q);for(let et=0;et<it;et++){let ft=(et+1)%Q,Et=D[ft]-D[et],zt=K[ft]-K[et],Ut=Math.hypot(Et,zt)||1;ut[et]=-zt/Ut,Lt[et]=Et/Ut;}j||(ut[Q-1]=ut[Q-2],Lt[Q-1]=Lt[Q-2]);let pt=(et,ft)=>{let Et=j?(et-1+Q)%Q:Math.max(0,et-1),zt=ut[Et]+ut[et],Ut=Lt[Et]+Lt[et],Xt=Math.hypot(zt,Ut);if(Xt<1e-6)zt=ut[et],Ut=Lt[et];else {zt/=Xt,Ut/=Xt;let ne=Math.max(zt*ut[et]+Ut*Lt[et],1/3);zt/=ne,Ut/=ne;}return [D[et]+zt*ft,K[et]+Ut*ft]},Rt=Zt(D[0],K[0]),Bt=(et,ft)=>{for(let Et=0;Et+1<ft.length;Et+=40){let zt=ft.slice(Et,Math.min(Et+40+1,ft.length));zt.length<2||a.push({type:"Feature",properties:{kind:et,layer:Rt,run:U,...Ot(zt)},geometry:{type:"LineString",coordinates:zt.map(([Ut,Xt])=>ht(Ut,Xt))}});}},dt=[];for(let et=0;et<Q;et++){let[ft,Et]=pt(et,Me/2);dt.push([ft,Et,V[et]-ee]);}if(j&&dt.push(dt[0]),!sn.size)Bt("kerb-joint",dt);else {let et=[];for(let ft=0;ft<dt.length;ft++)Jn(D[ft%Q],K[ft%Q])?(et.length>=2&&Bt("kerb-joint",et),et=[]):et.push(dt[ft]);et.length>=2&&Bt("kerb-joint",et);}let St=[],Pt=[];for(let et=0;et<Q;et++){let ft=V[et]-ee;St.push([D[et],K[et],ft]);let[Et,zt]=pt(et,Me);Pt.push([Et,zt,ft]);}j&&(St.push(St[0]),Pt.push(Pt[0]));let ce=(et,ft)=>{for(let Et=0;Et+1<et.length;Et+=40){let zt=Math.min(Et+40+1,et.length),Ut=et.slice(Et,zt),Xt=ft.slice(Et,zt);if(Ut.length<2)continue;let ne=Dn([...Ut,...Xt.slice().reverse()].flatMap(([xe,Pe])=>[xe,Pe]));ne.length<6||Jt.push({type:"Feature",properties:{kind:"kerb",layer:Rt,run:U,...Ot(Ut)},geometry:{type:"Polygon",coordinates:[It(ne)]}});}};if(!sn.size)ce(St,Pt);else {let et=[],ft=[];for(let Et=0;Et<St.length;Et++)Jn(D[Et%Q],K[Et%Q])?(et.length>=2&&ce(et,ft),et=[],ft=[]):(et.push(St[Et]),ft.push(Pt[Et]));et.length>=2&&ce(et,ft);}let re=Me+.3+.15/2,Qt=[],He=0,qe=false,rn=(et=false)=>{Qt.length>=2&&He>=4&&qt.push({pts:Qt,emit:ft=>Bt("mark-edge",ft),head:qe,tail:et}),Qt=[],He=0,qe=false;},pn=(et,ft,Et)=>[et,ft,(S(et,ft,Et)??Et)-ee],an=(et,ft)=>{let Et=0,zt=1;for(let Ut=0;Ut<6;Ut++){let Xt=(Et+zt)/2,ne=et.x+(ft.x-et.x)*Xt,xe=et.y+(ft.y-et.y)*Xt;Vt(ne,xe,re,U,st[ft.v],3,ut[ft.v],Lt[ft.v],ft.h)?zt=Xt:Et=Xt;}return pn(et.x+(ft.x-et.x)*Et,et.y+(ft.y-et.y)*Et,et.h+(ft.h-et.h)*Et)},Be=null,We=j?Q+1:Q;for(let et=0;et<We;et++){let ft=et%Q,Et=Wt.size?Kt(D[ft],K[ft]):null,zt=sn.size?Jn(D[ft],K[ft]):null,Ut=zt?(zt.k.on?zt.k.width:0)+(zt.k.verge==="gutter"?zt.k.vergeM:0):Me,Xt=Et?Ut+Et.offset+.15/2:zt?Ut+.3+.15/2:re,[ne,xe]=pt(ft,Xt),Pe=Dt(ne,xe)&&(!Et||Et.on),je=Pe&&Vt(ne,xe,Xt-.05,U,st[ft],3,ut[ft],Lt[ft],V[ft]),fe={x:ne,y:xe,v:ft,h:V[ft],tight:je,ok:Pe&&!je};if(fe.ok){!Qt.length&&Be?.tight&&(Qt.push(an(fe,Be)),qe=true);let Ce=pn(ne,xe,V[ft]);Qt.length&&(He+=Math.hypot(ne-Qt[Qt.length-1][0],xe-Qt[Qt.length-1][1])),Qt.push(Ce);}else if(Qt.length&&je&&Be?.ok){let Ce=an(Be,fe);He+=Math.hypot(Ce[0]-Qt[Qt.length-1][0],Ce[1]-Qt[Qt.length-1][1]),Qt.push(Ce),rn(true);}else rn();Be=fe;}rn();});let ve=1.5,pe=[];for(let E of qt)E.head&&pe.push({r:E,i:0}),E.tail&&pe.push({r:E,i:E.pts.length-1});let Te=[];for(let E=0;E<pe.length;E++)for(let U=E+1;U<pe.length;U++){let j=pe[E],B=pe[U];if(j.r===B.r)continue;let D=j.r.pts[j.i],K=B.r.pts[B.i],V=Math.hypot(D[0]-K[0],D[1]-K[1]);V<ve&&Math.abs(D[2]-K[2])<.3&&Te.push([V,j,B]);}Te.sort((E,U)=>E[0]-U[0]);let Ve=new Set;for(let[,E,U]of Te){if(Ve.has(E)||Ve.has(U))continue;Ve.add(E),Ve.add(U);let j=E.r.pts[E.i],B=U.r.pts[U.i],D=[(j[0]+B[0])/2,(j[1]+B[1])/2,(j[2]+B[2])/2];E.r.pts[E.i]=D,U.r.pts[U.i]=D.slice();}for(let E of qt)E.emit(E.pts);a.edgeGrid={grid:xt,CELL:lt},a.slits=N,a.topAt=S,a.kerbBands=Jt,a.noses=mt.filter(E=>!E.skip);let so=2500;a.raisedIslands=wt.map(({ring:E,path:U})=>({type:"Feature",properties:{kind:"island",liftPath:U.map(([j,B,D])=>{let[K,V]=ht(j,B);return K+","+V+","+D.toFixed(2)}).join(";")},geometry:{type:"Polygon",coordinates:[[...E,E[0]].map(([j,B])=>ht(j,B))]}}));for(let E of b){if(!(E.length>3&&E[0]===E[E.length-1]))continue;let U=0,j=0;for(let dt=0;dt+1<E.length;dt++){let St=E[dt],Pt=E[dt+1];U+=c[3*St]*c[3*Pt+1]-c[3*Pt]*c[3*St+1],j=Math.max(j,c[3*St+2]-ee);}if(U/=2,!(U<0&&-U>=4&&-U<=so&&j>.5))continue;let D=E.map(dt=>[c[3*dt],c[3*dt+1],Math.max(0,c[3*dt+2]-ee)]),K=0,V=0;for(let[dt,St]of D)K+=dt,V+=St;K/=D.length,V/=D.length;let st=0,ot=0,Q=0;for(let[dt,St]of D)st+=(dt-K)**2,ot+=(St-V)**2,Q+=(dt-K)*(St-V);let it=.5*Math.atan2(2*Q,st-ot),ut=Math.cos(it),Lt=Math.sin(it),pt=new Map;for(let[dt,St,Pt]of D){let ce=Math.round((dt-K)*ut+(St-V)*Lt),re=pt.get(ce)??{x:0,y:0,h:0,n:0};re.x+=dt,re.y+=St,re.h+=Pt,re.n++,pt.set(ce,re);}let Rt=[...pt.entries()].sort((dt,St)=>dt[0]-St[0]).map(([,dt])=>[dt.x/dt.n,dt.y/dt.n,dt.h/dt.n]),Bt=Rt.length>=2?{liftPath:Rt.map(([dt,St,Pt])=>{let[ce,re]=ht(dt,St);return ce+","+re+","+Pt.toFixed(2)}).join(";")}:Ot(D);a.raisedIslands.push({type:"Feature",properties:{kind:"island",...Bt},geometry:{type:"Polygon",coordinates:[D.map(([dt,St])=>ht(dt,St))]}});}return a.noseBeds=vt.map(({pts:E})=>({type:"Feature",properties:{kind:"roadway-fill",...Ot(E.map(([U,j,B])=>[U,j,Math.max(0,B)]))},geometry:{type:"Polygon",coordinates:[E.map(([U,j])=>ht(U,j))]}})),a},ea=(t,e,n,s)=>{let{positions:o,part:a,indices:r}=t,{grid:l,CELL:i}=e,f=new Map;for(let g of n)for(let w=0;w<g.length;w++){let p=g[w],S=g[(w+1)%g.length],L=Math.floor((p[0]+S[0])/2/i)*1e7+Math.floor((p[1]+S[1])/2/i),b=f.get(L),x=[p[0],p[1],S[0],S[1]];b?b.push(x):f.set(L,[x]);}let h=(g,w,p)=>{let S=Math.floor(g/i),L=Math.floor(w/i);for(let b=L-1;b<=L+1;b++)for(let x=S-1;x<=S+1;x++)for(let I of f.get(x*1e7+b)??[]){let R=I[2]-I[0],T=I[3]-I[1],k=R*R+T*T,m=k>0?Math.max(0,Math.min(1,((g-I[0])*R+(w-I[1])*T)/k)):0;if(Math.hypot(I[0]+R*m-g,I[1]+T*m-w)<p)return true}return false},c=(g,w,p)=>{let S=Math.floor(g/i),L=Math.floor(w/i);for(let b=L-1;b<=L+1;b++)for(let x=S-1;x<=S+1;x++)for(let I of l.get(x*1e7+b)??[]){let R=I[2]-I[0],T=I[3]-I[1],k=R*R+T*T,m=k>0?Math.max(0,Math.min(1,((g-I[0])*R+(w-I[1])*T)/k)):0;if(Math.hypot(I[0]+R*m-g,I[1]+T*m-w)<p)return true}return false},u=[],d=0;for(let g=0;g+2<r.length;g+=3){let w=r[g],p=r[g+1],S=r[g+2],L=a[w];if(L===1||L===3||L===4){let b=(o[3*w]+o[3*p]+o[3*S])/3,x=(o[3*w+1]+o[3*p+1]+o[3*S+1])/3;if(!c(b,x,Me+.15)||h(b,x,Me+.15)){d++;continue}let I=(o[3*w+2]+o[3*p+2]+o[3*S+2])/3-(L===3?Nn:0);if([[.6,0],[-0.6,0],[0,.6],[0,-0.6]].every(([T,k])=>{let m=s(b+T,x+k,I);return m!==null&&Math.abs(m-I)<.3})){d++;continue}}u.push(w,p,S);}return t.indices=Uint32Array.from(u),d},na=(t,e)=>{if(!e||!e.length)return;let{positions:n,part:s,indices:o}=t,a=(p,S,L,b,x,I)=>(L-p)*(I-S)-(b-S)*(x-p),r=(p,S,L,b,x,I)=>{let R=x-L,T=I-b,k=R*R+T*T,m=k>0?Math.max(0,Math.min(1,((p-L)*R+(S-b)*T)/k)):0;return Math.hypot(L+R*m-p,b+T*m-S)},l=(p,S,L)=>{let[b,x]=p.far,I=a(p.q1[0],p.q1[1],p.q2[0],p.q2[1],b,x),R=a(p.q1[0],p.q1[1],p.q2[0],p.q2[1],S,L);if(R*I<0&&Math.abs(R)/(Math.hypot(p.q2[0]-p.q1[0],p.q2[1]-p.q1[1])||1)>.02)return false;let T=a(b,x,p.q1[0],p.q1[1],S,L),k=a(p.q1[0],p.q1[1],p.q2[0],p.q2[1],S,L),m=a(p.q2[0],p.q2[1],b,x,S,L);if(T>=0&&k>=0&&m>=0||T<=0&&k<=0&&m<=0||Math.hypot(S-p.c[0],L-p.c[1])<p.R+Me+.5)return true;let[_,v]=p.b;return Math.min(r(S,L,b,x,p.q1[0],p.q1[1]),r(S,L,b,x,p.q2[0],p.q2[1]),r(S,L,_,v,p.q1[0],p.q1[1]),r(S,L,_,v,p.q2[0],p.q2[1]))<Me+.3},i=Array.from(n),f=Array.from(t.normals),h=Array.from(s),c=Array.from(t.height),u=(p,S,L,b,x,I,R,T)=>(i.push(p,S,L),f.push(b,x,I),h.push(R),c.push(T),h.length-1),d=(p,S,L)=>{let b=x=>{let I=p.b[0]-x[0],R=p.b[1]-x[1],T=Math.hypot(I,R)||1;return ((S-x[0])*I+(L-x[1])*R)/T};return Math.min(b(p.q1),b(p.q2))},g=(p,S,L)=>u(i[3*p]+(i[3*S]-i[3*p])*L,i[3*p+1]+(i[3*S+1]-i[3*p+1])*L,i[3*p+2]+(i[3*S+2]-i[3*p+2])*L,f[3*p],f[3*p+1],f[3*p+2],h[p],c[p]+(c[S]-c[p])*L),w=[];for(let p=0;p+2<o.length;p+=3){let S=o[p],L=o[p+1],b=o[p+2],x=s[S];if(x===1||x===3||x===4){let I=(n[3*S]+n[3*L]+n[3*b])/3,R=(n[3*S+1]+n[3*L+1]+n[3*b+1])/3,T=e.find(k=>Math.hypot(I-k.b[0],R-k.b[1])<60&&[S,L,b].some(m=>l(k,n[3*m],n[3*m+1])));if(T){let k=[S,L,b],m=k.map(z=>d(T,n[3*z],n[3*z+1])),v=m.map(z=>z<=0).filter(Boolean).length;if(v===0)continue;if(v<3){let z=[];for(let N=0;N<3;N++){let q=k[N],G=k[(N+1)%3],Z=m[N],at=m[(N+1)%3];Z<=0&&z.push(q),Z<=0!=at<=0&&z.push(g(q,G,Z/(Z-at)));}for(let N=1;N+1<z.length;N++)w.push(z[0],z[N],z[N+1]);continue}}}w.push(S,L,b);}for(let p of e){let S=u(p.far[0],p.far[1],p.farZ-.004,0,0,1,0,p.farZ-ee);for(let x=0;x+1<p.fan.length;x++){let I=p.fanZ[x],R=p.fanZ[x+1],T=u(p.fan[x][0],p.fan[x][1],I-.004,0,0,1,0,I-ee),k=u(p.fan[x+1][0],p.fan[x+1][1],R-.004,0,0,1,0,R-ee);a(p.far[0],p.far[1],p.fan[x][0],p.fan[x][1],p.fan[x+1][0],p.fan[x+1][1])>0?w.push(S,T,k):w.push(S,k,T);}let[L,b]=p.c;for(let x=0;x+1<p.arc.length;x++){let I=p.arc[x],R=p.arc[x+1],T=(p.arcZ[x]+p.arcZ[x+1])/2,k=T-ee,m=T+Nn,_=Math.max(0,T-ee-1.4),v=I[0]-L,z=I[1]-b,N=R[0]-L,q=R[1]-b,G=Math.hypot(v,z)||1,Z=Math.hypot(N,q)||1,at=v/G,mt=z/G,vt=N/Z,wt=q/Z,C=[I[0]+at*Me,I[1]+mt*Me],rt=[R[0]+vt*Me,R[1]+wt*Me],kt=a(I[0],I[1],R[0],R[1],rt[0],rt[1])>0;((bt,lt,xt,Yt)=>kt?w.push(bt,lt,xt,bt,xt,Yt):w.push(bt,xt,lt,bt,Yt,xt))(u(I[0],I[1],m,0,0,1,3,k),u(R[0],R[1],m,0,0,1,3,k),u(rt[0],rt[1],m,0,0,1,3,k),u(C[0],C[1],m,0,0,1,3,k));let gt=(bt,lt,xt,Yt,Ct,Vt,Dt,ht,Ot,Zt)=>{let Wt=u(bt,lt,Vt,Dt,ht,0,4,k),Kt=u(xt,Yt,Vt,Ot,Zt,0,4,k),qt=u(xt,Yt,Ct,Ot,Zt,0,4,k),Jt=u(bt,lt,Ct,Dt,ht,0,4,k),ve=xt-bt,Te=[Yt-lt,-ve];Te[0]*Dt+Te[1]*ht>=0?w.push(Wt,Jt,Kt,Kt,Jt,qt):w.push(Wt,Kt,Jt,Kt,qt,Jt);};gt(I[0],I[1],R[0],R[1],_,m,-at,-mt,-vt,-wt),gt(C[0],C[1],rt[0],rt[1],T,m,at,mt,vt,wt);}}Object.assign(t,{positions:Float64Array.from(i),normals:Float32Array.from(f),part:Uint8Array.from(h),height:Float32Array.from(c),indices:Uint32Array.from(w)});},oa=(t,e)=>{let n=[];for(let f of e){let h=0,c=0,u=0;for(let[d,g,w]of f)h+=d,c+=g,u+=w;h/=f.length,c/=f.length,u/=f.length;for(let d=0;d<f.length;d++)n.push(f[d],f[(d+1)%f.length],[h,c,u]);}if(!n.length)return;let s=t.positions.length/3,o=new Float64Array(t.positions.length+n.length*3);o.set(t.positions);let a=new Float32Array(t.normals.length+n.length*3);a.set(t.normals);let r=new Uint8Array(t.part.length+n.length);r.set(t.part);let l=new Float32Array(t.height.length+n.length);l.set(t.height);let i=new Uint32Array(t.indices.length+n.length);i.set(t.indices),n.forEach(([f,h,c],u)=>{let d=s+u;o[3*d]=f,o[3*d+1]=h,o[3*d+2]=c,a[3*d+2]=1,r[d]=0,l[d]=c-ee,i[t.indices.length+u]=d;}),Object.assign(t,{positions:o,normals:a,part:r,height:l,indices:i});},sa=(t,e)=>{let{positions:n,part:s,indices:o}=t,a=4,r=new Map;for(let c=0;c+2<o.length;c+=3){let u=s[o[c]];if(u!==0&&u!==3)continue;let d=[n[3*o[c]],n[3*o[c+1]],n[3*o[c+2]]],g=[n[3*o[c]+1],n[3*o[c+1]+1],n[3*o[c+2]+1]];for(let w=Math.floor(Math.min(...d)/a);w<=Math.floor(Math.max(...d)/a);w++)for(let p=Math.floor(Math.min(...g)/a);p<=Math.floor(Math.max(...g)/a);p++){let S=w*1e7+p,L=r.get(S);L?L.push(c):r.set(S,[c]);}}let l=(c,u,d,g,w=.05)=>{for(let p of r.get(Math.floor(c/a)*1e7+Math.floor(u/a))??[]){let S=o[p],L=o[p+1],b=o[p+2];if(s[S]!==d)continue;let x=n[3*S],I=n[3*S+1],R=n[3*L],T=n[3*L+1],k=n[3*b],m=n[3*b+1],_=(T-m)*(x-k)+(k-R)*(I-m);if(Math.abs(_)<1e-12)continue;let v=((T-m)*(c-k)+(k-R)*(u-m))/_,z=((m-I)*(c-k)+(x-k)*(u-m))/_,N=1-v-z;if(v<-1e-6||z<-1e-6||N<-1e-6)continue;let q=v*n[3*S+2]+z*n[3*L+2]+N*n[3*b+2];if(Math.abs(q-g)<w)return q}return null},i=(c,u,d,g)=>l(c,u,d,g)!==null,f=(c,u)=>{let[d,g]=$(c,u);return [+d.toFixed(8),+g.toFixed(8)]},h=[];for(let c of e){let u=c.properties.kind,d=u==="kerb-joint"?3:0,g=c.properties.liftPath?c.properties.liftPath.split(";").map(b=>+b.split(",")[2]):null,w=c.geometry.coordinates.map(([b,x],I)=>{let[R,T]=H([b,x]),k=g?g[I]:c.properties.lift??0;return [R,T,k]}),p=[],S=()=>{let b=0;for(let x=1;x<p.length;x++)b+=Math.hypot(p[x][0]-p[x-1][0],p[x][1]-p[x-1][1]);if(p.length>=2&&b>=1){let x=p.every(R=>Math.abs(R[2]-p[0][2])<=.02),I={kind:u,layer:c.properties.layer,run:c.properties.run};x?I.lift=+p[0][2].toFixed(2):I.liftPath=p.map(([R,T,k])=>{let[m,_]=f(R,T);return m+","+_+","+k.toFixed(2)}).join(";"),h.push({type:"Feature",properties:I,geometry:{type:"LineString",coordinates:p.map(([R,T])=>f(R,T))}});}p=[];},L=ee+(d===3?Nn:0);for(let b of w){if(!i(b[0],b[1],d,b[2]+L)){S();continue}let x=p[p.length-1];if(x){let I=(x[0]+b[0])/2,R=(x[1]+b[1])/2,T=(x[2]+b[2])/2,k=l(I,R,d,T+L,Math.abs(x[2]-b[2])<.3?.3:.05);k===null?S():Math.abs(k-T-L)>=.05&&p.push([I,R,k-L]);}p.push(b);}S();}return h},ir=3,ra=.03,ia=(t,e)=>{let{positions:n,part:s,indices:o}=t,a=4,r=new Map;for(let c=0;c+2<o.length;c+=3){if(s[o[c]]!==0)continue;let u=[n[3*o[c]],n[3*o[c+1]],n[3*o[c+2]]],d=[n[3*o[c]+1],n[3*o[c+1]+1],n[3*o[c+2]+1]];for(let g=Math.floor(Math.min(...u)/a);g<=Math.floor(Math.max(...u)/a);g++)for(let w=Math.floor(Math.min(...d)/a);w<=Math.floor(Math.max(...d)/a);w++){let p=g*1e7+w,S=r.get(p);S?S.push(c):r.set(p,[c]);}}let l=(c,u,d)=>{let g=null;for(let w of r.get(Math.floor(c/a)*1e7+Math.floor(u/a))??[]){let p=o[w],S=o[w+1],L=o[w+2],b=n[3*p],x=n[3*p+1],I=n[3*S],R=n[3*S+1],T=n[3*L],k=n[3*L+1],m=(R-k)*(b-T)+(T-I)*(x-k);if(Math.abs(m)<1e-12)continue;let _=((R-k)*(c-T)+(T-I)*(u-k))/m,v=((k-x)*(c-T)+(b-T)*(u-k))/m,z=1-_-v;if(_<-1e-6||v<-1e-6||z<-1e-6)continue;let N=_*n[3*p+2]+v*n[3*S+2]+z*n[3*L+2]-ee;Math.abs(N-d)>ir||(g===null||Math.abs(N-d)<Math.abs(g-d))&&(g=N);}return g},i=c=>{let u=c.properties.liftPath;if(!u){let g=c.properties.lift??0;return ()=>g}let d=[];for(let g of String(u).split("|"))for(let w of g.split(";")){let[p,S,L]=w.split(",").map(Number),[b,x]=H([p,S]);d.push([b,x,L]);}return (g,w)=>{let p=1/0,S=0;for(let[L,b,x]of d){let I=(L-g)**2+(b-w)**2;I<p&&(p=I,S=x);}return S}},f=2,h=(c,u)=>{let[d,g]=$(c,u);return [+d.toFixed(8),+g.toFixed(8)]};return e.map(c=>{let u=c.geometry,d=u.type==="LineString"?[u.coordinates]:u.type==="Polygon"?[u.coordinates[0]]:u.type==="MultiLineString"?u.coordinates:u.type==="MultiPolygon"?u.coordinates.map(I=>I[0]):null;if(!d)return c;let g=i(c),w=false,p=d.map(I=>{let R=[],T=I.map(H);for(let k=0;k<T.length;k++){let m=k===0?1:Math.max(1,Math.ceil(Math.hypot(T[k][0]-T[k-1][0],T[k][1]-T[k-1][1])/f));for(let _=k===0?0:1;_<=m;_++){let v=k===0?0:_/m,z=k===0?T[0][0]:T[k-1][0]+(T[k][0]-T[k-1][0])*v,N=k===0?T[0][1]:T[k-1][1]+(T[k][1]-T[k-1][1])*v,q=g(z,N),G=l(z,N,q);G!==null&&Math.abs(G-q)>.01&&(w=true),R.push([z,N,q,G]);}}return R});if(!w)return c;let{lift:S,liftPath:L,...b}=c.properties,x=p.map(I=>I.map(([R,T,k,m])=>{let[_,v]=h(R,T);return _+","+v+","+Math.max(0,m===null?k:m+ra).toFixed(2)}).join(";")).join("|");return {...c,properties:{...b,liftPath:x}}})},aa=.004,ca=new Set(["mark-arrow","mark-yield"]),ar=[243,241,223].map(t=>Math.min(1,t/255/(.6+.4*Math.sin(50*Math.PI/180)))),la=(t,e)=>{let{positions:n,part:s,indices:o}=t,a=4,r=new Map;for(let _=0;_+2<o.length;_+=3){if(s[o[_]]!==0)continue;let v=[n[3*o[_]],n[3*o[_+1]],n[3*o[_+2]]],z=[n[3*o[_]+1],n[3*o[_+1]+1],n[3*o[_+2]+1]];for(let N=Math.floor(Math.min(...v)/a);N<=Math.floor(Math.max(...v)/a);N++)for(let q=Math.floor(Math.min(...z)/a);q<=Math.floor(Math.max(...z)/a);q++){let G=N*1e7+q,Z=r.get(G);Z?Z.push(_):r.set(G,[_]);}}let l=_=>[o[_],o[_+1],o[_+2]].map(v=>[n[3*v],n[3*v+1],n[3*v+2]]),i=(_,v,z,N,q)=>{let G=(v[1]-z[1])*(_[0]-z[0])+(z[0]-v[0])*(_[1]-z[1]);if(Math.abs(G)<1e-12)return _[2];let Z=((v[1]-z[1])*(N-z[0])+(z[0]-v[0])*(q-z[1]))/G,at=((z[1]-_[1])*(N-z[0])+(_[0]-z[0])*(q-z[1]))/G;return Z*_[2]+at*v[2]+(1-Z-at)*z[2]},f=(_,v,z,N,q)=>{let G=(v[1]-z[1])*(_[0]-z[0])+(z[0]-v[0])*(_[1]-z[1]);if(Math.abs(G)<1e-12)return false;let Z=((v[1]-z[1])*(N-z[0])+(z[0]-v[0])*(q-z[1]))/G,at=((z[1]-_[1])*(N-z[0])+(_[0]-z[0])*(q-z[1]))/G;return Z>=-1e-6&&at>=-1e-6&&1-Z-at>=-1e-6},h=(_,v,z,N)=>{let q=(z[0]-v[0])*(N[1]-v[1])-(z[1]-v[1])*(N[0]-v[0])>0,G=_;for(let[Z,at]of [[v,z],[z,N],[N,v]]){let mt=wt=>{let C=(at[0]-Z[0])*(wt[1]-Z[1])-(at[1]-Z[1])*(wt[0]-Z[0]);return q?C:-C},vt=[];for(let wt=0;wt<G.length;wt++){let C=G[wt],rt=G[(wt+1)%G.length],kt=mt(C),At=mt(rt);if(kt>=0&&vt.push(C),kt>=0!=At>=0){let gt=kt/(kt-At);vt.push([C[0]+(rt[0]-C[0])*gt,C[1]+(rt[1]-C[1])*gt]);}}if(G=vt,G.length<3)return G}return G},c=_=>{let v=0;for(let z=0;z<_.length;z++){let N=_[z],q=_[(z+1)%_.length];v+=N[0]*q[1]-q[0]*N[1];}return v/2},u=(_,v,z)=>(v[0]-_[0])*(z[1]-_[1])-(v[1]-_[1])*(z[0]-_[0]),d=(_,v)=>Math.abs(_[0]-v[0])<=1e-9&&Math.abs(_[1]-v[1])<=1e-9,g=(_,v,z,N)=>!d(N,_)&&!d(N,v)&&!d(N,z)&&u(_,v,N)>=-1e-9&&u(v,z,N)>=-1e-9&&u(z,_,N)>=-1e-9,w=_=>{let v=[];for(let N of _){let q=v[v.length-1];(!q||Math.hypot(N[0]-q[0],N[1]-q[1])>1e-6)&&v.push(N);}for(;v.length>1&&Math.hypot(v[0][0]-v[v.length-1][0],v[0][1]-v[v.length-1][1])<=1e-6;)v.pop();c(v)<0&&v.reverse();for(let N=true;N&&v.length>3;){N=false;for(let q=0;q<v.length;q++){let G=v[(q+v.length-1)%v.length],Z=v[q],at=v[(q+1)%v.length];if(Math.abs(u(G,Z,at))<=1e-9*(Math.hypot(Z[0]-G[0],Z[1]-G[1])+Math.hypot(at[0]-Z[0],at[1]-Z[1])+1e-9)){v.splice(q,1),N=true;break}}}let z=[];for(;v.length>3;){let N=-1,q=-1/0;for(let G=0;G<v.length;G++){let Z=v[(G+v.length-1)%v.length],at=v[G],mt=v[(G+1)%v.length];if(!(u(Z,at,mt)<=0)&&!v.some(wt=>g(Z,at,mt,wt))){N=G;break}}if(N<0){for(let G=0;G<v.length;G++){let Z=u(v[(G+v.length-1)%v.length],v[G],v[(G+1)%v.length]);Z>q&&(q=Z,N=G);}if(N<0)break}z.push([v[(N+v.length-1)%v.length],v[N],v[(N+1)%v.length]]),v.splice(N,1);}return v.length===3&&z.push(v),z},p={pos:[],nrm:[],hgt:[],idx:[]},S=n.length/3,L=new Set;for(let _ of e){if(!ca.has(_.properties.kind)||_.geometry.type!=="Polygon")continue;let v=_.geometry.coordinates[0].map(H);if(v.length>1&&v[0][0]===v[v.length-1][0]&&v[0][1]===v[v.length-1][1]&&v.pop(),v.length<3)continue;let z=_.properties.liftPath,N=ee+(z?Math.min(...String(z).split(/[|;]/).map(wt=>+wt.split(",")[2])):_.properties.lift??0),q=v.reduce((wt,C)=>wt+C[0],0)/v.length,G=v.reduce((wt,C)=>wt+C[1],0)/v.length,Z=null;for(let wt of r.get(Math.floor(q/a)*1e7+Math.floor(G/a))??[]){let[C,rt,kt]=l(wt);if(!f(C,rt,kt,q,G))continue;let At=i(C,rt,kt,q,G);Math.abs(At-N)<=ir&&(Z===null||Math.abs(At-N)<Math.abs(Z-N))&&(Z=At);}if(Z===null)continue;let at=w(v),mt=at.reduce((wt,C)=>wt+Math.abs(c(C)),0);if(Math.abs(mt-Math.abs(c(v)))>.005*Math.abs(c(v))+1e-4)continue;let vt=false;for(let[wt,C,rt]of at){let kt=[wt[0],C[0],rt[0]],At=[wt[1],C[1],rt[1]],gt=new Set;for(let bt=Math.floor(Math.min(...kt)/a);bt<=Math.floor(Math.max(...kt)/a);bt++)for(let lt=Math.floor(Math.min(...At)/a);lt<=Math.floor(Math.max(...At)/a);lt++)for(let xt of r.get(bt*1e7+lt)??[]){if(gt.has(xt))continue;gt.add(xt);let[Yt,Ct,Vt]=l(xt),Dt=h([wt,C,rt],Yt,Ct,Vt);if(Dt.length<3)continue;let ht=Dt.reduce((Kt,qt)=>Kt+qt[0],0)/Dt.length,Ot=Dt.reduce((Kt,qt)=>Kt+qt[1],0)/Dt.length;if(Math.abs(i(Yt,Ct,Vt,ht,Ot)-Z)>1)continue;let Zt=o[xt],Wt=S+p.hgt.length;for(let[Kt,qt]of Dt){let Jt=i(Yt,Ct,Vt,Kt,qt);p.pos.push(Kt,qt,Jt+aa),p.nrm.push(t.normals[3*Zt],t.normals[3*Zt+1],t.normals[3*Zt+2]),p.hgt.push(Jt-ee);}for(let Kt=1;Kt+1<Dt.length;Kt++)p.idx.push(Wt,Wt+Kt,Wt+Kt+1);vt=true;}}vt&&L.add(_);}if(!p.idx.length)return L;let b=p.hgt.length,x=new Float64Array(n.length+p.pos.length);x.set(n),x.set(p.pos,n.length);let I=new Float32Array(t.normals.length+p.nrm.length);I.set(t.normals),I.set(p.nrm,t.normals.length);let R=new Uint8Array(s.length+b);R.set(s),R.fill(2,s.length);let T=new Float32Array(t.height.length+b);T.set(t.height),T.set(p.hgt,t.height.length);let k=new Uint32Array(o.length+p.idx.length);k.set(o),k.set(p.idx,o.length);let m=new Float32Array(10*(S+b));if(t.kerbPaint)m.set(t.kerbPaint);else for(let _=0;_<S;_++)m[10*_]=-1;for(let _=S;_<S+b;_++)m.set([...ar,...ar,0,0,0,0],10*_);return Object.assign(t,{positions:x,normals:I,part:R,height:T,indices:k,kerbPaint:m,paintStart:o.length}),L},fa=(t,e)=>{if(!sn.size)return;let{grid:n,CELL:s}=e,o=(x,I)=>{let R=null,T=Math.floor(x/s),k=Math.floor(I/s);for(let m=k-1;m<=k+1;m++)for(let _=T-1;_<=T+1;_++)for(let v of n.get(_*1e7+m)??[]){let z=v[2]-v[0],N=v[3]-v[1],q=z*z+N*N,G=q>0?Math.max(0,Math.min(1,((x-v[0])*z+(I-v[1])*N)/q)):0,Z=v[0]+z*G,at=v[1]+N*G,mt=Math.hypot(Z-x,at-I);(!R||mt<R[2])&&(R=[Z,at,mt]);}return R},a=t.positions,r=t.normals,l=t.part,i=t.height,f=t.indices,h=Array.from(a),c=Array.from(r),u=Array.from(l),d=Array.from(i),g=[],w=u.length,p=[],S=.5,L=(x,I)=>{let R=0,T=0,k=-1;for(let G=0;G<3;G++){let Z=x[G],at=x[(G+1)%3],mt=Math.hypot(Z[0]-at[0],Z[1]-at[1]);mt>k&&(k=mt,R=(at[0]-Z[0])/(mt||1),T=(at[1]-Z[1])/(mt||1));}if(k<=S){I.push(x);return}let m=G=>G[0]*R+G[1]*T,_=x.map(m),v=Math.min(..._),z=Math.max(..._),N=Math.ceil((z-v)/S),q=(G,Z,at)=>{let mt=[];for(let vt=0;vt<G.length;vt++){let wt=G[vt],C=G[(vt+1)%G.length],rt=(m(wt)-Z)*(at?1:-1),kt=(m(C)-Z)*(at?1:-1);if(rt>=0&&mt.push(wt),rt>=0!=kt>=0){let At=rt/(rt-kt);mt.push(wt.map((gt,bt)=>gt+(C[bt]-gt)*At));}}return mt};for(let G=0;G<N;G++){let Z=v+(z-v)*G/N,at=v+(z-v)*(G+1)/N,mt=q(q(x,Z,true),at,false);for(let vt=1;vt+1<mt.length;vt++)I.push([mt[0],mt[vt],mt[vt+1]]);}};for(let x=0;x+2<f.length;x+=3){let I=f[x],R=f[x+1],T=f[x+2],k=l[I];if(k!==1&&k!==3&&k!==4){p.push(I,R,T);continue}let m=(a[3*I]+a[3*R]+a[3*T])/3,_=(a[3*I+1]+a[3*R+1]+a[3*T+1])/3,v=Jn(m,_);if(!v){p.push(I,R,T);continue}let z=v.k;if(!z.on&&k!==1)continue;if(!z.on){for(let Z of [I,R,T]){let at=i[Z],mt=a[3*Z+2],vt=at+ee;mt>vt+.01&&(mt=vt);let wt=u.length;h.push(a[3*Z],a[3*Z+1],mt),c.push(r[3*I],r[3*I+1],r[3*I+2]),u.push(k),d.push(at),g.push(-1,0,0,0,0,0,0,0,0,0),p.push(wt);}continue}let N=[];L([I,R,T].map(Z=>[a[3*Z],a[3*Z+1],a[3*Z+2],i[Z]]),N);let q=v.kc.heightAt[v.side],G=z.on?[...z.color,...z.stripe??z.color]:null;for(let Z of N)for(let[at,mt,vt,wt]of Z){let C=at,rt=mt,kt=vt,At=le(v.kc.base,C,rt).at,gt=wt+ee;if(kt>gt+.01&&(kt=gt+(kt-gt)*q(At)/Nn),z.on&&k!==1){let lt=o(C,rt);if(lt&<[2]>.005){let xt=z.width/Me;C=lt[0]+(C-lt[0])*xt,rt=lt[1]+(rt-lt[1])*xt;}}let bt=u.length;h.push(C,rt,kt),c.push(r[3*I],r[3*I+1],r[3*I+2]),u.push(k),d.push(wt),G?g.push(...G,At,z.stripe?z.stripeM:0,z.joint,z.grain):g.push(-1,0,0,0,0,0,0,0,0,0),p.push(bt);}}let b=new Float32Array(u.length*10);for(let x=0;x<w;x++)b[10*x]=-1;b.set(g,w*10),Object.assign(t,{positions:Float64Array.from(h),normals:Float32Array.from(c),part:Uint8Array.from(u),height:Float32Array.from(d),indices:Uint32Array.from(p),kerbPaint:b});},ha=t=>{if(!Ue.length)return;let e=t.positions,n=t.normals,s=t.part,o=t.height,a=t.kerbPaint??null,r=t.indices,l=Array.from(e),i=Array.from(n),f=Array.from(s),h=Array.from(o),c=a?Array.from(a):null,u=[],d=(L,b,x,I,R,T,k,m,_)=>{let v=f.length;return l.push(L,b,x),i.push(I,R,T),f.push(k),h.push(m),c&&c.push(..._),v},g=L=>c?c.slice(10*L,10*L+10):null,w=new Map,p=(L,b,x)=>{let I=L<b?L+":"+b:b+":"+L,R=w.get(I);if(R!==void 0)return R;let T=(_,v,z)=>_[z*L+v]+(_[z*b+v]-_[z*L+v])*x,k=c?Array.from({length:10},(_,v)=>T(c,v,10)):null,m=d(T(l,0,3),T(l,1,3),T(l,2,3),i[3*L],i[3*L+1],i[3*L+2],f[L],h[L]+(h[b]-h[L])*x,k);return w.set(I,m),m},S=0;for(let L=0;L+2<r.length;L+=3){let b=[r[L],r[L+1],r[L+2]],x=null;for(let k of Ue)if(b.some(m=>{let _=_e(k,l[3*m],l[3*m+1]);return _.zone&&_.a>Ae})){x=k;break}if(!x){u.push(...b);continue}S++;let I=b.map(k=>_e(x,l[3*k],l[3*k+1]).a-Ae);if(I.every(k=>k>=0))continue;let R=[],T=[];for(let k=0;k<3;k++){let m=(k+1)%3;if(I[k]<=0&&R.push(b[k]),I[k]<=0!=I[m]<=0){let _=p(b[k],b[m],I[k]/(I[k]-I[m]));R.push(_),T.push(_);}}for(let k=1;k+1<R.length;k++)u.push(R[0],R[k],R[k+1]);if(s[b[0]]===3&&T.length===2){let[k,m]=T,_=z=>h[z]+ee;if(l[3*k+2]-_(k)<.01&&l[3*m+2]-_(m)<.01)continue;let v=[d(l[3*k],l[3*k+1],l[3*k+2],x.ux,x.uy,0,4,h[k],g(k)),d(l[3*m],l[3*m+1],l[3*m+2],x.ux,x.uy,0,4,h[m],g(m)),d(l[3*m],l[3*m+1],_(m),x.ux,x.uy,0,4,h[m],g(m)),d(l[3*k],l[3*k+1],_(k),x.ux,x.uy,0,4,h[k],g(k))];u.push(v[0],v[1],v[2],v[0],v[2],v[3],v[0],v[2],v[1],v[0],v[3],v[2]);}}S&&Object.assign(t,{positions:Float64Array.from(l),normals:Float32Array.from(i),part:Uint8Array.from(f),height:Float32Array.from(h),indices:Uint32Array.from(u),...c?{kerbPaint:Float32Array.from(c)}:{}});},ua=4,da=800,Do=t=>{let e=0;for(let n=0;n<t.length;n+=2){let s=(n+2)%t.length;e+=t[n]*t[s+1]-t[s]*t[n+1];}return e/2},cr=t=>{let e=[];for(let n=t.length-2;n>=0;n-=2)e.push(t[n],t[n+1]);return e},Dn=t=>{if(!Ue.length)return t;let e=t;for(let n of Ue){let s=e.length/2,o=[];for(let r=0;r<s;r++){let l=_e(n,e[2*r],e[2*r+1]);o.push(l.zone&&l.a>Ae);}if(!o.some(Boolean))continue;if(o.every(Boolean))return [];let a=[];for(let r=0;r<s;r++){let l=(r+1)%s,i=e[2*r],f=e[2*r+1],h=e[2*l],c=e[2*l+1];if(o[r]||a.push(i,f),o[r]!==o[l]){let u=_e(n,i,f).a,d=_e(n,h,c).a,g=(Ae-u)/(d-u);g>0&&g<1&&a.push(i+(h-i)*g,f+(c-f)*g);}}if(e=a,e.length<6)return []}return e},pa=t=>{let e=[];for(let n=0;n+2<t.length;n+=3){let s=Math.round(t[n+2]*100)/100,o=n>=3?Math.round(t[n-1]*100)/100:null,a=n+5<t.length?Math.round(t[n+5]*100)/100:null;if(o===s&&a===s&&n/3%10!==0)continue;let[r,l]=$(t[n],t[n+1]);e.push(`${+r.toFixed(8)},${+l.toFixed(8)},${s}`);}return e.length>=2?e.join(";"):null},ya=t=>{let e=[],n=[],s=[];if(!t||!t.outline)return {beds:e,islands:n,kerbs:s};let o=(a,r)=>{let l=a.length/2,i=[];for(let f=0;f<l;f++){let h=a[2*((f-1+l)%l)],c=a[2*((f-1+l)%l)+1],u=a[2*f],d=a[2*f+1],g=a[2*((f+1)%l)],w=a[2*((f+1)%l)+1],p=[-(d-c),u-h],S=[-(w-d),g-u],L=Math.hypot(p[0],p[1])||1,b=Math.hypot(S[0],S[1])||1,x=p[0]/L+S[0]/b,I=p[1]/L+S[1]/b,R=Math.hypot(x,I)||1;x/=R,I/=R;let T=Math.max(.5,x*(S[0]/b)+I*(S[1]/b));i.push(u+x*Me/T,d+I*Me/T);}Math.abs(Do(i))<.5||s.push({type:"Feature",properties:{kind:"kerb",lift:r},geometry:{type:"Polygon",coordinates:[It(a),It(cr(i))]}});};for(let a of t.outline){let r=Dn(a.outer);if(r.length<6)continue;let l=[];for(let i of a.holes??[]){let f=Math.abs(Do(i));if(f>=ua&&f<=da){let c=Do(i)<0?cr(i):i,u=Dn(c);if(u.length<6)continue;n.push({type:"Feature",properties:{kind:"island",lift:0},geometry:{type:"Polygon",coordinates:[It(u)]}}),o(u,0);continue}let h=Dn(i);h.length>=6&&l.push(It(h));}e.push({type:"Feature",properties:{kind:"roadway",lift:0},geometry:{type:"Polygon",coordinates:[It(r),...l]}});}for(let a of t.raised??[]){let r=Dn(a.outer);if(r.length<6)continue;let l=pa(a.profile),i=0;for(let f=2;f<a.profile.length;f+=3)i=Math.max(i,a.profile[f]);e.push({type:"Feature",properties:l?{kind:"roadway",liftPath:l}:{kind:"roadway",lift:+i.toFixed(2)},geometry:{type:"Polygon",coordinates:[It(r)]}});}return {beds:e,islands:n,kerbs:s}},Ee=[],to=[],eo=[],lr=[],Bn=null,Bo=null;if(A){let t=Ji();Bo=t;let e=ya(t);to=e.beds,eo=e.islands,Ee=ta(t),lr=[...e.kerbs,...Ee.kerbBands??[]],ea(t,Ee.edgeGrid,Ee.slits,Ee.topAt),oa(t,Ee.slits),na(t,Ee.noses),to=[...to,...Ee.noseBeds??[]],eo=[...eo,...Ee.raisedIslands??[]],fa(t,Ee.edgeGrid),ha(t),Ee=fo(sa(t,Ee));for(let o of la(t,[...Ro,...Fn,...ue]))o.properties.baked=true;let n=t.positions.length/3,s=new Float64Array(n*2);for(let o=0;o<n;o++){let[a,r]=$(t.positions[3*o],t.positions[3*o+1]);s[2*o]=a,s[2*o+1]=r;}Bn={lonlat:s,z:Float32Array.from({length:n},(o,a)=>t.positions[3*a+2]),normals:t.normals,part:t.part,height:t.height,indices:t.indices},t.kerbPaint&&(Bn.kerbPaint=t.kerbPaint),t.paintStart!==void 0&&(Bn.paintStart=t.paintStart);}let ma=A?[...bn.filter(t=>t.properties.kind!=="roadway"),...to,...eo,...lr]:bn,no=t=>Bo?ia(Bo,t):t,oo=[...ma,...Ee,...ii,...no(fo(Vi)),...no(Ro),...no(Fn),...no(fo(ue)),...ai];return No&&(oo.kerbMesh=No),Bn&&(oo.mesh=Bn,oo.meshNodes=wn.graph.nodes.filter(t=>t.crossing&&t.rays.length).map(t=>{let[e,n]=$(t.x,t.y);return [e,n,Math.max(...t.rays.map(s=>s.width))/2]})),oo}var co={top:[.247,.259,.275],side:[.604,.604,.588],bottom:[.45,.45,.44],kerbTop:[.847,.835,.804],kerbSide:[.765,.753,.722],island:[.725,.718,.69],grain:.06,liftTone:.3},Ko=new WeakMap;function xa(y,M,A){let P=Ko.get(y);P||Ko.set(y,P=new Map);let O=P.get(M);return O||P.set(M,O={program:A(),refs:0}),O.refs++,O.program}function wa(y,M){let A=Ko.get(y);if(A){for(let[P,O]of A)if(O.program===M){--O.refs<=0&&(y.deleteProgram(M),A.delete(P));return}}}function $o(y,M,A=null,P="road-mesh"){let{normals:O,part:F,height:W,indices:J,paintStart:H}=M,$=M.lonlat?M.lonlat.length/2:M.positions.length/3,Y=ct=>M.lonlat?[M.lonlat[2*ct],M.lonlat[2*ct+1]]:M.toDegrees(M.positions[3*ct],M.positions[3*ct+1]),Mt=ct=>M.lonlat?M.z[ct]:M.positions[3*ct+2],X=(ct,nt)=>[(ct+180)/360,(1-Math.log(Math.tan(Math.PI/4+nt*Math.PI/360))/Math.PI)/2],[_t,Ht]=Y(0),[Nt,ie]=X(_t,Ht),Ft=M.kerbPaint??null,Gt=Ft?20:10,te=new Float32Array($*Gt),Oe=M.lonlat;for(let ct=0,nt=0;ct<$;ct++,nt+=Gt){let Tt,yt;Oe?(Tt=(Oe[2*ct]+180)/360,yt=(1-Math.log(Math.tan(Math.PI/4+Oe[2*ct+1]*Math.PI/360))/Math.PI)/2):[Tt,yt]=X(...Y(ct));let tt=Tt-Nt,me=yt-ie,ae=Math.fround(tt),we=Math.fround(me);if(te[nt]=ae,te[nt+1]=we,te[nt+2]=Mt(ct),te[nt+3]=O[3*ct],te[nt+4]=-O[3*ct+1],te[nt+5]=O[3*ct+2],te[nt+6]=F[ct],te[nt+7]=W[ct],Ft)for(let It=0;It<10;It++)te[nt+8+It]=Ft[10*ct+It];te[nt+Gt-2]=tt-ae,te[nt+Gt-1]=me-we;}let Ie=150*Math.PI/180,ye=50*Math.PI/180,Se=[Math.sin(Ie)*Math.cos(ye),-Math.cos(Ie)*Math.cos(ye),Math.sin(ye)],he=null,Ne=null,Re=0,De=[],be=A??{top:[.263,.271,.294],side:[.796,.78,.741],bottom:[.557,.546,.519],kerbTop:[.984,.988,.996],kerbSide:[.84,.86,.89],island:[.86,.84,.78],grain:0,liftTone:.3},ze=ct=>"vec3("+ct.map(nt=>nt.toFixed(3)).join(", ")+")",Qe=40075016686e-3*Math.cos(Ht*Math.PI/180);return {id:P,type:"custom",renderingMode:"3d",onAdd(ct,nt){if(he)return;let Tt=(It,mn)=>{let tn=nt.createShader(It);if(nt.shaderSource(tn,mn),nt.compileShader(tn),!nt.getShaderParameter(tn,nt.COMPILE_STATUS))throw new Error(nt.getShaderInfoLog(tn));return tn},yt=["#version 300 es","layout(location=0) in vec3 a_pos;","layout(location=1) in vec3 a_normal;","layout(location=2) in float a_part;","layout(location=3) in float a_height;",...Ft?["layout(location=4) in vec3 a_ca;","layout(location=5) in vec3 a_cb;","layout(location=6) in vec4 a_kp;","out vec3 v_ca; out vec3 v_cb; out vec4 v_kp;"]:[],"layout(location=7) in vec2 a_lo;","uniform mat4 u_matrix; uniform vec2 u_camHi; uniform vec2 u_camLo; uniform float u_metres;","out vec3 v_normal; out float v_part; out float v_height; out vec2 v_m;","void main() {",...Ft?[" v_ca = a_ca; v_cb = a_cb; v_kp = a_kp;"]:[]," v_normal = a_normal; v_part = a_part; v_height = a_height; v_m = a_pos.xy * u_metres;"," vec2 p = (a_pos.xy - u_camHi) + (a_lo - u_camLo);"," gl_Position = u_matrix * vec4(p, a_pos.z, 1.0);","}"].join(`
|
|
2
|
+
`),tt=["#version 300 es","precision highp float;","in vec3 v_normal; in float v_part; in float v_height; in vec2 v_m;",...Ft?["in vec3 v_ca; in vec3 v_cb; in vec4 v_kp;"]:[],"uniform vec3 u_sun;","out vec4 color;","float hash(vec2 p) { return fract(sin(dot(p, vec2(127.1, 311.7))) * 43758.5453); }","void main() {"," vec3 n = normalize(v_normal);"," float light = 0.6 + 0.4 * max(dot(n, u_sun), 0.0);"," vec3 top = mix("+ze(be.top)+", vec3(1.0), clamp(v_height / 8.0, 0.0, 1.0) * "+be.liftTone.toFixed(2)+");"," top *= 1.0 + "+be.grain.toFixed(3)+" * (hash(floor(v_m / 0.06)) - 0.5) * 2.0;"," vec3 side = "+ze(be.side)+";"," vec3 kerbTop = "+ze(be.kerbTop)+";"," vec3 kerbSide = "+ze(be.kerbSide)+";"," vec3 island = "+ze(be.island)+";"," vec3 base = v_part < 0.5 ? top : v_part < 1.5 ? side : v_part < 2.5 ? "+ze(be.bottom)+" : v_part < 3.5 ? kerbTop : v_part < 4.5 ? kerbSide : island;",...Ft?[" if (v_ca.r >= 0.0) {"," float al = v_kp.x;"," vec3 k = (v_kp.y > 0.0 && mod(al, 2.0 * v_kp.y) >= v_kp.y) ? v_cb : v_ca;"," if (v_kp.z > 0.0 && fwidth(al) < 0.04) { float m = mod(al, v_kp.z); if (m < 0.02 || m > v_kp.z - 0.02) k *= 0.6; }"," k *= 1.0 + v_kp.w * (hash(floor(v_m / 0.04)) - 0.5) * 2.0;"," base = v_part > 3.5 || v_part < 1.5 ? k * 0.86 : k;"," }"]:[]," color = vec4(base * light, 1.0);","}"].join(`
|
|
3
|
+
`);he=xa(nt,yt+`
|
|
4
|
+
//--
|
|
5
|
+
`+tt,()=>{let It=nt.createProgram();if(nt.attachShader(It,Tt(nt.VERTEX_SHADER,yt)),nt.attachShader(It,Tt(nt.FRAGMENT_SHADER,tt)),nt.linkProgram(It),!nt.getProgramParameter(It,nt.LINK_STATUS))throw new Error(nt.getProgramInfoLog(It));return It}),Ne=nt.createVertexArray(),nt.bindVertexArray(Ne);let me=nt.createBuffer();De.push(me),nt.bindBuffer(nt.ARRAY_BUFFER,me),nt.bufferData(nt.ARRAY_BUFFER,te,nt.STATIC_DRAW);let ae=Gt*4;nt.enableVertexAttribArray(0),nt.vertexAttribPointer(0,3,nt.FLOAT,false,ae,0),nt.enableVertexAttribArray(1),nt.vertexAttribPointer(1,3,nt.FLOAT,false,ae,12),nt.enableVertexAttribArray(2),nt.vertexAttribPointer(2,1,nt.FLOAT,false,ae,24),nt.enableVertexAttribArray(3),nt.vertexAttribPointer(3,1,nt.FLOAT,false,ae,28),Ft&&(nt.enableVertexAttribArray(4),nt.vertexAttribPointer(4,3,nt.FLOAT,false,ae,32),nt.enableVertexAttribArray(5),nt.vertexAttribPointer(5,3,nt.FLOAT,false,ae,44),nt.enableVertexAttribArray(6),nt.vertexAttribPointer(6,4,nt.FLOAT,false,ae,56)),nt.enableVertexAttribArray(7),nt.vertexAttribPointer(7,2,nt.FLOAT,false,ae,(Gt-2)*4);let we=nt.createBuffer();De.push(we),nt.bindBuffer(nt.ELEMENT_ARRAY_BUFFER,we),nt.bufferData(nt.ELEMENT_ARRAY_BUFFER,J,nt.STATIC_DRAW),nt.bindVertexArray(null),Re=J.length;},onRemove(ct,nt){he&&wa(nt,he),Ne&&nt.deleteVertexArray(Ne);for(let Tt of De)nt.deleteBuffer(Tt);he=null,Ne=null;},render(ct){if(!he)return;ct.useProgram(he);let nt=y.getCenter(),[Tt,yt]=X(nt.lng,nt.lat),tt=Tt-Nt,me=yt-ie,ae=Math.fround(tt),we=Math.fround(me);ct.uniformMatrix4fv(ct.getUniformLocation(he,"u_matrix"),false,y.transform.objectMatrix(Tt,yt,0)),ct.uniform2f(ct.getUniformLocation(he,"u_camHi"),ae,we),ct.uniform2f(ct.getUniformLocation(he,"u_camLo"),tt-ae,me-we),ct.uniform3fv(ct.getUniformLocation(he,"u_sun"),Se),ct.uniform1f(ct.getUniformLocation(he,"u_metres"),Qe),ct.enable(ct.DEPTH_TEST),ct.depthFunc(ct.LEQUAL),ct.depthMask(true),ct.disable(ct.CULL_FACE),ct.disable(ct.BLEND),ct.enable(ct.POLYGON_OFFSET_FILL),ct.polygonOffset(4,256),ct.bindVertexArray(Ne);let It=H!==void 0?H:Re;ct.drawElements(ct.TRIANGLES,It,ct.UNSIGNED_INT,0),ct.disable(ct.POLYGON_OFFSET_FILL),It<Re&&ct.drawElements(ct.TRIANGLES,Re-It,ct.UNSIGNED_INT,It*4),ct.bindVertexArray(null);}}}var Aa=y=>y+7&-8;var Vo=y=>{let M={mesh:null,kerbMesh:null};if(!y||y.byteLength<24)return M;let A=y.byteOffset%8===0&&y instanceof Uint8Array?y.buffer.slice(y.byteOffset,y.byteOffset+y.byteLength):y instanceof ArrayBuffer?y:new Uint8Array(y).slice().buffer,P=new DataView(A);if(P.getUint32(0,true)===va)return _a(A);if(P.getUint32(0,true)!==827147340)return M;let O=P.getFloat64(4,true),F=P.getFloat64(12,true),W=P.getUint32(20,true),J=[],H=24;for(let $=0;$<W;$++){let Y=P.getUint32(H,true),Mt=P.getUint32(H+4,true),X=P.getUint32(H+8,true),_t=X&2?P.getUint32(H+12,true):void 0;if(H+=16,!Y){J.push(null);continue}let Ht=new Float32Array(A,H,2*Y);H+=8*Y;let Nt=new Float64Array(2*Y);for(let ye=0;ye<Y;ye++)Nt[2*ye]=Ht[2*ye]+O,Nt[2*ye+1]=Ht[2*ye+1]+F;let ie=new Float32Array(A,H,Y).slice();H+=4*Y;let Ft=new Float32Array(A,H,3*Y).slice();H+=12*Y;let Gt=new Float32Array(A,H,Y).slice();H+=4*Y;let te;X&1&&(te=new Float32Array(A,H,10*Y).slice(),H+=40*Y);let Oe=new Uint32Array(A,H,Mt).slice();H+=4*Mt;let Ie=new Uint8Array(A,H,Y).slice();H+=Y,H=Aa(H),J.push({lonlat:Nt,z:ie,normals:Ft,part:Ie,height:Gt,indices:Oe,...te?{kerbPaint:te}:{},..._t!==void 0?{paintStart:_t}:{}});}return {mesh:J[0]??null,kerbMesh:J[1]??null}};var va=843924556;var La=[0,1,-1,Math.fround(.9647977352142334)],Sa=y=>y+3&-4;var _a=y=>{let M=new DataView(y),A=M.getFloat64(4,true),P=M.getFloat64(12,true),O=M.getFloat64(20,true),F=M.getFloat64(28,true),W=M.getUint32(36,true),J=(O-A)/65535,H=(F-P)/65535,$=[],Y=40;for(let Mt=0;Mt<W;Mt++){let X=M.getUint32(Y,true),_t=M.getUint32(Y+4,true),Ht=M.getUint32(Y+8,true),Nt=Ht&2?M.getUint32(Y+12,true):void 0;if(Y+=16,!X){$.push(null);continue}let ie=Y,Ft=!!(Ht&4),Gt;Ft&&(Gt=new Uint32Array(y,Y,_t).slice(),Y+=4*_t);let te=new Uint16Array(y,Y,X);Y+=2*X;let Oe=new Uint16Array(y,Y,X);Y+=2*X;let Ie=new Int16Array(y,Y,X);Y+=2*X;let ye=new Int16Array(y,Y,X);Y+=2*X;let Se=new Float64Array(2*X),he=new Float32Array(X),Ne=new Float32Array(X),Re=0,De=0;for(let Tt=0;Tt<X;Tt++)Re=Re+te[Tt]&65535,De=De+Oe[Tt]&65535,Se[2*Tt]=Re===65535?O:A+Re*J,Se[2*Tt+1]=De===65535?F:P+De*H,he[Tt]=Ie[Tt]/1e3,Ne[Tt]=ye[Tt]/1e3;if(!Ft){let Tt=new Uint16Array(y,Y,_t);Y+=2*_t,Gt=new Uint32Array(_t);let yt=0;for(let tt=0;tt<_t;tt++)yt=yt+Tt[tt]&65535,Gt[tt]=yt;}let be=new Int8Array(y,Y,X);Y+=X;let ze=new Int8Array(y,Y,X);Y+=X;let Qe=new Float32Array(3*X);for(let Tt=0;Tt<X;Tt++){let yt=be[Tt]/127,tt=ze[Tt]/127,me=1-Math.abs(yt)-Math.abs(tt);if(me<0){let we=yt;yt=(1-Math.abs(tt))*(we>=0?1:-1),tt=(1-Math.abs(we))*(tt>=0?1:-1);}let ae=Math.hypot(yt,tt,me)||1;Qe[3*Tt]=yt/ae,Qe[3*Tt+1]=tt/ae,Qe[3*Tt+2]=me/ae;}let ct;if(Ht&1){let Tt=new Uint8Array(y,Y,10*X);Y+=10*X,ct=new Float32Array(10*X);for(let yt=0;yt<Tt.length;yt++)ct[yt]=La[Tt[yt]]??0;}let nt=new Uint8Array(y,Y,X).slice();Y+=X,Y=ie+Sa(Y-ie),$.push({lonlat:Se,z:he,normals:Qe,part:nt,height:Ne,indices:Gt,...ct?{kerbPaint:ct}:{},...Nt!==void 0?{paintStart:Nt}:{}});}return {mesh:$[0]??null,kerbMesh:$[1]??null}};var kr="pascal";var qo=y=>typeof y=="number"?y+.23:y;function Ea(y){let M={...y};typeof y.elevation=="number"&&(M.elevation=qo(y.elevation)),typeof y.base=="number"&&(M.base=qo(y.base));let A=y.paint;return A&&typeof A.elevation=="number"&&(M.paint={...A,elevation:qo(A.elevation)}),M}function Pa(y){let M=new Float32Array(y.z.length);for(let A=0;A<M.length;A++)M[A]=y.z[A]<=.001?y.z[A]:y.z[A]+.23;return {...y,z:M}}function xr(y,M){return y===kr?Ea(M):M}function wr(y,M){return y===kr?Pa(M):M}var Oa=(y,M)=>{if(!Array.isArray(M)||M.length<2)return 1/0;let A=Math.cos(y[1]*Math.PI/180)*111320,P=111320,O=y[0]*A,F=y[1]*P,W=1/0,J=M.length;for(let H=0;H<J;H++){let $=M[H],Y=M[(H+1)%J],Mt=$[0]*A-O,X=$[1]*P-F,_t=Y[0]*A-O,Ht=Y[1]*P-F,Nt=_t-Mt,ie=Ht-X,Ft=Nt*Nt+ie*ie,Gt=Ft>0?Math.max(0,Math.min(1,-(Mt*Nt+X*ie)/Ft)):0,te=Math.hypot(Mt+Nt*Gt,X+ie*Gt);te<W&&(W=te);}return W},Ar=(y,M)=>y===M||y==="both",Ia=(y,M)=>{if(y.kind!=="road"||!Array.isArray(y.points)||y.points.length<2)return null;let A=F=>Array.isArray(M)&&M.length>=3&&Oa(F,M)<=2,P=!y.closedStart&&(!!y.openStart||A(y.points[0])||Ar(y.openMap,"start")),O=!y.closedEnd&&(!!y.openEnd||A(y.points[y.points.length-1])||Ar(y.openMap,"end"));return P&&O?"both":P?"start":O?"end":null},Lr=y=>{let M=typeof y=="string"?y.split(",").map(W=>W.trim()):[],A=W=>M.includes(W),P={openStart:A("start")||A("both"),openEnd:A("end")||A("both")},O=A("-start")||A("none"),F=A("-end")||A("none");return {...P,...O?{closedStart:true}:{},...F?{closedEnd:true}:{}}};var vr=(y,M)=>y&&M?"both":y?"forward":M?"backward":null,Sr=(y,M,A)=>{let P=new Set(M??[]),O=(Y,Mt)=>P.has(`${Y}:${Mt}`)||(y??[]).some(X=>X.kind===Y&&(X.direction??"forward")===Mt),F=Y=>{let Mt=O(Y,"forward"),X=O(Y,"backward");return A&&(Mt||X)?"both":vr(Mt,X)},W={},J=F("stop-line"),H=F("crosswalk"),$=vr(O("lane-arrow","forward"),O("lane-arrow","backward"));return J&&(W.stopObjects=J),H&&(W.zebraObjects=H),$&&(W.arrowObjects=$),W},_r=(y,M={})=>{let A=y.present,P={kind:y.kind};if(y.kind==="road"||y.kind==="walkway"?((!A||A.cls)&&(P.cls=y.cls),(!A||A.width)&&(P.width=y.widthM),(A?A.lanes:y.lanes>0)&&(P.lanes=y.lanes),(A?A.oneway:y.oneway)&&(P.oneway=y.oneway),(!A||A.layer||y.level!==0)&&(P.layer=y.level)):(A?A.marked:y.marked)&&(P.marked=y.marked),y.name&&(P.name=y.name),y.kind==="road"&&y.profile&&(P.profile=JSON.parse(JSON.stringify(y.profile))),y.kind==="road"&&M.arrowObjects){let F=M.arrowObjects(y);F&&(P.arrowObjects=F);}if(y.kind==="road"&&M.stopObjects){let F=M.stopObjects(y);F&&(P.stopObjects=F);}if(y.kind==="road"&&M.zebraObjects){let F=M.zebraObjects(y);F&&(P.zebraObjects=F);}if(y.kind==="road"){let F=Ia(y,M.outline);F&&(P.open=F);}return y.kind==="road"&&(y.look==="asphalt"||y.look==="ribbon")&&(P.look=y.look),{type:"Feature",geometry:y.kind==="crossing-node"?{type:"Point",coordinates:[y.points[0][0],y.points[0][1]]}:{type:"LineString",coordinates:y.points.map(F=>[F[0],F[1]])},properties:P}},Ra=["stop-line","crosswalk","lane-arrow","yield-line","hatch","text"],za=y=>{let M=P=>Array.isArray(P?.lanes)?P.lanes.reduce((O,F)=>O+(F.widthM>0?F.widthM:3.5),0):0,A=M(y.backward);return M(y.forward)+(A>0?A+(y.median?.widthM>0?y.median.widthM:0):0)},Er=(y,M)=>{if(!y||!Ra.includes(y.kind))return null;let A=M?.points;if(!Array.isArray(A)||A.length<2)return null;let P=Math.cos(A[0][1]*Math.PI/180),O=[],F=0;for(let Nt=1;Nt<A.length;Nt++){let ie=Math.hypot((A[Nt][0]-A[Nt-1][0])*P,A[Nt][1]-A[Nt-1][1]);O.push(ie),F+=ie;}if(!(F>0))return null;let W=Math.min(1,Math.max(0,Number.isFinite(y.t)?y.t:0)),J=W*F,H=0;for(;H<O.length-1&&(O[H]===0||J>O[H]);)J-=O[H],H++;let $=A[H],Y=A[H+1],Mt=O[H]>0?Math.min(1,J/O[H]):0,X=[$[0]+(Y[0]-$[0])*Mt,$[1]+(Y[1]-$[1])*Mt],_t=Math.atan2(Y[1]-$[1],(Y[0]-$[0])*P)*180/Math.PI,Ht={kind:"ld-object",object:y.kind,key:y.key,t:W,heading:_t,offsetM:Number.isFinite(y.offsetM)?y.offsetM:0,headingDeg:Number.isFinite(y.headingDeg)?y.headingDeg:0,direction:y.direction==="backward"?"backward":"forward",params:JSON.parse(JSON.stringify(y.params??{})),hostWidth:M.profile?za(M.profile):M.widthM,hostOneway:M.profile?!M.profile.backward?.lanes?.length:!!M.oneway,hostCls:typeof M.cls=="string"?M.cls:""};return M.profile&&(Ht.profile=JSON.parse(JSON.stringify(M.profile))),{type:"Feature",geometry:{type:"Point",coordinates:X},properties:Ht}},Fa=["diag","chevron","grid","solid","none"],Ta=["white","yellow","red","green","blue","orange"],Pr=y=>{let M=Array.isArray(y?.outline)?y.outline.filter(J=>Array.isArray(J)&&J.length>=2):[];if(M.length<3)return null;let A=M.map(([J,H])=>[J,H]),P=A[0],O=A[A.length-1];(P[0]!==O[0]||P[1]!==O[1])&&A.push([P[0],P[1]]);let F=Number(y.stepM),W=Number(y.angleDeg);return {type:"Feature",geometry:{type:"Polygon",coordinates:[A]},properties:{kind:"ld-area",key:y.key??null,mark:typeof y.kind=="string"?y.kind:"island",pattern:Fa.includes(y.pattern)?y.pattern:"diag",stepM:Number.isFinite(F)&&F>0?F:2,angleDeg:Number.isFinite(W)?W:45,color:Ta.includes(y.color)?y.color:"white",outline:y.outlineOn!==false,dash:y.dashOutline===true,temp:y.temp===true,layer:Number.isFinite(y.level)?y.level:0}}};var Ir=(y,M)=>!(y[2]<M[0]||y[0]>M[2]||y[3]<M[1]||y[1]>M[3]);var Rr=(y,M,A)=>{let P=A.filter($=>Ir($.bbox,y));if(!P.length)return [];let O=2**M,F=$=>Math.min(O-1,Math.max(0,Math.floor(($+180)/360*O))),W=$=>{let Y=$*Math.PI/180;return Math.min(O-1,Math.max(0,Math.floor((1-Math.log(Math.tan(Y)+1/Math.cos(Y))/Math.PI)/2*O)))},J=[],H=new Set;for(let $ of P){let Y=[Math.max(y[0],$.bbox[0]),Math.max(y[1],$.bbox[1]),Math.min(y[2],$.bbox[2]),Math.min(y[3],$.bbox[3])];for(let Mt=F(Y[0]);Mt<=F(Y[2]);Mt++)for(let X=W(Y[3]);X<=W(Y[1]);X++){let _t=`${Mt}/${X}`;H.has(_t)||(H.add(_t),J.push([Mt,X]));}}return J},Na=y=>{let M=1/0,A=1/0,P=-1/0,O=-1/0;for(let[F,W]of y.points)F<M&&(M=F),F>P&&(P=F),W<A&&(A=W),W>O&&(O=W);return [M,A,P,O]},Da=(y,M,A)=>{let P=new Map;for(let J of y)!P.has(J.id)&&Ir(Na(J),M)&&P.set(J.id,J);let O=[...P.values()].sort((J,H)=>J.areaId-H.areaId||J.id-H.id);if(!O.length)return [];let W=A.find(J=>J.id===O[0].areaId)?.anchor??O.find(J=>J.kind==="road")??null;return W?[W,...O.filter(J=>J.id!==W.id)]:O},Or=y=>({kind:y.kind,points:y.points,widthM:y.widthM,lanes:y.lanes,oneway:y.oneway,level:y.level,cls:y.cls??"",marked:y.marked,name:y.name,...y.profile?{profile:y.profile}:{},...y.open?Lr(y.open):{},...y.closed==="start"||y.closed==="both"?{closedStart:true}:{},...y.closed==="end"||y.closed==="both"?{closedEnd:true}:{},...y.look==="asphalt"||y.look==="ribbon"?{look:y.look}:{},...typeof y.marksOff=="string"&&y.marksOff?{marksOff:y.marksOff.split(",").map(M=>M.trim()).filter(Boolean)}:{}}),Ba=(y,M,A,P,O=[])=>{let F=Da(y,A,P),W=new Map(F.map(X=>[X.id,Or(X)])),J=new Map(P.map(X=>[X.id,X.outline])),H=new Map;for(let X of M){let _t=H.get(X.wayId);_t?_t.some(Ht=>Ht.id===X.id)||_t.push(X):H.set(X.wayId,[X]);}let $=F.map(X=>{let _t=Or(X),Ht=_t.kind==="road"?Sr(H.get(X.id),_t.marksOff,_t.oneway):{};return _r(_t,{outline:J.get(X.areaId),stopObjects:()=>Ht.stopObjects??null,zebraObjects:()=>Ht.zebraObjects??null,arrowObjects:()=>Ht.arrowObjects??null})}),Y=new Set;for(let X of M){if(Y.has(X.id))continue;Y.add(X.id);let _t=W.get(X.wayId);if(!_t)continue;let Ht={key:`oid${X.id}`,kind:X.kind,t:X.t,offsetM:X.offsetM,headingDeg:X.headingDeg,direction:X.direction==="backward"?"backward":"forward",params:X.params??{}},Nt=Er(Ht,_t);Nt&&$.push(Nt);}let Mt=new Set;for(let X of O??[]){if(Mt.has(X.id))continue;Mt.add(X.id);let _t=Pr({key:`aid${X.id}`,kind:X.mark??X.kind,outline:X.outline??X.shape,level:X.level,pattern:X.pattern,stepM:X.stepM,angleDeg:X.angleDeg,color:X.color,outlineOn:X.outlineOn,dashOutline:X.dashOutline,temp:X.temp});_t&&$.push(_t);}return $},Sn=17,ja=17.5,zr=y=>{let M=String(y.id??""),A=/(^|-)mark-|kerb-joint/.test(M)?ja:Sn;return {...y,minzoom:Math.max(Number(y.minzoom??0),A)}},Ca=(y,M)=>{let A=[],P=new Set,[O,F,W,J]=M;for(let H of y)for(let $ of H?.restrictions??[]){if(!Array.isArray($?.via)||!Array.isArray($?.from)||!Array.isArray($?.to))continue;let[Y,Mt]=$.via;if(Y<O||Y>W||Mt<F||Mt>J)continue;let X=[...$.via,...$.from,...$.to,$.only?1:0].join(",");P.has(X)||(P.add(X),A.push({via:$.via,from:$.from,to:$.to,only:$.only===true}));}return A};var Ua="navi-gram-tj",Zo=(y=Ua)=>`/styles/${y}.json`,Ga="ld-roads",_n="ld-",Jo="ld",Nr="/tiles/ldroads/mvt/{z}/{x}/{y}.pbf",En=16;var Qo=`${_n}road-bed`,ts=`${_n}kerb`,Ya=`${_n}island`;var Dr=(y,M,{source:A=Ga,sourceLayer:P}={})=>y({variant:M}).layers.map(O=>zr({...xr(M,O),id:`${_n}${String(O.id)}`,source:A,...P?{"source-layer":P}:{}})),Ha=y=>Math.min(1,Math.max(0,y));var Wa=y=>{if(typeof y!="string")return null;let M=y.trim().toLowerCase(),A=/^#([0-9a-f]{3})$/.exec(M);return A?[...A[1]].map(P=>parseInt(P+P,16)/255):(A=/^#([0-9a-f]{6})(?:[0-9a-f]{2})?$/.exec(M),A?[0,2,4].map(P=>parseInt(A[1].slice(P,P+2),16)/255):(A=/^rgba?\(\s*([\d.]+)\s*[, ]\s*([\d.]+)\s*[, ]\s*([\d.]+)\s*(?:[,/]\s*[\d.]+%?\s*)?\)$/.exec(M),A?[A[1],A[2],A[3]].map(P=>Ha(Number(P)/255)):null))};var Fr=y=>y&&typeof y=="object"?JSON.parse(JSON.stringify(y)):y,Ka=y=>{let M=2166136261;for(let A=0;A<y.length;A++)M=Math.imul(M^y.charCodeAt(A),16777619)>>>0;return M.toString(16).padStart(8,"0")},Gn=y=>{if(!y||typeof y!="object"||y.version!==8||!Array.isArray(y.layers))return null;let M={};for(let P of y.layers){if(!P||typeof P.id!="string"||!P.id.startsWith(_n))continue;let O={type:String(P.type??""),paint:Fr(P.paint??{}),layout:Fr(P.layout??{})};typeof P.minzoom=="number"&&(O.minzoom=P.minzoom),typeof P.maxzoom=="number"&&(O.maxzoom=P.maxzoom),M[P.id]=O;}let A=Object.keys(M);return A.length?{layers:M,key:Ka(JSON.stringify(A.map(P=>[P,M[P]])))}:null},Tr=y=>!y||y.layout?.visibility!=="none",Br=(y,M)=>{let A={...M},P=y?.layers?.[Qo],O=y?.layers?.[ts],F=(W,J)=>{let H=Wa(J);H&&(A[W]=H);};return F("top",P?.paint?.["osmgl-surface-color"]),F("side",P?.paint?.["osmgl-surface-side-color"]),F("kerbTop",O?.paint?.["osmgl-surface-color"]),F("kerbSide",O?.paint?.["osmgl-surface-side-color"]),F("island",y?.layers?.[Ya]?.paint?.["osmgl-surface-color"]),{colors:A,asphalt:Tr(P),kerb:Tr(O),asphaltFrom:typeof P?.minzoom=="number"?P.minzoom:null,kerbFrom:typeof O?.minzoom=="number"?O.minzoom:null}},Xa=/(elevation|-base$|bevel|weld|deck|depth-test)/,$a=(y,M)=>JSON.stringify(y)===JSON.stringify(M),jr=(y,M,{geometry:A=true}={})=>{let P=[];if(!M)return P;for(let O of ["paint","layout"]){let F=M[O]??{},W=y?.[O]??{};for(let J of new Set([...Object.keys(W),...Object.keys(F)])){if(!A&&Xa.test(J))continue;let H=Object.prototype.hasOwnProperty.call(F,J)?F[J]:void 0;$a(H,W[J])||P.push({where:O,key:J,value:H});}}return P};function Cr(y,M,A){let P=2**A,O=new Map;for(let[W,J]of y)O.set(W,J.mesh);let F=W=>{let J=O.get(W);if(!J)return null;let H=M.get(J);if(!H){let[$,Y]=W.split("/").map(Number);H=ub([J],[Va($,Y,P)]),M.set(J,H);}return H};return (W,J,H)=>{let $=Math.floor((W+180)/360*P),Y=J*Math.PI/180,Mt=Math.floor((1-Math.log(Math.tan(Y)+1/Math.cos(Y))/Math.PI)/2*P),X=null;for(let _t=-1;_t<=1;_t++)for(let Ht=-1;Ht<=1;Ht++){let Nt=F(`${$+_t}/${Mt+Ht}`)?.(W,J,H);typeof Nt=="number"&&(X===null||(H!==void 0?Math.abs(Nt-H)<Math.abs(X-H):Nt>X))&&(X=Nt);}return X!==null?X:O.has(`${$}/${Mt}`)?null:void 0}}function Va(y,M,A){let P=F=>F/A*360-180,O=F=>Math.atan(Math.sinh(Math.PI*(1-2*F/A)))*180/Math.PI;return [P(y),O(M+1),P(y+1),O(M)]}var Ur=()=>({props:new Map,zoom:new Map}),Gr=(y,M)=>JSON.stringify(y)===JSON.stringify(M),qa=new Set([Qo,ts]);function Za(y,M,A){let P=[];for(let O of y){if(qa.has(O.id))continue;let F=M?.layers[O.id],W=new Map;for(let Mt of jr(O,F))W.set(Mt.key,{where:Mt.where,value:Mt.value});let J=A.props.get(O.id)??new Map;for(let[Mt,X]of W){let _t=J.get(Mt);(!_t||!Gr(_t.value,X.value))&&P.push({id:O.id,kind:X.where,key:Mt,value:X.value});}for(let[Mt,X]of J){if(W.has(Mt))continue;let _t=O[X.where]?.[Mt];P.push({id:O.id,kind:X.where,key:Mt,value:Mt==="visibility"&&_t===void 0?"visible":_t});}let H=typeof F?.minzoom=="number"?F.minzoom:O.minzoom,$=typeof F?.maxzoom=="number"?F.maxzoom:O.maxzoom,Y=A.zoom.get(O.id)??[O.minzoom,O.maxzoom];(Y[0]!==H||Y[1]!==$)&&P.push({id:O.id,kind:"zoom",minzoom:H,maxzoom:$});}return P}function Ja(y,M,A){let P=M.find(J=>J.id===A.id);if(A.kind==="zoom"){P&&P.minzoom===A.minzoom&&P.maxzoom===A.maxzoom?y.zoom.delete(A.id):y.zoom.set(A.id,[A.minzoom,A.maxzoom]);return}let O=y.props.get(A.id)??new Map,F=P?.[A.kind]?.[A.key];Gr(A.value,F)||A.key==="visibility"&&A.value==="visible"&&F===void 0?O.delete(A.key):O.set(A.key,{where:A.kind,value:A.value}),O.size?y.props.set(A.id,O):y.props.delete(A.id);}function Yr(y,M,A,P){let O=0;for(let F of Za(M,A,P))y.getLayer(F.id)&&(F.kind==="zoom"?y.setLayerZoomRange(F.id,F.minzoom,F.maxzoom):F.kind==="paint"?y.setPaintProperty(F.id,F.key,F.value):y.setLayoutProperty(F.id,F.key,F.value),Ja(P,M,F),O++);return O}async function Hr(y,M=fetch){try{let A=new AbortController,P=setTimeout(()=>A.abort(),8e3),O=await M(y,{cache:"no-cache",signal:A.signal}).finally(()=>clearTimeout(P));return O.status===404||O.status===410?null:O.ok?Gn(await O.json()):void 0}catch{return}}var yn="ld-roads",$r=14,Qa=6e4,tc=10*6e4,ec=/^ld-(graph-|water$|green$|buildings$)/,Wr=96,Kr=48,nc="ld-pascal-mesh",oc="ld-kerbs",sc="/tiles/ldroads/index",rc=(y,M,A)=>`/tiles/ldroads/${$r}/${y}/${M}?v=${encodeURIComponent(A)}`,ic=(y,M)=>`/tiles/ldroads/mesh/${En}/${y}/${M}.bin?f=2`,Vr=y=>({url:y.url(Nr),minzoom:En,maxzoom:En}),os=()=>Dr(Xo,"pascal",{source:yn,sourceLayer:Jo}).filter(y=>!ec.test(String(y.id)));function ac(){return os().map(y=>String(y.id))}function ss(y=De){let M={version:1,sources:{[yn]:Vr(y)},layers:os()};return fd(M).layers.filter(A=>A.id.startsWith("ld-"))}function qr(y){let A=y.filter(P=>!String(P.id).startsWith("ld-")).findIndex(P=>P.id==="roadarrow");return A>=0?A+1:Sa$1(y)}function cc(y,M=De){let A=y,P={...A.sources??{},[yn]:Vr(M)},O=qr(A.layers),F=A.layers.filter(W=>!String(W.id).startsWith("ld-"));return F.splice(O,0,...os()),{...y,sources:P,layers:F}}var Zr=/^\/(tileserver|tiles|traffic|objects3d)\//;function es(y,M){if(typeof y!="string")return y;let A=/^(?:https?:\/\/[^/]+)?(\/[^/].*)$/i.exec(y);return !A||!Zr.test(A[1])?y:/[?&]key=/.test(A[1])?M.base?M.base+A[1]:A[1]:M.url(A[1])}function Xr(y,M){for(let A of Object.values(y.sources??{}))if(A&&(Array.isArray(A.tiles)&&(A.tiles=A.tiles.map(P=>es(P,M))),A.url!==void 0&&(A.url=es(A.url,M)),A["osmgl-model-endpoint"]!==void 0)){let P=String(A["osmgl-model-endpoint"]).replace(/\/$/,""),O=/^(?:https?:\/\/[^/]+)?(\/[^/].*)$/i.exec(P);O&&Zr.test(O[1]+"/")&&(A["osmgl-model-endpoint"]=(M.base?M.base:"")+O[1]);}y.glyphs=es(y.glyphs,M);}async function lc(y,M,A){let P=M.base||(typeof location<"u"?location.href:"http://localhost/");await Promise.all(Object.values(y??{}).map(async O=>{if(!(!O||typeof O.url!="string"||Array.isArray(O.tiles)||/\{z\}/.test(O.url)))try{let F=await A(O.url);if(!F.ok)return;let W=await F.json();if(!Array.isArray(W.tiles)||!W.tiles.length)return;let J=new URL(O.url,P);O.tiles=W.tiles.map(H=>/^[a-z]+:\/\//i.test(H)?H:new URL(H,J).toString().replace(/%7B/gi,"{").replace(/%7D/gi,"}")),W.minzoom!==void 0&&(O.minzoom=W.minzoom),W.maxzoom!==void 0&&(O.maxzoom=W.maxzoom),delete O.url;}catch{}}));}async function fc(y,{endpoints:M=De,fetch:A=fetch}={}){let P=y;if(typeof P=="string"){let Y=await A(P,{cache:"no-cache"});if(!Y.ok)throw new Error(`[osmgl] стиль ${P}: HTTP ${Y.status}`);P=await Y.json();}let O=structuredClone(P);if(!Array.isArray(O.layers))throw new Error("[osmgl] не стиль: нет layers");Xr(O,M);let F=O.metadata?.["osmgl:version"]!==void 0;F&&(await lc(O.sources,M,A),Xr(O,M));let W=Gn(O),J=qr(O.layers),H=O.layers.filter(Y=>!String(Y.id).startsWith("ld-"));return H.splice(J,0,...ss(M)),O.layers=H,{style:F?wd(O).style:O,look:W}}var hc=y=>{let M=1/0,A=1/0,P=-1/0,O=-1/0;for(let[F,W]of y)F<M&&(M=F),F>P&&(P=F),W<A&&(A=W),W>O&&(O=W);return [M,A,P,O]};function uc(y,M={}){return new lo(y,M)}var lo=class{constructor(M,A={}){this.map=M;this.areas=[];this.version="";this.tiles=new Map;this.indexTimer=null;this.disposed=false;this.sceneListeners=new Set;this.surfaceListeners=new Set;this.surface=void 0;this.surfaceSig="";this.surfaceIndex=new WeakMap;this.last=null;this.lastSig="";this.offline=false;this.look=null;this.lookApplied=Ur();this.lookDefaults=null;this.lookMissingSince=0;this.seenSource=null;this.styleLook=null;this.meshTiles=new Map;this.meshLoading=new Set;this.meshFailures=new Map;this.meshRetry=null;this.meshWanted=[];this.meshLayers=new Map;this.meshTimer=null;this.onMove=()=>this.scheduleMesh();this.onIdle=()=>{if(this.disposed)return;let M=this.map.getSource(yn);M&&M!==this.seenSource&&(this.seenSource=M,this.applyLook());let A=[];try{A=this.map.querySourceFeatures(yn,{sourceLayer:Jo,filter:O=>typeof O.liftPath=="string"});}catch{return}let P=`${A.length}|${A.slice(0,8).map(O=>String(O.properties.liftPath).slice(0,24)).join(";")}`;if(P!==this.lastSig){this.lastSig=P,this.last=A.map(O=>({type:"Feature",properties:O.properties,geometry:null}));for(let O of this.sceneListeners)O();}};this.at=A.endpoints??De,this.lookUrl=A.lookUrl===null?null:A.lookUrl??this.at.url(Zo()),this.ready=new Promise(P=>{this.readyResolve=P;}),M.on("idle",this.onIdle),M.on("moveend",this.onMove),this.refreshIndex(),this.refreshLook(),this.indexTimer=setInterval(()=>{typeof document<"u"&&document.hidden||(this.refreshIndex(),(!this.lookMissingSince||Date.now()-this.lookMissingSince>tc)&&this.refreshLook());},Qa);}destroy(){this.disposed=true,this.map.off("idle",this.onIdle),this.map.off("moveend",this.onMove),this.indexTimer&&clearInterval(this.indexTimer),this.meshTimer&&clearTimeout(this.meshTimer),this.meshRetry&&clearTimeout(this.meshRetry),this.dropMeshes();}sceneFeatures(){return this.last}surfaceAt(){return this.surface===void 0&&(this.surface=this.meshTiles.size?Cr(this.meshTiles,this.surfaceIndex,En):null),this.surface}onSurface(M){return this.surfaceListeners.add(M),()=>this.surfaceListeners.delete(M)}onScene(M){return this.sceneListeners.add(M),()=>this.sceneListeners.delete(M)}async publicWays(M){if(await this.ready,this.offline||!this.areas.length)return [];let A=await Promise.all(Rr(M,$r,this.areas).map(([O,F])=>this.loadTile(O,F))),P=new Set;return A.flatMap(O=>O.ways).filter(O=>P.has(O.id)?false:(P.add(O.id),true))}state(){return {version:this.version,areas:this.areas.length,dataTiles:this.tiles.size,meshTiles:this.meshTiles.size,meshShown:this.meshWanted.length,features:this.last?.length??0,look:this.look?.key??null,styleLook:this.styleLook?.key??null,lookUrl:this.lookUrl,lookEdits:[...this.lookApplied.props.values()].reduce((M,A)=>M+A.size,0)+this.lookApplied.zoom.size}}setStyleLook(M){(M?.key??null)!==(this.styleLook?.key??null)&&(this.styleLook=M,this.applyLook());}async refreshLook(){if(!this.lookUrl)return;let M=await Hr(this.lookUrl);M===void 0||this.disposed||(this.lookMissingSince=M===null?Date.now():0,(M?.key??null)!==(this.look?.key??null)&&(this.look=M,this.applyLook()));}applyLook(){this.lookDefaults??(this.lookDefaults=ss(this.at)),Yr(this.map,this.lookDefaults,this.styleLook??this.look,this.lookApplied),this.showMeshes();}async refreshIndex(){try{let M=new AbortController,A=setTimeout(()=>M.abort(),8e3),P=await fetch(this.at.url(sc),{cache:"no-cache",signal:M.signal}).finally(()=>clearTimeout(A));if(!P.ok)throw new Error(`HTTP ${P.status}`);let O=await P.json();if(this.offline=!1,O.version===this.version)return;let F=this.version==="";this.version=O.version,this.areas=O.areas.map(W=>({id:W.id,name:W.name,outline:W.outline,anchor:W.anchor,bbox:W.bbox??hc(W.outline)})),this.tiles.clear(),F||this.map.refreshSource(yn),this.scheduleMesh(!F);}catch(M){this.version===""&&!this.offline&&(this.offline=true,console.warn("[osmgl] детальные дороги недоступны:",M));}finally{this.readyResolve();}}loadTile(M,A){let P=`${M}/${A}`,O=this.tiles.get(P);return O||(O=fetch(this.at.url(rc(M,A,this.version))).then(F=>F.ok?F.json():Promise.reject(new Error(`HTTP ${F.status}`))).then(F=>({ways:F.ways??[],objects:F.objects??[]})).catch(F=>(this.tiles.delete(P),console.warn("[osmgl] тайл данных детальных дорог",P,F),{ways:[],objects:[]})),this.tiles.set(P,O)),O}scheduleMesh(M=false){this.disposed||(this.meshTimer&&clearTimeout(this.meshTimer),this.meshTimer=setTimeout(()=>{this.meshTimer=null,this.loadMeshes(M);},150));}visibleMeshTiles(){if(this.offline||!this.areas.length||this.map.getZoom()<Sn-1)return [];let M=this.map.getBounds(),A=2**En,P=Ft=>Math.floor((Ft+180)/360*A),O=Ft=>{let Gt=Math.max(-85,Math.min(85,Ft))*Math.PI/180;return (1-Math.log(Math.tan(Gt)+1/Math.cos(Gt))/Math.PI)/2*A},F=Ft=>Ft/A*360-180,W=Ft=>Math.atan(Math.sinh(Math.PI*(1-2*Ft/A)))*180/Math.PI,J=this.map.getCenter(),H=(J.lng+180)/360*A,$=O(J.lat),Y=Kr,Mt=2,[X,_t,Ht,Nt]=[Math.max(Math.min(P(M.west),Math.floor(H)-Mt),Math.floor(H)-Y),Math.min(Math.max(P(M.east),Math.floor(H)+Mt),Math.floor(H)+Y),Math.max(Math.min(Math.floor(O(M.north)),Math.floor($)-Mt),Math.floor($)-Y),Math.min(Math.max(Math.floor(O(M.south)),Math.floor($)+Mt),Math.floor($)+Y)],ie=[];for(let Ft=X;Ft<=_t;Ft++)for(let Gt=Ht;Gt<=Nt;Gt++){let[te,Oe,Ie,ye]=[F(Ft),W(Gt+1),F(Ft+1),W(Gt)];this.areas.some(Se=>Se.bbox[0]<=Ie&&Se.bbox[2]>=te&&Se.bbox[1]<=ye&&Se.bbox[3]>=Oe)&&ie.push([Ft,Gt,(Ft+.5-H)**2+(Gt+.5-$)**2]);}return ie.sort((Ft,Gt)=>Ft[2]-Gt[2]).slice(0,Kr).map(([Ft,Gt])=>[Ft,Gt])}async loadMeshes(M){if(!this.offline&&this.areas.length&&this.map.getZoom()<Sn-1)return;let A=this.visibleMeshTiles();if(this.meshWanted=A.map(([P,O])=>`${P}/${O}`),this.showMeshes(),await Promise.all(A.map(async([P,O])=>{let F=`${P}/${O}`,W=this.meshTiles.get(F);if(!(W&&!M||this.meshLoading.has(F))){this.meshLoading.add(F);try{let J=await fetch(this.at.url(ic(P,O)),{cache:"no-cache"}),H=J.headers.get("etag");if(J.status===204||J.status===404)this.meshTiles.set(F,{etag:H,mesh:null,kerbMesh:null});else if(J.ok){if(W&&H&&W.etag===H)return;let{mesh:$,kerbMesh:Y}=Vo(new Uint8Array(await J.arrayBuffer()));this.meshTiles.set(F,{etag:H,mesh:$,kerbMesh:Y}),J.headers.get("x-ld-stale")&&setTimeout(()=>this.scheduleMesh(!0),5e3);}else {this.meshFailed(F);return}this.meshFailures.delete(F);}catch(J){console.warn("[osmgl] сетка детальных дорог",F,J),this.meshFailed(F);return}finally{this.meshLoading.delete(F);}this.showMeshes(),this.surfaceChanged();}})),this.meshTiles.size>Wr){let P=new Set(this.meshWanted);for(let O of [...this.meshTiles.keys()]){if(this.meshTiles.size<=Wr)break;P.has(O)||this.meshTiles.delete(O);}}}meshFailed(M){let A=(this.meshFailures.get(M)??0)+1;this.meshFailures.set(M,A),!(this.meshRetry||this.disposed)&&(this.meshRetry=setTimeout(()=>{this.meshRetry=null,this.scheduleMesh();},Math.min(600*2**(A-1),1e4)));}surfaceChanged(){let M=[...this.meshTiles].map(([A,P])=>`${A}:${P.etag}:${P.mesh?P.mesh.z.length:0}`).join(",");if(M!==this.surfaceSig){this.surfaceSig=M,this.surface=void 0;for(let A of this.surfaceListeners)A();}}showMeshes(){if(this.disposed)return;let M=Br(this.styleLook??this.look,co),A=M.colors,P=JSON.stringify([M.colors,M.asphaltFrom,M.kerbFrom]),O=new Map;for(let F of this.meshWanted){let W=this.meshTiles.get(F);if(!W)continue;let J=`${W.etag}|${P}`;M.asphalt&&W.mesh&&O.set(`${nc}:${F}`,{mesh:W.mesh,sig:J,from:M.asphaltFrom}),M.kerb&&W.kerbMesh&&O.set(`${oc}:${F}`,{mesh:W.kerbMesh,sig:J,from:M.kerbFrom});}for(let[F,W]of this.meshLayers)O.get(F)?.sig===W&&this.map.getLayer(F)||(ns(this.map,F,null),this.meshLayers.delete(F));for(let[F,W]of O)this.meshLayers.has(F)||(ns(this.map,F,W.mesh,A,W.from),this.meshLayers.set(F,W.sig));}dropMeshes(){for(let M of this.meshLayers.keys())ns(this.map,M,null);this.meshLayers.clear();}};function ns(y,M,A,P=co,O=null){if(y.getLayer(M)&&y.removeLayer(M),!A)return;let F=$o(y,wr("pascal",A),P,M),W=F.render,J=O??Sn;typeof W=="function"&&(F.render=function(...$){if(!(y.getZoom()<J))return W.apply(this,$)});let H="ld-walkway";y.addLayer(F,y.getLayer(H)?H:void 0);}
|
|
6
|
+
export{yn as LD_SOURCE,lo as LdRoadsLayer,co as PASCAL_MESH_COLORS,uc as attachLdRoads,ka as buildMarkings,Xo as cityStyle,Vo as decodeMeshTile,ss as ldDefaultsV2,ac as ldLayerIds,Gn as ldLookOf,fc as prepareThemeStyle,$o as roadMeshLayer,Ba as standInput,Ca as standRestrictions,cc as withLdRoadsLayers};//# sourceMappingURL=ld-roads.js.map
|
|
7
|
+
//# sourceMappingURL=ld-roads.js.map
|