clone

an offline map explorer where each world, from a game map to a city's open data, ships as one .atlas file

fix: stop decluttering text labels too

Dami committed 53a883b
Text-display categories are locations like any other, and zone titles name
regions that are on the map. Decluttering them dropped whichever ones
overlapped, which is the same silent loss that decluttering markers caused.
Nothing is decluttered now.
commit
53a883ba5d4f7f39213c366af9678e0dbfb92521
parent
89f45b016ec266935ba92661a932914a9d1352ce
author
Dami <dami.etoile@gmail.com>
2 files changed, +4 -7
Massets/app.js2+-
Mfrontend/app.js9+++------
M assets/app.js +1 -1
@@ -4,6 +4,6 @@
44 `,""),n.push(t,""),n}function Mm(n,t,e){return e%2===0&&(n+=t),n}var Ac=class{constructor(t,e,i,r,s){this.overlaps=i,this.pixelRatio=e,this.resolution=t,this.alignAndScaleFill_,this.instructions=r.instructions,this.coordinates=r.coordinates,this.coordinateCache_={},this.renderedTransform_=Lt(),this.hitDetectionInstructions=r.hitDetectionInstructions,this.pixelCoordinates_=null,this.viewRotation_=0,this.fillStates=r.fillStates||{},this.strokeStates=r.strokeStates||{},this.textStates=r.textStates||{},this.widths_={},this.labels_={},this.zIndexContext_=s?new _o:null}getZIndexContext(){return this.zIndexContext_}createLabel(t,e,i,r){let s=t+e+i+r;if(this.labels_[s])return this.labels_[s];let o=r?this.strokeStates[r]:null,a=i?this.fillStates[i]:null,l=this.textStates[e],h=this.pixelRatio,c=[l.scale[0]*h,l.scale[1]*h],u=l.justify?Ur[l.justify]:Lc(Array.isArray(t)?t[0]:t,l.textAlign||Ii),f=r&&o.lineWidth?o.lineWidth:0,g=Array.isArray(t)?t:String(t).split(`55 `).reduce(Am,[]),{width:p,height:_,widths:m,heights:x,lineWidths:E}=Ld(l,g),C=p+f,y=[],w=(C+2)*c[0],R=(_+f)*c[1],A={width:w<0?Math.floor(w):Math.ceil(w),height:R<0?Math.floor(R):Math.ceil(R),contextInstructions:y};(c[0]!=1||c[1]!=1)&&y.push("scale",c),r&&(y.push("strokeStyle",o.strokeStyle),y.push("lineWidth",f),y.push("lineCap",o.lineCap),y.push("lineJoin",o.lineJoin),y.push("miterLimit",o.miterLimit),y.push("setLineDash",[o.lineDash]),y.push("lineDashOffset",o.lineDashOffset)),i&&y.push("fillStyle",a.fillStyle),y.push("textBaseline","middle"),y.push("textAlign","center");let b=.5-u,S=u*C+b*f,T=[],z=[],G=0,F=0,B=0,lt=0,M;for(let X=0,O=g.length;X<O;X+=2){let $=g[X];if($===`66 `){F+=G,G=0,S=u*C+b*f,++lt;continue}let N=g[X+1]||l.font;N!==M&&(r&&T.push("font",N),i&&z.push("font",N),M=N),G=Math.max(G,x[B]);let tt=[$,S+b*m[B]+u*(m[B]-E[lt]),.5*(f+G)+F];S+=m[B],r&&T.push("strokeText",tt),i&&z.push("fillText",tt),++B}return Array.prototype.push.apply(y,T),Array.prototype.push.apply(y,z),this.labels_[s]=A,A}replayTextBackground_(t,e,i,r,s,o,a){t.beginPath(),t.moveTo.apply(t,e),t.lineTo.apply(t,i),t.lineTo.apply(t,r),t.lineTo.apply(t,s),t.lineTo.apply(t,e),o&&(this.alignAndScaleFill_=o[2],t.fillStyle=o[1],this.fill_(t)),a&&(this.setStrokeStyle_(t,a),t.stroke())}calculateImageOrLabelDimensions_(t,e,i,r,s,o,a,l,h,c,u,f,g,p,_,m){a*=f[0],l*=f[1];let x=i-a,E=r-l,C=s+h>t?t-h:s,y=o+c>e?e-c:o,w=p[3]+C*f[0]+p[1],R=p[0]+y*f[1]+p[2],A=x-p[3],b=E-p[0];(_||u!==0)&&(Li[0]=A,Ai[0]=A,Li[1]=b,ci[1]=b,ci[0]=A+w,hi[0]=ci[0],hi[1]=b+R,Ai[1]=hi[1]);let S;return u!==0?(S=kt(Lt(),i,r,1,1,u,-i,-r),dt(S,Li),dt(S,ci),dt(S,hi),dt(S,Ai),Jt(Math.min(Li[0],ci[0],hi[0],Ai[0]),Math.min(Li[1],ci[1],hi[1],Ai[1]),Math.max(Li[0],ci[0],hi[0],Ai[0]),Math.max(Li[1],ci[1],hi[1],Ai[1]),Kn)):Jt(Math.min(A,A+w),Math.min(b,b+R),Math.max(A,A+w),Math.max(b,b+R),Kn),g&&(x=Math.round(x),E=Math.round(E)),{drawImageX:x,drawImageY:E,drawImageW:C,drawImageH:y,originX:h,originY:c,declutterBox:{minX:Kn[0],minY:Kn[1],maxX:Kn[2],maxY:Kn[3],value:m},canvasTransform:S,scale:f}}replayImageOrLabel_(t,e,i,r,s,o,a){let l=!!(o||a),h=r.declutterBox,c=a?a[2]*r.scale[0]/2:0;return h.minX-c<=e[0]&&h.maxX+c>=0&&h.minY-c<=e[1]&&h.maxY+c>=0&&(l&&this.replayTextBackground_(t,Li,ci,hi,Ai,o,a),Ad(t,r.canvasTransform,s,i,r.originX,r.originY,r.drawImageW,r.drawImageH,r.drawImageX,r.drawImageY,r.scale)),!0}fill_(t){let e=this.alignAndScaleFill_;if(e){let i=dt(this.renderedTransform_,[0,0]),r=512*this.pixelRatio;t.save(),t.translate(i[0]%r,i[1]%r),e!==1&&t.scale(e,e)}t.fill(),e&&t.restore()}setStrokeStyle_(t,e){t.strokeStyle=e[1],e[1]&&(t.lineWidth=e[2],t.lineCap=e[3],t.lineJoin=e[4],t.miterLimit=e[5],t.lineDashOffset=e[7],t.setLineDash(e[6]))}drawLabelWithPointPlacement_(t,e,i,r){let s=this.textStates[e],o=this.createLabel(t,e,r,i),a=this.strokeStates[i],l=this.pixelRatio,h=Lc(Array.isArray(t)?t[0]:t,s.textAlign||Ii),c=Ur[s.textBaseline||rn],u=a&&a.lineWidth?a.lineWidth:0,f=o.width/l-2*s.scale[0],g=h*f+2*(.5-h)*u,p=c*o.height/l+2*(.5-c)*u;return{label:o,anchorX:g,anchorY:p}}execute_(t,e,i,r,s,o,a,l){let h=this.zIndexContext_,c;this.pixelCoordinates_&&zt(i,this.renderedTransform_)?c=this.pixelCoordinates_:(this.pixelCoordinates_||(this.pixelCoordinates_=[]),c=Vt(this.coordinates,0,this.coordinates.length,2,i,this.pixelCoordinates_),du(this.renderedTransform_,i));let u=0,f=r.length,g=0,p,_=[],m,x,E,C,y,w,R,A,b,S,T,z,G,F=0,B=0,lt=this.coordinateCache_,M=this.viewRotation_,X=Math.round(Math.atan2(-i[1],i[0])*1e12)/1e12,O={context:t,pixelRatio:this.pixelRatio,resolution:this.resolution,rotation:M},$=this.instructions!=r||this.overlaps?0:200,N,tt,it,wt;for(;u<f;){let L=r[u];switch(L[0]){case D.BEGIN_GEOMETRY:N=L[1],wt=L[3],N.getGeometry()?a!==void 0&&!ht(a,wt.getExtent())?u=L[2]+1:++u:u=L[2],h&&(h.zIndex=L[4]);break;case D.BEGIN_PATH:F>$&&(this.fill_(t),F=0),B>$&&(t.stroke(),B=0),!F&&!B&&(t.beginPath(),y=NaN,w=NaN),++u;break;case D.CIRCLE:g=L[1],E=L[2]??0;let Ct=c[g],ot=c[g+1],Re=c[g+2]-E,Fi=c[g+3]-E,ne=Re-Ct,qn=Fi-ot,Hr=Math.sqrt(ne*ne+qn*qn);t.moveTo(Ct+Hr,ot),t.arc(Ct,ot,Hr,0,2*Math.PI,!0),++u;break;case D.CLOSE_PATH:t.closePath(),++u;break;case D.CUSTOM:g=L[1],p=L[2];let zi=L[3],Ni=L[4],un=L[5];O.geometry=zi,O.feature=N,u in lt||(lt[u]=[]);let Ze=lt[u];un?un(c,g,p,2,Ze):(Ze[0]=c[g],Ze[1]=c[g+1],Ze.length=2),h&&(h.zIndex=L[6]),Ni(Ze,O),++u;break;case D.DRAW_IMAGE:g=L[1],p=L[2],b=L[3],m=L[4],x=L[5];let dn=L[6],$n=L[7],Jn=L[8],qr=L[9],ui=L[10],Qn=L[11],pg=L[12],$r=L[13];C=L[14]||"declutter";let tr=L[15];if(!b&&L.length>=20){S=L[19],T=L[20],z=L[21],G=L[22];let vt=this.drawLabelWithPointPlacement_(S,T,z,G);b=vt.label,L[3]=b;let Se=L[23];m=(vt.anchorX-Se)*this.pixelRatio,L[4]=m;let re=L[24];x=(vt.anchorY-re)*this.pixelRatio,L[5]=x,dn=b.height,L[6]=dn,$r=b.width,L[13]=$r}let Fo;L.length>25&&(Fo=L[25]);let zo,Jr,Qr;L.length>17?(zo=L[16],Jr=L[17],Qr=L[18]):(zo=ni,Jr=null,Qr=null),ui&&X?Qn+=M:!ui&&!X&&(Qn-=M);let mg=0;for(;g<p;g+=2){if(Fo&&Fo[mg++]<$r/this.pixelRatio)continue;let vt=this.calculateImageOrLabelDimensions_(b.width,b.height,c[g],c[g+1],$r,dn,m,x,Jn,qr,Qn,pg,s,zo,!!Jr||!!Qr,N),Se=[t,e,b,vt,$n,Jr,Qr];if(l){let re,Te,se;if(tr){let gt=p-g;if(!tr[gt]){tr[gt]={args:Se,declutterMode:C};continue}let Ut=tr[gt];re=Ut.args,Te=Ut.declutterMode,delete tr[gt],se=yf(re)}let Be,Ve;if(re&&(Te!=="declutter"||!l.collides(se))&&(Be=!0),(C!=="declutter"||!l.collides(vt.declutterBox))&&(Ve=!0),Te==="declutter"&&C==="declutter"){let gt=Be&&Ve;Be=gt,Ve=gt}Be&&(Te!=="none"&&l.insert(se),this.replayImageOrLabel_.apply(this,re)),Ve&&(C!=="none"&&l.insert(vt.declutterBox),this.replayImageOrLabel_.apply(this,Se))}else this.replayImageOrLabel_.apply(this,Se)}++u;break;case D.DRAW_CHARS:let hh=L[1],uh=L[2],No=L[3],_g=L[4];G=L[5];let xg=L[6],dh=L[7],fh=L[8];z=L[9];let Go=L[10];S=L[11],Array.isArray(S)&&(S=S.reduce(Mm,"")),T=L[12];let gh=[L[13],L[13]];C=L[14]||"declutter";let yg=L[15],ph=L[16],Xo=this.textStates[T],er=Xo.font,ir=[Xo.scale[0]*dh,Xo.scale[1]*dh],nr;er in this.widths_?nr=this.widths_[er]:(nr={},this.widths_[er]=nr);let mh=_f(c,hh,uh,2),_h=Math.abs(ir[0])*Pl(er,S,nr);if(_g||_h<=mh){let vt=this.textStates[T].textAlign,Se=(mh-_h)*Lc(S,vt),re=xf(c,hh,uh,2,S,Se,xg,Math.abs(ir[0]),Pl,er,nr,X?0:this.viewRotation_,yg);t:if(re){let Te=[],se,Be,Ve,gt,Ut;if(z)for(se=0,Be=re.length;se<Be;++se){Ut=re[se],Ve=Ut[4],gt=this.createLabel(Ve,T,"",z),m=Ut[2]+(ir[0]<0?-Go:Go)-ph,x=No*gt.height+(.5-No)*2*Go*ir[1]/ir[0]-fh;let je=this.calculateImageOrLabelDimensions_(gt.width,gt.height,Ut[0],Ut[1],gt.width,gt.height,m,x,0,0,Ut[3],gh,!1,ni,!1,N);if(l&&C==="declutter"&&l.collides(je.declutterBox))break t;Te.push([t,e,gt,je,1,null,null])}if(G)for(se=0,Be=re.length;se<Be;++se){Ut=re[se],Ve=Ut[4],gt=this.createLabel(Ve,T,G,""),m=Ut[2]-ph,x=No*gt.height-fh;let je=this.calculateImageOrLabelDimensions_(gt.width,gt.height,Ut[0],Ut[1],gt.width,gt.height,m,x,0,0,Ut[3],gh,!1,ni,!1,N);if(l&&C==="declutter"&&l.collides(je.declutterBox))break t;Te.push([t,e,gt,je,1,null,null])}l&&C!=="none"&&l.load(Te.map(yf));for(let je=0,Eg=Te.length;je<Eg;++je)this.replayImageOrLabel_.apply(this,Te[je])}}++u;break;case D.END_GEOMETRY:if(o!==void 0){N=L[1];let vt=o(N,wt,C);if(vt)return vt}++u;break;case D.FILL:$?F++:this.fill_(t),++u;break;case D.MOVE_TO_LINE_TO:g=L[1],p=L[2],E=L[3];let Gi,rr,ts;if(E){let Se=(L[4]??!1)||Math.abs(c[g]-c[p-2])<1e-6&&Math.abs(c[g+1]-c[p-1])<1e-6;Eo(c,g,p,2,E,Se,_),wo(_,2,Se),Gi=_,rr=0,ts=Gi.length}else Gi=c,rr=g,ts=p;tt=Gi[rr],it=Gi[rr+1],t.moveTo(tt,it),y=tt+.5|0,w=it+.5|0;for(let vt=rr+2;vt<ts;vt+=2)tt=Gi[vt],it=Gi[vt+1],R=tt+.5|0,A=it+.5|0,(vt==ts-2||R!==y||A!==w)&&(t.lineTo(tt,it),y=R,w=A);++u;break;case D.SET_FILL_STYLE:this.alignAndScaleFill_=L[2],F?(this.fill_(t),F=0,B&&(t.stroke(),B=0)):B&&L[1]&&(t.stroke(),B=0),t.fillStyle=L[1],++u;break;case D.SET_STROKE_STYLE:F&&L[1]&&(this.fill_(t),F=0),B&&(t.stroke(),B=0),this.setStrokeStyle_(t,L),++u;break;case D.STROKE:$?B++:t.stroke(),++u;break;default:++u;break}}F&&this.fill_(t),B&&t.stroke()}execute(t,e,i,r,s,o){this.viewRotation_=r,this.execute_(t,e,i,this.instructions,s,void 0,void 0,o)}executeHitDetection(t,e,i,r,s){return this.viewRotation_=i,this.execute_(t,[t.canvas.width,t.canvas.height],e,this.hitDetectionInstructions,!0,r,s)}},wf=Ac;var Mi=["Polygon","Circle","LineString","Image","Text","Default"],Oc=["Image","Text"],Cf=Mi.filter(n=>!Oc.includes(n)),vf=!1,bf=!1;function Pm(){let n=0,t=i=>{let r=nt(1,1,null,{willReadFrequently:i}),s=0,o=performance.now();for(;performance.now()-o<50;++s)r.fillStyle=`rgba(255,0,${s%256},1)`,r.fillRect(0,0,1,1),r.getImageData(0,0,1,1);return n=s>n?s:n,s};vf={[t(!0)]:!0,[t(!1)]:!1,[t(void 0)]:void 0}[n],bf=!0}var Pc=class{constructor(t,e,i,r,s,o,a){this.maxExtent_=t,this.overlaps_=r,this.pixelRatio_=i,this.resolution_=e,this.renderBuffer_=o,this.executorsByZIndex_={},this.hitDetectionContext_=null,this.hitDetectionTransform_=Lt(),this.renderedContext_=null,this.deferredZIndexContexts_={},this.createExecutors_(s,a)}clip(t,e){let i=this.getClipCoords(e);t.beginPath(),t.moveTo(i[0],i[1]),t.lineTo(i[2],i[3]),t.lineTo(i[4],i[5]),t.lineTo(i[6],i[7]),t.clip()}createExecutors_(t,e){for(let i in t){let r=this.executorsByZIndex_[i];r===void 0&&(r={},this.executorsByZIndex_[i]=r);let s=t[i];for(let o in s){let a=s[o];r[o]=new wf(this.resolution_,this.pixelRatio_,this.overlaps_,a,e)}}}hasExecutors(t){for(let e in this.executorsByZIndex_){let i=this.executorsByZIndex_[e];for(let r=0,s=t.length;r<s;++r)if(t[r]in i)return!0}return!1}forEachFeatureAtCoordinate(t,e,i,r,s,o){bf===!1&&Pm(),r=Math.round(r);let a=r*2+1,l=kt(this.hitDetectionTransform_,r+.5,r+.5,1/e,-1/e,-i,-t[0],-t[1]),h=!this.hitDetectionContext_;h&&(this.hitDetectionContext_=nt(a,a,null,{willReadFrequently:vf}));let c=this.hitDetectionContext_;c.canvas.width!==a||c.canvas.height!==a?(c.canvas.width=a,c.canvas.height=a):h||c.clearRect(0,0,a,a);let u;this.renderBuffer_!==void 0&&(u=ut(),Ki(u,t),_n(u,e*(this.renderBuffer_+r),u));let f=Om(r),g;function p(w,R,A){let b=c.getImageData(0,0,a,a).data;for(let S=0,T=f.length;S<T;S++)if(b[f[S]]>0){if(!o||A==="none"||g!=="Image"&&g!=="Text"||o.includes(w)){let z=(f[S]-3)/4,G=r-z%a,F=r-(z/a|0),B=s(w,R,G*G+F*F);if(B)return B}c.clearRect(0,0,a,a);break}}let _=Object.keys(this.executorsByZIndex_).map(Number);_.sort(Zt);let m,x,E,C,y;for(m=_.length-1;m>=0;--m){let w=_[m].toString();for(E=this.executorsByZIndex_[w],x=Mi.length-1;x>=0;--x)if(g=Mi[x],C=E[g],C!==void 0&&(y=C.executeHitDetection(c,l,i,p,u),y))return y}}getClipCoords(t){let e=this.maxExtent_;if(!e)return null;let i=e[0],r=e[1],s=e[2],o=e[3],a=[i,r,i,o,s,o,s,r];return Vt(a,0,8,2,t,a),a}isEmpty(){return de(this.executorsByZIndex_)}execute(t,e,i,r,s,o,a){let l=Object.keys(this.executorsByZIndex_).map(Number);l.sort(a?yh:Zt),o=o||Mi;let h=Mi.length;for(let c=0,u=l.length;c<u;++c){let f=l[c].toString(),g=this.executorsByZIndex_[f];for(let p=0,_=o.length;p<_;++p){let m=o[p],x=g[m];if(x!==void 0){let E=a===null?void 0:x.getZIndexContext(),C=E?E.getContext():t,y=this.maxExtent_&&m!=="Image"&&m!=="Text";if(y&&(C.save(),this.clip(C,i)),!E||m==="Text"||m==="Image"?x.execute(C,e,i,r,s,a):E.pushFunction(w=>x.execute(w,e,i,r,s,a)),y&&C.restore(),E){E.offset();let w=l[c]*h+Mi.indexOf(m);this.deferredZIndexContexts_[w]||(this.deferredZIndexContexts_[w]=[]),this.deferredZIndexContexts_[w].push(E)}}}}this.renderedContext_=t}getDeferredZIndexContexts(){return this.deferredZIndexContexts_}getRenderedContext(){return this.renderedContext_}renderDeferred(){let t=this.deferredZIndexContexts_,e=Object.keys(t).map(Number).sort(Zt);for(let i=0,r=e.length;i<r;++i)t[e[i]].forEach(s=>{s.draw(this.renderedContext_),s.clear()}),t[e[i]].length=0}},Mc={};function Om(n){if(Mc[n]!==void 0)return Mc[n];let t=n*2+1,e=n*n,i=new Array(e+1);for(let s=0;s<=n;++s)for(let o=0;o<=n;++o){let a=s*s+o*o;if(a>e)break;let l=i[a];l||(l=[],i[a]=l),l.push(((n+s)*t+(n+o))*4+3),s>0&&l.push(((n-s)*t+(n+o))*4+3),o>0&&(l.push(((n+s)*t+(n-o))*4+3),s>0&&l.push(((n-s)*t+(n-o))*4+3))}let r=[];for(let s=0,o=i.length;s<o;++s)i[s]&&r.push(...i[s]);return Mc[n]=r,r}var Rf=Pc;var kc=class extends yo{constructor(t,e,i,r,s,o,a){super(),this.context_=t,this.pixelRatio_=e,this.extent_=i,this.transform_=r,this.transformRotation_=r?Wi(Math.atan2(r[1],r[0]),10):0,this.viewRotation_=s,this.squaredTolerance_=o,this.userTransform_=a,this.contextFillState_=null,this.contextStrokeState_=null,this.contextTextState_=null,this.fillState_=null,this.strokeState_=null,this.image_=null,this.imageAnchorX_=0,this.imageAnchorY_=0,this.imageHeight_=0,this.imageOpacity_=0,this.imageOriginX_=0,this.imageOriginY_=0,this.imageRotateWithView_=!1,this.imageRotation_=0,this.imageScale_=[0,0],this.imageWidth_=0,this.text_="",this.textOffsetX_=0,this.textOffsetY_=0,this.textRotateWithView_=!1,this.textRotation_=0,this.textScale_=[0,0],this.textFillState_=null,this.textStrokeState_=null,this.textState_=null,this.pixelCoordinates_=[],this.tmpLocalTransform_=Lt()}drawImages_(t,e,i,r){if(!this.image_)return;let s=Vt(t,e,i,r,this.transform_,this.pixelCoordinates_),o=this.context_,a=this.tmpLocalTransform_,l=o.globalAlpha;this.imageOpacity_!=1&&(o.globalAlpha=l*this.imageOpacity_);let h=this.imageRotation_;this.transformRotation_===0&&(h-=this.viewRotation_),this.imageRotateWithView_&&(h+=this.viewRotation_);for(let c=0,u=s.length;c<u;c+=2){let f=s[c]-this.imageAnchorX_,g=s[c+1]-this.imageAnchorY_;if(h!==0||this.imageScale_[0]!=1||this.imageScale_[1]!=1){let p=f+this.imageAnchorX_,_=g+this.imageAnchorY_;kt(a,p,_,1,1,h,-p,-_),o.save(),o.transform.apply(o,a),o.translate(p,_),o.scale(this.imageScale_[0],this.imageScale_[1]),o.drawImage(this.image_,this.imageOriginX_,this.imageOriginY_,this.imageWidth_,this.imageHeight_,-this.imageAnchorX_,-this.imageAnchorY_,this.imageWidth_,this.imageHeight_),o.restore()}else o.drawImage(this.image_,this.imageOriginX_,this.imageOriginY_,this.imageWidth_,this.imageHeight_,f,g,this.imageWidth_,this.imageHeight_)}this.imageOpacity_!=1&&(o.globalAlpha=l)}drawText_(t,e,i,r){if(!this.textState_||this.text_==="")return;this.textFillState_&&this.setContextFillState_(this.textFillState_),this.textStrokeState_&&this.setContextStrokeState_(this.textStrokeState_),this.setContextTextState_(this.textState_);let s=Vt(t,e,i,r,this.transform_,this.pixelCoordinates_),o=this.context_,a=this.textRotation_;for(this.transformRotation_===0&&(a-=this.viewRotation_),this.textRotateWithView_&&(a+=this.viewRotation_);e<i;e+=r){let l=s[e]+this.textOffsetX_,h=s[e+1]+this.textOffsetY_;a!==0||this.textScale_[0]!=1||this.textScale_[1]!=1?(o.save(),o.translate(l-this.textOffsetX_,h-this.textOffsetY_),o.rotate(a),o.translate(this.textOffsetX_,this.textOffsetY_),o.scale(this.textScale_[0],this.textScale_[1]),this.textStrokeState_&&o.strokeText(this.text_,0,0),this.textFillState_&&o.fillText(this.text_,0,0),o.restore()):(this.textStrokeState_&&o.strokeText(this.text_,l,h),this.textFillState_&&o.fillText(this.text_,l,h))}}moveToLineTo_(t,e,i,r,s,o){let a=this.context_,l=Vt(t,e,i,r,this.transform_,this.pixelCoordinates_);if(Math.abs(o)>0){let c=l.length,u=s||Math.abs(l[0]-l[c-2])<1e-6&&Math.abs(l[1]-l[c-1])<1e-6;l=Eo(l,0,c,2,o,u,l),wo(l,2,u)}a.moveTo(l[0],l[1]);let h=l.length;s&&(h-=2);for(let c=2;c<h;c+=2)a.lineTo(l[c],l[c+1]);return s&&a.closePath(),i}drawRings_(t,e,i,r,s){for(let o=0,a=i.length;o<a;++o)e=this.moveToLineTo_(t,e,i[o],r,!0,s);return e}drawCircle(t){if(this.squaredTolerance_&&(t=t.simplifyTransformed(this.squaredTolerance_,this.userTransform_)),!!ht(this.extent_,t.getExtent())){if(this.fillState_||this.strokeState_){this.fillState_&&this.setContextFillState_(this.fillState_),this.strokeState_&&this.setContextStrokeState_(this.strokeState_);let e=Eu(t,this.transform_,this.pixelCoordinates_),i=e[2]-e[0],r=e[3]-e[1],s=Math.sqrt(i*i+r*r),o=this.context_;o.beginPath(),o.arc(e[0],e[1],s,0,2*Math.PI),this.fillState_&&o.fill(),this.strokeState_&&o.stroke()}this.text_!==""&&this.drawText_(t.getCenter(),0,2,2)}}setStyle(t){this.setFillStrokeStyle(t.getFill(),t.getStroke()),this.setImageStyle(t.getImage()),this.setTextStyle(t.getText())}setTransform(t){this.transform_=t}drawGeometry(t){switch(t.getType()){case"Point":this.drawPoint(t);break;case"LineString":this.drawLineString(t);break;case"Polygon":this.drawPolygon(t);break;case"MultiPoint":this.drawMultiPoint(t);break;case"MultiLineString":this.drawMultiLineString(t);break;case"MultiPolygon":this.drawMultiPolygon(t);break;case"GeometryCollection":this.drawGeometryCollection(t);break;case"Circle":this.drawCircle(t);break;default:}}drawFeature(t,e){let i=e.getGeometryFunction()(t);i&&(this.setStyle(e),this.drawGeometry(i))}drawGeometryCollection(t){let e=t.getGeometriesArray();for(let i=0,r=e.length;i<r;++i)this.drawGeometry(e[i])}drawPoint(t){this.squaredTolerance_&&(t=t.simplifyTransformed(this.squaredTolerance_,this.userTransform_));let e=t.getFlatCoordinates(),i=t.getStride();this.image_&&this.drawImages_(e,0,e.length,i),this.text_!==""&&this.drawText_(e,0,e.length,i)}drawMultiPoint(t){this.squaredTolerance_&&(t=t.simplifyTransformed(this.squaredTolerance_,this.userTransform_));let e=t.getFlatCoordinates(),i=t.getStride();this.image_&&this.drawImages_(e,0,e.length,i),this.text_!==""&&this.drawText_(e,0,e.length,i)}drawLineString(t){if(this.squaredTolerance_&&(t=t.simplifyTransformed(this.squaredTolerance_,this.userTransform_)),!!ht(this.extent_,t.getExtent())){if(this.strokeState_){this.setContextStrokeState_(this.strokeState_);let e=this.context_,i=t.getFlatCoordinates();e.beginPath(),this.moveToLineTo_(i,0,i.length,t.getStride(),!1,this.strokeState_.strokeOffset),e.stroke()}if(this.text_!==""){let e=t.getFlatMidpoint();this.drawText_(e,0,2,2)}}}drawMultiLineString(t){this.squaredTolerance_&&(t=t.simplifyTransformed(this.squaredTolerance_,this.userTransform_));let e=t.getExtent();if(ht(this.extent_,e)){if(this.strokeState_){this.setContextStrokeState_(this.strokeState_);let i=this.context_,r=t.getFlatCoordinates(),s=0,o=t.getEnds(),a=t.getStride();i.beginPath();for(let l=0,h=o.length;l<h;++l)s=this.moveToLineTo_(r,s,o[l],a,!1,this.strokeState_.strokeOffset);i.stroke()}if(this.text_!==""){let i=t.getFlatMidpoints();this.drawText_(i,0,i.length,2)}}}drawPolygon(t){if(this.squaredTolerance_&&(t=t.simplifyTransformed(this.squaredTolerance_,this.userTransform_)),!!ht(this.extent_,t.getExtent())){if(this.strokeState_||this.fillState_){this.fillState_&&this.setContextFillState_(this.fillState_),this.strokeState_&&this.setContextStrokeState_(this.strokeState_);let e=this.context_;e.beginPath(),this.drawRings_(t.getOrientedFlatCoordinates(),0,t.getEnds(),t.getStride(),this.strokeState_?.strokeOffset),this.fillState_&&e.fill(),this.strokeState_&&e.stroke()}if(this.text_!==""){let e=t.getFlatInteriorPoint();this.drawText_(e,0,2,2)}}}drawMultiPolygon(t){if(this.squaredTolerance_&&(t=t.simplifyTransformed(this.squaredTolerance_,this.userTransform_)),!!ht(this.extent_,t.getExtent())){if(this.strokeState_||this.fillState_){this.fillState_&&this.setContextFillState_(this.fillState_),this.strokeState_&&this.setContextStrokeState_(this.strokeState_);let e=this.context_,i=t.getOrientedFlatCoordinates(),r=0,s=t.getEndss(),o=t.getStride();e.beginPath();for(let a=0,l=s.length;a<l;++a){let h=s[a];r=this.drawRings_(i,r,h,o,this.strokeState_?.strokeOffset)}this.fillState_&&e.fill(),this.strokeState_&&e.stroke()}if(this.text_!==""){let e=t.getFlatInteriorPoints();this.drawText_(e,0,e.length,2)}}}setContextFillState_(t){let e=this.context_,i=this.contextFillState_;i?i.fillStyle!=t.fillStyle&&(i.fillStyle=t.fillStyle,e.fillStyle=t.fillStyle):(e.fillStyle=t.fillStyle,this.contextFillState_={fillStyle:t.fillStyle})}setContextStrokeState_(t){let e=this.context_,i=this.contextStrokeState_;i?(i.lineCap!=t.lineCap&&(i.lineCap=t.lineCap,e.lineCap=t.lineCap),zt(i.lineDash,t.lineDash)||e.setLineDash(i.lineDash=t.lineDash),i.lineDashOffset!=t.lineDashOffset&&(i.lineDashOffset=t.lineDashOffset,e.lineDashOffset=t.lineDashOffset),i.lineJoin!=t.lineJoin&&(i.lineJoin=t.lineJoin,e.lineJoin=t.lineJoin),i.lineWidth!=t.lineWidth&&(i.lineWidth=t.lineWidth,e.lineWidth=t.lineWidth),i.miterLimit!=t.miterLimit&&(i.miterLimit=t.miterLimit,e.miterLimit=t.miterLimit),i.strokeStyle!=t.strokeStyle&&(i.strokeStyle=t.strokeStyle,e.strokeStyle=t.strokeStyle)):(e.lineCap=t.lineCap,e.setLineDash(t.lineDash),e.lineDashOffset=t.lineDashOffset,e.lineJoin=t.lineJoin,e.lineWidth=t.lineWidth,e.miterLimit=t.miterLimit,e.strokeStyle=t.strokeStyle,this.contextStrokeState_={lineCap:t.lineCap,lineDash:t.lineDash,lineDashOffset:t.lineDashOffset,lineJoin:t.lineJoin,lineWidth:t.lineWidth,miterLimit:t.miterLimit,strokeStyle:t.strokeStyle})}setContextTextState_(t){let e=this.context_,i=this.contextTextState_,r=t.textAlign?t.textAlign:Ii;i?(i.font!=t.font&&(i.font=t.font,e.font=t.font),i.textAlign!=r&&(i.textAlign=r,e.textAlign=r),i.textBaseline!=t.textBaseline&&(i.textBaseline=t.textBaseline,e.textBaseline=t.textBaseline)):(e.font=t.font,e.textAlign=r,e.textBaseline=t.textBaseline,this.contextTextState_={font:t.font,textAlign:r,textBaseline:t.textBaseline})}setFillStrokeStyle(t,e){if(!t)this.fillState_=null;else{let i=t.getColor();this.fillState_={fillStyle:jt(i||St)}}if(!e)this.strokeState_=null;else{let i=e.getColor(),r=e.getLineCap(),s=e.getLineDash(),o=e.getLineDashOffset(),a=e.getLineJoin(),l=e.getWidth(),h=e.getMiterLimit(),c=s||Ht,u=e.getOffset();this.strokeState_={lineCap:r!==void 0?r:Ge,lineDash:this.pixelRatio_===1?c:c.map(f=>f*this.pixelRatio_),lineDashOffset:(o||qt)*this.pixelRatio_,lineJoin:a!==void 0?a:Xe,lineWidth:(l!==void 0?l:ri)*this.pixelRatio_,miterLimit:h!==void 0?h:ii,strokeStyle:jt(i||Yt),strokeOffset:(u??0)*this.pixelRatio_}}}setImageStyle(t){let e;if(!t||!(e=t.getSize())){this.image_=null;return}let i=t.getPixelRatio(this.pixelRatio_),r=t.getAnchor(),s=t.getOrigin();this.image_=t.getImage(this.pixelRatio_),this.imageAnchorX_=r[0]*i,this.imageAnchorY_=r[1]*i,this.imageHeight_=e[1]*i,this.imageOpacity_=t.getOpacity(),this.imageOriginX_=s[0],this.imageOriginY_=s[1],this.imageRotateWithView_=t.getRotateWithView(),this.imageRotation_=t.getRotation();let o=t.getScaleArray();this.imageScale_=[o[0]*this.pixelRatio_/i,o[1]*this.pixelRatio_/i],this.imageWidth_=e[0]*i}setTextStyle(t){if(!t)this.text_="";else{let e=t.getFill();if(!e)this.textFillState_=null;else{let g=e.getColor();this.textFillState_={fillStyle:jt(g||St)}}let i=t.getStroke();if(!i)this.textStrokeState_=null;else{let g=i.getColor(),p=i.getLineCap(),_=i.getLineDash(),m=i.getLineDashOffset(),x=i.getLineJoin(),E=i.getWidth(),C=i.getMiterLimit();this.textStrokeState_={lineCap:p!==void 0?p:Ge,lineDash:_||Ht,lineDashOffset:m||qt,lineJoin:x!==void 0?x:Xe,lineWidth:E!==void 0?E:ri,miterLimit:C!==void 0?C:ii,strokeStyle:jt(g||Yt)}}let r=t.getFont(),s=t.getOffsetX(),o=t.getOffsetY(),a=t.getRotateWithView(),l=t.getRotation(),h=t.getScaleArray(),c=t.getText(),u=t.getTextAlign(),f=t.getTextBaseline();this.textState_={font:r!==void 0?r:Qs,textAlign:u!==void 0?u:Ii,textBaseline:f!==void 0?f:rn},this.text_=c!==void 0?Array.isArray(c)?c.reduce((g,p,_)=>g+=_%2?" ":p,""):c:"",this.textOffsetX_=s!==void 0?this.pixelRatio_*s:0,this.textOffsetY_=o!==void 0?this.pixelRatio_*o:0,this.textRotateWithView_=a!==void 0?a:!1,this.textRotation_=l!==void 0?l:0,this.textScale_=[this.pixelRatio_*h[0],this.pixelRatio_*h[1]]}}},Sf=kc;var ve=.5;function Tf(n,t,e,i,r,s,o,a,l){let h=l?xi(r,l):r,c=n[0]*ve,u=n[1]*ve,f=nt(c,u);f.imageSmoothingEnabled=!1;let g=f.canvas,p=new Sf(f,ve,r,null,o,a,l?Vi(Hi(),l):null),_=e.length,m=Math.floor((256*256*256-1)/_),x={};for(let C=1;C<=_;++C){let y=e[C-1],w=y.getStyleFunction()||i;if(!w)continue;let R=w(y,s);if(!R)continue;Array.isArray(R)||(R=[R]);let b=(C*m).toString(16).padStart(7,"#00000");for(let S=0,T=R.length;S<T;++S){let z=R[S],G=z.getGeometryFunction()(y);if(!G||!ht(h,G.getExtent()))continue;let F=z.clone(),B=F.getFill();B&&B.setColor(b);let lt=F.getStroke();lt&&(lt.setColor(b),lt.setLineDash(null)),F.setText(void 0);let M=z.getImage();if(M){let N=M.getImageSize();if(!N)continue;let tt=nt(N[0],N[1],void 0,{alpha:!1}),it=tt.canvas;tt.fillStyle=b,tt.fillRect(0,0,it.width,it.height),F.setImage(new sn({img:it,anchor:M.getAnchor(),anchorXUnits:"pixels",anchorYUnits:"pixels",offset:M.getOrigin(),opacity:1,size:M.getSize(),scale:M.getScale(),rotation:M.getRotation(),rotateWithView:M.getRotateWithView()}))}let X=F.getZIndex()||0,O=x[X];O||(O={},x[X]=O,O.Polygon=[],O.Circle=[],O.LineString=[],O.Point=[]);let $=G.getType();if($==="GeometryCollection"){let N=G.getGeometriesArrayRecursive();for(let tt=0,it=N.length;tt<it;++tt){let wt=N[tt];O[wt.getType().replace("Multi","")].push(wt,F)}}else O[$.replace("Multi","")].push(G,F)}}let E=Object.keys(x).map(Number).sort(Zt);for(let C=0,y=E.length;C<y;++C){let w=x[E[C]];for(let R in w){let A=w[R];for(let b=0,S=A.length;b<S;b+=2){p.setStyle(A[b+1]);for(let T=0,z=t.length;T<z;++T)p.setTransform(t[T]),p.drawGeometry(A[b])}}}return f.getImageData(0,0,g.width,g.height)}function If(n,t,e){let i=[];if(e){let r=Math.floor(Math.round(n[0])*ve),s=Math.floor(Math.round(n[1])*ve),o=(et(r,0,e.width-1)+et(s,0,e.height-1)*e.width)*4,a=e.data[o],l=e.data[o+1],c=e.data[o+2]+256*(l+256*a),u=Math.floor((256*256*256-1)/t.length);c&&c%u===0&&i.push(t[c/u-1])}return i}var km=.5,Lf={Point:Wm,LineString:Nm,Polygon:Um,MultiPoint:Ym,MultiLineString:Gm,MultiPolygon:Xm,GeometryCollection:zm,Circle:Dm};function Af(n,t){return parseInt(Y(n),10)-parseInt(Y(t),10)}function Dc(n,t){let e=Fc(n,t);return e*e}function Fc(n,t){return km*n/t}function Dm(n,t,e,i,r){let s=e.getFill(),o=e.getStroke();if(s||o){let l=n.getBuilder(e.getZIndex(),"Circle");l.setFillStrokeStyle(s,o),l.drawCircle(t,i,r)}let a=e.getText();if(a&&a.getText()){let l=n.getBuilder(e.getZIndex(),"Text");l.setTextStyle(a),l.drawText(t,i,r)}}function zc(n,t,e,i,r,s,o,a){let l=[],h=e.getImage();if(h){let f=!0,g=h.getImageState();g==W.LOADED||g==W.ERROR?f=!1:g==W.IDLE&&h.load(),f&&l.push(h.ready())}let c=e.getFill();c&&c.loading()&&l.push(c.ready());let u=l.length>0;return u&&Promise.all(l).then(()=>r(null)),Fm(n,t,e,i,s,o,a),u}function Fm(n,t,e,i,r,s,o){let a=e.getGeometryFunction()(t);if(!a)return;let l=a.simplifyTransformed(i,r);if(e.getRenderer())Mf(n,l,e,t,o);else{let c=Lf[l.getType()];c(n,l,e,t,o,s)}}function Mf(n,t,e,i,r){if(t.getType()=="GeometryCollection"){let o=t.getGeometries();for(let a=0,l=o.length;a<l;++a)Mf(n,o[a],e,i,r);return}n.getBuilder(e.getZIndex(),"Default").drawCustom(t,i,e.getRenderer(),e.getHitDetectionRenderer(),r)}function zm(n,t,e,i,r,s){let o=t.getGeometriesArray(),a,l;for(a=0,l=o.length;a<l;++a){let h=Lf[o[a].getType()];h(n,o[a],e,i,r,s)}}function Nm(n,t,e,i,r){let s=e.getStroke();if(s){let a=n.getBuilder(e.getZIndex(),"LineString");a.setFillStrokeStyle(null,s),a.drawLineString(t,i,r)}let o=e.getText();if(o&&o.getText()){let a=n.getBuilder(e.getZIndex(),"Text");a.setTextStyle(o),a.drawText(t,i,r)}}function Gm(n,t,e,i,r){let s=e.getStroke();if(s){let a=n.getBuilder(e.getZIndex(),"LineString");a.setFillStrokeStyle(null,s),a.drawMultiLineString(t,i,r)}let o=e.getText();if(o&&o.getText()){let a=n.getBuilder(e.getZIndex(),"Text");a.setTextStyle(o),a.drawText(t,i,r)}}function Xm(n,t,e,i,r){let s=e.getFill(),o=e.getStroke();if(o||s){let l=n.getBuilder(e.getZIndex(),"Polygon");l.setFillStrokeStyle(s,o),l.drawMultiPolygon(t,i,r)}let a=e.getText();if(a&&a.getText()){let l=n.getBuilder(e.getZIndex(),"Text");l.setTextStyle(a),l.drawText(t,i,r)}}function Wm(n,t,e,i,r,s){let o=e.getImage(),a=e.getText(),l=a&&a.getText(),h=s&&o&&l?{}:void 0;if(o){if(o.getImageState()!=W.LOADED)return;let c=n.getBuilder(e.getZIndex(),"Image");c.setImageStyle(o,h),c.drawPoint(t,i,r)}if(l){let c=n.getBuilder(e.getZIndex(),"Text");c.setTextStyle(a,h),c.drawText(t,i,r)}}function Ym(n,t,e,i,r,s){let o=e.getImage(),a=o&&o.getOpacity()!==0,l=e.getText(),h=l&&l.getText(),c=s&&a&&h?{}:void 0;if(a){if(o.getImageState()!=W.LOADED)return;let u=n.getBuilder(e.getZIndex(),"Image");u.setImageStyle(o,c),u.drawMultiPoint(t,i,r)}if(h){let u=n.getBuilder(e.getZIndex(),"Text");u.setTextStyle(l,c),u.drawText(t,i,r)}}function Um(n,t,e,i,r){let s=e.getFill(),o=e.getStroke();if(s||o){let l=n.getBuilder(e.getZIndex(),"Polygon");l.setFillStrokeStyle(s,o),l.drawPolygon(t,i,r)}let a=e.getText();if(a&&a.getText()){let l=n.getBuilder(e.getZIndex(),"Text");l.setTextStyle(a),l.drawText(t,i,r)}}var Nc=class extends xo{constructor(t){super(t),this.boundHandleStyleImageChange_=this.handleStyleImageChange_.bind(this),this.animatingOrInteracting_,this.hitDetectionImageData_=null,this.clipExtent_=null,this.extendX_=!1,this.renderedFeatures_=null,this.renderedRevision_=-1,this.renderedResolution_=NaN,this.renderedExtent_=ut(),this.wrappedRenderedExtent_=ut(),this.renderedRotation_,this.renderedCenter_=null,this.renderedProjection_=null,this.renderedPixelRatio_=1,this.renderedRenderOrder_=null,this.renderedFrameDeclutter_,this.replayGroup_=null,this.replayGroupChanged=!0,this.clipping=!0,this.targetContext_=null,this.opacity_=1}renderWorlds(t,e,i){let r=e.extent,s=e.viewState,o=s.center,a=s.resolution,l=s.projection,h=s.rotation,c=l.getExtent(),u=this.getLayer().getSource(),f=this.getLayer().getDeclutter(),g=e.pixelRatio,p=e.viewHints,_=!(p[Rt.ANIMATING]||p[Rt.INTERACTING]),m=this.context,x=Math.round(V(r)/a*g),E=Math.round(ct(r)/a*g),C=u.getWrapX()&&l.canWrapX(),y=C?V(c):null,w=C?Math.ceil((r[2]-c[2])/y)+(this.extendX_?2:1):1,R=C?Math.floor((r[0]-c[0])/y)-(this.extendX_?1:0):0;do{let A=this.getRenderTransform(o,a,0,g,x,E,R*y);e.declutter&&(A=A.slice(0)),t.execute(m,[m.canvas.width,m.canvas.height],A,h,_,i===void 0?Mi:i?Oc:Cf,i?f&&e.declutter[f]:void 0)}while(++R<w)}setDrawContext_(){this.opacity_!==1&&(this.targetContext_=this.context,this.context=nt(this.context.canvas.width,this.context.canvas.height,uc))}resetDrawContext_(){if(this.opacity_!==1&&this.targetContext_){let t=this.targetContext_.globalAlpha;this.targetContext_.globalAlpha=this.opacity_,this.targetContext_.drawImage(this.context.canvas,0,0),this.targetContext_.globalAlpha=t,qi(this.context),uc.push(this.context.canvas),this.context=this.targetContext_,this.targetContext_=null}}renderDeclutter(t){!this.replayGroup_||!this.getLayer().getDeclutter()||this.renderWorlds(this.replayGroup_,t,!0)}renderDeferredInternal(t){this.replayGroup_&&(this.clipExtent_&&this.clipUnrotated(this.context,t,this.clipExtent_),this.replayGroup_.renderDeferred(),this.clipExtent_&&(this.context.restore(),this.clipExtent_=null),this.resetDrawContext_())}renderFrame(t,e){let i=t.layerStatesArray[t.layerIndex];this.opacity_=i.opacity;let r=t.viewState;this.prepareContainer(t,e);let s=this.context,o=this.replayGroup_,a=o&&!o.isEmpty();if(!a&&!(this.getLayer().hasListener(Dt.PRERENDER)||this.getLayer().hasListener(Dt.POSTRENDER)))return this.container;this.setDrawContext_(),this.preRender(s,t);let l=r.projection;this.clipExtent_=null;let h=!1;if(a&&i.extent&&this.clipping){let c=ye(i.extent,l);a=ht(c,t.extent),a&&!Pe(c,t.extent)&&(t.declutter?this.clipExtent_=c:(this.clipUnrotated(s,t,c),h=!0))}return a&&this.renderWorlds(o,t,this.getLayer().getDeclutter()?!1:void 0),h&&s.restore(),this.postRender(s,t),this.renderedRotation_!==r.rotation&&(this.renderedRotation_=r.rotation,this.hitDetectionImageData_=null),t.declutter||this.resetDrawContext_(),this.container}getFeatures(t){return new Promise(e=>{if(this.frameState&&!this.hitDetectionImageData_&&!this.animatingOrInteracting_){let i=this.frameState.size.slice(),r=this.renderedCenter_,s=this.renderedResolution_,o=this.renderedRotation_,a=this.renderedProjection_,l=this.wrappedRenderedExtent_,h=this.getLayer(),c=[],u=i[0]*ve,f=i[1]*ve;c.push(this.getRenderTransform(r,s,o,ve,u,f,0).slice());let g=h.getSource(),p=a.getExtent();if(g.getWrapX()&&a.canWrapX()&&!Pe(p,l)){let m=l[0],x=V(p),E=0,C;for(;m<p[0];)--E,C=x*E,c.push(this.getRenderTransform(r,s,o,ve,u,f,C).slice()),m+=x;for(E=0,m=l[2];m>p[2];)++E,C=x*E,c.push(this.getRenderTransform(r,s,o,ve,u,f,C).slice()),m-=x}let _=Hi();this.hitDetectionImageData_=Tf(i,c,this.renderedFeatures_,h.getStyleFunction(),l,s,o,Dc(s,this.renderedPixelRatio_),_?a:null)}e(If(t,this.renderedFeatures_,this.hitDetectionImageData_))})}forEachFeatureAtCoordinate(t,e,i,r,s){if(!this.replayGroup_)return;let o=e.viewState.resolution,a=e.viewState.rotation,l=this.getLayer(),h={},c=function(f,g,p){let _=Y(f),m=h[_];if(m){if(m!==!0&&p<m.distanceSq){if(p===0)return h[_]=!0,s.splice(s.lastIndexOf(m),1),r(f,l,g);m.geometry=g,m.distanceSq=p}}else{if(p===0)return h[_]=!0,r(f,l,g);s.push(h[_]={feature:f,layer:l,geometry:g,distanceSq:p,callback:r})}},u=this.getLayer().getDeclutter();return this.replayGroup_.forEachFeatureAtCoordinate(t,o,a,i,c,u?e.declutter?.[u]?.all().map(f=>f.value):null)}handleFontsChanged(){let t=this.getLayer();t.getVisible()&&this.replayGroup_&&t.changed()}handleStyleImageChange_(t){this.renderIfReadyAndVisible()}prepareFrame(t){let e=this.getLayer(),i=e.getSource();if(!i)return!1;let r=t.viewHints[Rt.ANIMATING],s=t.viewHints[Rt.INTERACTING],o=e.getUpdateWhileAnimating(),a=e.getUpdateWhileInteracting();if(this.ready&&!o&&r||!a&&s)return this.animatingOrInteracting_=!0,!0;this.animatingOrInteracting_=!1;let l=t.extent,h=t.viewState,c=h.projection,u=h.resolution,f=t.pixelRatio,g=e.getRevision(),p=e.getRenderBuffer(),_=e.getRenderOrder();_===void 0&&(_=Af);let m=h.center.slice(),x=_n(l,p*u),E=x.slice(),C=[x.slice()],y=c.getExtent(),w=i.getWrapX()&&c.canWrapX();if(this.extendX_=!1,w){let M=i.getExtent();M&&!ke(M)&&(this.extendX_=M[0]<y[0]||M[2]>y[2])}if(w&&(!Pe(y,t.extent)||this.extendX_)){let M=V(y),X=Math.max(V(x)/2,M),O=y[0],$=y[2];this.extendX_&&(O-=M,$+=M),x[0]=O-X,x[2]=$+X,fs(m,c);let N=sa(C[0],c);N[0]<y[0]&&N[2]<y[2]?C.push([N[0]+M,N[1],N[2]+M,N[3]]):N[0]>y[0]&&N[2]>y[2]&&C.push([N[0]-M,N[1],N[2]-M,N[3]])}if(this.ready&&this.renderedResolution_==u&&this.renderedPixelRatio_===f&&this.renderedRevision_==g&&this.renderedRenderOrder_==_&&this.renderedFrameDeclutter_===!!t.declutter&&Pe(this.wrappedRenderedExtent_,x))return zt(this.renderedExtent_,E)||(this.hitDetectionImageData_=null,this.renderedExtent_=E),this.renderedCenter_=m,this.replayGroupChanged=!1,!0;this.replayGroup_=null;let R=new mf(Fc(u,f),x,u,f),A=Hi(),b;if(A){for(let M=0,X=C.length;M<X;++M){let O=C[M],$=xi(O,c);i.loadFeatures($,uu(u,c),A)}b=Vi(A,c)}else for(let M=0,X=C.length;M<X;++M)i.loadFeatures(C[M],u,c);let S=Dc(u,f),T=!0,z=(M,X)=>{let O,$=M.getStyleFunction()||e.getStyleFunction();if($&&(O=$(M,u)),O){let N=this.renderFeature(M,S,O,R,b,this.getLayer().getDeclutter(),X);T=T&&!N}},G=xi(x,c),F=i.getFeaturesInExtent(G);_&&F.sort(_);for(let M=0,X=F.length;M<X;++M)z(F[M],M);this.renderedFeatures_=F,this.ready=T;let B=R.finish(),lt=new Rf(x,u,f,i.getOverlaps(),B,e.getRenderBuffer(),!!t.declutter);return this.renderedResolution_=u,this.renderedRevision_=g,this.renderedRenderOrder_=_,this.renderedFrameDeclutter_=!!t.declutter,this.renderedExtent_=E,this.wrappedRenderedExtent_=x,this.renderedCenter_=m,this.renderedProjection_=c,this.renderedPixelRatio_=f,this.replayGroup_=lt,this.hitDetectionImageData_=null,this.replayGroupChanged=!0,!0}renderFeature(t,e,i,r,s,o,a){if(!i)return!1;let l=!1;if(Array.isArray(i))for(let h=0,c=i.length;h<c;++h)l=zc(r,t,i[h],e,this.boundHandleStyleImageChange_,s,o,a)||l;else l=zc(r,t,i,e,this.boundHandleStyleImageChange_,s,o,a);return l}},Pf=Nc;var Gc=class extends lo{constructor(t){super(t)}createRenderer(){return new Pf(this)}},ee=Gc;var Km=!1;function Zm(n,t,e,i,r,s,o){let a=new XMLHttpRequest;a.open("GET",typeof n=="function"?n(e,i,r):n,!0),t.getType()=="arraybuffer"&&(a.responseType="arraybuffer"),a.withCredentials=Km,a.onload=function(l){if(!a.status||a.status>=200&&a.status<300){let h=t.getType();try{let c;h=="text"||h=="json"?c=a.responseText:h=="xml"?c=a.responseXML||a.responseText:h=="arraybuffer"&&(c=a.response),c?s(t.readFeatures(c,{extent:e,featureProjection:r}),t.readProjection(c)):o()}catch{o()}}else o()},a.onerror=o,a.send()}function Xc(n,t){return function(e,i,r,s,o){Zm(n,t,e,i,r,(a,l)=>{this.addFeatures(a),s!==void 0&&s(a)},()=>{this.changed(),o!==void 0&&o()})}}function Of(n,t){return[[-1/0,-1/0,1/0,1/0]]}function Wc(n,t,e,i,r,s,o){let a,l,h=(e-t)/i;if(h===1)a=t;else if(h===2)a=t,l=r;else if(h!==0){let c=n[t],u=n[t+1],f=0,g=[0];for(let m=t+i;m<e;m+=i){let x=n[m],E=n[m+1];f+=Math.sqrt((x-c)*(x-c)+(E-u)*(E-u)),g.push(f),c=x,u=E}let p=r*f,_=xh(g,p);_<0?(l=(p-g[-_-2])/(g[-_-1]-g[-_-2]),a=t+(-_-2)*i):a=t+_*i}o=o>1?o:2,s=s||new Array(o);for(let c=0;c<o;++c)s[c]=a===void 0?NaN:l===void 0?n[a+c]:Nt(n[a+c],n[a+i+c],l);return s}var kf=Lt(),Kr=class n{constructor(t,e,i,r,s,o){this.styleFunction,this.extent_,this.id_=o,this.type_=t,this.flatCoordinates_=e,this.flatInteriorPoints_=null,this.flatMidpoints_=null,this.ends_=i||null,this.properties_=s,this.squaredTolerance_,this.stride_=r,this.simplifiedGeometry_}get(t){return this.properties_[t]}getExtent(){return this.extent_||(this.extent_=this.type_==="Point"?cs(this.flatCoordinates_):xn(this.flatCoordinates_,0,this.flatCoordinates_.length,this.stride_)),this.extent_}getFlatInteriorPoint(){if(!this.flatInteriorPoints_){let t=Bt(this.getExtent());this.flatInteriorPoints_=Er(this.flatCoordinates_,0,this.ends_,this.stride_,t,0)}return this.flatInteriorPoints_}getFlatInteriorPoints(){if(!this.flatInteriorPoints_){let t=Du(this.flatCoordinates_,this.ends_),e=ho(this.flatCoordinates_,0,t,this.stride_);this.flatInteriorPoints_=Ss(this.flatCoordinates_,0,t,this.stride_,e)}return this.flatInteriorPoints_}getFlatMidpoint(){return this.flatMidpoints_||(this.flatMidpoints_=Wc(this.flatCoordinates_,0,this.flatCoordinates_.length,this.stride_,.5)),this.flatMidpoints_}getFlatMidpoints(){if(!this.flatMidpoints_){this.flatMidpoints_=[];let t=this.flatCoordinates_,e=0,i=this.ends_;for(let r=0,s=i.length;r<s;++r){let o=i[r],a=Wc(t,e,o,this.stride_,.5);fe(this.flatMidpoints_,a),e=o}}return this.flatMidpoints_}getId(){return this.id_}getOrientedFlatCoordinates(){return this.flatCoordinates_}getGeometry(){return this}getSimplifiedGeometry(t){return this}simplifyTransformed(t,e){return this}getProperties(){return this.properties_}getPropertiesInternal(){return this.properties_}getStride(){return this.stride_}getStyleFunction(){return this.styleFunction}getType(){return this.type_}transform(t){t=Et(t);let e=t.getExtent(),i=t.getWorldExtent();if(e&&i){let r=ct(i)/ct(e);kt(kf,i[0],i[3],r,-r,0,0,0),Vt(this.flatCoordinates_,0,this.flatCoordinates_.length,this.stride_,kf,this.flatCoordinates_)}}applyTransform(t){t(this.flatCoordinates_,this.flatCoordinates_,this.stride_)}clone(){return new n(this.type_,this.flatCoordinates_.slice(),this.ends_?.slice(),this.stride_,Object.assign({},this.properties_),this.id_)}getEnds(){return this.ends_}enableSimplifyTransformed(){return this.simplifyTransformed=es((t,e)=>{if(t===this.squaredTolerance_)return this.simplifiedGeometry_;this.simplifiedGeometry_=this.clone(),e&&this.simplifiedGeometry_.applyTransform(e);let i=this.simplifiedGeometry_.getFlatCoordinates(),r;switch(this.type_){case"LineString":i.length=xr(i,0,this.simplifiedGeometry_.flatCoordinates_.length,this.simplifiedGeometry_.stride_,t,i,0),r=[i.length];break;case"MultiLineString":r=[],i.length=Mu(i,0,this.simplifiedGeometry_.ends_,this.simplifiedGeometry_.stride_,t,i,0,r);break;case"Polygon":r=[],i.length=yr(i,0,this.simplifiedGeometry_.ends_,this.simplifiedGeometry_.stride_,Math.sqrt(t),i,0,r);break;default:}return r&&(this.simplifiedGeometry_=new n(this.type_,i,r,this.stride_,this.properties_,this.id_)),this.squaredTolerance_=t,this.simplifiedGeometry_}),this}};Kr.prototype.getFlatCoordinates=Kr.prototype.getOrientedFlatCoordinates;var ln=Kr;var Yc=class{constructor(t){this.rbush_=new Qi(t),this.items_={}}insert(t,e){let i={minX:t[0],minY:t[1],maxX:t[2],maxY:t[3],value:e};this.rbush_.insert(i),this.items_[Y(e)]=i}load(t,e){let i=new Array(e.length);for(let r=0,s=e.length;r<s;r++){let o=t[r],a=e[r],l={minX:o[0],minY:o[1],maxX:o[2],maxY:o[3],value:a};i[r]=l,this.items_[Y(a)]=l}this.rbush_.load(i)}remove(t){let e=Y(t),i=this.items_[e];return delete this.items_[e],this.rbush_.remove(i)!==null}update(t,e){let i=this.items_[Y(e)],r=[i.minX,i.minY,i.maxX,i.maxY];Ui(r,t)||(this.remove(e),this.insert(t,e))}getAll(){return this.rbush_.all().map(function(e){return e.value})}getInExtent(t){let e={minX:t[0],minY:t[1],maxX:t[2],maxY:t[3]};return this.rbush_.search(e).map(function(r){return r.value})}forEach(t){return this.forEach_(this.getAll(),t)}forEachInExtent(t,e){return this.forEach_(this.getInExtent(t),e)}forEach_(t,e){let i;for(let r=0,s=t.length;r<s;r++)if(i=e(t[r]),i)return i;return i}isEmpty(){return de(this.items_)}clear(){this.rbush_.clear(),this.items_={}}getExtent(t){let e=this.rbush_.toJSON();return Jt(e.minX,e.minY,e.maxX,e.maxY,t)}concat(t){this.rbush_.load(t.rbush_.all());for(let e in t.items_)this.items_[e]=t.items_[e]}},Uc=Yc;var Kc=class extends xt{constructor(t){super(),this.projection=Et(t.projection),this.attributions_=Df(t.attributions),this.attributionsCollapsible_=t.attributionsCollapsible??!0,this.loading=!1,this.state_=t.state!==void 0?t.state:"ready",this.wrapX_=t.wrapX!==void 0?t.wrapX:!1,this.interpolate_=!!t.interpolate,this.viewResolver=null,this.viewRejector=null;let e=this;this.viewPromise_=new Promise(function(i,r){e.viewResolver=i,e.viewRejector=r})}getAttributions(){return this.attributions_}getAttributionsCollapsible(){return this.attributionsCollapsible_}getProjection(){return this.projection}getResolutions(t){return null}getView(){return this.viewPromise_}ready(){let t=this.getState();return t==="ready"?Promise.resolve():t==="error"?Promise.reject(new Error("Source failed to load")):new Promise((e,i)=>{let r=()=>{let s=this.getState();s==="ready"?(this.un("change",r),e()):s==="error"&&(this.un("change",r),i(new Error("Source failed to load")))};this.on("change",r)})}getState(){return this.state_}getWrapX(){return this.wrapX_}getInterpolate(){return this.interpolate_}refresh(){this.changed()}setAttributions(t){this.attributions_=Df(t),this.changed()}setState(t){this.state_=t,this.changed()}};function Df(n){return n?typeof n=="function"?n:(Array.isArray(n)||(n=[n]),t=>n):null}var Co=Kc;var ie={ADDFEATURE:"addfeature",CHANGEFEATURE:"changefeature",CLEAR:"clear",REMOVEFEATURE:"removefeature",FEATURESLOADSTART:"featuresloadstart",FEATURESLOADEND:"featuresloadend",FEATURESLOADERROR:"featuresloaderror"};var Ue=class extends Tt{constructor(t,e,i){super(t),this.feature=e,this.features=i}},Zc=class extends Co{constructor(t){t=t||{},super({attributions:t.attributions,interpolate:!0,projection:void 0,state:"ready",wrapX:t.wrapX!==void 0?t.wrapX:!0}),this.on,this.once,this.un,this.loader_=$e,this.format_=t.format||null,this.overlaps_=t.overlaps===void 0?!0:t.overlaps,this.url_=t.url,t.loader!==void 0?this.loader_=t.loader:this.url_!==void 0&&(Z(this.format_,"`format` must be set when `url` is set"),this.loader_=Xc(this.url_,this.format_)),this.strategy_=t.strategy!==void 0?t.strategy:Of;let e=t.useSpatialIndex!==void 0?t.useSpatialIndex:!0;this.featuresRtree_=e?new Uc:null,this.loadedExtentsRtree_=new Uc,this.nullGeometryFeatures_={},this.idIndex_={},this.uidIndex_={},this.featureChangeKeys_={},this.featuresCollection_=null;let i,r;Array.isArray(t.features)?r=t.features:t.features&&(i=t.features,r=i.getArray()),!e&&i===void 0&&(i=new Pt(r)),r!==void 0&&this.addFeaturesInternal(r),i!==void 0&&this.bindFeaturesCollection_(i)}addFeature(t){this.addFeatureInternal(t),this.changed()}addFeatureInternal(t){let e=Y(t);if(!this.addToIndex_(e,t)){this.featuresCollection_&&this.featuresCollection_.remove(t);return}this.setupChangeEvents_(e,t);let i=t.getGeometry();if(i){let r=i.getExtent();this.featuresRtree_&&this.featuresRtree_.insert(r,t)}else this.nullGeometryFeatures_[e]=t;this.dispatchEvent(new Ue(ie.ADDFEATURE,t))}setupChangeEvents_(t,e){e instanceof ln||(this.featureChangeKeys_[t]=[K(e,P.CHANGE,this.handleFeatureChange_,this),K(e,ue.PROPERTYCHANGE,this.handleFeatureChange_,this)])}addToIndex_(t,e){let i=!0;if(e.getId()!==void 0){let r=String(e.getId());if(!(r in this.idIndex_))this.idIndex_[r]=e;else if(e instanceof ln){let s=this.idIndex_[r];s instanceof ln?Array.isArray(s)?s.push(e):this.idIndex_[r]=[s,e]:i=!1}else i=!1}return i&&(Z(!(t in this.uidIndex_),"The passed `feature` was already added to the source"),this.uidIndex_[t]=e),i}addFeatures(t){this.addFeaturesInternal(t),this.changed()}addFeaturesInternal(t){let e=[],i=[],r=[];for(let s=0,o=t.length;s<o;s++){let a=t[s],l=Y(a);this.addToIndex_(l,a)&&i.push(a)}for(let s=0,o=i.length;s<o;s++){let a=i[s],l=Y(a);this.setupChangeEvents_(l,a);let h=a.getGeometry();if(h){let c=h.getExtent();e.push(c),r.push(a)}else this.nullGeometryFeatures_[l]=a}if(this.featuresRtree_&&this.featuresRtree_.load(e,r),this.hasListener(ie.ADDFEATURE))for(let s=0,o=i.length;s<o;s++)this.dispatchEvent(new Ue(ie.ADDFEATURE,i[s]))}bindFeaturesCollection_(t){let e=!1;this.addEventListener(ie.ADDFEATURE,function(i){e||(e=!0,t.push(i.feature),e=!1)}),this.addEventListener(ie.REMOVEFEATURE,function(i){e||(e=!0,t.remove(i.feature),e=!1)}),t.addEventListener(It.ADD,i=>{e||(e=!0,this.addFeature(i.element),e=!1)}),t.addEventListener(It.REMOVE,i=>{e||(e=!0,this.removeFeature(i.element),e=!1)}),this.featuresCollection_=t}clear(t){if(t){for(let i in this.featureChangeKeys_)this.featureChangeKeys_[i].forEach(J);this.featuresCollection_||(this.featureChangeKeys_={},this.idIndex_={},this.uidIndex_={})}else if(this.featuresRtree_){this.featuresRtree_.forEach(i=>{this.removeFeatureInternal(i)});for(let i in this.nullGeometryFeatures_)this.removeFeatureInternal(this.nullGeometryFeatures_[i])}this.featuresCollection_&&this.featuresCollection_.clear(),this.featuresRtree_&&this.featuresRtree_.clear(),this.nullGeometryFeatures_={};let e=new Ue(ie.CLEAR);this.dispatchEvent(e),this.changed()}forEachFeature(t){if(this.featuresRtree_)return this.featuresRtree_.forEach(t);this.featuresCollection_&&this.featuresCollection_.forEach(t)}forEachFeatureAtCoordinateDirect(t,e){let i=[t[0],t[1],t[0],t[1]];return this.forEachFeatureInExtent(i,function(r){let s=r.getGeometry();if(s instanceof ln||s.intersectsCoordinate(t))return e(r)})}forEachFeatureInExtent(t,e){if(this.featuresRtree_)return this.featuresRtree_.forEachInExtent(t,e);this.featuresCollection_&&this.featuresCollection_.forEach(e)}forEachFeatureIntersectingExtent(t,e){return this.forEachFeatureInExtent(t,function(i){let r=i.getGeometry();if(r instanceof ln||r.intersectsExtent(t)){let s=e(i);if(s)return s}})}getFeaturesCollection(){return this.featuresCollection_}getFeatures(){let t;return this.featuresCollection_?t=this.featuresCollection_.getArray().slice(0):this.featuresRtree_&&(t=this.featuresRtree_.getAll(),de(this.nullGeometryFeatures_)||fe(t,Object.values(this.nullGeometryFeatures_))),t}getFeaturesAtCoordinate(t){let e=[];return this.forEachFeatureAtCoordinateDirect(t,function(i){e.push(i)}),e}getFeaturesInExtent(t,e){if(this.featuresRtree_){if(!(e&&e.canWrapX()&&this.getWrapX()))return this.featuresRtree_.getInExtent(t);let r=ds(t,e);return[].concat(...r.map(s=>this.featuresRtree_.getInExtent(s)))}return this.featuresCollection_?this.featuresCollection_.getArray().slice(0):[]}getClosestFeatureToCoordinate(t,e){let i=t[0],r=t[1],s=null,o=[NaN,NaN],a=1/0,l=[-1/0,-1/0,1/0,1/0];return e=e||He,this.featuresRtree_.forEachInExtent(l,function(h){if(e(h)){let c=h.getGeometry(),u=a;if(a=c instanceof ln?0:c.closestPointXY(i,r,o,a),a<u){s=h;let f=Math.sqrt(a);l[0]=i-f,l[1]=r-f,l[2]=i+f,l[3]=r+f}}}),s}getExtent(t){return this.featuresRtree_?.getExtent(t)??null}getFeatureById(t){let e=this.idIndex_[t.toString()];return e!==void 0?e:null}getFeatureByUid(t){let e=this.uidIndex_[t];return e!==void 0?e:null}getFormat(){return this.format_}getOverlaps(){return this.overlaps_}getUrl(){return this.url_}handleFeatureChange_(t){let e=t.target,i=Y(e),r=e.getGeometry();if(!r)i in this.nullGeometryFeatures_||(this.featuresRtree_&&this.featuresRtree_.remove(e),this.nullGeometryFeatures_[i]=e);else{let o=r.getExtent();i in this.nullGeometryFeatures_?(delete this.nullGeometryFeatures_[i],this.featuresRtree_&&this.featuresRtree_.insert(o,e)):this.featuresRtree_&&this.featuresRtree_.update(o,e)}let s=e.getId();if(s!==void 0){let o=s.toString();this.idIndex_[o]!==e&&(this.removeFromIdIndex_(e),this.idIndex_[o]=e)}else this.removeFromIdIndex_(e),this.uidIndex_[i]=e;this.changed(),this.dispatchEvent(new Ue(ie.CHANGEFEATURE,e))}hasFeature(t){let e=t.getId();if(e!==void 0){let i=this.idIndex_[String(e)];return Array.isArray(i)?i.includes(t):i===t}return Y(t)in this.uidIndex_}isEmpty(){return this.featuresRtree_?this.featuresRtree_.isEmpty()&&de(this.nullGeometryFeatures_):this.featuresCollection_?this.featuresCollection_.getLength()===0:!0}loadFeatures(t,e,i){let r=this.loadedExtentsRtree_,s=this.strategy_(t,e,i);for(let o=0,a=s.length;o<a;++o){let l=s[o];if(!r.forEachInExtent(l,function(c){return Pe(c.extent,l)})){this.loading=Number(this.loading)+1,this.dispatchEvent(new Ue(ie.FEATURESLOADSTART));let c=p=>{this.loading=Number(this.loading)-1,this.dispatchEvent(new Ue(ie.FEATURESLOADEND,void 0,p))},u=()=>{this.changed(),this.loading=Number(this.loading)-1,this.dispatchEvent(new Ue(ie.FEATURESLOADERROR))},f=!1,g=this.loader_.call(this,l,e,i,p=>f||c(p),()=>f||u());g instanceof Promise?(f=!0,g.then(p=>{this.addFeatures(p),c(p)}).catch(u)):this.loader_.length<4&&(this.loading=!1),r.insert(l,{extent:l.slice()})}}}refresh(){this.clear(!0),this.loadedExtentsRtree_.clear(),super.refresh()}removeLoadedExtent(t){let e=this.loadedExtentsRtree_,i=[];e.forEachInExtent(t,function(r){i.push(r)}),i.forEach(r=>{e.remove(r);let s=ra(r.extent,t);for(let o of s)e.insert(o,{extent:o})})}removeFeatures(t){let e=!1;for(let i=0,r=t.length;i<r;++i)e=this.removeFeatureInternal(t[i])||e;e&&this.changed()}removeFeature(t){if(!t)return;this.removeFeatureInternal(t)&&this.changed()}removeFeatureInternal(t){let e=Y(t);if(!(e in this.uidIndex_))return!1;e in this.nullGeometryFeatures_?delete this.nullGeometryFeatures_[e]:this.featuresRtree_&&this.featuresRtree_.remove(t),this.featureChangeKeys_[e]?.forEach(J),delete this.featureChangeKeys_[e];let r=t.getId();if(r!==void 0){let s=r.toString(),o=this.idIndex_[s];o===t?delete this.idIndex_[s]:Array.isArray(o)&&(o.splice(o.indexOf(t),1),o.length===1&&(this.idIndex_[s]=o[0]))}return delete this.uidIndex_[e],this.hasListener(ie.REMOVEFEATURE)&&this.dispatchEvent(new Ue(ie.REMOVEFEATURE,t)),!0}removeFromIdIndex_(t){for(let e in this.idIndex_)if(this.idIndex_[e]===t){delete this.idIndex_[e];break}}setLoader(t){this.loader_=t}setUrl(t){Z(this.format_,"`format` must be set when `url` is set"),this.url_=t,this.setLoader(Xc(t,this.format_))}setOverlaps(t){this.overlaps_=t,this.changed()}},Pi=Zc;var Zn=[0,0,0],Oi=5,Bc=class{constructor(t){let e=t.minZoom,i=t.resolutions;e===void 0&&i&&(e=i.findIndex(o=>o!==void 0)),this.minZoom=e!==void 0?e:0,this.resolutions_=i,Z(wh(this.resolutions_,(o,a)=>a-o,!0),"`resolutions` must be sorted in descending order");let r;if(!t.origins){for(let o=0,a=this.resolutions_.length-1;o<a;++o)if(!r)r=this.resolutions_[o]/this.resolutions_[o+1];else if(this.resolutions_[o]/this.resolutions_[o+1]!==r){r=void 0;break}}this.zoomFactor_=r,this.maxZoom=this.resolutions_.length-1,this.origin_=t.origin!==void 0?t.origin:null,this.origins_=null,t.origins!==void 0&&(this.origins_=t.origins,Z(this.origins_.length==this.resolutions_.length,"Number of `origins` and `resolutions` must be equal"));let s=t.extent;s!==void 0&&!this.origin_&&!this.origins_&&(this.origin_=ae(s)),Z(!this.origin_&&this.origins_||this.origin_&&!this.origins_,"Either `origin` or `origins` must be configured, never both"),this.tileSizes_=null,t.tileSizes!==void 0&&(this.tileSizes_=t.tileSizes,Z(this.tileSizes_.length==this.resolutions_.length,"Number of `tileSizes` and `resolutions` must be equal")),this.tileSize_=t.tileSize!==void 0?t.tileSize:this.tileSizes_?null:256,Z(!this.tileSize_&&this.tileSizes_||this.tileSize_&&!this.tileSizes_,"Either `tileSize` or `tileSizes` must be configured, never both"),this.extent_=s!==void 0?s:null,this.fullTileRanges_=null,this.tmpSize_=[0,0],this.tmpExtent_=[0,0,0,0],t.tileRanges!==void 0?this.fullTileRanges_=t.tileRanges:t.sizes!==void 0?this.fullTileRanges_=t.sizes.map((o,a)=>{let l=new po(Math.min(0,o[0]),Math.max(o[0]-1,-1),Math.min(0,o[1]),Math.max(o[1]-1,-1));if(s){let h=this.getTileRangeForExtentAndZ(s,a);l.minX=Math.max(h.minX,l.minX),l.maxX=Math.min(h.maxX,l.maxX),l.minY=Math.max(h.minY,l.minY),l.maxY=Math.min(h.maxY,l.maxY)}return l}):s&&this.calculateTileRanges_(s)}forEachTileCoord(t,e,i){let r=this.getTileRangeForExtentAndZ(t,e);for(let s=r.minX,o=r.maxX;s<=o;++s)for(let a=r.minY,l=r.maxY;a<=l;++a)i([e,s,a])}forEachTileCoordParentTileRange(t,e,i,r){let s,o,a,l=null,h=t[0]-1;for(this.zoomFactor_===2?(o=t[1],a=t[2]):l=this.getTileCoordExtent(t,r);h>=this.minZoom;){if(o!==void 0&&a!==void 0?(o=Math.floor(o/2),a=Math.floor(a/2),s=on(o,o,a,a,i)):s=this.getTileRangeForExtentAndZ(l,h,i),e(h,s))return!0;--h}return!1}getExtent(){return this.extent_}getMaxZoom(){return this.maxZoom}getMinZoom(){return this.minZoom}getOrigin(t){return this.origin_?this.origin_:this.origins_[t]}getOrigins(){return this.origins_}getResolution(t){return this.resolutions_[t]}getResolutions(){return this.resolutions_}getTileCoordChildTileRange(t,e,i){if(t[0]<this.maxZoom){if(this.zoomFactor_===2){let s=t[1]*2,o=t[2]*2;return on(s,s+1,o,o+1,e)}let r=this.getTileCoordExtent(t,i||this.tmpExtent_);return this.getTileRangeForExtentAndZ(r,t[0]+1,e)}return null}getTileRangeForTileCoordAndZ(t,e,i){if(e>this.maxZoom||e<this.minZoom)return null;let r=t[0],s=t[1],o=t[2];if(e===r)return on(s,o,s,o,i);if(this.zoomFactor_){let l=Math.pow(this.zoomFactor_,e-r),h=Math.floor(s*l),c=Math.floor(o*l);if(e<r)return on(h,h,c,c,i);let u=Math.floor(l*(s+1))-1,f=Math.floor(l*(o+1))-1;return on(h,u,c,f,i)}let a=this.getTileCoordExtent(t,this.tmpExtent_);return this.getTileRangeForExtentAndZ(a,e,i)}getTileRangeForExtentAndZ(t,e,i){this.getTileCoordForXYAndZ_(t[0],t[3],e,!1,Zn);let r=Zn[1],s=Zn[2];this.getTileCoordForXYAndZ_(t[2],t[1],e,!0,Zn);let o=Zn[1],a=Zn[2];return on(r,o,s,a,i)}getTileCoordCenter(t){let e=this.getOrigin(t[0]),i=this.getResolution(t[0]),r=pt(this.getTileSize(t[0]),this.tmpSize_);return[e[0]+(t[1]+.5)*r[0]*i,e[1]-(t[2]+.5)*r[1]*i]}getTileCoordExtent(t,e){let i=this.getOrigin(t[0]),r=this.getResolution(t[0]),s=pt(this.getTileSize(t[0]),this.tmpSize_),o=i[0]+t[1]*s[0]*r,a=i[1]-(t[2]+1)*s[1]*r,l=o+s[0]*r,h=a+s[1]*r;return Jt(o,a,l,h,e)}getTileCoordForCoordAndResolution(t,e,i){return this.getTileCoordForXYAndResolution_(t[0],t[1],e,!1,i)}getTileCoordForXYAndResolution_(t,e,i,r,s){let o=this.getZForResolution(i),a=i/this.getResolution(o),l=this.getOrigin(o),h=pt(this.getTileSize(o),this.tmpSize_),c=a*(t-l[0])/i/h[0],u=a*(l[1]-e)/i/h[1];return r?(c=cr(c,Oi)-1,u=cr(u,Oi)-1):(c=lr(c,Oi),u=lr(u,Oi)),Wn(o,c,u,s)}getTileCoordForXYAndZ_(t,e,i,r,s){let o=this.getOrigin(i),a=this.getResolution(i),l=pt(this.getTileSize(i),this.tmpSize_),h=(t-o[0])/a/l[0],c=(o[1]-e)/a/l[1];return r?(h=cr(h,Oi)-1,c=cr(c,Oi)-1):(h=lr(h,Oi),c=lr(c,Oi)),Wn(i,h,c,s)}getTileCoordForCoordAndZ(t,e,i){return this.getTileCoordForXYAndZ_(t[0],t[1],e,!1,i)}getTileCoordResolution(t){return this.resolutions_[t[0]]}getTileSize(t){return this.tileSize_?this.tileSize_:this.tileSizes_[t]}getFullTileRange(t){return this.fullTileRanges_?this.fullTileRanges_[t]:this.extent_?this.getTileRangeForExtentAndZ(this.extent_,t):null}getZForResolution(t,e){let i=gn(this.resolutions_,t,e||0);return et(i,this.minZoom,this.maxZoom)}tileCoordIntersectsViewport(t,e){return Ia(e,0,e.length,2,this.getTileCoordExtent(t))}calculateTileRanges_(t){let e=this.resolutions_.length,i=new Array(e);for(let r=this.minZoom;r<e;++r)i[r]=this.getTileRangeForExtentAndZ(t,r);this.fullTileRanges_=i}},Zr=Bc;function vo(n){let t=n.getDefaultTileGrid();return t||(t=Vm(n),n.setDefaultTileGrid(t)),t}function Ff(n,t,e){let i=t[0],r=n.getTileCoordCenter(t),s=bo(e);if(!me(s,r)){let o=V(s),a=Math.ceil((s[0]-r[0])/o);return r[0]+=o*a,n.getTileCoordForCoordAndZ(r,i)}return t}function Bm(n,t,e,i){i=i!==void 0?i:"top-left";let r=Nf(n,t,e);return new Zr({extent:n,origin:Oh(n,i),resolutions:r,tileSize:e})}function zf(n){let t=n||{},e=t.extent||Et("EPSG:3857").getExtent(),i={extent:e,minZoom:t.minZoom,tileSize:t.tileSize,resolutions:Nf(e,t.maxZoom,t.tileSize,t.maxResolution)};return new Zr(i)}function Nf(n,t,e,i){t=t!==void 0?t:42,e=pt(e!==void 0?e:256);let r=ct(n),s=V(n);i=i>0?i:Math.max(s/e[0],r/e[1]);let o=t+1,a=new Array(o);for(let l=0;l<o;++l)a[l]=i/Math.pow(2,l);return a}function Vm(n,t,e,i){let r=bo(n);return Bm(r,t,e,i)}function bo(n){n=Et(n);let t=n.getExtent();if(!t){let e=180*Je.degrees/n.getMetersPerUnit();t=Jt(-e,-e,e,e)}return t}var jm=/\{z\}/g,Hm=/\{x\}/g,qm=/\{y\}/g,$m=/\{-y\}/g;function Gf(n,t,e,i,r){return n.replace(jm,t.toString()).replace(Hm,e.toString()).replace(qm,i.toString()).replace($m,function(){if(r===void 0)throw new Error("If the URL template has a {-y} placeholder, the grid extent must be known");return(r-i).toString()})}function Xf(n){let t=[],e=/\{([a-z])-([a-z])\}/.exec(n);if(e){let i=e[1].charCodeAt(0),r=e[2].charCodeAt(0),s;for(s=i;s<=r;++s)t.push(n.replace(e[0],String.fromCharCode(s)));return t}if(e=/\{(\d+)-(\d+)\}/.exec(n),e){let i=parseInt(e[2],10);for(let r=parseInt(e[1],10);r<=i;r++)t.push(n.replace(e[0],r.toString()));return t}return t.push(n),t}function Jm(n,t){return(function(e,i,r){if(!e)return;let s,o=e[0];if(t){let a=t.getFullTileRange(o);a&&(s=a.getHeight()-1)}return Gf(n,o,e[1],e[2],s)})}function Wf(n,t){let e=n.length,i=new Array(e);for(let r=0;r<e;++r)i[r]=Jm(n[r],t);return Qm(i)}function Qm(n){return n.length===1?n[0]:(function(t,e,i){if(!t)return;let r=rf(t),s=Me(r,n.length);return n[s](t,e,i)})}var Vc=class extends Co{constructor(t){super({attributions:t.attributions,attributionsCollapsible:t.attributionsCollapsible,projection:t.projection,state:t.state,wrapX:t.wrapX,interpolate:t.interpolate}),this.on,this.once,this.un,this.tilePixelRatio_=t.tilePixelRatio!==void 0?t.tilePixelRatio:1,this.tileGrid=t.tileGrid!==void 0?t.tileGrid:null;let e=[256,256];this.tileGrid&&pt(this.tileGrid.getTileSize(this.tileGrid.getMinZoom()),e),this.tmpSize=[0,0],this.key_=t.key||Y(this),this.tileOptions={transition:t.transition,interpolate:t.interpolate},this.zDirection=t.zDirection?t.zDirection:0}getGutterForProjection(t){return 0}getKey(){return this.key_}setKey(t){this.key_!==t&&(this.key_=t,this.changed())}getResolutions(t){let e=t?this.getTileGridForProjection(t):this.tileGrid;return e?e.getResolutions():null}getTile(t,e,i,r,s,o){return j()}getTileGrid(){return this.tileGrid}getTileGridForProjection(t){return this.tileGrid?this.tileGrid:vo(t)}getTilePixelRatio(t){return this.tilePixelRatio_}getTilePixelSize(t,e,i){let r=this.getTileGridForProjection(i),s=this.getTilePixelRatio(e),o=pt(r.getTileSize(t),this.tmpSize);return s==1?o:md(o,s,this.tmpSize)}getTileCoordForTileUrlFunction(t,e){let i=e!==void 0?e:this.getProjection(),r=e!==void 0?this.getTileGridForProjection(i):this.tileGrid||this.getTileGridForProjection(i);return this.getWrapX()&&i.isGlobal()&&(t=Ff(r,t,i)),sf(t,r)?t:null}clear(){}refresh(){this.clear(),super.refresh()}},Ro=class extends Tt{constructor(t,e){super(t),this.tile=e}},Yf=Vc;var So={TILELOADSTART:"tileloadstart",TILELOADEND:"tileloadend",TILELOADERROR:"tileloaderror"};var jc=class n extends Yf{constructor(t){super({attributions:t.attributions,cacheSize:t.cacheSize,projection:t.projection,state:t.state,tileGrid:t.tileGrid,tilePixelRatio:t.tilePixelRatio,wrapX:t.wrapX,transition:t.transition,interpolate:t.interpolate,key:t.key,attributionsCollapsible:t.attributionsCollapsible,zDirection:t.zDirection}),this.generateTileUrlFunction_=this.tileUrlFunction===n.prototype.tileUrlFunction,this.tileLoadFunction=t.tileLoadFunction,t.tileUrlFunction&&(this.tileUrlFunction=t.tileUrlFunction),this.urls=null,t.urls?this.setUrls(t.urls):t.url&&this.setUrl(t.url),this.tileLoadingKeys_={}}getTileLoadFunction(){return this.tileLoadFunction}getTileUrlFunction(){return Object.getPrototypeOf(this).tileUrlFunction===this.tileUrlFunction?this.tileUrlFunction.bind(this):this.tileUrlFunction}getUrls(){return this.urls}handleTileChange(t){let e=t.target,i=Y(e),r=e.getState(),s;r==k.LOADING?(this.tileLoadingKeys_[i]=!0,s=So.TILELOADSTART):i in this.tileLoadingKeys_&&(delete this.tileLoadingKeys_[i],s=r==k.ERROR?So.TILELOADERROR:r==k.LOADED?So.TILELOADEND:void 0),s!=null&&this.dispatchEvent(new Ro(s,e))}setTileLoadFunction(t){this.tileLoadFunction=t,this.changed()}setTileUrlFunction(t,e){this.tileUrlFunction=t,typeof e<"u"?this.setKey(e):this.changed()}setUrl(t){let e=Xf(t);this.urls=e,this.setUrls(e)}setUrls(t){this.urls=t;let e=t.join(`7-`);this.generateTileUrlFunction_?this.setTileUrlFunction(Wf(t,this.tileGrid),e):this.setKey(e)}tileUrlFunction(t,e,i){}},Uf=jc;var Hc=class extends Uf{constructor(t){super({attributions:t.attributions,cacheSize:t.cacheSize,projection:t.projection,state:t.state,tileGrid:t.tileGrid,tileLoadFunction:t.tileLoadFunction?t.tileLoadFunction:t_,tilePixelRatio:t.tilePixelRatio,tileUrlFunction:t.tileUrlFunction,url:t.url,urls:t.urls,wrapX:t.wrapX,transition:t.transition,interpolate:t.interpolate!==void 0?t.interpolate:!0,key:t.key,attributionsCollapsible:t.attributionsCollapsible,zDirection:t.zDirection}),this.crossOrigin=t.crossOrigin!==void 0?t.crossOrigin:null,this.referrerPolicy=t.referrerPolicy,this.tileClass=t.tileClass!==void 0?t.tileClass:fo,this.tileGridForProjection={},this.reprojectionErrorThreshold_=t.reprojectionErrorThreshold,this.renderReprojectionEdges_=!1}getGutterForProjection(t){return this.getProjection()&&t&&!Tn(this.getProjection(),t)?0:this.getGutter()}getGutter(){return 0}getKey(){let t=super.getKey();return this.getInterpolate()||(t+=":disable-interpolation"),t}getTileGridForProjection(t){let e=this.getProjection();if(this.tileGrid&&(!e||Tn(e,t)))return this.tileGrid;let i=Y(t);return i in this.tileGridForProjection||(this.tileGridForProjection[i]=vo(t)),this.tileGridForProjection[i]}createTile_(t,e,i,r,s,o){let a=[t,e,i],l=this.getTileCoordForTileUrlFunction(a,s),h=l?this.tileUrlFunction(l,r,s):void 0,c=new this.tileClass(a,h!==void 0?k.IDLE:k.EMPTY,h!==void 0?h:"",{crossOrigin:this.crossOrigin,referrerPolicy:this.referrerPolicy},this.tileLoadFunction,this.tileOptions);return c.key=o,c.addEventListener(P.CHANGE,this.handleTileChange.bind(this)),c}getTile(t,e,i,r,s,o){let a=this.getProjection();if(!a||!s||Tn(a,s))return this.getTileInternal(t,e,i,r,a||s);let l=[t,e,i],h=this.getKey(),c=this.getTileGridForProjection(a),u=this.getTileGridForProjection(s),f=this.getTileCoordForTileUrlFunction(l,s),g=new mo(a,c,s,u,l,f,this.getTilePixelRatio(r),this.getGutter(),(p,_,m,x)=>this.getTileInternal(p,_,m,x,a,o),this.reprojectionErrorThreshold_,this.renderReprojectionEdges_,this.tileOptions);return g.key=h,g}getTileInternal(t,e,i,r,s,o){let a=this.getKey(),l=Yn(this,a,t,e,i);if(o&&o.containsKey(l))return o.get(l);let h=this.createTile_(t,e,i,r,s,a);return o?.set(l,h),h}setRenderReprojectionEdges(t){this.renderReprojectionEdges_!=t&&(this.renderReprojectionEdges_=t,this.changed())}setTileGridForProjection(t,e){let i=Et(t);if(i){let r=Y(i);r in this.tileGridForProjection||(this.tileGridForProjection[r]=e)}}};function t_(n,t){if(bt){let e=n.getCrossOrigin(),i="same-origin",r="same-origin";e==="anonymous"||e===""?(i="cors",r="omit"):e==="use-credentials"&&(i="cors",r="include");let s={mode:i,credentials:r,referrerPolicy:n.getReferrerPolicy()};fetch(t,s).then(o=>{if(!o.ok)throw new Error(`HTTP ${o.status}`);return o.blob()}).then(o=>createImageBitmap(o)).then(o=>{let a=n.getImage();a.width=o.width,a.height=o.height,a.getContext("2d").drawImage(o,0,0),o.close?.(),a.dispatchEvent(new Event("load"))}).catch(()=>{n.getImage().dispatchEvent(new Event("error"))});return}n.getImage().src=t}var Kf=Hc;var qc=class extends Kf{constructor(t){t=t||{};let e=t.projection!==void 0?t.projection:"EPSG:3857",i=t.tileGrid!==void 0?t.tileGrid:zf({extent:bo(e),maxResolution:t.maxResolution,maxZoom:t.maxZoom,minZoom:t.minZoom,tileSize:t.tileSize});super({attributions:t.attributions,cacheSize:t.cacheSize,crossOrigin:t.crossOrigin,referrerPolicy:t.referrerPolicy,interpolate:t.interpolate,projection:e,reprojectionErrorThreshold:t.reprojectionErrorThreshold,tileGrid:i,tileLoadFunction:t.tileLoadFunction,tilePixelRatio:t.tilePixelRatio,tileUrlFunction:t.tileUrlFunction,url:t.url,urls:t.urls,wrapX:t.wrapX!==void 0?t.wrapX:!0,transition:t.transition,attributionsCollapsible:t.attributionsCollapsible,zDirection:t.zDirection}),this.gutter_=t.gutter!==void 0?t.gutter:0}getGutter(){return this.gutter_}},Zf=qc;var q=n=>document.querySelector(n),I={game:q("#game-select"),map:q("#map-select"),variant:q("#variant-select"),variantField:q("#variant-field"),gameTitle:q("#game-title"),title:q("#map-title"),meta:q("#map-meta"),legend:q("#legend"),search:q("#pin-search"),searchResults:q("#search-results"),visibleCount:q("#visible-count"),viewport:q("#map"),layers:q("#layers"),zoneToggle:q("#zone-toggle"),zoneCount:q("#zone-count"),zoneIndex:q("#zone-index"),zoneList:q("#zone-list"),loading:q("#map-loading"),labelsHint:q("#labels-hint"),gridHint:q("#grid-hint"),gridNavigator:q("#grid-navigator"),gridInput:q("#grid-input"),gridBack:q("#grid-back"),detail:q("#pin-detail"),detailTitle:q("#detail-title"),detailCategory:q("#detail-category"),detailDescription:q("#detail-description"),detailID:q("#detail-id"),detailCoordinates:q("#detail-coordinates"),detailLinks:q("#detail-links"),detailDot:q("#detail-dot"),sidebar:q("#sidebar"),mobileLegend:q("#mobile-legend"),fatal:q("#fatal-error"),fatalMessage:q("#fatal-message")},Lo=["#d6f36b","#72d5f4","#ff9e64","#df83ff","#62e6ae","#ff6f91","#f4d35e","#8aa9ff","#e7a56d","#83d483"],Di="0123456789bcdefghjkmnpqrstuvwxyz",e_=3,i_=2,d={catalog:null,game:null,map:null,variant:null,engine:null,projection:null,layers:null,sources:null,hiddenCategories:new Set,collapsedSections:new Set,pins:[],pinByID:new Map,selectedPin:null,hoveredPin:null,pinLabelsVisible:!1,gridEnabled:!1,gridPrefix:"",zonesVisible:!0,zoneRecords:new Map,highlightedZones:new Set,focusedZoneID:null,search:"",fitZoom:0,zoneTitleCount:0,eligibleLocations:0,tileRun:0,tileStats:{requested:0,loaded:0,errors:0,peakPending:0},styleCache:new Map,markerIcons:new Map};async function n_(){s_();try{let n=await fetch("/static/catalog.json");if(!n.ok)throw new Error(`catalog request returned ${n.status}`);if(d.catalog=await n.json(),!d.catalog.games.length)throw new Error("the embedded catalog contains no maps");r_(),ih(I.game,d.catalog.games,"title"),Jf(d.catalog.games[0].slug),W_(),requestAnimationFrame(()=>I.viewport.focus({preventScroll:!0}))}catch(n){I.loading.hidden=!0,I.fatalMessage.textContent=n instanceof Error?n.message:String(n),I.fatal.hidden=!1}}function r_(){let n=d.catalog.tileGrid.size,t=[0,-n,n,0];d.projection=new mi({code:"ATLAS:PIXELS",units:"pixels",extent:t}),d.sources={grid:new Pi({wrapX:!1}),gridContext:new Pi({wrapX:!1}),zones:new Pi({wrapX:!1}),zoneTitles:new Pi({wrapX:!1}),text:new Pi({wrapX:!1}),pins:new Pi({wrapX:!1}),priority:new Pi({wrapX:!1})},d.layers={raster:new mc({zIndex:0}),rasterDetail:new mc({zIndex:1}),grid:new ee({source:d.sources.grid,style:Hf,renderOrder:be,renderBuffer:40,zIndex:5}),zones:new ee({source:d.sources.zones,style:M_,renderBuffer:32,zIndex:10}),zoneTitles:new ee({source:d.sources.zoneTitles,style:P_,renderOrder:be,declutter:"atlas-annotations",renderBuffer:160,zIndex:20}),zoneTitleDetail:new ee({source:d.sources.zoneTitles,style:O_,renderOrder:be,renderBuffer:160,zIndex:44}),text:new ee({source:d.sources.text,style:S_,renderOrder:be,declutter:"atlas-annotations",renderBuffer:220,zIndex:30}),textDetail:new ee({source:d.sources.text,style:T_,renderOrder:be,renderBuffer:220,zIndex:45}),zoneText:new ee({source:d.sources.text,style:I_,renderOrder:be,declutter:"atlas-zone-focus",renderBuffer:220,zIndex:41}),pins:new ee({source:d.sources.pins,style:v_,renderOrder:be,renderBuffer:48,zIndex:40}),zonePins:new ee({source:d.sources.pins,style:b_,renderOrder:be,renderBuffer:48,zIndex:42}),pinLabels:new ee({source:d.sources.pins,style:R_,renderOrder:be,renderBuffer:180,zIndex:45}),gridContext:new ee({source:d.sources.gridContext,style:Hf,renderOrder:be,renderBuffer:40,zIndex:48}),priority:new ee({source:d.sources.priority,style:L_,renderOrder:be,renderBuffer:220,zIndex:50})},d.engine=new jd({target:I.viewport,layers:Object.values(d.layers),controls:Os({attribution:!1,rotate:!1,zoom:!1}),interactions:Gs({onFocusOnly:!1}),view:$f(5)}),d.engine.on("movestart",()=>{d.engine.getViewport().classList.add("is-dragging")}),d.engine.on("moveend",()=>{d.engine.getViewport().classList.remove("is-dragging"),Oo()}),I.viewport.addEventListener("wheel",()=>{document.activeElement!==I.viewport&&I.viewport.focus({preventScroll:!0})},{capture:!0,passive:!0}),d.engine.on("singleclick",e=>{if(d.gridEnabled){let r=d.engine.forEachFeatureAtPixel(e.pixel,s=>s.get("gridCell")||null,{hitTolerance:1,layerFilter:s=>s===d.layers.grid||s===d.layers.gridContext});if(r&&r.role!=="leaf"){Jc(r.hash);return}}let i=d.engine.forEachFeatureAtPixel(e.pixel,(r,s)=>s!==d.layers.pins&&s!==d.layers.pinLabels&&s!==d.layers.text&&s!==d.layers.textDetail&&s!==d.layers.priority?null:r.get("pin")||null,{hitTolerance:5});i&&cg(i)}),d.engine.on("pointermove",e=>{if(e.dragging){Io(null);return}let i=d.engine.forEachFeatureAtPixel(e.pixel,(o,a)=>a!==d.layers.pins&&a!==d.layers.pinLabels&&a!==d.layers.text&&a!==d.layers.textDetail&&a!==d.layers.priority?null:o.get("pin")||null,{hitTolerance:4,layerFilter:o=>o===d.layers.pins||o===d.layers.pinLabels||o===d.layers.text||o===d.layers.textDetail||o===d.layers.priority}),r=i?.category.displayType==="text"?null:i;Io(r||null);let s=d.gridEnabled&&d.engine.hasFeatureAtPixel(e.pixel,{layerFilter:o=>o===d.layers.grid||o===d.layers.gridContext});d.engine.getTargetElement().style.cursor=i||s?"pointer":""}),d.engine.getViewport().addEventListener("pointerleave",()=>Io(null))}function $f(n){let t=d.catalog.tileGrid.size;return new Qt({projection:d.projection,center:[t/2,-t/2],resolutions:eg(n),minZoom:0,maxZoom:n,extent:[0,-t,t,0],constrainResolution:!1,smoothResolutionConstraint:!1,showFullExtent:!0,zoom:0})}function s_(){I.game.addEventListener("change",()=>Jf(I.game.value)),I.map.addEventListener("change",()=>Qf(Number(I.map.value))),I.variant.addEventListener("change",()=>tg(Number(I.variant.value))),I.legend.addEventListener("change",n=>{let t=n.target;if(t.dataset.group){E_(Number(t.dataset.group));return}if(!t.dataset.category)return;let e=Number(t.dataset.category);t.checked?d.hiddenCategories.delete(e):d.hiddenCategories.add(e),Bn(),Br()}),I.layers.addEventListener("click",n=>{let t=n.target.closest("[data-section]");if(!t)return;let e=t.dataset.section;d.collapsedSections.has(e)?d.collapsedSections.delete(e):d.collapsedSections.add(e),rg()}),q("#show-all").addEventListener("click",()=>Vf(!0)),q("#hide-all").addEventListener("click",()=>Vf(!1)),I.zoneToggle.addEventListener("change",()=>{nh(I.zoneToggle.checked)}),I.zoneIndex.addEventListener("click",n=>{let t=n.target.closest("[data-zone]");t&&m_(Number(t.dataset.zone))}),I.zoneIndex.addEventListener("contextmenu",n=>{let t=n.target.closest("[data-zone]");t&&(n.preventDefault(),__(Number(t.dataset.zone)))}),I.search.addEventListener("input",()=>{d.search=I.search.value.trim().toLocaleLowerCase(),Bn(),lg()}),I.searchResults.addEventListener("click",n=>{let t=n.target.closest("[data-location]");if(!t)return;let e=d.pinByID.get(Number(t.dataset.location));e&&jf(e)}),I.detailLinks.addEventListener("click",n=>{let t=n.target.closest("[data-location]");if(!t)return;let e=d.pinByID.get(Number(t.dataset.location));e&&jf(e)}),q("#close-detail").addEventListener("click",Vn),q("#zoom-in").addEventListener("click",()=>To(1)),q("#zoom-out").addEventListener("click",()=>To(-1)),I.gridBack.addEventListener("click",ng),I.gridInput.addEventListener("input",()=>{let n=Po(),t=[...I.gridInput.value.toLocaleLowerCase()].filter(e=>Di.includes(e)).slice(0,n).join("");I.gridInput.value=t,Jc(t)}),I.viewport.addEventListener("keydown",n=>{if(!qf(n.target)){if(n.key==="+"||n.key==="=")To(1);else if(n.key==="-")To(-1);else if(n.key==="Escape")Vn();else return;n.preventDefault()}}),window.addEventListener("keydown",n=>{if(!qf(n.target)){if((n.metaKey||n.ctrlKey)&&n.key.toLocaleLowerCase()==="k"){n.preventDefault(),I.search.focus(),I.search.select();return}a_(n)||n.key.toLocaleLowerCase()==="z"&&(n.preventDefault(),d.pinLabelsVisible=!d.pinLabelsVisible,I.labelsHint.textContent=`Z \xB7 labels ${d.pinLabelsVisible?"on":"off"}`,d.layers.pinLabels.changed())}}),window.addEventListener("resize",()=>d.engine?.updateSize()),I.mobileLegend.addEventListener("click",()=>{let n=I.sidebar.classList.toggle("is-open");I.mobileLegend.setAttribute("aria-expanded",String(n))})}function Jf(n){d.game=d.catalog.games.find(t=>t.slug===n)||d.catalog.games[0],I.game.value=d.game.slug,ih(I.map,d.game.maps,"title","id"),I.map.disabled=d.game.maps.length===1,I.map.title=I.map.disabled?"This game has one map":"Choose a map",Qf(d.game.maps[0].id)}function Qf(n){d.map=d.game.maps.find(t=>t.id===n)||d.game.maps[0],document.documentElement.style.setProperty("--icon-outset-color",ah()),I.map.value=String(d.map.id),ih(I.variant,d.map.variants,"name"),I.variantField.hidden=d.map.variants.length<2,d.styleCache.clear(),Io(null),d.gridPrefix="",d.hiddenCategories.clear(),d.collapsedSections.clear(),d.collapsedSections.add("zones");for(let t of d.map.groups)for(let e of t.categories)e.visible||d.hiddenCategories.add(e.id);d.search="",I.search.value="",I.searchResults.hidden=!0,Vn(),c_(),f_(),d_(),tg(0,!0),I.gameTitle.textContent=d.game.title,I.title.textContent=d.map.title,I.meta.textContent=`${cn(d.map.pinCount)} locations \xB7 ${cn(d.map.zones?.length||0)} regions`,I.sidebar.classList.remove("is-open"),I.mobileLegend.setAttribute("aria-expanded","false")}function tg(n,t=!1){d.variant=d.map.variants[n]||d.map.variants[0];let e=d.variant,i=Hn(e);I.variant.value=String(d.map.variants.indexOf(d.variant)),t?d.engine.setView($f(i)):(d.engine.getView().setMinZoom(e.minZoom),d.engine.getView().setMaxZoom(i));let r=++d.tileRun,s=0;d.tileStats={requested:0,loaded:0,errors:0,peakPending:0},I.loading.hidden=!1;let o=f=>{f.on("tileloadstart",()=>{d.tileRun===r&&(s++,d.tileStats.requested++,d.tileStats.peakPending=Math.max(d.tileStats.peakPending,s))});let g=p=>{d.tileRun===r&&(s=Math.max(0,s-1),p?d.tileStats.errors++:d.tileStats.loaded++,s===0&&d.tileStats.loaded>0&&(I.loading.hidden=!0))};return f.on("tileloadend",()=>g(!1)),f.on("tileloaderror",()=>g(!0)),f},a=(f,g)=>o(new Zf({projection:d.projection,tileGrid:new Zr({extent:[0,-d.catalog.tileGrid.size,d.catalog.tileGrid.size,0],origin:[0,0],resolutions:eg(f),tileSize:d.catalog.tileGrid.tileSize}),cacheSize:64,interpolate:e.interpolate,transition:0,wrapX:!1,tileUrlFunction:([p,_,m])=>{let x=e.formats[p];if(!(!x||_<0||m<0||!g(p,_,m)))return`/static/tiles/${encodeURIComponent(e.tiles)}/${p}/${_}/${m}.${x}`}})),l=e.fullZoom??e.maxZoom,h=a(l,(f,g,p)=>Bf(e,f,g,p)),c=d.layers.raster.getSource();d.layers.raster.setSource(h),d.layers.raster.setExtent(Ao()),d.layers.raster.setBackground(e.background||void 0),c?.clear();let u=d.layers.rasterDetail.getSource();e.maxZoom>l?(d.layers.rasterDetail.setSource(a(e.maxZoom,(f,g,p)=>f>l&&Bf(e,f,g,p))),d.layers.rasterDetail.setExtent(Ao()),d.layers.rasterDetail.setVisible(!0)):d.layers.rasterDetail.setVisible(!1),u?.clear(),Qc(),d.gridEnabled&&(hn(),d.layers.pins.changed(),d.layers.text.changed(),d.layers.priority.changed()),t?requestAnimationFrame(C_):Oo()}function Bf(n,t,e,i){let r=n.coverage?.[t];if(!r)return!0;let s=e-r.x,o=i-r.y;if(s<0||o<0||s>=r.w||o>=r.h)return!1;let a=o_(n,t,r),l=o*r.w+s;return(a[l>>3]&1<<(l&7))!==0}function o_(n,t,e){if(!e.decoded){let i=atob(e.bits),r=new Uint8Array(i.length);for(let s=0;s<i.length;s++)r[s]=i.charCodeAt(s);e.decoded=r}return e.decoded}function eg(n){let t=d.catalog.tileGrid.size/d.catalog.tileGrid.tileSize;return Array.from({length:n+1},(e,i)=>t/2**i)}function Hn(n){return n.maxZoom+i_}function Ao(){let n=d.catalog.tileGrid.size,t=d.variant?.bounds||{x:0,y:0,width:n,height:n};return[t.x,-(t.y+t.height),t.x+t.width,-t.y]}function a_(n){return n.key.toLocaleLowerCase()==="g"?(n.preventDefault(),ig(),!0):n.key==="Escape"&&d.gridEnabled?(n.preventDefault(),ng(),!0):!1}function ig(n=!d.gridEnabled){d.gridEnabled=n,Qc(),hn(),d.layers.pins.changed(),d.layers.text.changed(),d.layers.priority.changed()}function Jc(n){let t=Po(),e=[...n.toLocaleLowerCase()].filter(r=>Di.includes(r)).slice(0,t).join(""),i=e!==d.gridPrefix;d.gridPrefix=e,d.gridEnabled||(d.gridEnabled=!0),Qc(),hn(),d.layers.pins.changed(),d.layers.text.changed(),d.layers.priority.changed(),i&&(Vn(),d.engine.getView().fit(Mo(),{size:d.engine.getSize(),padding:[52,52,52,52],maxZoom:Hn(d.variant),duration:180}))}function ng(){if(d.gridEnabled){if(!d.gridPrefix){ig(!1);return}Jc(d.gridPrefix.slice(0,-1))}}function Qc(){if(!d.sources||(d.sources.grid.clear(),d.sources.gridContext.clear(),I.gridNavigator.hidden=!d.gridEnabled,I.gridHint.textContent=d.gridEnabled?`G \xB7 ${d.gridPrefix||"root"}`:"G \xB7 grid off",!d.gridEnabled||!d.variant))return;let n=Po();if(I.gridInput.maxLength=n,I.gridInput.value=d.gridPrefix,I.gridBack.title=d.gridPrefix?"Back one geohash level":"Close geohash grid",l_(),d.gridPrefix.length>=n){$c(d.gridPrefix,Mo(),"leaf");return}for(let t of Di){let e=d.gridPrefix+t;$c(e,th(e),"child")}}function l_(){for(let n=0;n<d.gridPrefix.length;n++){let t=d.gridPrefix.slice(0,n),e=d.gridPrefix.slice(0,n+1);for(let i of Di){let r=t+i;r!==e&&$c(r,th(r),"neighbor",d.gridPrefix.length-n)}}}function $c(n,t,e,i=0){let[r,s,o,a]=t,l=d.pins.filter(u=>{if(u.filteredHidden)return!1;let[f,g]=u.coordinate;return f>=r&&f<=o&&g>=s&&g<=a}).length,h=new sr({geometry:new Ci([[[r,s],[r,a],[o,a],[o,s],[r,s]]]),gridCell:{hash:n,extent:t,role:e,count:l,contextDistance:i},priority:e==="neighbor"?-i*100+Di.indexOf(n[n.length-1]):Di.indexOf(n[n.length-1])});(e==="neighbor"?d.sources.gridContext:d.sources.grid).addFeature(h)}function Mo(){return th(d.gridPrefix)}function th(n){let t=[...Ao()],e=!0;for(let i of n){let r=Di.indexOf(i);if(!(r<0))for(let s of[16,8,4,2,1]){if(e){let o=(t[0]+t[2])/2;r&s?t[0]=o:t[2]=o}else{let o=(t[1]+t[3])/2;r&s?t[1]=o:t[3]=o}e=!e}}return t}function Po(){return e_}function eh(n){if(!d.gridEnabled||!d.gridPrefix)return!1;let t=Mo(),[e,i]=n.coordinate;return e>=t[0]&&e<=t[2]&&i>=t[1]&&i<=t[3]}function ih(n,t,e,i){n.replaceChildren(),t.forEach((r,s)=>{let o=document.createElement("option");o.value=i?String(r[i]):r.slug||String(s),o.textContent=r[e],n.append(o)})}function c_(){let n=document.createDocumentFragment();for(let t of d.map.groups){if(!t.categories.length)continue;let e=document.createElement("section");e.className="layer-section",e.dataset.groupSection=String(t.id);let i=t.categories.reduce((s,o)=>s+o.locations.length,0);e.append(h_(`group-${t.id}`,t.title,i,t.id));let r=document.createElement("div");r.className="category-toggles";for(let s of t.categories)r.append(u_(s));e.append(r),n.append(e)}I.legend.replaceChildren(n),rg(),Br()}function h_(n,t,e,i){let r=document.createElement("div");r.className="layer-header";let s=document.createElement("button");s.type="button",s.className="layer-title",s.dataset.section=n;let o=document.createElement("span");o.className="layer-chevron",o.setAttribute("aria-hidden","true"),o.innerHTML='<svg viewBox="0 0 24 24"><path d="m9 6 6 6-6 6"/></svg>';let a=document.createElement("span");a.textContent=t;let l=document.createElement("span");l.className="layer-count",l.textContent=cn(e),s.append(o,a,l);let h=document.createElement("label");h.className="layer-switch";let c=document.createElement("input");c.type="checkbox",c.dataset.group=String(i),c.setAttribute("aria-label",`Show ${t}`);let u=document.createElement("span");return u.setAttribute("aria-hidden","true"),h.append(c,u),r.append(s,h),r}function u_(n){let t=n.displayType==="text",e=document.createElement("label");e.className="category-toggle",lh(e,n);let i=document.createElement("input");i.type="checkbox",i.dataset.category=String(n.id),i.checked=!d.hiddenCategories.has(n.id);let r=document.createElement("span");t?(r.className="text-symbol",r.textContent="Tt",r.title="Drawn as a text label"):(r.className="category-icon",ch(r,n,Do(n.title)),r.title=n.icon||n.title);let s=document.createElement("span");s.className="category-name",s.textContent=n.title;let o=document.createElement("span");return o.className="category-count",o.textContent=cn(n.locations.length),e.append(i,r,s,o),e}function rg(){for(let n of I.layers.querySelectorAll("[data-section]")){let t=d.collapsedSections.has(n.dataset.section);n.setAttribute("aria-expanded",String(!t)),n.closest(".layer-section").classList.toggle("is-collapsed",t)}}function d_(){d.sources.pins.clear(),d.sources.text.clear(),d.sources.priority.clear(),d.pins=[],d.pinByID.clear();for(let n of d.map.groups)for(let t of n.categories){t.displayType!=="text"&&A_(t);for(let e of t.locations){let i={location:e,category:t,group:n,coordinate:rh(e.lat,e.lng),filteredHidden:!1,priority:F_(t,e),feature:null};i.feature=new sr({geometry:new wi(i.coordinate),pin:i,priority:i.priority}),d.pins.push(i),d.pinByID.set(e.id,i),t.displayType==="text"?d.sources.text.addFeature(i.feature):d.sources.pins.addFeature(i.feature)}}Bn()}function f_(){let n=d.map.zones||[];d.sources.zones.clear(),d.sources.zoneTitles.clear(),d.zoneRecords.clear(),d.highlightedZones.clear(),d.focusedZoneID=null,d.zoneTitleCount=0,nh(!0),I.zoneIndex.hidden=n.length===0,I.zoneCount.textContent=cn(n.length);for(let t of n){let e=ut(),i=[],r=!1;for(let l of t.features||[]){let h=x_(l);h&&(r=!0,i.push(h),hs(e,h.getExtent()),d.sources.zones.addFeature(new sr({geometry:h,zone:t,color:jn(t.id),child:t.parentRegionId!=null})))}if(!r)continue;let s=jn(t.id),o=t.center?rh(t.center.lat,t.center.lng):Bt(e),a=Math.max(e[2]-e[0],e[3]-e[1]);d.sources.zoneTitles.addFeature(new sr({geometry:new wi(o),zone:t,color:s,child:t.parentRegionId!=null,span:a,priority:(t.parentRegionId==null?2e6:1e6)+Math.round(a)})),d.zoneRecords.set(t.id,{zone:t,extent:e.slice(),geometries:i,color:s})}d.zoneTitleCount=d.sources.zoneTitles.getFeatures().length,g_()}function g_(){let n=document.createDocumentFragment();for(let{zone:t,depth:e}of p_()){let i=d.zoneRecords.get(t.id);if(!i)continue;let r=document.createElement("button");r.type="button",r.className="zone-index-item",r.dataset.zone=String(t.id),r.style.setProperty("--zone-color",i.color),r.style.setProperty("--zone-depth",String(e)),r.setAttribute("aria-pressed","false"),r.title=`${t.title}: click to jump; right-click to toggle highlight`;let s=document.createElement("span");s.className="zone-index-marker",s.setAttribute("aria-hidden","true");let o=document.createElement("span");o.textContent=t.title,r.append(s,o),n.append(r)}I.zoneList.replaceChildren(n),I.zoneIndex.hidden=d.zoneRecords.size===0}function p_(){let n=[...d.zoneRecords.values()].map(o=>o.zone),t=new Set(n.map(o=>o.id)),e=new Map;for(let o of n){let a=t.has(o.parentRegionId)?o.parentRegionId:null;e.has(a)||e.set(a,[]),e.get(a).push(o)}for(let o of e.values())o.sort((a,l)=>a.title.localeCompare(l.title,void 0,{numeric:!0,sensitivity:"base"}));let i=[],r=new Set,s=(o,a)=>{if(!r.has(o.id)){r.add(o.id),i.push({zone:o,depth:a});for(let l of e.get(o.id)||[])s(l,a+1)}};for(let o of e.get(null)||[])s(o,0);for(let o of n)s(o,0);return i}function nh(n){d.zonesVisible=n,I.zoneToggle.checked=n,d.layers.zones.setVisible(n),d.layers.zoneTitles.setVisible(n),d.layers.zoneTitleDetail.setVisible(n)}function m_(n){let t=d.zoneRecords.get(n);t&&(d.focusedZoneID=n,sg(),Vn(),d.engine.getView().fit(t.extent,{size:d.engine.getSize(),padding:[54,54,54,54],maxZoom:Hn(d.variant),duration:220}),I.sidebar.classList.remove("is-open"),I.mobileLegend.setAttribute("aria-expanded","false"))}function __(n){d.zoneRecords.has(n)&&(d.highlightedZones.has(n)?d.highlightedZones.delete(n):(d.highlightedZones.add(n),nh(!0)),d.hoveredPin=null,og(),ag(),sg(),d.layers.zones.changed(),d.layers.zoneTitles.changed(),d.layers.zoneTitleDetail.changed())}function sg(){I.zoneIndex.classList.toggle("has-highlights",d.highlightedZones.size>0);for(let n of I.zoneList.querySelectorAll("[data-zone]")){let t=Number(n.dataset.zone),e=d.highlightedZones.has(t);n.classList.toggle("is-highlighted",e),n.classList.toggle("is-current",d.focusedZoneID===t),n.setAttribute("aria-pressed",String(e))}}function x_(n){if(!n?.coordinates)return null;let t=([e,i])=>rh(i,e);return n.type==="Polygon"?new Ci(n.coordinates.map(e=>e.map(t))):n.type==="MultiPolygon"?new qd(n.coordinates.map(e=>e.map(i=>i.map(t)))):null}function rh(n,t){let e=d.catalog.tileGrid,i=2**e.sourceZoom,r=(t+180)/360*i,s=n*Math.PI/180,o=(1-Math.asinh(Math.tan(s))/Math.PI)/2*i;return[(r-e.firstTile)*e.tileSize,-(o-e.firstTile)*e.tileSize]}function Bn(){for(let n of d.pins){let t=d.hiddenCategories.has(n.category.id),e=d.search&&!n.location.title.toLocaleLowerCase().includes(d.search);n.filteredHidden=!!(t||e)}og(),ag(),d.selectedPin?.filteredHidden&&Vn()}function og(){if(!d.highlightedZones.size){for(let t of d.pins)t.insideHighlightedZone=!1;return}let n=[...d.highlightedZones].map(t=>d.zoneRecords.get(t)).filter(Boolean);for(let t of d.pins)t.insideHighlightedZone=n.some(e=>e.geometries.some(i=>y_(i,t.coordinate)))}function y_(n,t){if(n.intersectsCoordinate(t))return!0;let e=n.getClosestPoint(t),i=e[0]-t[0],r=e[1]-t[1];return i*i+r*r<=1}function ag(){d.eligibleLocations=d.pins.filter(n=>!Ke(n)).length,hn(),d.layers.pins.changed(),d.layers.zonePins.changed(),d.layers.pinLabels.changed(),d.layers.text.changed(),d.layers.zoneText.changed(),d.layers.textDetail.changed(),d.layers.priority.changed(),Oo()}function hn(){d.sources.priority.clear();for(let n of d.pins){if(Ke(n))continue;let t=!!d.search&&n.location.title.toLocaleLowerCase().includes(d.search);(n===d.selectedPin||n===d.hoveredPin||t||eh(n))&&d.sources.priority.addFeature(n.feature)}}function Io(n){d.hoveredPin!==n&&(d.hoveredPin=n,d.sources&&(hn(),d.layers.pins.changed(),d.layers.priority.changed()))}function lg(){if(!d.search){I.searchResults.hidden=!0,I.searchResults.replaceChildren();return}let n=d.pins.filter(e=>!d.hiddenCategories.has(e.category.id)&&e.location.title.toLocaleLowerCase().includes(d.search)).sort((e,i)=>e.location.title.localeCompare(i.location.title)).slice(0,20),t=document.createDocumentFragment();if(!n.length){let e=document.createElement("p");e.className="search-empty",e.textContent="No visible locations match.",t.append(e)}for(let e of n){let i=document.createElement("button");i.type="button",i.className="search-result",i.dataset.location=String(e.location.id),lh(i,e.category);let r=document.createElement("span");r.className="result-dot",ch(r,e.category,Do(e.category.title));let s=document.createElement("span"),o=document.createElement("strong");o.textContent=e.location.title;let a=document.createElement("small");a.textContent=`${e.category.title} \xB7 ${e.group.title}`,s.append(o,a),i.append(r,s),t.append(i)}I.searchResults.replaceChildren(t),I.searchResults.hidden=!1}function Vf(n){if(d.hiddenCategories.clear(),!n)for(let t of d.map.groups)for(let e of t.categories)d.hiddenCategories.add(e.id);sh(),Bn(),lg(),Br()}function sh(){for(let n of document.querySelectorAll("[data-category]"))n.checked=!d.hiddenCategories.has(Number(n.dataset.category))}function E_(n){let t=d.map.groups.find(i=>i.id===n);if(!t)return;let e=t.categories.some(i=>!d.hiddenCategories.has(i.id));for(let i of t.categories)e?d.hiddenCategories.add(i.id):d.hiddenCategories.delete(i.id);sh(),Bn(),Br()}function Br(){if(d.map)for(let n of d.map.groups){let t=I.legend.querySelector(`input[data-group="${n.id}"]`);t&&(t.checked=n.categories.some(e=>!d.hiddenCategories.has(e.id)))}}function jf(n){d.hiddenCategories.delete(n.category.id),d.search="",I.search.value="",I.searchResults.hidden=!0,sh(),Bn(),Br(),cg(n,!0)}function cg(n,t=!1){if(d.selectedPin=n,hn(),d.layers.pins.changed(),d.layers.pinLabels.changed(),d.layers.text.changed(),d.layers.textDetail.changed(),d.layers.priority.changed(),I.detailTitle.textContent=n.location.title,I.detailCategory.textContent=`${n.group.title} / ${n.category.title}`,I.detailDescription.textContent=G_(n.location.description)||"No description is included in the archive.",I.detailID.textContent=String(n.location.id),I.detailCoordinates.textContent=`${n.location.lat.toFixed(6)}, ${n.location.lng.toFixed(6)}`,w_(n),lh(I.detailDot,n.category),ch(I.detailDot,n.category,Do(n.category.title)),I.detail.hidden=!1,t){let e=d.engine.getView();e.animate({center:n.coordinate,zoom:Math.min(Hn(d.variant),Math.max(e.getZoom()||0,4)),duration:220})}}function w_(n){let t=(n.location.links||[]).filter(i=>d.pinByID.has(i.locationId));if(I.detailLinks.hidden=t.length===0,!t.length){I.detailLinks.replaceChildren();return}let e=document.createDocumentFragment();for(let i of t){let r=document.createElement("button");r.type="button",r.className="detail-link",r.dataset.location=String(i.locationId),r.textContent=i.title,e.append(r)}I.detailLinks.replaceChildren(e)}function Vn(){d.selectedPin=null,d.sources&&(hn(),d.layers.pins.changed(),d.layers.pinLabels.changed(),d.layers.text.changed(),d.layers.textDetail.changed(),d.layers.priority.changed()),I.detail.hidden=!0}function C_(){if(!d.engine||!d.variant)return;let n=d.engine.getView();n.fit(Ao(),{size:d.engine.getSize(),padding:[36,36,36,36],maxZoom:d.variant.maxZoom,duration:0}),d.fitZoom=n.getZoom()||0,Oo()}function To(n){let t=d.engine.getView(),e=t.getZoom()||0;t.animate({zoom:X_(e+n,d.variant.minZoom,Hn(d.variant)),duration:140})}function Oo(){let n=d.engine?.getView().getZoom();if(I.viewport.dataset.zoom=Number.isFinite(n)?n.toFixed(3):"",!d.engine||!d.pins.length){I.visibleCount.textContent="0 locations visible";return}let t=d.engine.getView().calculateExtent(d.engine.getSize()),e=0;for(let i of d.pins){if(Ke(i))continue;let[r,s]=i.coordinate;r>=t[0]&&r<=t[2]&&s>=t[1]&&s<=t[3]&&e++}I.visibleCount.textContent=`${cn(d.eligibleLocations)} enabled \xB7 ${cn(e)} in view`}function be(n,t){return(n.get("priority")||0)-(t.get("priority")||0)}function v_(n){let t=n.get("pin");return!t||Ke(t)||t.insideHighlightedZone||Vr(t)?null:oh(t,!1)}function b_(n){let t=n.get("pin");return!t||!d.highlightedZones.size||!t.insideHighlightedZone||Ke(t)||Vr(t)?null:oh(t,!1)}function R_(n){let t=n.get("pin");return!t||Ke(t)||!d.pinLabelsVisible||!jr()?null:hg(t)}function S_(n){let t=n.get("pin");if(!t||Ke(t)||t.insideHighlightedZone||Vr(t)||jr())return null;let e=d.fitZoom+Math.log2(z_(t.category));return(d.engine.getView().getZoom()||0)<e?null:ko(t,!1)}function T_(n){let t=n.get("pin");return!t||Ke(t)||t.insideHighlightedZone||Vr(t)||!jr()?null:ko(t,!1)}function I_(n){let t=n.get("pin");return!t||!d.highlightedZones.size||!t.insideHighlightedZone||Ke(t)||Vr(t)?null:ko(t,!1)}function L_(n){let t=n.get("pin");if(!t||Ke(t))return null;if(t.category.displayType==="text")return ko(t,t===d.selectedPin);let e=oh(t,t===d.selectedPin);return t===d.hoveredPin||t===d.selectedPin?[e,hg(t)]:e}function oh(n,t){let e=`marker:${n.category.id}:${t?1:0}`;if(d.styleCache.has(e))return d.styleCache.get(e);let i=n.category.color||jn(n.category.id),r=t?2e7:n.priority,s=d.markerIcons.get(ug(n.category)),o;return s?o=new Mt({image:new sn({src:s,width:t?36:31,height:t?36:31}),zIndex:r}):o=new Mt({text:new si({text:Do(n.category.title),font:`900 ${t?15:13}px Inter, sans-serif`,fill:new _t({color:i}),stroke:new At({color:ah(),width:t?4:3})}),zIndex:r}),d.styleCache.set(e,o),o}function hg(n){let t=`marker-label:${n.location.id}`;if(d.styleCache.has(t))return d.styleCache.get(t);let e=new Mt({text:new si({text:n.location.title,offsetY:21,font:'700 10px "Arial Narrow", "Roboto Condensed", sans-serif',fill:new _t({color:"#f4f6ed"}),stroke:new At({color:"rgba(0,0,0,0.98)",width:3}),backgroundFill:new _t({color:"rgba(10,13,9,0.72)"}),padding:[2,4,2,4],overflow:!0}),zIndex:n.priority});return d.styleCache.set(t,e),e}function A_(n){if(!n.iconAsset)return;let t=ug(n);if(d.markerIcons.has(t))return;d.markerIcons.set(t,null);let e=new Image;e.onload=()=>{let i=document.createElement("canvas");i.width=64,i.height=64;let r=i.getContext("2d"),s=n.color||jn(n.id),o=document.createElement("canvas");o.width=64,o.height=64;let a=o.getContext("2d");a.imageSmoothingEnabled=!n.iconPicture,a.drawImage(e,6,6,52,52),n.iconPicture||(a.globalCompositeOperation="source-in",a.fillStyle=s,a.fillRect(0,0,64,64));let l=document.createElement("canvas");l.width=64,l.height=64;let h=l.getContext("2d");h.drawImage(e,6,6,52,52),h.globalCompositeOperation="source-in",h.fillStyle=ah(),h.fillRect(0,0,64,64);for(let c=-3;c<=3;c++)for(let u=-3;u<=3;u++)u*u+c*c<=10&&r.drawImage(l,u,c);r.drawImage(o,0,0),d.markerIcons.set(t,i.toDataURL("image/png")),d.styleCache.delete(`marker:${n.id}:0`),d.styleCache.delete(`marker:${n.id}:1`),d.layers.pins.changed(),d.layers.zonePins.changed(),d.layers.priority.changed()},e.onerror=()=>d.markerIcons.set(t,!1),e.src=gg(n.iconAsset)}function ug(n){return`${n.iconAsset||""}:${n.color||jn(n.id)}:${d.map?.iconOutset||"light"}`}function ah(){return d.map?.iconOutset==="dark"?"rgba(7, 9, 7, 0.98)":"rgba(255, 255, 255, 0.96)"}function ko(n,t){let e=`text:${n.location.id}:${t?1:0}`;if(d.styleCache.has(e))return d.styleCache.get(e);let r=[new Mt({text:new si({text:n.location.title,font:`${t?"900":"800"} 14px "Arial Narrow", "Roboto Condensed", sans-serif`,fill:new _t({color:t?"#d6f36b":"#f3f5e9"}),stroke:new At({color:"rgba(0,0,0,0.95)",width:4}),backgroundFill:new _t({color:t?"rgba(17,21,14,0.9)":"rgba(10,13,9,0.58)"}),backgroundStroke:t?new At({color:"#d6f36b",width:1}):void 0,padding:[3,6,3,6],overflow:!0}),zIndex:t?2e7:n.priority+3e6})];return d.styleCache.set(e,r),r}function Hf(n){let t=n.get("gridCell");if(!t)return null;let e=`grid:${t.hash}:${t.role}:${t.contextDistance}`;if(d.styleCache.has(e))return d.styleCache.get(e);let i=Lo[Math.max(0,Di.indexOf(t.hash[t.hash.length-1]))%Lo.length],r=t.role==="leaf",s=t.role==="neighbor",o=new Mt({fill:new _t({color:s?`rgba(3, 5, 3, ${Math.min(.52,.3+t.contextDistance*.06)})`:ki(i,r?.14:.055)}),stroke:new At({color:r?"#ffffff":ki(i,s?.44:.82),width:r?2.5:s?1:1.4}),text:new si({text:t.hash,font:`${r?"900 17px":s?"750 11px":"800 13px"} "Arial Narrow", "Roboto Condensed", sans-serif`,fill:new _t({color:r?"#ffffff":s?ki(i,.72):i}),stroke:new At({color:"rgba(0,0,0,0.96)",width:4}),backgroundFill:new _t({color:s?"rgba(4,6,4,0.88)":"rgba(9,12,8,0.76)"}),padding:s?[2,4,2,4]:[3,5,3,5],overflow:!0}),zIndex:r?100:n.get("priority")});return d.styleCache.set(e,o),o}function M_(n){if(!d.zonesVisible)return null;let t=n.get("zone"),e=n.get("child"),i=d.highlightedZones.has(t.id),r=fg(t.id),s=`zone:${t.id}:${e?1:0}:${i?1:r?2:0}`;if(d.styleCache.has(s))return d.styleCache.get(s);let o=n.get("color");if(r){let h=new Mt({fill:new _t({color:`rgba(3, 5, 3, ${e?.38:.32})`}),stroke:new At({color:ki(o,e?.24:.32),width:e?1:1.3,lineDash:e?[3,4]:[7,5]}),zIndex:e?101:100});return d.styleCache.set(s,h),h}let a=new Mt({fill:new _t({color:ki(o,e?.035:.07)}),stroke:new At({color:ki(o,e?.5:.72),width:e?1.2:1.8,lineDash:e?[3,4]:[7,5]})});if(!i)return d.styleCache.set(s,a),a;let l=[new Mt({stroke:new At({color:"rgba(255,255,255,0.94)",width:5}),zIndex:9e3}),new Mt({fill:new _t({color:ki(o,.22)}),stroke:new At({color:o,width:2.6}),zIndex:9001})];return d.styleCache.set(s,l),l}function P_(n){if(!d.zonesVisible||jr())return null;let t=n.get("child"),e=d.highlightedZones.has(n.get("zone").id),i=d.engine.getView().getZoom()||0;if(!e&&t&&i<d.fitZoom+3)return null;let r=n.get("span")/d.engine.getView().getResolution();return!e&&d.zoneTitleCount>40&&r<52?null:dg(n)}function O_(n){return!d.zonesVisible||!jr()?null:dg(n)}function dg(n){let t=n.get("child"),e=n.get("zone"),i=d.highlightedZones.has(e.id),r=fg(e.id),s=`zone-title:${e.id}:${t?1:0}:${i?1:r?2:0}`;if(d.styleCache.has(s))return d.styleCache.get(s);let o=n.get("color"),a=new Mt({text:new si({text:e.title.toLocaleUpperCase(),font:`${t?"700 12px":"800 14px"} "Arial Narrow", "Roboto Condensed", sans-serif`,fill:new _t({color:i?"#11140f":r?"rgba(185,192,177,0.56)":t?"#c7ccbd":"#f1f4e7"}),stroke:new At({color:i?"rgba(255,255,255,0.96)":r?"rgba(0,0,0,0.82)":"rgba(0,0,0,0.95)",width:i?2:r?3:4}),backgroundFill:new _t({color:i?o:r?"rgba(4,6,4,0.84)":"rgba(11,14,10,0.72)"}),backgroundStroke:new At({color:i?"#ffffff":ki(o,r?.24:.55),width:i?2:1}),padding:[5,8,5,8],overflow:!0}),zIndex:i?91e5:n.get("priority")});return d.styleCache.set(s,a),a}function fg(n){if(!d.highlightedZones.size||d.highlightedZones.has(n))return!1;for(let t of d.highlightedZones)if(k_(n,t))return!1;return!0}function k_(n,t){let e=new Set,i=d.zoneRecords.get(t)?.zone.parentRegionId;for(;i!=null&&!e.has(i);){if(i===n)return!0;e.add(i),i=d.zoneRecords.get(i)?.zone.parentRegionId}return!1}function Vr(n){return n===d.selectedPin||n===d.hoveredPin||eh(n)||!!d.search&&n.location.title.toLocaleLowerCase().includes(d.search)}function Ke(n){return n.filteredHidden||D_(n)}function D_(n){return!d.highlightedZones.size||n.insideHighlightedZone||n===d.selectedPin?!1:!(d.search&&n.location.title.toLocaleLowerCase().includes(d.search))}function F_(n,t){return Math.max(0,1e6-Math.min(n.locations.length,999)*1e3)+N_(t.id)%1e3}function z_(n){return n.locations.length>200?4:n.locations.length>75?2.5:1}function jr(){return(d.engine?.getView().getZoom()||0)>=(d.variant?.maxZoom||0)-.05}function N_(n){return Math.imul(Number(n)||0,2654435761)>>>0}function jn(n){let t=Math.abs(Number(n)||0);return Lo[(Math.imul(t,2654435761)>>>0)%Lo.length]}function ki(n,t){let e=String(n||"#ffffff").replace("#",""),i=e.length===3?e.split("").map(s=>s+s).join(""):e.slice(0,6).padEnd(6,"f"),r=Number.parseInt(i,16);return`rgba(${r>>16&255}, ${r>>8&255}, ${r&255}, ${t})`}function lh(n,t){n.style.setProperty("--pin-color",t.color||jn(t.id))}function ch(n,t,e){if(n.classList.remove("has-source-icon"),n.style.removeProperty("--pin-icon"),n.textContent="",!t.iconAsset){n.textContent=e;return}n.style.setProperty("--pin-icon",`url("${gg(t.iconAsset)}")`),n.classList.add("has-source-icon")}function gg(n){return`/static/icons/${n.split("/").map(e=>encodeURIComponent(e)).join("/")}`}function Do(n){return n.split(/\s+/).slice(0,2).map(t=>t[0]||"").join("")}function G_(n){return String(n||"").replace(/\[([^\]]+)\]\([^)]+\)/g,"$1").replace(/[*_`>#]/g,"").replace(/\r/g,"").replace(/\n{3,}/g,`7+`);this.generateTileUrlFunction_?this.setTileUrlFunction(Wf(t,this.tileGrid),e):this.setKey(e)}tileUrlFunction(t,e,i){}},Uf=jc;var Hc=class extends Uf{constructor(t){super({attributions:t.attributions,cacheSize:t.cacheSize,projection:t.projection,state:t.state,tileGrid:t.tileGrid,tileLoadFunction:t.tileLoadFunction?t.tileLoadFunction:t_,tilePixelRatio:t.tilePixelRatio,tileUrlFunction:t.tileUrlFunction,url:t.url,urls:t.urls,wrapX:t.wrapX,transition:t.transition,interpolate:t.interpolate!==void 0?t.interpolate:!0,key:t.key,attributionsCollapsible:t.attributionsCollapsible,zDirection:t.zDirection}),this.crossOrigin=t.crossOrigin!==void 0?t.crossOrigin:null,this.referrerPolicy=t.referrerPolicy,this.tileClass=t.tileClass!==void 0?t.tileClass:fo,this.tileGridForProjection={},this.reprojectionErrorThreshold_=t.reprojectionErrorThreshold,this.renderReprojectionEdges_=!1}getGutterForProjection(t){return this.getProjection()&&t&&!Tn(this.getProjection(),t)?0:this.getGutter()}getGutter(){return 0}getKey(){let t=super.getKey();return this.getInterpolate()||(t+=":disable-interpolation"),t}getTileGridForProjection(t){let e=this.getProjection();if(this.tileGrid&&(!e||Tn(e,t)))return this.tileGrid;let i=Y(t);return i in this.tileGridForProjection||(this.tileGridForProjection[i]=vo(t)),this.tileGridForProjection[i]}createTile_(t,e,i,r,s,o){let a=[t,e,i],l=this.getTileCoordForTileUrlFunction(a,s),h=l?this.tileUrlFunction(l,r,s):void 0,c=new this.tileClass(a,h!==void 0?k.IDLE:k.EMPTY,h!==void 0?h:"",{crossOrigin:this.crossOrigin,referrerPolicy:this.referrerPolicy},this.tileLoadFunction,this.tileOptions);return c.key=o,c.addEventListener(P.CHANGE,this.handleTileChange.bind(this)),c}getTile(t,e,i,r,s,o){let a=this.getProjection();if(!a||!s||Tn(a,s))return this.getTileInternal(t,e,i,r,a||s);let l=[t,e,i],h=this.getKey(),c=this.getTileGridForProjection(a),u=this.getTileGridForProjection(s),f=this.getTileCoordForTileUrlFunction(l,s),g=new mo(a,c,s,u,l,f,this.getTilePixelRatio(r),this.getGutter(),(p,_,m,x)=>this.getTileInternal(p,_,m,x,a,o),this.reprojectionErrorThreshold_,this.renderReprojectionEdges_,this.tileOptions);return g.key=h,g}getTileInternal(t,e,i,r,s,o){let a=this.getKey(),l=Yn(this,a,t,e,i);if(o&&o.containsKey(l))return o.get(l);let h=this.createTile_(t,e,i,r,s,a);return o?.set(l,h),h}setRenderReprojectionEdges(t){this.renderReprojectionEdges_!=t&&(this.renderReprojectionEdges_=t,this.changed())}setTileGridForProjection(t,e){let i=Et(t);if(i){let r=Y(i);r in this.tileGridForProjection||(this.tileGridForProjection[r]=e)}}};function t_(n,t){if(bt){let e=n.getCrossOrigin(),i="same-origin",r="same-origin";e==="anonymous"||e===""?(i="cors",r="omit"):e==="use-credentials"&&(i="cors",r="include");let s={mode:i,credentials:r,referrerPolicy:n.getReferrerPolicy()};fetch(t,s).then(o=>{if(!o.ok)throw new Error(`HTTP ${o.status}`);return o.blob()}).then(o=>createImageBitmap(o)).then(o=>{let a=n.getImage();a.width=o.width,a.height=o.height,a.getContext("2d").drawImage(o,0,0),o.close?.(),a.dispatchEvent(new Event("load"))}).catch(()=>{n.getImage().dispatchEvent(new Event("error"))});return}n.getImage().src=t}var Kf=Hc;var qc=class extends Kf{constructor(t){t=t||{};let e=t.projection!==void 0?t.projection:"EPSG:3857",i=t.tileGrid!==void 0?t.tileGrid:zf({extent:bo(e),maxResolution:t.maxResolution,maxZoom:t.maxZoom,minZoom:t.minZoom,tileSize:t.tileSize});super({attributions:t.attributions,cacheSize:t.cacheSize,crossOrigin:t.crossOrigin,referrerPolicy:t.referrerPolicy,interpolate:t.interpolate,projection:e,reprojectionErrorThreshold:t.reprojectionErrorThreshold,tileGrid:i,tileLoadFunction:t.tileLoadFunction,tilePixelRatio:t.tilePixelRatio,tileUrlFunction:t.tileUrlFunction,url:t.url,urls:t.urls,wrapX:t.wrapX!==void 0?t.wrapX:!0,transition:t.transition,attributionsCollapsible:t.attributionsCollapsible,zDirection:t.zDirection}),this.gutter_=t.gutter!==void 0?t.gutter:0}getGutter(){return this.gutter_}},Zf=qc;var q=n=>document.querySelector(n),I={game:q("#game-select"),map:q("#map-select"),variant:q("#variant-select"),variantField:q("#variant-field"),gameTitle:q("#game-title"),title:q("#map-title"),meta:q("#map-meta"),legend:q("#legend"),search:q("#pin-search"),searchResults:q("#search-results"),visibleCount:q("#visible-count"),viewport:q("#map"),layers:q("#layers"),zoneToggle:q("#zone-toggle"),zoneCount:q("#zone-count"),zoneIndex:q("#zone-index"),zoneList:q("#zone-list"),loading:q("#map-loading"),labelsHint:q("#labels-hint"),gridHint:q("#grid-hint"),gridNavigator:q("#grid-navigator"),gridInput:q("#grid-input"),gridBack:q("#grid-back"),detail:q("#pin-detail"),detailTitle:q("#detail-title"),detailCategory:q("#detail-category"),detailDescription:q("#detail-description"),detailID:q("#detail-id"),detailCoordinates:q("#detail-coordinates"),detailLinks:q("#detail-links"),detailDot:q("#detail-dot"),sidebar:q("#sidebar"),mobileLegend:q("#mobile-legend"),fatal:q("#fatal-error"),fatalMessage:q("#fatal-message")},Lo=["#d6f36b","#72d5f4","#ff9e64","#df83ff","#62e6ae","#ff6f91","#f4d35e","#8aa9ff","#e7a56d","#83d483"],Di="0123456789bcdefghjkmnpqrstuvwxyz",e_=3,i_=2,d={catalog:null,game:null,map:null,variant:null,engine:null,projection:null,layers:null,sources:null,hiddenCategories:new Set,collapsedSections:new Set,pins:[],pinByID:new Map,selectedPin:null,hoveredPin:null,pinLabelsVisible:!1,gridEnabled:!1,gridPrefix:"",zonesVisible:!0,zoneRecords:new Map,highlightedZones:new Set,focusedZoneID:null,search:"",fitZoom:0,zoneTitleCount:0,eligibleLocations:0,tileRun:0,tileStats:{requested:0,loaded:0,errors:0,peakPending:0},styleCache:new Map,markerIcons:new Map};async function n_(){s_();try{let n=await fetch("/static/catalog.json");if(!n.ok)throw new Error(`catalog request returned ${n.status}`);if(d.catalog=await n.json(),!d.catalog.games.length)throw new Error("the embedded catalog contains no maps");r_(),ih(I.game,d.catalog.games,"title"),Jf(d.catalog.games[0].slug),W_(),requestAnimationFrame(()=>I.viewport.focus({preventScroll:!0}))}catch(n){I.loading.hidden=!0,I.fatalMessage.textContent=n instanceof Error?n.message:String(n),I.fatal.hidden=!1}}function r_(){let n=d.catalog.tileGrid.size,t=[0,-n,n,0];d.projection=new mi({code:"ATLAS:PIXELS",units:"pixels",extent:t}),d.sources={grid:new Pi({wrapX:!1}),gridContext:new Pi({wrapX:!1}),zones:new Pi({wrapX:!1}),zoneTitles:new Pi({wrapX:!1}),text:new Pi({wrapX:!1}),pins:new Pi({wrapX:!1}),priority:new Pi({wrapX:!1})},d.layers={raster:new mc({zIndex:0}),rasterDetail:new mc({zIndex:1}),grid:new ee({source:d.sources.grid,style:Hf,renderOrder:be,renderBuffer:40,zIndex:5}),zones:new ee({source:d.sources.zones,style:M_,renderBuffer:32,zIndex:10}),zoneTitles:new ee({source:d.sources.zoneTitles,style:P_,renderOrder:be,renderBuffer:160,zIndex:20}),zoneTitleDetail:new ee({source:d.sources.zoneTitles,style:O_,renderOrder:be,renderBuffer:160,zIndex:44}),text:new ee({source:d.sources.text,style:S_,renderOrder:be,renderBuffer:220,zIndex:30}),textDetail:new ee({source:d.sources.text,style:T_,renderOrder:be,renderBuffer:220,zIndex:45}),zoneText:new ee({source:d.sources.text,style:I_,renderOrder:be,renderBuffer:220,zIndex:41}),pins:new ee({source:d.sources.pins,style:v_,renderOrder:be,renderBuffer:48,zIndex:40}),zonePins:new ee({source:d.sources.pins,style:b_,renderOrder:be,renderBuffer:48,zIndex:42}),pinLabels:new ee({source:d.sources.pins,style:R_,renderOrder:be,renderBuffer:180,zIndex:45}),gridContext:new ee({source:d.sources.gridContext,style:Hf,renderOrder:be,renderBuffer:40,zIndex:48}),priority:new ee({source:d.sources.priority,style:L_,renderOrder:be,renderBuffer:220,zIndex:50})},d.engine=new jd({target:I.viewport,layers:Object.values(d.layers),controls:Os({attribution:!1,rotate:!1,zoom:!1}),interactions:Gs({onFocusOnly:!1}),view:$f(5)}),d.engine.on("movestart",()=>{d.engine.getViewport().classList.add("is-dragging")}),d.engine.on("moveend",()=>{d.engine.getViewport().classList.remove("is-dragging"),Oo()}),I.viewport.addEventListener("wheel",()=>{document.activeElement!==I.viewport&&I.viewport.focus({preventScroll:!0})},{capture:!0,passive:!0}),d.engine.on("singleclick",e=>{if(d.gridEnabled){let r=d.engine.forEachFeatureAtPixel(e.pixel,s=>s.get("gridCell")||null,{hitTolerance:1,layerFilter:s=>s===d.layers.grid||s===d.layers.gridContext});if(r&&r.role!=="leaf"){Jc(r.hash);return}}let i=d.engine.forEachFeatureAtPixel(e.pixel,(r,s)=>s!==d.layers.pins&&s!==d.layers.pinLabels&&s!==d.layers.text&&s!==d.layers.textDetail&&s!==d.layers.priority?null:r.get("pin")||null,{hitTolerance:5});i&&cg(i)}),d.engine.on("pointermove",e=>{if(e.dragging){Io(null);return}let i=d.engine.forEachFeatureAtPixel(e.pixel,(o,a)=>a!==d.layers.pins&&a!==d.layers.pinLabels&&a!==d.layers.text&&a!==d.layers.textDetail&&a!==d.layers.priority?null:o.get("pin")||null,{hitTolerance:4,layerFilter:o=>o===d.layers.pins||o===d.layers.pinLabels||o===d.layers.text||o===d.layers.textDetail||o===d.layers.priority}),r=i?.category.displayType==="text"?null:i;Io(r||null);let s=d.gridEnabled&&d.engine.hasFeatureAtPixel(e.pixel,{layerFilter:o=>o===d.layers.grid||o===d.layers.gridContext});d.engine.getTargetElement().style.cursor=i||s?"pointer":""}),d.engine.getViewport().addEventListener("pointerleave",()=>Io(null))}function $f(n){let t=d.catalog.tileGrid.size;return new Qt({projection:d.projection,center:[t/2,-t/2],resolutions:eg(n),minZoom:0,maxZoom:n,extent:[0,-t,t,0],constrainResolution:!1,smoothResolutionConstraint:!1,showFullExtent:!0,zoom:0})}function s_(){I.game.addEventListener("change",()=>Jf(I.game.value)),I.map.addEventListener("change",()=>Qf(Number(I.map.value))),I.variant.addEventListener("change",()=>tg(Number(I.variant.value))),I.legend.addEventListener("change",n=>{let t=n.target;if(t.dataset.group){E_(Number(t.dataset.group));return}if(!t.dataset.category)return;let e=Number(t.dataset.category);t.checked?d.hiddenCategories.delete(e):d.hiddenCategories.add(e),Bn(),Br()}),I.layers.addEventListener("click",n=>{let t=n.target.closest("[data-section]");if(!t)return;let e=t.dataset.section;d.collapsedSections.has(e)?d.collapsedSections.delete(e):d.collapsedSections.add(e),rg()}),q("#show-all").addEventListener("click",()=>Vf(!0)),q("#hide-all").addEventListener("click",()=>Vf(!1)),I.zoneToggle.addEventListener("change",()=>{nh(I.zoneToggle.checked)}),I.zoneIndex.addEventListener("click",n=>{let t=n.target.closest("[data-zone]");t&&m_(Number(t.dataset.zone))}),I.zoneIndex.addEventListener("contextmenu",n=>{let t=n.target.closest("[data-zone]");t&&(n.preventDefault(),__(Number(t.dataset.zone)))}),I.search.addEventListener("input",()=>{d.search=I.search.value.trim().toLocaleLowerCase(),Bn(),lg()}),I.searchResults.addEventListener("click",n=>{let t=n.target.closest("[data-location]");if(!t)return;let e=d.pinByID.get(Number(t.dataset.location));e&&jf(e)}),I.detailLinks.addEventListener("click",n=>{let t=n.target.closest("[data-location]");if(!t)return;let e=d.pinByID.get(Number(t.dataset.location));e&&jf(e)}),q("#close-detail").addEventListener("click",Vn),q("#zoom-in").addEventListener("click",()=>To(1)),q("#zoom-out").addEventListener("click",()=>To(-1)),I.gridBack.addEventListener("click",ng),I.gridInput.addEventListener("input",()=>{let n=Po(),t=[...I.gridInput.value.toLocaleLowerCase()].filter(e=>Di.includes(e)).slice(0,n).join("");I.gridInput.value=t,Jc(t)}),I.viewport.addEventListener("keydown",n=>{if(!qf(n.target)){if(n.key==="+"||n.key==="=")To(1);else if(n.key==="-")To(-1);else if(n.key==="Escape")Vn();else return;n.preventDefault()}}),window.addEventListener("keydown",n=>{if(!qf(n.target)){if((n.metaKey||n.ctrlKey)&&n.key.toLocaleLowerCase()==="k"){n.preventDefault(),I.search.focus(),I.search.select();return}a_(n)||n.key.toLocaleLowerCase()==="z"&&(n.preventDefault(),d.pinLabelsVisible=!d.pinLabelsVisible,I.labelsHint.textContent=`Z \xB7 labels ${d.pinLabelsVisible?"on":"off"}`,d.layers.pinLabels.changed())}}),window.addEventListener("resize",()=>d.engine?.updateSize()),I.mobileLegend.addEventListener("click",()=>{let n=I.sidebar.classList.toggle("is-open");I.mobileLegend.setAttribute("aria-expanded",String(n))})}function Jf(n){d.game=d.catalog.games.find(t=>t.slug===n)||d.catalog.games[0],I.game.value=d.game.slug,ih(I.map,d.game.maps,"title","id"),I.map.disabled=d.game.maps.length===1,I.map.title=I.map.disabled?"This game has one map":"Choose a map",Qf(d.game.maps[0].id)}function Qf(n){d.map=d.game.maps.find(t=>t.id===n)||d.game.maps[0],document.documentElement.style.setProperty("--icon-outset-color",ah()),I.map.value=String(d.map.id),ih(I.variant,d.map.variants,"name"),I.variantField.hidden=d.map.variants.length<2,d.styleCache.clear(),Io(null),d.gridPrefix="",d.hiddenCategories.clear(),d.collapsedSections.clear(),d.collapsedSections.add("zones");for(let t of d.map.groups)for(let e of t.categories)e.visible||d.hiddenCategories.add(e.id);d.search="",I.search.value="",I.searchResults.hidden=!0,Vn(),c_(),f_(),d_(),tg(0,!0),I.gameTitle.textContent=d.game.title,I.title.textContent=d.map.title,I.meta.textContent=`${cn(d.map.pinCount)} locations \xB7 ${cn(d.map.zones?.length||0)} regions`,I.sidebar.classList.remove("is-open"),I.mobileLegend.setAttribute("aria-expanded","false")}function tg(n,t=!1){d.variant=d.map.variants[n]||d.map.variants[0];let e=d.variant,i=Hn(e);I.variant.value=String(d.map.variants.indexOf(d.variant)),t?d.engine.setView($f(i)):(d.engine.getView().setMinZoom(e.minZoom),d.engine.getView().setMaxZoom(i));let r=++d.tileRun,s=0;d.tileStats={requested:0,loaded:0,errors:0,peakPending:0},I.loading.hidden=!1;let o=f=>{f.on("tileloadstart",()=>{d.tileRun===r&&(s++,d.tileStats.requested++,d.tileStats.peakPending=Math.max(d.tileStats.peakPending,s))});let g=p=>{d.tileRun===r&&(s=Math.max(0,s-1),p?d.tileStats.errors++:d.tileStats.loaded++,s===0&&d.tileStats.loaded>0&&(I.loading.hidden=!0))};return f.on("tileloadend",()=>g(!1)),f.on("tileloaderror",()=>g(!0)),f},a=(f,g)=>o(new Zf({projection:d.projection,tileGrid:new Zr({extent:[0,-d.catalog.tileGrid.size,d.catalog.tileGrid.size,0],origin:[0,0],resolutions:eg(f),tileSize:d.catalog.tileGrid.tileSize}),cacheSize:64,interpolate:e.interpolate,transition:0,wrapX:!1,tileUrlFunction:([p,_,m])=>{let x=e.formats[p];if(!(!x||_<0||m<0||!g(p,_,m)))return`/static/tiles/${encodeURIComponent(e.tiles)}/${p}/${_}/${m}.${x}`}})),l=e.fullZoom??e.maxZoom,h=a(l,(f,g,p)=>Bf(e,f,g,p)),c=d.layers.raster.getSource();d.layers.raster.setSource(h),d.layers.raster.setExtent(Ao()),d.layers.raster.setBackground(e.background||void 0),c?.clear();let u=d.layers.rasterDetail.getSource();e.maxZoom>l?(d.layers.rasterDetail.setSource(a(e.maxZoom,(f,g,p)=>f>l&&Bf(e,f,g,p))),d.layers.rasterDetail.setExtent(Ao()),d.layers.rasterDetail.setVisible(!0)):d.layers.rasterDetail.setVisible(!1),u?.clear(),Qc(),d.gridEnabled&&(hn(),d.layers.pins.changed(),d.layers.text.changed(),d.layers.priority.changed()),t?requestAnimationFrame(C_):Oo()}function Bf(n,t,e,i){let r=n.coverage?.[t];if(!r)return!0;let s=e-r.x,o=i-r.y;if(s<0||o<0||s>=r.w||o>=r.h)return!1;let a=o_(n,t,r),l=o*r.w+s;return(a[l>>3]&1<<(l&7))!==0}function o_(n,t,e){if(!e.decoded){let i=atob(e.bits),r=new Uint8Array(i.length);for(let s=0;s<i.length;s++)r[s]=i.charCodeAt(s);e.decoded=r}return e.decoded}function eg(n){let t=d.catalog.tileGrid.size/d.catalog.tileGrid.tileSize;return Array.from({length:n+1},(e,i)=>t/2**i)}function Hn(n){return n.maxZoom+i_}function Ao(){let n=d.catalog.tileGrid.size,t=d.variant?.bounds||{x:0,y:0,width:n,height:n};return[t.x,-(t.y+t.height),t.x+t.width,-t.y]}function a_(n){return n.key.toLocaleLowerCase()==="g"?(n.preventDefault(),ig(),!0):n.key==="Escape"&&d.gridEnabled?(n.preventDefault(),ng(),!0):!1}function ig(n=!d.gridEnabled){d.gridEnabled=n,Qc(),hn(),d.layers.pins.changed(),d.layers.text.changed(),d.layers.priority.changed()}function Jc(n){let t=Po(),e=[...n.toLocaleLowerCase()].filter(r=>Di.includes(r)).slice(0,t).join(""),i=e!==d.gridPrefix;d.gridPrefix=e,d.gridEnabled||(d.gridEnabled=!0),Qc(),hn(),d.layers.pins.changed(),d.layers.text.changed(),d.layers.priority.changed(),i&&(Vn(),d.engine.getView().fit(Mo(),{size:d.engine.getSize(),padding:[52,52,52,52],maxZoom:Hn(d.variant),duration:180}))}function ng(){if(d.gridEnabled){if(!d.gridPrefix){ig(!1);return}Jc(d.gridPrefix.slice(0,-1))}}function Qc(){if(!d.sources||(d.sources.grid.clear(),d.sources.gridContext.clear(),I.gridNavigator.hidden=!d.gridEnabled,I.gridHint.textContent=d.gridEnabled?`G \xB7 ${d.gridPrefix||"root"}`:"G \xB7 grid off",!d.gridEnabled||!d.variant))return;let n=Po();if(I.gridInput.maxLength=n,I.gridInput.value=d.gridPrefix,I.gridBack.title=d.gridPrefix?"Back one geohash level":"Close geohash grid",l_(),d.gridPrefix.length>=n){$c(d.gridPrefix,Mo(),"leaf");return}for(let t of Di){let e=d.gridPrefix+t;$c(e,th(e),"child")}}function l_(){for(let n=0;n<d.gridPrefix.length;n++){let t=d.gridPrefix.slice(0,n),e=d.gridPrefix.slice(0,n+1);for(let i of Di){let r=t+i;r!==e&&$c(r,th(r),"neighbor",d.gridPrefix.length-n)}}}function $c(n,t,e,i=0){let[r,s,o,a]=t,l=d.pins.filter(u=>{if(u.filteredHidden)return!1;let[f,g]=u.coordinate;return f>=r&&f<=o&&g>=s&&g<=a}).length,h=new sr({geometry:new Ci([[[r,s],[r,a],[o,a],[o,s],[r,s]]]),gridCell:{hash:n,extent:t,role:e,count:l,contextDistance:i},priority:e==="neighbor"?-i*100+Di.indexOf(n[n.length-1]):Di.indexOf(n[n.length-1])});(e==="neighbor"?d.sources.gridContext:d.sources.grid).addFeature(h)}function Mo(){return th(d.gridPrefix)}function th(n){let t=[...Ao()],e=!0;for(let i of n){let r=Di.indexOf(i);if(!(r<0))for(let s of[16,8,4,2,1]){if(e){let o=(t[0]+t[2])/2;r&s?t[0]=o:t[2]=o}else{let o=(t[1]+t[3])/2;r&s?t[1]=o:t[3]=o}e=!e}}return t}function Po(){return e_}function eh(n){if(!d.gridEnabled||!d.gridPrefix)return!1;let t=Mo(),[e,i]=n.coordinate;return e>=t[0]&&e<=t[2]&&i>=t[1]&&i<=t[3]}function ih(n,t,e,i){n.replaceChildren(),t.forEach((r,s)=>{let o=document.createElement("option");o.value=i?String(r[i]):r.slug||String(s),o.textContent=r[e],n.append(o)})}function c_(){let n=document.createDocumentFragment();for(let t of d.map.groups){if(!t.categories.length)continue;let e=document.createElement("section");e.className="layer-section",e.dataset.groupSection=String(t.id);let i=t.categories.reduce((s,o)=>s+o.locations.length,0);e.append(h_(`group-${t.id}`,t.title,i,t.id));let r=document.createElement("div");r.className="category-toggles";for(let s of t.categories)r.append(u_(s));e.append(r),n.append(e)}I.legend.replaceChildren(n),rg(),Br()}function h_(n,t,e,i){let r=document.createElement("div");r.className="layer-header";let s=document.createElement("button");s.type="button",s.className="layer-title",s.dataset.section=n;let o=document.createElement("span");o.className="layer-chevron",o.setAttribute("aria-hidden","true"),o.innerHTML='<svg viewBox="0 0 24 24"><path d="m9 6 6 6-6 6"/></svg>';let a=document.createElement("span");a.textContent=t;let l=document.createElement("span");l.className="layer-count",l.textContent=cn(e),s.append(o,a,l);let h=document.createElement("label");h.className="layer-switch";let c=document.createElement("input");c.type="checkbox",c.dataset.group=String(i),c.setAttribute("aria-label",`Show ${t}`);let u=document.createElement("span");return u.setAttribute("aria-hidden","true"),h.append(c,u),r.append(s,h),r}function u_(n){let t=n.displayType==="text",e=document.createElement("label");e.className="category-toggle",lh(e,n);let i=document.createElement("input");i.type="checkbox",i.dataset.category=String(n.id),i.checked=!d.hiddenCategories.has(n.id);let r=document.createElement("span");t?(r.className="text-symbol",r.textContent="Tt",r.title="Drawn as a text label"):(r.className="category-icon",ch(r,n,Do(n.title)),r.title=n.icon||n.title);let s=document.createElement("span");s.className="category-name",s.textContent=n.title;let o=document.createElement("span");return o.className="category-count",o.textContent=cn(n.locations.length),e.append(i,r,s,o),e}function rg(){for(let n of I.layers.querySelectorAll("[data-section]")){let t=d.collapsedSections.has(n.dataset.section);n.setAttribute("aria-expanded",String(!t)),n.closest(".layer-section").classList.toggle("is-collapsed",t)}}function d_(){d.sources.pins.clear(),d.sources.text.clear(),d.sources.priority.clear(),d.pins=[],d.pinByID.clear();for(let n of d.map.groups)for(let t of n.categories){t.displayType!=="text"&&A_(t);for(let e of t.locations){let i={location:e,category:t,group:n,coordinate:rh(e.lat,e.lng),filteredHidden:!1,priority:F_(t,e),feature:null};i.feature=new sr({geometry:new wi(i.coordinate),pin:i,priority:i.priority}),d.pins.push(i),d.pinByID.set(e.id,i),t.displayType==="text"?d.sources.text.addFeature(i.feature):d.sources.pins.addFeature(i.feature)}}Bn()}function f_(){let n=d.map.zones||[];d.sources.zones.clear(),d.sources.zoneTitles.clear(),d.zoneRecords.clear(),d.highlightedZones.clear(),d.focusedZoneID=null,d.zoneTitleCount=0,nh(!0),I.zoneIndex.hidden=n.length===0,I.zoneCount.textContent=cn(n.length);for(let t of n){let e=ut(),i=[],r=!1;for(let l of t.features||[]){let h=x_(l);h&&(r=!0,i.push(h),hs(e,h.getExtent()),d.sources.zones.addFeature(new sr({geometry:h,zone:t,color:jn(t.id),child:t.parentRegionId!=null})))}if(!r)continue;let s=jn(t.id),o=t.center?rh(t.center.lat,t.center.lng):Bt(e),a=Math.max(e[2]-e[0],e[3]-e[1]);d.sources.zoneTitles.addFeature(new sr({geometry:new wi(o),zone:t,color:s,child:t.parentRegionId!=null,span:a,priority:(t.parentRegionId==null?2e6:1e6)+Math.round(a)})),d.zoneRecords.set(t.id,{zone:t,extent:e.slice(),geometries:i,color:s})}d.zoneTitleCount=d.sources.zoneTitles.getFeatures().length,g_()}function g_(){let n=document.createDocumentFragment();for(let{zone:t,depth:e}of p_()){let i=d.zoneRecords.get(t.id);if(!i)continue;let r=document.createElement("button");r.type="button",r.className="zone-index-item",r.dataset.zone=String(t.id),r.style.setProperty("--zone-color",i.color),r.style.setProperty("--zone-depth",String(e)),r.setAttribute("aria-pressed","false"),r.title=`${t.title}: click to jump; right-click to toggle highlight`;let s=document.createElement("span");s.className="zone-index-marker",s.setAttribute("aria-hidden","true");let o=document.createElement("span");o.textContent=t.title,r.append(s,o),n.append(r)}I.zoneList.replaceChildren(n),I.zoneIndex.hidden=d.zoneRecords.size===0}function p_(){let n=[...d.zoneRecords.values()].map(o=>o.zone),t=new Set(n.map(o=>o.id)),e=new Map;for(let o of n){let a=t.has(o.parentRegionId)?o.parentRegionId:null;e.has(a)||e.set(a,[]),e.get(a).push(o)}for(let o of e.values())o.sort((a,l)=>a.title.localeCompare(l.title,void 0,{numeric:!0,sensitivity:"base"}));let i=[],r=new Set,s=(o,a)=>{if(!r.has(o.id)){r.add(o.id),i.push({zone:o,depth:a});for(let l of e.get(o.id)||[])s(l,a+1)}};for(let o of e.get(null)||[])s(o,0);for(let o of n)s(o,0);return i}function nh(n){d.zonesVisible=n,I.zoneToggle.checked=n,d.layers.zones.setVisible(n),d.layers.zoneTitles.setVisible(n),d.layers.zoneTitleDetail.setVisible(n)}function m_(n){let t=d.zoneRecords.get(n);t&&(d.focusedZoneID=n,sg(),Vn(),d.engine.getView().fit(t.extent,{size:d.engine.getSize(),padding:[54,54,54,54],maxZoom:Hn(d.variant),duration:220}),I.sidebar.classList.remove("is-open"),I.mobileLegend.setAttribute("aria-expanded","false"))}function __(n){d.zoneRecords.has(n)&&(d.highlightedZones.has(n)?d.highlightedZones.delete(n):(d.highlightedZones.add(n),nh(!0)),d.hoveredPin=null,og(),ag(),sg(),d.layers.zones.changed(),d.layers.zoneTitles.changed(),d.layers.zoneTitleDetail.changed())}function sg(){I.zoneIndex.classList.toggle("has-highlights",d.highlightedZones.size>0);for(let n of I.zoneList.querySelectorAll("[data-zone]")){let t=Number(n.dataset.zone),e=d.highlightedZones.has(t);n.classList.toggle("is-highlighted",e),n.classList.toggle("is-current",d.focusedZoneID===t),n.setAttribute("aria-pressed",String(e))}}function x_(n){if(!n?.coordinates)return null;let t=([e,i])=>rh(i,e);return n.type==="Polygon"?new Ci(n.coordinates.map(e=>e.map(t))):n.type==="MultiPolygon"?new qd(n.coordinates.map(e=>e.map(i=>i.map(t)))):null}function rh(n,t){let e=d.catalog.tileGrid,i=2**e.sourceZoom,r=(t+180)/360*i,s=n*Math.PI/180,o=(1-Math.asinh(Math.tan(s))/Math.PI)/2*i;return[(r-e.firstTile)*e.tileSize,-(o-e.firstTile)*e.tileSize]}function Bn(){for(let n of d.pins){let t=d.hiddenCategories.has(n.category.id),e=d.search&&!n.location.title.toLocaleLowerCase().includes(d.search);n.filteredHidden=!!(t||e)}og(),ag(),d.selectedPin?.filteredHidden&&Vn()}function og(){if(!d.highlightedZones.size){for(let t of d.pins)t.insideHighlightedZone=!1;return}let n=[...d.highlightedZones].map(t=>d.zoneRecords.get(t)).filter(Boolean);for(let t of d.pins)t.insideHighlightedZone=n.some(e=>e.geometries.some(i=>y_(i,t.coordinate)))}function y_(n,t){if(n.intersectsCoordinate(t))return!0;let e=n.getClosestPoint(t),i=e[0]-t[0],r=e[1]-t[1];return i*i+r*r<=1}function ag(){d.eligibleLocations=d.pins.filter(n=>!Ke(n)).length,hn(),d.layers.pins.changed(),d.layers.zonePins.changed(),d.layers.pinLabels.changed(),d.layers.text.changed(),d.layers.zoneText.changed(),d.layers.textDetail.changed(),d.layers.priority.changed(),Oo()}function hn(){d.sources.priority.clear();for(let n of d.pins){if(Ke(n))continue;let t=!!d.search&&n.location.title.toLocaleLowerCase().includes(d.search);(n===d.selectedPin||n===d.hoveredPin||t||eh(n))&&d.sources.priority.addFeature(n.feature)}}function Io(n){d.hoveredPin!==n&&(d.hoveredPin=n,d.sources&&(hn(),d.layers.pins.changed(),d.layers.priority.changed()))}function lg(){if(!d.search){I.searchResults.hidden=!0,I.searchResults.replaceChildren();return}let n=d.pins.filter(e=>!d.hiddenCategories.has(e.category.id)&&e.location.title.toLocaleLowerCase().includes(d.search)).sort((e,i)=>e.location.title.localeCompare(i.location.title)).slice(0,20),t=document.createDocumentFragment();if(!n.length){let e=document.createElement("p");e.className="search-empty",e.textContent="No visible locations match.",t.append(e)}for(let e of n){let i=document.createElement("button");i.type="button",i.className="search-result",i.dataset.location=String(e.location.id),lh(i,e.category);let r=document.createElement("span");r.className="result-dot",ch(r,e.category,Do(e.category.title));let s=document.createElement("span"),o=document.createElement("strong");o.textContent=e.location.title;let a=document.createElement("small");a.textContent=`${e.category.title} \xB7 ${e.group.title}`,s.append(o,a),i.append(r,s),t.append(i)}I.searchResults.replaceChildren(t),I.searchResults.hidden=!1}function Vf(n){if(d.hiddenCategories.clear(),!n)for(let t of d.map.groups)for(let e of t.categories)d.hiddenCategories.add(e.id);sh(),Bn(),lg(),Br()}function sh(){for(let n of document.querySelectorAll("[data-category]"))n.checked=!d.hiddenCategories.has(Number(n.dataset.category))}function E_(n){let t=d.map.groups.find(i=>i.id===n);if(!t)return;let e=t.categories.some(i=>!d.hiddenCategories.has(i.id));for(let i of t.categories)e?d.hiddenCategories.add(i.id):d.hiddenCategories.delete(i.id);sh(),Bn(),Br()}function Br(){if(d.map)for(let n of d.map.groups){let t=I.legend.querySelector(`input[data-group="${n.id}"]`);t&&(t.checked=n.categories.some(e=>!d.hiddenCategories.has(e.id)))}}function jf(n){d.hiddenCategories.delete(n.category.id),d.search="",I.search.value="",I.searchResults.hidden=!0,sh(),Bn(),Br(),cg(n,!0)}function cg(n,t=!1){if(d.selectedPin=n,hn(),d.layers.pins.changed(),d.layers.pinLabels.changed(),d.layers.text.changed(),d.layers.textDetail.changed(),d.layers.priority.changed(),I.detailTitle.textContent=n.location.title,I.detailCategory.textContent=`${n.group.title} / ${n.category.title}`,I.detailDescription.textContent=G_(n.location.description)||"No description is included in the archive.",I.detailID.textContent=String(n.location.id),I.detailCoordinates.textContent=`${n.location.lat.toFixed(6)}, ${n.location.lng.toFixed(6)}`,w_(n),lh(I.detailDot,n.category),ch(I.detailDot,n.category,Do(n.category.title)),I.detail.hidden=!1,t){let e=d.engine.getView();e.animate({center:n.coordinate,zoom:Math.min(Hn(d.variant),Math.max(e.getZoom()||0,4)),duration:220})}}function w_(n){let t=(n.location.links||[]).filter(i=>d.pinByID.has(i.locationId));if(I.detailLinks.hidden=t.length===0,!t.length){I.detailLinks.replaceChildren();return}let e=document.createDocumentFragment();for(let i of t){let r=document.createElement("button");r.type="button",r.className="detail-link",r.dataset.location=String(i.locationId),r.textContent=i.title,e.append(r)}I.detailLinks.replaceChildren(e)}function Vn(){d.selectedPin=null,d.sources&&(hn(),d.layers.pins.changed(),d.layers.pinLabels.changed(),d.layers.text.changed(),d.layers.textDetail.changed(),d.layers.priority.changed()),I.detail.hidden=!0}function C_(){if(!d.engine||!d.variant)return;let n=d.engine.getView();n.fit(Ao(),{size:d.engine.getSize(),padding:[36,36,36,36],maxZoom:d.variant.maxZoom,duration:0}),d.fitZoom=n.getZoom()||0,Oo()}function To(n){let t=d.engine.getView(),e=t.getZoom()||0;t.animate({zoom:X_(e+n,d.variant.minZoom,Hn(d.variant)),duration:140})}function Oo(){let n=d.engine?.getView().getZoom();if(I.viewport.dataset.zoom=Number.isFinite(n)?n.toFixed(3):"",!d.engine||!d.pins.length){I.visibleCount.textContent="0 locations visible";return}let t=d.engine.getView().calculateExtent(d.engine.getSize()),e=0;for(let i of d.pins){if(Ke(i))continue;let[r,s]=i.coordinate;r>=t[0]&&r<=t[2]&&s>=t[1]&&s<=t[3]&&e++}I.visibleCount.textContent=`${cn(d.eligibleLocations)} enabled \xB7 ${cn(e)} in view`}function be(n,t){return(n.get("priority")||0)-(t.get("priority")||0)}function v_(n){let t=n.get("pin");return!t||Ke(t)||t.insideHighlightedZone||Vr(t)?null:oh(t,!1)}function b_(n){let t=n.get("pin");return!t||!d.highlightedZones.size||!t.insideHighlightedZone||Ke(t)||Vr(t)?null:oh(t,!1)}function R_(n){let t=n.get("pin");return!t||Ke(t)||!d.pinLabelsVisible||!jr()?null:hg(t)}function S_(n){let t=n.get("pin");if(!t||Ke(t)||t.insideHighlightedZone||Vr(t)||jr())return null;let e=d.fitZoom+Math.log2(z_(t.category));return(d.engine.getView().getZoom()||0)<e?null:ko(t,!1)}function T_(n){let t=n.get("pin");return!t||Ke(t)||t.insideHighlightedZone||Vr(t)||!jr()?null:ko(t,!1)}function I_(n){let t=n.get("pin");return!t||!d.highlightedZones.size||!t.insideHighlightedZone||Ke(t)||Vr(t)?null:ko(t,!1)}function L_(n){let t=n.get("pin");if(!t||Ke(t))return null;if(t.category.displayType==="text")return ko(t,t===d.selectedPin);let e=oh(t,t===d.selectedPin);return t===d.hoveredPin||t===d.selectedPin?[e,hg(t)]:e}function oh(n,t){let e=`marker:${n.category.id}:${t?1:0}`;if(d.styleCache.has(e))return d.styleCache.get(e);let i=n.category.color||jn(n.category.id),r=t?2e7:n.priority,s=d.markerIcons.get(ug(n.category)),o;return s?o=new Mt({image:new sn({src:s,width:t?36:31,height:t?36:31}),zIndex:r}):o=new Mt({text:new si({text:Do(n.category.title),font:`900 ${t?15:13}px Inter, sans-serif`,fill:new _t({color:i}),stroke:new At({color:ah(),width:t?4:3})}),zIndex:r}),d.styleCache.set(e,o),o}function hg(n){let t=`marker-label:${n.location.id}`;if(d.styleCache.has(t))return d.styleCache.get(t);let e=new Mt({text:new si({text:n.location.title,offsetY:21,font:'700 10px "Arial Narrow", "Roboto Condensed", sans-serif',fill:new _t({color:"#f4f6ed"}),stroke:new At({color:"rgba(0,0,0,0.98)",width:3}),backgroundFill:new _t({color:"rgba(10,13,9,0.72)"}),padding:[2,4,2,4],overflow:!0}),zIndex:n.priority});return d.styleCache.set(t,e),e}function A_(n){if(!n.iconAsset)return;let t=ug(n);if(d.markerIcons.has(t))return;d.markerIcons.set(t,null);let e=new Image;e.onload=()=>{let i=document.createElement("canvas");i.width=64,i.height=64;let r=i.getContext("2d"),s=n.color||jn(n.id),o=document.createElement("canvas");o.width=64,o.height=64;let a=o.getContext("2d");a.imageSmoothingEnabled=!n.iconPicture,a.drawImage(e,6,6,52,52),n.iconPicture||(a.globalCompositeOperation="source-in",a.fillStyle=s,a.fillRect(0,0,64,64));let l=document.createElement("canvas");l.width=64,l.height=64;let h=l.getContext("2d");h.drawImage(e,6,6,52,52),h.globalCompositeOperation="source-in",h.fillStyle=ah(),h.fillRect(0,0,64,64);for(let c=-3;c<=3;c++)for(let u=-3;u<=3;u++)u*u+c*c<=10&&r.drawImage(l,u,c);r.drawImage(o,0,0),d.markerIcons.set(t,i.toDataURL("image/png")),d.styleCache.delete(`marker:${n.id}:0`),d.styleCache.delete(`marker:${n.id}:1`),d.layers.pins.changed(),d.layers.zonePins.changed(),d.layers.priority.changed()},e.onerror=()=>d.markerIcons.set(t,!1),e.src=gg(n.iconAsset)}function ug(n){return`${n.iconAsset||""}:${n.color||jn(n.id)}:${d.map?.iconOutset||"light"}`}function ah(){return d.map?.iconOutset==="dark"?"rgba(7, 9, 7, 0.98)":"rgba(255, 255, 255, 0.96)"}function ko(n,t){let e=`text:${n.location.id}:${t?1:0}`;if(d.styleCache.has(e))return d.styleCache.get(e);let r=[new Mt({text:new si({text:n.location.title,font:`${t?"900":"800"} 14px "Arial Narrow", "Roboto Condensed", sans-serif`,fill:new _t({color:t?"#d6f36b":"#f3f5e9"}),stroke:new At({color:"rgba(0,0,0,0.95)",width:4}),backgroundFill:new _t({color:t?"rgba(17,21,14,0.9)":"rgba(10,13,9,0.58)"}),backgroundStroke:t?new At({color:"#d6f36b",width:1}):void 0,padding:[3,6,3,6],overflow:!0}),zIndex:t?2e7:n.priority+3e6})];return d.styleCache.set(e,r),r}function Hf(n){let t=n.get("gridCell");if(!t)return null;let e=`grid:${t.hash}:${t.role}:${t.contextDistance}`;if(d.styleCache.has(e))return d.styleCache.get(e);let i=Lo[Math.max(0,Di.indexOf(t.hash[t.hash.length-1]))%Lo.length],r=t.role==="leaf",s=t.role==="neighbor",o=new Mt({fill:new _t({color:s?`rgba(3, 5, 3, ${Math.min(.52,.3+t.contextDistance*.06)})`:ki(i,r?.14:.055)}),stroke:new At({color:r?"#ffffff":ki(i,s?.44:.82),width:r?2.5:s?1:1.4}),text:new si({text:t.hash,font:`${r?"900 17px":s?"750 11px":"800 13px"} "Arial Narrow", "Roboto Condensed", sans-serif`,fill:new _t({color:r?"#ffffff":s?ki(i,.72):i}),stroke:new At({color:"rgba(0,0,0,0.96)",width:4}),backgroundFill:new _t({color:s?"rgba(4,6,4,0.88)":"rgba(9,12,8,0.76)"}),padding:s?[2,4,2,4]:[3,5,3,5],overflow:!0}),zIndex:r?100:n.get("priority")});return d.styleCache.set(e,o),o}function M_(n){if(!d.zonesVisible)return null;let t=n.get("zone"),e=n.get("child"),i=d.highlightedZones.has(t.id),r=fg(t.id),s=`zone:${t.id}:${e?1:0}:${i?1:r?2:0}`;if(d.styleCache.has(s))return d.styleCache.get(s);let o=n.get("color");if(r){let h=new Mt({fill:new _t({color:`rgba(3, 5, 3, ${e?.38:.32})`}),stroke:new At({color:ki(o,e?.24:.32),width:e?1:1.3,lineDash:e?[3,4]:[7,5]}),zIndex:e?101:100});return d.styleCache.set(s,h),h}let a=new Mt({fill:new _t({color:ki(o,e?.035:.07)}),stroke:new At({color:ki(o,e?.5:.72),width:e?1.2:1.8,lineDash:e?[3,4]:[7,5]})});if(!i)return d.styleCache.set(s,a),a;let l=[new Mt({stroke:new At({color:"rgba(255,255,255,0.94)",width:5}),zIndex:9e3}),new Mt({fill:new _t({color:ki(o,.22)}),stroke:new At({color:o,width:2.6}),zIndex:9001})];return d.styleCache.set(s,l),l}function P_(n){if(!d.zonesVisible||jr())return null;let t=n.get("child"),e=d.highlightedZones.has(n.get("zone").id),i=d.engine.getView().getZoom()||0;if(!e&&t&&i<d.fitZoom+3)return null;let r=n.get("span")/d.engine.getView().getResolution();return!e&&d.zoneTitleCount>40&&r<52?null:dg(n)}function O_(n){return!d.zonesVisible||!jr()?null:dg(n)}function dg(n){let t=n.get("child"),e=n.get("zone"),i=d.highlightedZones.has(e.id),r=fg(e.id),s=`zone-title:${e.id}:${t?1:0}:${i?1:r?2:0}`;if(d.styleCache.has(s))return d.styleCache.get(s);let o=n.get("color"),a=new Mt({text:new si({text:e.title.toLocaleUpperCase(),font:`${t?"700 12px":"800 14px"} "Arial Narrow", "Roboto Condensed", sans-serif`,fill:new _t({color:i?"#11140f":r?"rgba(185,192,177,0.56)":t?"#c7ccbd":"#f1f4e7"}),stroke:new At({color:i?"rgba(255,255,255,0.96)":r?"rgba(0,0,0,0.82)":"rgba(0,0,0,0.95)",width:i?2:r?3:4}),backgroundFill:new _t({color:i?o:r?"rgba(4,6,4,0.84)":"rgba(11,14,10,0.72)"}),backgroundStroke:new At({color:i?"#ffffff":ki(o,r?.24:.55),width:i?2:1}),padding:[5,8,5,8],overflow:!0}),zIndex:i?91e5:n.get("priority")});return d.styleCache.set(s,a),a}function fg(n){if(!d.highlightedZones.size||d.highlightedZones.has(n))return!1;for(let t of d.highlightedZones)if(k_(n,t))return!1;return!0}function k_(n,t){let e=new Set,i=d.zoneRecords.get(t)?.zone.parentRegionId;for(;i!=null&&!e.has(i);){if(i===n)return!0;e.add(i),i=d.zoneRecords.get(i)?.zone.parentRegionId}return!1}function Vr(n){return n===d.selectedPin||n===d.hoveredPin||eh(n)||!!d.search&&n.location.title.toLocaleLowerCase().includes(d.search)}function Ke(n){return n.filteredHidden||D_(n)}function D_(n){return!d.highlightedZones.size||n.insideHighlightedZone||n===d.selectedPin?!1:!(d.search&&n.location.title.toLocaleLowerCase().includes(d.search))}function F_(n,t){return Math.max(0,1e6-Math.min(n.locations.length,999)*1e3)+N_(t.id)%1e3}function z_(n){return n.locations.length>200?4:n.locations.length>75?2.5:1}function jr(){return(d.engine?.getView().getZoom()||0)>=(d.variant?.maxZoom||0)-.05}function N_(n){return Math.imul(Number(n)||0,2654435761)>>>0}function jn(n){let t=Math.abs(Number(n)||0);return Lo[(Math.imul(t,2654435761)>>>0)%Lo.length]}function ki(n,t){let e=String(n||"#ffffff").replace("#",""),i=e.length===3?e.split("").map(s=>s+s).join(""):e.slice(0,6).padEnd(6,"f"),r=Number.parseInt(i,16);return`rgba(${r>>16&255}, ${r>>8&255}, ${r&255}, ${t})`}function lh(n,t){n.style.setProperty("--pin-color",t.color||jn(t.id))}function ch(n,t,e){if(n.classList.remove("has-source-icon"),n.style.removeProperty("--pin-icon"),n.textContent="",!t.iconAsset){n.textContent=e;return}n.style.setProperty("--pin-icon",`url("${gg(t.iconAsset)}")`),n.classList.add("has-source-icon")}function gg(n){return`/static/icons/${n.split("/").map(e=>encodeURIComponent(e)).join("/")}`}function Do(n){return n.split(/\s+/).slice(0,2).map(t=>t[0]||"").join("")}function G_(n){return String(n||"").replace(/\[([^\]]+)\]\([^)]+\)/g,"$1").replace(/[*_`>#]/g,"").replace(/\r/g,"").replace(/\n{3,}/g,`88 99 `).trim()}function cn(n){return new Intl.NumberFormat().format(n)}function X_(n,t,e){return Math.min(e,Math.max(t,n))}function qf(n){return n instanceof HTMLElement&&(n.matches("input, textarea, select")||n.isContentEditable)}function W_(){let n=()=>({game:d.game?.title,map:d.map?.title,variant:d.variant?.name,zoom:d.engine?.getView().getZoom(),center:d.engine?.getView().getCenter(),resolution:d.engine?.getView().getResolution(),nativeMaxZoom:d.variant?.maxZoom,maxZoom:d.variant?Hn(d.variant):null,interpolate:d.variant?.interpolate,tileStats:{...d.tileStats},pins:d.pins.length,eligibleLocations:d.eligibleLocations,domNodes:document.querySelectorAll("*").length,canvases:document.querySelectorAll("canvas").length,rasterCacheSize:64,pinLabelsVisible:d.pinLabelsVisible,hoveredPin:d.hoveredPin?.location.title||null,zones:{visible:d.zonesVisible,count:d.zoneRecords.size,focused:d.zoneRecords.get(d.focusedZoneID)?.zone.title||null,highlighted:[...d.highlightedZones].map(t=>d.zoneRecords.get(t)?.zone.title).filter(Boolean),focusedPins:d.pins.filter(t=>!t.filteredHidden&&t.insideHighlightedZone).length},grid:{enabled:d.gridEnabled,prefix:d.gridPrefix,maximumDepth:Po(),extent:d.gridEnabled?Mo():null,cells:[...d.sources.grid.getFeatures(),...d.sources.gridContext.getFeatures()].map(t=>t.get("gridCell")),priorityPins:d.gridPrefix?d.pins.filter(t=>!t.filteredHidden&&eh(t)).length:0}});window.__atlasDebug={snapshot:n,setLayerVisible:(t,e)=>d.layers[t]?.setVisible(e)},window.render_game_to_text=()=>JSON.stringify({coordinateSystem:"ATLAS:PIXELS; origin top-left; x increases right; y decreases downward",...n()}),window.advanceTime=()=>d.engine?.renderSync()}n_();})();
M frontend/app.js +3 -6