mirror of
https://github.com/protomaps/PMTiles.git
synced 2026-02-04 10:51:07 +00:00
2 lines
11 KiB
JavaScript
2 lines
11 KiB
JavaScript
import{r as St,c as u,d as yt,p as Ct,b as G,t as Lt,e as Q,a as wt,S as z,E as Tt,F as Dt,f as Mt,P as It,m as K,h as w,i as e,v as Z,j as X,s as P,_ as kt,w as k,q as zt,x as Et,J as F,o as Ot,u as Ut}from"./Frame-Cpo70DD7.js";import{S as Ft,m as V,R as Pt,C as jt}from"./index-BcyptosN.js";var At=w('<div class="flex-1 flex flex-col"><div class="h-full flex-1">'),Rt=w('<button class="mx-2 underline cursor-pointer"type=button>close'),Ht=w('<div class="flex-1 overflow-hidden"><div class="app-well md:px-4 md:py-2 flex"><span class=flex-1>entries <!>-<!> of </span><button class="mx-2 cursor-pointer"type=button>prev</button><button class="mx-2 cursor-pointer"type=button>next</button></div><div class="h-full overflow-y-scroll"><table class="h-full text-right table-auto border-separate border-spacing-1 w-full pr-4"><thead><tr><th>tileID</th><th>z</th><th>x</th><th>y</th><th>offset</th><th>length</th><th>runlength</th></tr></thead><tbody>'),Nt=w('<button type=button class="underline cursor-pointer">'),Bt=w("<tr class=hover:bg-purple><td></td><td class=app-text-light></td><td class=app-text-light></td><td class=app-text-light></td><td></td><td></td><td>"),Zt=w("<a class=underline target=_blank rel=noreferrer>"),Vt=w('<div class="flex-1 flex h-full w-full font-mono text-xs md:text-sm"><div class="flex flex-col h-full flex-1"></div><div class="flex flex-col">'),Gt=w('<div class="flex-none overflow-x-scroll"><table class="text-right table-auto border-separate border-spacing-2 p-4 w-full text-xs"><thead><tr class=app-text-light><th>Layout (bytes)</th><th>offset</th><th>length</th></tr></thead><tbody><tr><td class=app-text-light>Root Dir</td><td></td><td></td></tr><tr><td class=app-text-light>Metadata</td><td></td><td></td></tr><tr><td class=app-text-light>Leaf Dirs</td><td></td><td></td></tr><tr><td class=app-text-light>Tile Data</td><td></td><td>'),Xt=w('<div class="flex w-1/3 h-full flex-1 overflow-hidden"><div class="w-full flex flex-1 overflow-hidden">'),qt=w('<div class="flex text-xs overflow-x-scroll"><table class="table-auto border-separate border-spacing-2 w-1/2"><tbody><tr><td class="text-right app-text-light">Addressed tiles</td><td></td></tr><tr><td class="text-right app-text-light">Tile entries</td><td></td></tr><tr><td class="text-right app-text-light">Tile contents</td><td></td></tr><tr><td class="text-right app-text-light">Clustered</td><td></td></tr><tr><td class="text-right app-text-light">Internal compression</td><td></td></tr><tr><td class="text-right app-text-light">Tile compression</td><td></td></tr></tbody></table><table class="table-auto border-separate border-spacing-2 w-1/2"><tbody><tr><td class="text-right app-text-light">Tile type</td><td></td></tr><tr><td class="text-right app-text-light">Min zoom</td><td></td></tr><tr><td class="text-right app-text-light">Max zoom</td><td></td></tr><tr><td class="text-right app-text-light">Center zoom</td><td></td></tr><tr><td class="text-right app-text-light">Bounds</td><td> <!> <!> </td></tr><tr><td class="text-right app-text-light">Center</td><td> ');const W=Number.MAX_VALUE,ot=r=>r===F.Unknown?"unknown":r===F.None?"none":r===F.Gzip?"gzip":r===F.Brotli?"brotli":r===F.Zstd?"zstd":"out of spec";function Jt(r){let i;const x=new Ft;let o;return Q(()=>{const a=[],b=[];if(r.entries){for(const c of r.entries)if(c.runLength===1){const[s,h,d]=k(c.tileId),n=x.bbox(h,d,s);a.push({type:"Feature",properties:{},geometry:{type:"Polygon",coordinates:[[[n[0],n[1]],[n[2],n[1]],[n[2],n[3]],[n[0],n[3]],[n[0],n[1]]]]}})}else{const s=[];for(let h=c.tileId;h<c.tileId+c.runLength;h++){const[d,n,g]=k(h),t=x.bbox(n,g,d),f=(t[0]+t[2])/2,p=(t[1]+t[3])/2;s.push([f,p])}b.push({type:"Feature",properties:{},geometry:{type:"LineString",coordinates:s}})}o.getSource("archive").setData({type:"FeatureCollection",features:a}),o.getSource("runs").setData({type:"FeatureCollection",features:b})}}),Q(()=>{if(r.hoveredTile){const[a,b,c]=k(r.hoveredTile),s=x.bbox(b,c,a);o.getSource("hoveredTile").setData({type:"Polygon",coordinates:[[[s[0],s[1]],[s[2],s[1]],[s[2],s[3]],[s[0],s[3]],[s[0],s[1]]]]}),o.flyTo({center:[(s[0]+s[2])/2,(s[1]+s[3])/2],zoom:Math.max(a-4,0)})}}),Ot(()=>{if(!i){console.error("Could not mount map element");return}V.getRTLTextPluginStatus()==="unavailable"&&V.setRTLTextPlugin("https://unpkg.com/@mapbox/mapbox-gl-rtl-text@0.2.3/mapbox-gl-rtl-text.min.js",!0);let a="white";window.matchMedia?.("(prefers-color-scheme: dark)").matches&&(a="black"),o=new V.Map({container:i,attributionControl:!1,style:{version:8,glyphs:"https://protomaps.github.io/basemaps-assets/fonts/{fontstack}/{range}.pbf",sprite:`https://protomaps.github.io/basemaps-assets/sprites/v4/${a}`,sources:{basemap:{type:"vector",tiles:["https://api.protomaps.com/tiles/v4/{z}/{x}/{y}.mvt?key=1003762824b9687f"],attribution:"© <a href='https://openstreetmap.org/copyright'>OpenStreetMap</a>",maxzoom:15},archive:{type:"geojson",data:{type:"FeatureCollection",features:[]},buffer:16,tolerance:0},runs:{type:"geojson",data:{type:"FeatureCollection",features:[]},buffer:16,tolerance:0},hoveredTile:{type:"geojson",data:{type:"FeatureCollection",features:[]},buffer:16,tolerance:0}},layers:[...Pt("basemap",jt(a),{lang:"en"}),{id:"archive",source:"archive",type:"line",paint:{"line-color":"#3131DC","line-opacity":.8,"line-width":2}},{id:"runs",source:"runs",type:"line",paint:{"line-color":"#ffffff","line-opacity":.3}},{id:"hoveredTile",source:"hoveredTile",type:"fill",paint:{"fill-color":"white","fill-opacity":.3}}]}}),o.addControl(new V.AttributionControl({compact:!1}),"bottom-right"),o.on("style.load",()=>{o.setProjection({type:"globe"}),o.resize()})}),(()=>{var a=At(),b=a.firstChild,c=i;return typeof c=="function"?Ut(c,b):i=b,a})()}function at(r){const[i,x]=G(0),o=a=>a>=0&&a<r.entries.length;return(()=>{var a=Ht(),b=a.firstChild,c=b.firstChild,s=c.firstChild,h=s.nextSibling,d=h.nextSibling,n=d.nextSibling;n.nextSibling;var g=c.nextSibling,t=g.nextSibling,f=b.nextSibling,p=f.firstChild,D=p.firstChild,T=D.nextSibling;return e(c,i,h),e(c,()=>i()+999,n),e(c,()=>r.entries.length,null),e(b,u(z,{get when(){return r.isLeaf},get children(){var l=Rt();return l.$$click=()=>r.setOpenedLeaf(W),l}}),g),g.$$click=()=>{x(i()-1e3)},t.$$click=()=>{x(i()+1e3)},e(T,u(Et,{get each(){return r.entries.slice(i(),i()+1e3)},children:l=>(()=>{var m=Bt(),v=m.firstChild,S=v.nextSibling,y=S.nextSibling,C=y.nextSibling,L=C.nextSibling,M=L.nextSibling,I=M.nextSibling;return m.$$mousemove=()=>r.setHoveredTile(l.tileId),e(v,()=>l.tileId),e(S,()=>k(l.tileId)[0]),e(y,()=>k(l.tileId)[1]),e(C,()=>k(l.tileId)[2]),e(L,u(z,{get when(){return l.runLength===0},get fallback(){return(()=>{var $=Zt();return e($,()=>l.offset),X(()=>P($,"href",zt(r.stateUrl,k(l.tileId)))),$})()},get children(){var $=Nt();return $.$$click=()=>r.setOpenedLeaf(l.tileId),e($,()=>l.offset),$}})),e(M,()=>l.length),e(I,u(z,{get when(){return l.runLength===0},get fallback(){return l.runLength},children:"0 (leaf)"})),m})()})),X(l=>{var m=!!o(i()-1e3),v=!o(i()-1e3),S=!o(i()-1e3),y=!!o(i()+1e3),C=!o(i()+1e3),L=!o(i()+1e3);return m!==l.e&&g.classList.toggle("underline",l.e=m),v!==l.t&&g.classList.toggle("app-text-light",l.t=v),S!==l.a&&(g.disabled=l.a=S),y!==l.o&&t.classList.toggle("underline",l.o=y),C!==l.i&&t.classList.toggle("app-text-light",l.i=C),L!==l.n&&(t.disabled=l.n=L),l},{e:void 0,t:void 0,a:void 0,o:void 0,i:void 0,n:void 0}),a})()}function Yt(r){const i=Mt(()=>{const d=r.genericTileset();if(d instanceof It)return d;throw alert("This isn't a PMTiles archive!"),"This isn't a PMTiles tileset"}),[x]=K(i,async d=>await d.archive.getHeader()),[o]=K(x,async d=>await i().archive.cache.getDirectory(i().archive.source,d.rootDirectoryOffset,d.rootDirectoryLength,d)),[a,b]=G(W),[c,s]=G(),[h]=K(a,async d=>{if(d===W)return;const n=x(),g=o();if(!g||!n)return;const t=g.find(f=>f.tileId===d);if(t)return await i().archive.cache.getDirectory(i().archive.source,n.leafDirectoryOffset+t.offset,t.length,n)});return(()=>{var d=Vt(),n=d.firstChild,g=n.nextSibling;return e(n,u(z,{get when(){return x()},children:t=>(()=>{var f=Gt(),p=f.firstChild,D=p.firstChild,T=D.nextSibling,l=T.firstChild,m=l.firstChild,v=m.nextSibling,S=v.nextSibling,y=l.nextSibling,C=y.firstChild,L=C.nextSibling,M=L.nextSibling,I=y.nextSibling,$=I.firstChild,j=$.nextSibling,E=j.nextSibling,q=I.nextSibling,J=q.firstChild,A=J.nextSibling,R=A.nextSibling;return e(v,()=>t().rootDirectoryOffset),e(S,()=>Z(t().rootDirectoryLength)),e(L,()=>t().jsonMetadataOffset),e(M,()=>Z(t().jsonMetadataLength)),e(j,()=>t().leafDirectoryOffset),e(E,()=>Z(t().leafDirectoryLength||0)),e(A,()=>t().tileDataOffset),e(R,()=>Z(t().tileDataLength||0)),X(_=>{var H=t().rootDirectoryLength.toString(),N=t().jsonMetadataLength.toString(),O=(t().leafDirectoryLength||0).toString(),B=(t().tileDataLength||0).toString();return H!==_.e&&P(S,"title",_.e=H),N!==_.t&&P(M,"title",_.t=N),O!==_.a&&P(E,"title",_.a=O),B!==_.o&&P(R,"title",_.o=B),_},{e:void 0,t:void 0,a:void 0,o:void 0}),f})()}),null),e(n,u(at,{get entries(){return o()||[]},get stateUrl(){return r.genericTileset().getStateUrl()},setHoveredTile:s,setOpenedLeaf:b}),null),e(d,u(z,{get when(){return h()},children:t=>(()=>{var f=Xt(),p=f.firstChild;return e(p,u(at,{get entries(){return t()},get stateUrl(){return r.genericTileset().getStateUrl()},setHoveredTile:s,setOpenedLeaf:b,isLeaf:!0})),f})()}),g),e(g,u(z,{get when(){return x()},children:t=>(()=>{var f=qt(),p=f.firstChild,D=p.firstChild,T=D.firstChild,l=T.firstChild,m=l.nextSibling,v=T.nextSibling,S=v.firstChild,y=S.nextSibling,C=v.nextSibling,L=C.firstChild,M=L.nextSibling,I=C.nextSibling,$=I.firstChild,j=$.nextSibling,E=I.nextSibling,q=E.firstChild,J=q.nextSibling,A=E.nextSibling,R=A.firstChild,_=R.nextSibling,H=p.nextSibling,N=H.firstChild,O=N.firstChild,B=O.firstChild,ct=B.nextSibling,tt=O.nextSibling,gt=tt.firstChild,ft=gt.nextSibling,et=tt.nextSibling,ht=et.firstChild,ut=ht.nextSibling,lt=et.nextSibling,xt=lt.firstChild,bt=xt.nextSibling,it=lt.nextSibling,pt=it.firstChild,U=pt.nextSibling,rt=U.firstChild,nt=rt.nextSibling,vt=nt.nextSibling,st=vt.nextSibling;st.nextSibling;var $t=it.nextSibling,_t=$t.firstChild,Y=_t.nextSibling,mt=Y.firstChild;return e(m,()=>t().numAddressedTiles.toLocaleString()),e(y,()=>t().numTileEntries.toLocaleString()),e(M,()=>t().numTileContents.toLocaleString()),e(j,()=>t().clustered?"true":"false"),e(J,()=>ot(t().internalCompression)),e(_,()=>ot(t().tileCompression)),e(ct,()=>kt(t().tileType)),e(ft,()=>t().minZoom),e(ut,()=>t().maxZoom),e(bt,()=>t().centerZoom),e(U,()=>t().minLon,rt),e(U,()=>t().minLat,nt),e(U,()=>t().maxLon,st),e(U,()=>t().maxLat,null),e(Y,()=>t().centerLon,mt),e(Y,()=>t().centerLat,null),f})()}),null),e(g,u(Jt,{get entries(){return h()||o()},get hoveredTile(){return c()}}),null),X(t=>{var f=h()!==void 0,p=h()===void 0,D=h()!==void 0,T=h()===void 0;return f!==t.e&&n.classList.toggle("w-1/3",t.e=f),p!==t.t&&n.classList.toggle("w-1/2",t.t=p),D!==t.a&&g.classList.toggle("w-1/3",t.a=D),T!==t.o&&g.classList.toggle("w-1/2",t.o=T),t},{e:void 0,t:void 0,a:void 0,o:void 0}),d})()}function Kt(){const r=Ct(location.hash),[i,x]=G(r.url?Lt(decodeURIComponent(r.url)):void 0);return Q(()=>{const a=i()?.getStateUrl();location.hash=wt(location.hash,{url:a?encodeURIComponent(a):void 0})}),u(Dt,{tileset:i,setTileset:x,page:"archive",pmtilesOnly:!0,get children(){return u(z,{get when(){return i()},get fallback(){return u(Tt,{setTileset:x})},children:o=>u(Yt,{genericTileset:o})})}})}const dt=document.getElementById("root");dt&&St(()=>u(Kt,{}),dt);yt(["click","mousemove"]);
|