@loaders.gl/pmtiles 4.2.0-alpha.4 → 4.2.0-alpha.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/dist.dev.js +682 -549
- package/dist/dist.min.js +14 -0
- package/dist/index.cjs +19 -16
- package/dist/index.cjs.map +7 -0
- package/dist/index.d.ts +3 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -1
- package/dist/lib/blob-source.js +29 -17
- package/dist/lib/parse-pmtiles.d.ts +2 -2
- package/dist/lib/parse-pmtiles.d.ts.map +1 -1
- package/dist/lib/parse-pmtiles.js +75 -57
- package/dist/pmtiles-source.d.ts +1 -1
- package/dist/pmtiles-source.d.ts.map +1 -1
- package/dist/pmtiles-source.js +83 -97
- package/package.json +13 -9
- package/src/lib/parse-pmtiles.ts +4 -2
- package/dist/index.js.map +0 -1
- package/dist/lib/blob-source.js.map +0 -1
- package/dist/lib/parse-pmtiles.js.map +0 -1
- package/dist/pmtiles-source.js.map +0 -1
package/dist/dist.min.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
(function webpackUniversalModuleDefinition(root, factory) {
|
|
2
|
+
if (typeof exports === 'object' && typeof module === 'object')
|
|
3
|
+
module.exports = factory();
|
|
4
|
+
else if (typeof define === 'function' && define.amd) define([], factory);
|
|
5
|
+
else if (typeof exports === 'object') exports['loaders'] = factory();
|
|
6
|
+
else root['loaders'] = factory();})(globalThis, function () {
|
|
7
|
+
"use strict";var __exports__=(()=>{var nr=Object.create;var Ve=Object.defineProperty;var rr=Object.getOwnPropertyDescriptor;var ir=Object.getOwnPropertyNames;var or=Object.getPrototypeOf,sr=Object.prototype.hasOwnProperty;var We=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports),Mt=(e,t)=>{for(var n in t)Ve(e,n,{get:t[n],enumerable:!0})},De=(e,t,n,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let i of ir(t))!sr.call(e,i)&&i!==n&&Ve(e,i,{get:()=>t[i],enumerable:!(r=rr(t,i))||r.enumerable});return e},be=(e,t,n)=>(De(e,t,"default"),n&&De(n,t,"default")),Ut=(e,t,n)=>(n=e!=null?nr(or(e)):{},De(t||!e||!e.__esModule?Ve(n,"default",{value:e,enumerable:!0}):n,e)),ar=e=>De(Ve({},"__esModule",{value:!0}),e);var kt=We((Ro,Lt)=>{Lt.exports=globalThis.loaders});var tn=We(ct=>{ct.read=function(e,t,n,r,i){var o,s,a=i*8-r-1,l=(1<<a)-1,c=l>>1,f=-7,u=n?i-1:0,h=n?-1:1,d=e[t+u];for(u+=h,o=d&(1<<-f)-1,d>>=-f,f+=a;f>0;o=o*256+e[t+u],u+=h,f-=8);for(s=o&(1<<-f)-1,o>>=-f,f+=r;f>0;s=s*256+e[t+u],u+=h,f-=8);if(o===0)o=1-c;else{if(o===l)return s?NaN:(d?-1:1)*(1/0);s=s+Math.pow(2,r),o=o-c}return(d?-1:1)*s*Math.pow(2,o-r)};ct.write=function(e,t,n,r,i,o){var s,a,l,c=o*8-i-1,f=(1<<c)-1,u=f>>1,h=i===23?Math.pow(2,-24)-Math.pow(2,-77):0,d=r?0:o-1,p=r?1:-1,m=t<0||t===0&&1/t<0?1:0;for(t=Math.abs(t),isNaN(t)||t===1/0?(a=isNaN(t)?1:0,s=f):(s=Math.floor(Math.log(t)/Math.LN2),t*(l=Math.pow(2,-s))<1&&(s--,l*=2),s+u>=1?t+=h/l:t+=h*Math.pow(2,1-u),t*l>=2&&(s++,l/=2),s+u>=f?(a=0,s=f):s+u>=1?(a=(t*l-1)*Math.pow(2,i),s=s+u):(a=t*Math.pow(2,u-1)*Math.pow(2,i),s=0));i>=8;e[n+d]=a&255,d+=p,a/=256,i-=8);for(s=s<<i|a,c+=i;c>0;e[n+d]=s&255,d+=p,s/=256,c-=8);e[n+d-p]|=m*128}});var ln=We((Ta,an)=>{"use strict";an.exports=x;var Le=tn();function x(e){this.buf=ArrayBuffer.isView&&ArrayBuffer.isView(e)?e:new Uint8Array(e||0),this.pos=0,this.type=0,this.length=this.buf.length}x.Varint=0;x.Fixed64=1;x.Bytes=2;x.Fixed32=5;var ft=(1<<16)*(1<<16),nn=1/ft,pi=12,sn=typeof TextDecoder>"u"?null:new TextDecoder("utf8");x.prototype={destroy:function(){this.buf=null},readFields:function(e,t,n){for(n=n||this.length;this.pos<n;){var r=this.readVarint(),i=r>>3,o=this.pos;this.type=r&7,e(i,t,this),this.pos===o&&this.skip(r)}return t},readMessage:function(e,t){return this.readFields(e,t,this.readVarint()+this.pos)},readFixed32:function(){var e=ke(this.buf,this.pos);return this.pos+=4,e},readSFixed32:function(){var e=on(this.buf,this.pos);return this.pos+=4,e},readFixed64:function(){var e=ke(this.buf,this.pos)+ke(this.buf,this.pos+4)*ft;return this.pos+=8,e},readSFixed64:function(){var e=ke(this.buf,this.pos)+on(this.buf,this.pos+4)*ft;return this.pos+=8,e},readFloat:function(){var e=Le.read(this.buf,this.pos,!0,23,4);return this.pos+=4,e},readDouble:function(){var e=Le.read(this.buf,this.pos,!0,52,8);return this.pos+=8,e},readVarint:function(e){var t=this.buf,n,r;return r=t[this.pos++],n=r&127,r<128||(r=t[this.pos++],n|=(r&127)<<7,r<128)||(r=t[this.pos++],n|=(r&127)<<14,r<128)||(r=t[this.pos++],n|=(r&127)<<21,r<128)?n:(r=t[this.pos],n|=(r&15)<<28,gi(n,e,this))},readVarint64:function(){return this.readVarint(!0)},readSVarint:function(){var e=this.readVarint();return e%2===1?(e+1)/-2:e/2},readBoolean:function(){return Boolean(this.readVarint())},readString:function(){var e=this.readVarint()+this.pos,t=this.pos;return this.pos=e,e-t>=pi&&sn?Ai(this.buf,t,e):bi(this.buf,t,e)},readBytes:function(){var e=this.readVarint()+this.pos,t=this.buf.subarray(this.pos,e);return this.pos=e,t},readPackedVarint:function(e,t){if(this.type!==x.Bytes)return e.push(this.readVarint(t));var n=z(this);for(e=e||[];this.pos<n;)e.push(this.readVarint(t));return e},readPackedSVarint:function(e){if(this.type!==x.Bytes)return e.push(this.readSVarint());var t=z(this);for(e=e||[];this.pos<t;)e.push(this.readSVarint());return e},readPackedBoolean:function(e){if(this.type!==x.Bytes)return e.push(this.readBoolean());var t=z(this);for(e=e||[];this.pos<t;)e.push(this.readBoolean());return e},readPackedFloat:function(e){if(this.type!==x.Bytes)return e.push(this.readFloat());var t=z(this);for(e=e||[];this.pos<t;)e.push(this.readFloat());return e},readPackedDouble:function(e){if(this.type!==x.Bytes)return e.push(this.readDouble());var t=z(this);for(e=e||[];this.pos<t;)e.push(this.readDouble());return e},readPackedFixed32:function(e){if(this.type!==x.Bytes)return e.push(this.readFixed32());var t=z(this);for(e=e||[];this.pos<t;)e.push(this.readFixed32());return e},readPackedSFixed32:function(e){if(this.type!==x.Bytes)return e.push(this.readSFixed32());var t=z(this);for(e=e||[];this.pos<t;)e.push(this.readSFixed32());return e},readPackedFixed64:function(e){if(this.type!==x.Bytes)return e.push(this.readFixed64());var t=z(this);for(e=e||[];this.pos<t;)e.push(this.readFixed64());return e},readPackedSFixed64:function(e){if(this.type!==x.Bytes)return e.push(this.readSFixed64());var t=z(this);for(e=e||[];this.pos<t;)e.push(this.readSFixed64());return e},skip:function(e){var t=e&7;if(t===x.Varint)for(;this.buf[this.pos++]>127;);else if(t===x.Bytes)this.pos=this.readVarint()+this.pos;else if(t===x.Fixed32)this.pos+=4;else if(t===x.Fixed64)this.pos+=8;else throw new Error("Unimplemented type: "+t)},writeTag:function(e,t){this.writeVarint(e<<3|t)},realloc:function(e){for(var t=this.length||16;t<this.pos+e;)t*=2;if(t!==this.length){var n=new Uint8Array(t);n.set(this.buf),this.buf=n,this.length=t}},finish:function(){return this.length=this.pos,this.pos=0,this.buf.subarray(0,this.length)},writeFixed32:function(e){this.realloc(4),Q(this.buf,e,this.pos),this.pos+=4},writeSFixed32:function(e){this.realloc(4),Q(this.buf,e,this.pos),this.pos+=4},writeFixed64:function(e){this.realloc(8),Q(this.buf,e&-1,this.pos),Q(this.buf,Math.floor(e*nn),this.pos+4),this.pos+=8},writeSFixed64:function(e){this.realloc(8),Q(this.buf,e&-1,this.pos),Q(this.buf,Math.floor(e*nn),this.pos+4),this.pos+=8},writeVarint:function(e){if(e=+e||0,e>268435455||e<0){yi(e,this);return}this.realloc(4),this.buf[this.pos++]=e&127|(e>127?128:0),!(e<=127)&&(this.buf[this.pos++]=(e>>>=7)&127|(e>127?128:0),!(e<=127)&&(this.buf[this.pos++]=(e>>>=7)&127|(e>127?128:0),!(e<=127)&&(this.buf[this.pos++]=e>>>7&127)))},writeSVarint:function(e){this.writeVarint(e<0?-e*2-1:e*2)},writeBoolean:function(e){this.writeVarint(Boolean(e))},writeString:function(e){e=String(e),this.realloc(e.length*4),this.pos++;var t=this.pos;this.pos=Bi(this.buf,e,this.pos);var n=this.pos-t;n>=128&&rn(t,n,this),this.pos=t-1,this.writeVarint(n),this.pos+=n},writeFloat:function(e){this.realloc(4),Le.write(this.buf,e,this.pos,!0,23,4),this.pos+=4},writeDouble:function(e){this.realloc(8),Le.write(this.buf,e,this.pos,!0,52,8),this.pos+=8},writeBytes:function(e){var t=e.length;this.writeVarint(t),this.realloc(t);for(var n=0;n<t;n++)this.buf[this.pos++]=e[n]},writeRawMessage:function(e,t){this.pos++;var n=this.pos;e(t,this);var r=this.pos-n;r>=128&&rn(n,r,this),this.pos=n-1,this.writeVarint(r),this.pos+=r},writeMessage:function(e,t,n){this.writeTag(e,x.Bytes),this.writeRawMessage(t,n)},writePackedVarint:function(e,t){t.length&&this.writeMessage(e,wi,t)},writePackedSVarint:function(e,t){t.length&&this.writeMessage(e,vi,t)},writePackedBoolean:function(e,t){t.length&&this.writeMessage(e,Ii,t)},writePackedFloat:function(e,t){t.length&&this.writeMessage(e,Pi,t)},writePackedDouble:function(e,t){t.length&&this.writeMessage(e,Fi,t)},writePackedFixed32:function(e,t){t.length&&this.writeMessage(e,Ti,t)},writePackedSFixed32:function(e,t){t.length&&this.writeMessage(e,Si,t)},writePackedFixed64:function(e,t){t.length&&this.writeMessage(e,Di,t)},writePackedSFixed64:function(e,t){t.length&&this.writeMessage(e,Vi,t)},writeBytesField:function(e,t){this.writeTag(e,x.Bytes),this.writeBytes(t)},writeFixed32Field:function(e,t){this.writeTag(e,x.Fixed32),this.writeFixed32(t)},writeSFixed32Field:function(e,t){this.writeTag(e,x.Fixed32),this.writeSFixed32(t)},writeFixed64Field:function(e,t){this.writeTag(e,x.Fixed64),this.writeFixed64(t)},writeSFixed64Field:function(e,t){this.writeTag(e,x.Fixed64),this.writeSFixed64(t)},writeVarintField:function(e,t){this.writeTag(e,x.Varint),this.writeVarint(t)},writeSVarintField:function(e,t){this.writeTag(e,x.Varint),this.writeSVarint(t)},writeStringField:function(e,t){this.writeTag(e,x.Bytes),this.writeString(t)},writeFloatField:function(e,t){this.writeTag(e,x.Fixed32),this.writeFloat(t)},writeDoubleField:function(e,t){this.writeTag(e,x.Fixed64),this.writeDouble(t)},writeBooleanField:function(e,t){this.writeVarintField(e,Boolean(t))}};function gi(e,t,n){var r=n.buf,i,o;if(o=r[n.pos++],i=(o&112)>>4,o<128||(o=r[n.pos++],i|=(o&127)<<3,o<128)||(o=r[n.pos++],i|=(o&127)<<10,o<128)||(o=r[n.pos++],i|=(o&127)<<17,o<128)||(o=r[n.pos++],i|=(o&127)<<24,o<128)||(o=r[n.pos++],i|=(o&1)<<31,o<128))return Y(e,i,t);throw new Error("Expected varint not more than 10 bytes")}function z(e){return e.type===x.Bytes?e.readVarint()+e.pos:e.pos+1}function Y(e,t,n){return n?t*4294967296+(e>>>0):(t>>>0)*4294967296+(e>>>0)}function yi(e,t){var n,r;if(e>=0?(n=e%4294967296|0,r=e/4294967296|0):(n=~(-e%4294967296),r=~(-e/4294967296),n^4294967295?n=n+1|0:(n=0,r=r+1|0)),e>=18446744073709552e3||e<-18446744073709552e3)throw new Error("Given varint doesn't fit into 10 bytes");t.realloc(10),mi(n,r,t),xi(r,t)}function mi(e,t,n){n.buf[n.pos++]=e&127|128,e>>>=7,n.buf[n.pos++]=e&127|128,e>>>=7,n.buf[n.pos++]=e&127|128,e>>>=7,n.buf[n.pos++]=e&127|128,e>>>=7,n.buf[n.pos]=e&127}function xi(e,t){var n=(e&7)<<4;t.buf[t.pos++]|=n|((e>>>=3)?128:0),e&&(t.buf[t.pos++]=e&127|((e>>>=7)?128:0),e&&(t.buf[t.pos++]=e&127|((e>>>=7)?128:0),e&&(t.buf[t.pos++]=e&127|((e>>>=7)?128:0),e&&(t.buf[t.pos++]=e&127|((e>>>=7)?128:0),e&&(t.buf[t.pos++]=e&127)))))}function rn(e,t,n){var r=t<=16383?1:t<=2097151?2:t<=268435455?3:Math.floor(Math.log(t)/(Math.LN2*7));n.realloc(r);for(var i=n.pos-1;i>=e;i--)n.buf[i+r]=n.buf[i]}function wi(e,t){for(var n=0;n<e.length;n++)t.writeVarint(e[n])}function vi(e,t){for(var n=0;n<e.length;n++)t.writeSVarint(e[n])}function Pi(e,t){for(var n=0;n<e.length;n++)t.writeFloat(e[n])}function Fi(e,t){for(var n=0;n<e.length;n++)t.writeDouble(e[n])}function Ii(e,t){for(var n=0;n<e.length;n++)t.writeBoolean(e[n])}function Ti(e,t){for(var n=0;n<e.length;n++)t.writeFixed32(e[n])}function Si(e,t){for(var n=0;n<e.length;n++)t.writeSFixed32(e[n])}function Di(e,t){for(var n=0;n<e.length;n++)t.writeFixed64(e[n])}function Vi(e,t){for(var n=0;n<e.length;n++)t.writeSFixed64(e[n])}function ke(e,t){return(e[t]|e[t+1]<<8|e[t+2]<<16)+e[t+3]*16777216}function Q(e,t,n){e[n]=t,e[n+1]=t>>>8,e[n+2]=t>>>16,e[n+3]=t>>>24}function on(e,t){return(e[t]|e[t+1]<<8|e[t+2]<<16)+(e[t+3]<<24)}function bi(e,t,n){for(var r="",i=t;i<n;){var o=e[i],s=null,a=o>239?4:o>223?3:o>191?2:1;if(i+a>n)break;var l,c,f;a===1?o<128&&(s=o):a===2?(l=e[i+1],(l&192)===128&&(s=(o&31)<<6|l&63,s<=127&&(s=null))):a===3?(l=e[i+1],c=e[i+2],(l&192)===128&&(c&192)===128&&(s=(o&15)<<12|(l&63)<<6|c&63,(s<=2047||s>=55296&&s<=57343)&&(s=null))):a===4&&(l=e[i+1],c=e[i+2],f=e[i+3],(l&192)===128&&(c&192)===128&&(f&192)===128&&(s=(o&15)<<18|(l&63)<<12|(c&63)<<6|f&63,(s<=65535||s>=1114112)&&(s=null))),s===null?(s=65533,a=1):s>65535&&(s-=65536,r+=String.fromCharCode(s>>>10&1023|55296),s=56320|s&1023),r+=String.fromCharCode(s),i+=a}return r}function Ai(e,t,n){return sn.decode(e.subarray(t,n))}function Bi(e,t,n){for(var r=0,i,o;r<t.length;r++){if(i=t.charCodeAt(r),i>55295&&i<57344)if(o)if(i<56320){e[n++]=239,e[n++]=191,e[n++]=189,o=i;continue}else i=o-55296<<10|i-56320|65536,o=null;else{i>56319||r+1===t.length?(e[n++]=239,e[n++]=191,e[n++]=189):o=i;continue}else o&&(e[n++]=239,e[n++]=191,e[n++]=189,o=null);i<128?e[n++]=i:(i<2048?e[n++]=i>>6|192:(i<65536?e[n++]=i>>12|224:(e[n++]=i>>18|240,e[n++]=i>>12&63|128),e[n++]=i>>6&63|128),e[n++]=i&63|128)}return n}});var Te={};Mt(Te,{PMTilesSource:()=>Re});be(Te,Ut(kt(),1));function re(e,t){if(!e)throw new Error(t||"loader assertion failed.")}var O={self:typeof self<"u"&&self,window:typeof window<"u"&&window,global:typeof global<"u"&&global,document:typeof document<"u"&&document},lr=O.self||O.window||O.global||{},cr=O.window||O.self||O.global||{},fr=O.global||O.self||O.window||{},ur=O.document||{};var $e=Boolean(typeof process!="object"||String(process)!=="[object process]"||process.browser);var Ct=typeof process<"u"&&process.version&&/v([0-9]*)/.exec(process.version),hr=Ct&&parseFloat(Ct[1])||0;function R(e){return R=typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?function(t){return typeof t}:function(t){return t&&typeof Symbol=="function"&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},R(e)}function Ke(e,t){if(R(e)!=="object"||e===null)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||"default");if(R(r)!=="object")return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return(t==="string"?String:Number)(e)}function Xe(e){var t=Ke(e,"string");return R(t)==="symbol"?t:String(t)}function B(e,t,n){return t=Xe(t),t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}var dr="",Ot={};function Ye(e){for(let t in Ot)if(e.startsWith(t)){let n=Ot[t];e=e.replace(t,n)}return!e.startsWith("http://")&&!e.startsWith("https://")&&(e=`${dr}${e}`),e}var ie=class{fetch;loadOptions;_needsRefresh=!0;props;constructor(t){this.props={...t},this.loadOptions={...t.loadOptions},this.fetch=pr(this.loadOptions)}setProps(t){this.props=Object.assign(this.props,t),this.setNeedsRefresh()}setNeedsRefresh(){this._needsRefresh=!0}getNeedsRefresh(t=!0){let n=this._needsRefresh;return t&&(this._needsRefresh=!1),n}};function pr(e){let t=e?.fetch;if(t&&typeof t=="function")return(r,i)=>t(r,i);let n=e?.fetch;return n&&typeof n!="function"?r=>fetch(r,n):r=>fetch(r)}var Nt="4.2.0-alpha.5";var gr=globalThis.loaders?.parseImageNode,Qe=typeof Image<"u",qe=typeof ImageBitmap<"u",yr=Boolean(gr),et=$e?!0:yr;function zt(e){switch(e){case"auto":return qe||Qe||et;case"imagebitmap":return qe;case"image":return Qe;case"data":return et;default:throw new Error(`@loaders.gl/images: image ${e} not supported in this environment`)}}function Zt(){if(qe)return"imagebitmap";if(Qe)return"image";if(et)return"data";throw new Error("Install '@loaders.gl/polyfills' to parse images under Node.js")}function mr(e){let t=xr(e);if(!t)throw new Error("Not an image");return t}function Rt(e){switch(mr(e)){case"data":return e;case"image":case"imagebitmap":let t=document.createElement("canvas"),n=t.getContext("2d");if(!n)throw new Error("getImageData");return t.width=e.width,t.height=e.height,n.drawImage(e,0,0),n.getImageData(0,0,e.width,e.height);default:throw new Error("getImageData")}}function xr(e){return typeof ImageBitmap<"u"&&e instanceof ImageBitmap?"imagebitmap":typeof Image<"u"&&e instanceof Image?"image":e&&typeof e=="object"&&e.data&&e.width&&e.height?"data":null}var wr=/^data:image\/svg\+xml/,vr=/\.svg((\?|#).*)?$/;function Ae(e){return e&&(wr.test(e)||vr.test(e))}function jt(e,t){if(Ae(t)){let r=new TextDecoder().decode(e);try{typeof unescape=="function"&&typeof encodeURIComponent=="function"&&(r=unescape(encodeURIComponent(r)))}catch(o){throw new Error(o.message)}return`data:image/svg+xml;base64,${btoa(r)}`}return tt(e,t)}function tt(e,t){if(Ae(t))throw new Error("SVG cannot be parsed directly to imagebitmap");return new Blob([new Uint8Array(e)])}async function Be(e,t,n){let r=jt(e,n),i=self.URL||self.webkitURL,o=typeof r!="string"&&i.createObjectURL(r);try{return await Pr(o||r,t)}finally{o&&i.revokeObjectURL(o)}}async function Pr(e,t){let n=new Image;return n.src=e,t.image&&t.image.decode&&n.decode?(await n.decode(),n):await new Promise((r,i)=>{try{n.onload=()=>r(n),n.onerror=o=>{let s=o instanceof Error?o.message:"error";i(new Error(s))}}catch(o){i(o)}})}var Fr={},Gt=!0;async function Ht(e,t,n){let r;Ae(n)?r=await Be(e,t,n):r=tt(e,n);let i=t&&t.imagebitmap;return await Ir(r,i)}async function Ir(e,t=null){if((Tr(t)||!Gt)&&(t=null),t)try{return await createImageBitmap(e,t)}catch(n){console.warn(n),Gt=!1}return await createImageBitmap(e)}function Tr(e){for(let t in e||Fr)return!1;return!0}function Jt(e){return!br(e,"ftyp",4)||!(e[8]&96)?null:Sr(e)}function Sr(e){switch(Dr(e,8,12).replace("\0"," ").trim()){case"avif":case"avis":return{extension:"avif",mimeType:"image/avif"};default:return null}}function Dr(e,t,n){return String.fromCharCode(...e.slice(t,n))}function Vr(e){return[...e].map(t=>t.charCodeAt(0))}function br(e,t,n=0){let r=Vr(t);for(let i=0;i<r.length;++i)if(r[i]!==e[i+n])return!1;return!0}var N=!1,oe=!0;function Ee(e){let t=se(e);return Br(t)||Mr(t)||Er(t)||_r(t)||Ar(t)}function Ar(e){let t=new Uint8Array(e instanceof DataView?e.buffer:e),n=Jt(t);return n?{mimeType:n.mimeType,width:0,height:0}:null}function Br(e){let t=se(e);return t.byteLength>=24&&t.getUint32(0,N)===2303741511?{mimeType:"image/png",width:t.getUint32(16,N),height:t.getUint32(20,N)}:null}function Er(e){let t=se(e);return t.byteLength>=10&&t.getUint32(0,N)===1195984440?{mimeType:"image/gif",width:t.getUint16(6,oe),height:t.getUint16(8,oe)}:null}function _r(e){let t=se(e);return t.byteLength>=14&&t.getUint16(0,N)===16973&&t.getUint32(2,oe)===t.byteLength?{mimeType:"image/bmp",width:t.getUint32(18,oe),height:t.getUint32(22,oe)}:null}function Mr(e){let t=se(e);if(!(t.byteLength>=3&&t.getUint16(0,N)===65496&&t.getUint8(2)===255))return null;let{tableMarkers:r,sofMarkers:i}=Ur(),o=2;for(;o+9<t.byteLength;){let s=t.getUint16(o,N);if(i.has(s))return{mimeType:"image/jpeg",height:t.getUint16(o+5,N),width:t.getUint16(o+7,N)};if(!r.has(s))return null;o+=2,o+=t.getUint16(o,N)}return null}function Ur(){let e=new Set([65499,65476,65484,65501,65534]);for(let n=65504;n<65520;++n)e.add(n);return{tableMarkers:e,sofMarkers:new Set([65472,65473,65474,65475,65477,65478,65479,65481,65482,65483,65485,65486,65487,65502])}}function se(e){if(e instanceof DataView)return e;if(ArrayBuffer.isView(e))return new DataView(e.buffer);if(e instanceof ArrayBuffer)return new DataView(e);throw new Error("toDataView")}async function Wt(e,t){let{mimeType:n}=Ee(e)||{},r=globalThis.loaders?.parseImageNode;return re(r),await r(e,n)}async function $t(e,t,n){t=t||{};let i=(t.image||{}).type||"auto",{url:o}=n||{},s=Lr(i),a;switch(s){case"imagebitmap":a=await Ht(e,t,o);break;case"image":a=await Be(e,t,o);break;case"data":a=await Wt(e,t);break;default:re(!1)}return i==="data"&&(a=Rt(a)),a}function Lr(e){switch(e){case"auto":case"data":return Zt();default:return zt(e),e}}var kr=["png","jpg","jpeg","gif","webp","bmp","ico","svg","avif"],Cr=["image/png","image/jpeg","image/gif","image/webp","image/avif","image/bmp","image/vnd.microsoft.icon","image/svg+xml"],Or={image:{type:"auto",decode:!0}},nt={id:"image",module:"images",name:"Images",version:Nt,mimeTypes:Cr,extensions:kr,parse:$t,tests:[e=>Boolean(Ee(new DataView(e)))],options:Or};var ae={x:0,y:1,z:2};function j(e,t={}){let{start:n=0,end:r=e.length,plane:i="xy"}=t,o=t.size||2,s=0,a=ae[i[0]],l=ae[i[1]];for(let c=n,f=r-o;c<r;c+=o)s+=(e[c+a]-e[f+a])*(e[c+l]+e[f+l]),f=c;return s/2}function it(e,t,n=2,r,i="xy"){let o=t&&t.length,s=o?t[0]*n:e.length,a=Xt(e,0,s,n,!0,r&&r[0],i),l=[];if(!a||a.next===a.prev)return l;let c,f,u,h,d,p,m;if(o&&(a=Hr(e,t,a,n,r,i)),e.length>80*n){h=f=e[0],d=u=e[1];for(let F=n;F<s;F+=n)p=e[F],m=e[F+1],p<h&&(h=p),m<d&&(d=m),p>f&&(f=p),m>u&&(u=m);c=Math.max(f-h,u-d),c=c!==0?32767/c:0}return le(a,l,n,h,d,c,0),l}function Xt(e,t,n,r,i,o,s){let a,l;o===void 0&&(o=j(e,{start:t,end:n,size:r,plane:s}));let c=ae[s[0]],f=ae[s[1]];if(i===o<0)for(a=t;a<n;a+=r)l=Kt(a,e[a+c],e[a+f],l);else for(a=n-r;a>=t;a-=r)l=Kt(a,e[a+c],e[a+f],l);return l&&Ue(l,l.next)&&(fe(l),l=l.next),l}function G(e,t){if(!e)return e;t||(t=e);let n=e,r;do if(r=!1,!n.steiner&&(Ue(n,n.next)||P(n.prev,n,n.next)===0)){if(fe(n),n=t=n.prev,n===n.next)break;r=!0}else n=n.next;while(r||n!==t);return t}function le(e,t,n,r,i,o,s){if(!e)return;!s&&o&&Xr(e,r,i,o);let a=e,l,c;for(;e.prev!==e.next;){if(l=e.prev,c=e.next,o?Rr(e,r,i,o):Zr(e)){t.push(l.i/n|0),t.push(e.i/n|0),t.push(c.i/n|0),fe(e),e=c.next,a=c.next;continue}if(e=c,e===a){s?s===1?(e=jr(G(e),t,n),le(e,t,n,r,i,o,2)):s===2&&Gr(e,t,n,r,i,o):le(G(e),t,n,r,i,o,1);break}}}function Zr(e){let t=e.prev,n=e,r=e.next;if(P(t,n,r)>=0)return!1;let i=t.x,o=n.x,s=r.x,a=t.y,l=n.y,c=r.y,f=i<o?i<s?i:s:o<s?o:s,u=a<l?a<c?a:c:l<c?l:c,h=i>o?i>s?i:s:o>s?o:s,d=a>l?a>c?a:c:l>c?l:c,p=r.next;for(;p!==t;){if(p.x>=f&&p.x<=h&&p.y>=u&&p.y<=d&&X(i,a,o,l,s,c,p.x,p.y)&&P(p.prev,p,p.next)>=0)return!1;p=p.next}return!0}function Rr(e,t,n,r){let i=e.prev,o=e,s=e.next;if(P(i,o,s)>=0)return!1;let a=i.x,l=o.x,c=s.x,f=i.y,u=o.y,h=s.y,d=a<l?a<c?a:c:l<c?l:c,p=f<u?f<h?f:h:u<h?u:h,m=a>l?a>c?a:c:l>c?l:c,F=f>u?f>h?f:h:u>h?u:h,_=rt(d,p,t,n,r),v=rt(m,F,t,n,r),y=e.prevZ,g=e.nextZ;for(;y&&y.z>=_&&g&&g.z<=v;){if(y.x>=d&&y.x<=m&&y.y>=p&&y.y<=F&&y!==i&&y!==s&&X(a,f,l,u,c,h,y.x,y.y)&&P(y.prev,y,y.next)>=0||(y=y.prevZ,g.x>=d&&g.x<=m&&g.y>=p&&g.y<=F&&g!==i&&g!==s&&X(a,f,l,u,c,h,g.x,g.y)&&P(g.prev,g,g.next)>=0))return!1;g=g.nextZ}for(;y&&y.z>=_;){if(y.x>=d&&y.x<=m&&y.y>=p&&y.y<=F&&y!==i&&y!==s&&X(a,f,l,u,c,h,y.x,y.y)&&P(y.prev,y,y.next)>=0)return!1;y=y.prevZ}for(;g&&g.z<=v;){if(g.x>=d&&g.x<=m&&g.y>=p&&g.y<=F&&g!==i&&g!==s&&X(a,f,l,u,c,h,g.x,g.y)&&P(g.prev,g,g.next)>=0)return!1;g=g.nextZ}return!0}function jr(e,t,n){let r=e;do{let i=r.prev,o=r.next.next;!Ue(i,o)&&Yt(i,r,r.next,o)&&ce(i,o)&&ce(o,i)&&(t.push(i.i/n|0),t.push(r.i/n|0),t.push(o.i/n|0),fe(r),fe(r.next),r=e=o),r=r.next}while(r!==e);return G(r)}function Gr(e,t,n,r,i,o){let s=e;do{let a=s.next.next;for(;a!==s.prev;){if(s.i!==a.i&&qr(s,a)){let l=Qt(s,a);s=G(s,s.next),l=G(l,l.next),le(s,t,n,r,i,o,0),le(l,t,n,r,i,o,0);return}a=a.next}s=s.next}while(s!==e)}function Hr(e,t,n,r,i,o){let s=[],a,l,c,f,u;for(a=0,l=t.length;a<l;a++)c=t[a]*r,f=a<l-1?t[a+1]*r:e.length,u=Xt(e,c,f,r,!1,i&&i[a+1],o),u===u.next&&(u.steiner=!0),s.push(Qr(u));for(s.sort(Jr),a=0;a<s.length;a++)n=Wr(s[a],n);return n}function Jr(e,t){return e.x-t.x}function Wr(e,t){let n=$r(e,t);if(!n)return t;let r=Qt(n,e);return G(r,r.next),G(n,n.next)}function $r(e,t){let n=t,r=e.x,i=e.y,o=-1/0,s;do{if(i<=n.y&&i>=n.next.y&&n.next.y!==n.y){let h=n.x+(i-n.y)*(n.next.x-n.x)/(n.next.y-n.y);if(h<=r&&h>o&&(o=h,s=n.x<n.next.x?n:n.next,h===r))return s}n=n.next}while(n!==t);if(!s)return null;let a=s,l=s.x,c=s.y,f=1/0,u;n=s;do r>=n.x&&n.x>=l&&r!==n.x&&X(i<c?r:o,i,l,c,i<c?o:r,i,n.x,n.y)&&(u=Math.abs(i-n.y)/(r-n.x),ce(n,e)&&(u<f||u===f&&(n.x>s.x||n.x===s.x&&Kr(s,n)))&&(s=n,f=u)),n=n.next;while(n!==a);return s}function Kr(e,t){return P(e.prev,e,t.prev)<0&&P(t.next,e,e.next)<0}function Xr(e,t,n,r){let i=e;do i.z===0&&(i.z=rt(i.x,i.y,t,n,r)),i.prevZ=i.prev,i.nextZ=i.next,i=i.next;while(i!==e);i.prevZ.nextZ=null,i.prevZ=null,Yr(i)}function Yr(e){let t,n,r=1,i,o,s,a,l,c;do{for(o=e,e=null,c=null,i=0;o;){for(i++,a=o,s=0,n=0;n<r&&(s++,a=a.nextZ,!!a);n++);for(l=r;s>0||l>0&&a;)s!==0&&(l===0||!a||o.z<=a.z)?(t=o,o=o.nextZ,s--):(t=a,a=a.nextZ,l--),c?c.nextZ=t:e=t,t.prevZ=c,c=t;o=a}c.nextZ=null,r*=2}while(i>1);return e}function rt(e,t,n,r,i){return e=(e-n)*i|0,t=(t-r)*i|0,e=(e|e<<8)&16711935,e=(e|e<<4)&252645135,e=(e|e<<2)&858993459,e=(e|e<<1)&1431655765,t=(t|t<<8)&16711935,t=(t|t<<4)&252645135,t=(t|t<<2)&858993459,t=(t|t<<1)&1431655765,e|t<<1}function Qr(e){let t=e,n=e;do(t.x<n.x||t.x===n.x&&t.y<n.y)&&(n=t),t=t.next;while(t!==e);return n}function X(e,t,n,r,i,o,s,a){return(i-s)*(t-a)>=(e-s)*(o-a)&&(e-s)*(r-a)>=(n-s)*(t-a)&&(n-s)*(o-a)>=(i-s)*(r-a)}function qr(e,t){return e.next.i!==t.i&&e.prev.i!==t.i&&!ei(e,t)&&(ce(e,t)&&ce(t,e)&&ti(e,t)&&(P(e.prev,e,t.prev)||P(e,t.prev,t))||Ue(e,t)&&P(e.prev,e,e.next)>0&&P(t.prev,t,t.next)>0)}function P(e,t,n){return(t.y-e.y)*(n.x-t.x)-(t.x-e.x)*(n.y-t.y)}function Ue(e,t){return e.x===t.x&&e.y===t.y}function Yt(e,t,n,r){let i=Me(P(e,t,n)),o=Me(P(e,t,r)),s=Me(P(n,r,e)),a=Me(P(n,r,t));return!!(i!==o&&s!==a||i===0&&_e(e,n,t)||o===0&&_e(e,r,t)||s===0&&_e(n,e,r)||a===0&&_e(n,t,r))}function _e(e,t,n){return t.x<=Math.max(e.x,n.x)&&t.x>=Math.min(e.x,n.x)&&t.y<=Math.max(e.y,n.y)&&t.y>=Math.min(e.y,n.y)}function Me(e){return e>0?1:e<0?-1:0}function ei(e,t){let n=e;do{if(n.i!==e.i&&n.next.i!==e.i&&n.i!==t.i&&n.next.i!==t.i&&Yt(n,n.next,e,t))return!0;n=n.next}while(n!==e);return!1}function ce(e,t){return P(e.prev,e,e.next)<0?P(e,t,e.next)>=0&&P(e,e.prev,t)>=0:P(e,t,e.prev)<0||P(e,e.next,t)<0}function ti(e,t){let n=e,r=!1,i=(e.x+t.x)/2,o=(e.y+t.y)/2;do n.y>o!=n.next.y>o&&n.next.y!==n.y&&i<(n.next.x-n.x)*(o-n.y)/(n.next.y-n.y)+n.x&&(r=!r),n=n.next;while(n!==e);return r}function Qt(e,t){let n=new ue(e.i,e.x,e.y),r=new ue(t.i,t.x,t.y),i=e.next,o=t.prev;return e.next=t,t.prev=e,n.next=i,i.prev=n,r.next=n,n.prev=r,o.next=r,r.prev=o,r}function Kt(e,t,n,r){let i=new ue(e,t,n);return r?(i.next=r.next,i.prev=r,r.next.prev=i,r.next=i):(i.prev=i,i.next=i),i}function fe(e){e.next.prev=e.prev,e.prev.next=e.next,e.prevZ&&(e.prevZ.nextZ=e.nextZ),e.nextZ&&(e.nextZ.prevZ=e.prevZ)}var ue=class{constructor(t,n,r){B(this,"i",void 0),B(this,"x",void 0),B(this,"y",void 0),B(this,"prev",null),B(this,"next",null),B(this,"z",0),B(this,"prevZ",null),B(this,"nextZ",null),B(this,"steiner",!1),this.i=t,this.x=n,this.y=r}};function at(e,t,n){let r=si(e),i=Object.keys(r).filter(o=>r[o]!==Array);return ai(e,{propArrayTypes:r,...t},{numericPropKeys:n&&n.numericPropKeys||i,PositionDataType:n?n.PositionDataType:Float32Array,triangulate:n?n.triangulate:!0})}function si(e){let t={};for(let n of e)if(n.properties)for(let r in n.properties){let i=n.properties[r];t[r]=di(i,t[r])}return t}function ai(e,t,n){let{pointPositionsCount:r,pointFeaturesCount:i,linePositionsCount:o,linePathsCount:s,lineFeaturesCount:a,polygonPositionsCount:l,polygonObjectsCount:c,polygonRingsCount:f,polygonFeaturesCount:u,propArrayTypes:h,coordLength:d}=t,{numericPropKeys:p=[],PositionDataType:m=Float32Array,triangulate:F=!0}=n,_=e[0]&&"id"in e[0],v=e.length>65535?Uint32Array:Uint16Array,y={type:"Point",positions:new m(r*d),globalFeatureIds:new v(r),featureIds:i>65535?new Uint32Array(r):new Uint16Array(r),numericProps:{},properties:[],fields:[]},g={type:"LineString",pathIndices:o>65535?new Uint32Array(s+1):new Uint16Array(s+1),positions:new m(o*d),globalFeatureIds:new v(o),featureIds:a>65535?new Uint32Array(o):new Uint16Array(o),numericProps:{},properties:[],fields:[]},V={type:"Polygon",polygonIndices:l>65535?new Uint32Array(c+1):new Uint16Array(c+1),primitivePolygonIndices:l>65535?new Uint32Array(f+1):new Uint16Array(f+1),positions:new m(l*d),globalFeatureIds:new v(l),featureIds:u>65535?new Uint32Array(l):new Uint16Array(l),numericProps:{},properties:[],fields:[]};F&&(V.triangles=[]);for(let M of[y,g,V])for(let T of p){let b=h[T];M.numericProps[T]=new b(M.positions.length/d)}g.pathIndices[s]=o,V.polygonIndices[c]=l,V.primitivePolygonIndices[f]=l;let C={pointPosition:0,pointFeature:0,linePosition:0,linePath:0,lineFeature:0,polygonPosition:0,polygonObject:0,polygonRing:0,polygonFeature:0,feature:0};for(let M of e){let T=M.geometry,b=M.properties||{};switch(T.type){case"Point":li(T,y,C,d,b),y.properties.push(st(b,p)),_&&y.fields.push({id:M.id}),C.pointFeature++;break;case"LineString":ci(T,g,C,d,b),g.properties.push(st(b,p)),_&&g.fields.push({id:M.id}),C.lineFeature++;break;case"Polygon":fi(T,V,C,d,b),V.properties.push(st(b,p)),_&&V.fields.push({id:M.id}),C.polygonFeature++;break;default:throw new Error("Invalid geometry type")}C.feature++}return hi(y,g,V,d)}function li(e,t,n,r,i){t.positions.set(e.data,n.pointPosition*r);let o=e.data.length/r;lt(t,i,n.pointPosition,o),t.globalFeatureIds.fill(n.feature,n.pointPosition,n.pointPosition+o),t.featureIds.fill(n.pointFeature,n.pointPosition,n.pointPosition+o),n.pointPosition+=o}function ci(e,t,n,r,i){t.positions.set(e.data,n.linePosition*r);let o=e.data.length/r;lt(t,i,n.linePosition,o),t.globalFeatureIds.fill(n.feature,n.linePosition,n.linePosition+o),t.featureIds.fill(n.lineFeature,n.linePosition,n.linePosition+o);for(let s=0,a=e.indices.length;s<a;++s){let l=e.indices[s],c=s===a-1?e.data.length:e.indices[s+1];t.pathIndices[n.linePath++]=n.linePosition,n.linePosition+=(c-l)/r}}function fi(e,t,n,r,i){t.positions.set(e.data,n.polygonPosition*r);let o=e.data.length/r;lt(t,i,n.polygonPosition,o),t.globalFeatureIds.fill(n.feature,n.polygonPosition,n.polygonPosition+o),t.featureIds.fill(n.polygonFeature,n.polygonPosition,n.polygonPosition+o);for(let s=0,a=e.indices.length;s<a;++s){let l=n.polygonPosition;t.polygonIndices[n.polygonObject++]=l;let c=e.areas[s],f=e.indices[s],u=e.indices[s+1];for(let d=0,p=f.length;d<p;++d){let m=f[d],F=d===p-1?u===void 0?e.data.length:u[0]:f[d+1];t.primitivePolygonIndices[n.polygonRing++]=n.polygonPosition,n.polygonPosition+=(F-m)/r}let h=n.polygonPosition;ui(t,c,f,{startPosition:l,endPosition:h,coordLength:r})}}function ui(e,t,n,{startPosition:r,endPosition:i,coordLength:o}){if(!e.triangles)return;let s=r*o,a=i*o,l=e.positions.subarray(s,a),c=n[0],f=n.slice(1).map(h=>(h-c)/o),u=it(l,f,o,t);for(let h=0,d=u.length;h<d;++h)e.triangles.push(r+u[h])}function ot(e,t){let n={};for(let r in e)n[r]={value:e[r],size:t};return n}function hi(e,t,n,r){let i={shape:"binary-feature-collection",points:{...e,positions:{value:e.positions,size:r},globalFeatureIds:{value:e.globalFeatureIds,size:1},featureIds:{value:e.featureIds,size:1},numericProps:ot(e.numericProps,1)},lines:{...t,positions:{value:t.positions,size:r},pathIndices:{value:t.pathIndices,size:1},globalFeatureIds:{value:t.globalFeatureIds,size:1},featureIds:{value:t.featureIds,size:1},numericProps:ot(t.numericProps,1)},polygons:{...n,positions:{value:n.positions,size:r},polygonIndices:{value:n.polygonIndices,size:1},primitivePolygonIndices:{value:n.primitivePolygonIndices,size:1},globalFeatureIds:{value:n.globalFeatureIds,size:1},featureIds:{value:n.featureIds,size:1},numericProps:ot(n.numericProps,1)}};return i.polygons&&n.triangles&&(i.polygons.triangles={value:new Uint32Array(n.triangles),size:1}),i}function lt(e,t,n,r){for(let i in e.numericProps)if(i in t){let o=t[i];e.numericProps[i].fill(o,n,n+r)}}function st(e,t){let n={};for(let r in e)t.includes(r)||(n[r]=e[r]);return n}function di(e,t){return t===Array||!Number.isFinite(e)?Array:t===Float64Array||Math.fround(e)!==e?Float64Array:Float32Array}var gt=Ut(ln(),1);function cn(e){let t=e.length;if(t<=1)return[e];let n=[],r,i;for(let o=0;o<t;o++){let s=Ei(e[o]);s!==0&&(i===void 0&&(i=s<0),i===s<0?(r&&n.push(r),r=[e[o]]):r&&r.push(e[o]))}return r&&n.push(r),n}function Ei(e){let t=0;for(let n=0,r=e.length-1,i,o;n<e.length;r=n++)i=e[n],o=e[r],t+=(o[0]-i[0])*(i[1]+o[1]);return t}function fn(e,t,n){t&&n&&(e===1?t.id=n.readVarint():e===2?_i(n,t):e===3?t.type=n.readVarint():e===4&&(t._geometry=n.pos))}function _i(e,t){let n=e.readVarint()+e.pos;for(;e.pos<n;){let r=t._keys[e.readVarint()],i=t._values[e.readVarint()];t.properties[r]=i}}var H=class{properties;extent;type;id;_pbf;_geometry;_keys;_values;static get types(){return["Unknown","Point","LineString","Polygon"]}constructor(t,n,r,i,o){this.properties={},this.extent=r,this.type=0,this.id=null,this._pbf=t,this._geometry=-1,this._keys=i,this._values=o,t.readFields(fn,this,n)}loadGeometry(){let t=this._pbf;t.pos=this._geometry;let n=t.readVarint()+t.pos,r=1,i=0,o=0,s=0,a=[],l;for(;t.pos<n;){if(i<=0){let c=t.readVarint();r=c&7,i=c>>3}if(i--,r===1||r===2)o+=t.readSVarint(),s+=t.readSVarint(),r===1&&(l&&a.push(l),l=[]),l&&l.push([o,s]);else if(r===7)l&&l.push(l[0].slice());else throw new Error(`unknown command ${r}`)}return l&&a.push(l),a}bbox(){let t=this._pbf;t.pos=this._geometry;let n=t.readVarint()+t.pos,r=1,i=0,o=0,s=0,a=1/0,l=-1/0,c=1/0,f=-1/0;for(;t.pos<n;){if(i<=0){let u=t.readVarint();r=u&7,i=u>>3}if(i--,r===1||r===2)o+=t.readSVarint(),s+=t.readSVarint(),o<a&&(a=o),o>l&&(l=o),s<c&&(c=s),s>f&&(f=s);else if(r!==7)throw new Error(`unknown command ${r}`)}return[a,c,l,f]}_toGeoJSON(t){let n=this.loadGeometry(),r=H.types[this.type],i,o;switch(this.type){case 1:let a=[];for(i=0;i<n.length;i++)a[i]=n[i][0];n=a,t(n,this);break;case 2:for(i=0;i<n.length;i++)t(n[i],this);break;case 3:for(n=cn(n),i=0;i<n.length;i++)for(o=0;o<n[i].length;o++)t(n[i][o],this);break}n.length===1?n=n[0]:r=`Multi${r}`;let s={type:"Feature",geometry:{type:r,coordinates:n},properties:this.properties};return this.id!==null&&(s.id=this.id),s}toGeoJSON(t){if(typeof t=="function")return this._toGeoJSON(t);let{x:n,y:r,z:i}=t,o=this.extent*Math.pow(2,i),s=this.extent*n,a=this.extent*r;function l(c){for(let f=0;f<c.length;f++){let u=c[f];u[0]=(u[0]+s)*360/o-180;let h=180-(u[1]+a)*360/o;u[1]=360/Math.PI*Math.atan(Math.exp(h*Math.PI/180))-90}}return this._toGeoJSON(l)}};var he=class{version;name;extent;length;_pbf;_keys;_values;_features;constructor(t,n){this.version=1,this.name="",this.extent=4096,this.length=0,this._pbf=t,this._keys=[],this._values=[],this._features=[],t.readFields(Mi,this,n),this.length=this._features.length}feature(t){if(t<0||t>=this._features.length)throw new Error("feature index out of bounds");this._pbf.pos=this._features[t];let n=this._pbf.readVarint()+this._pbf.pos;return new H(this._pbf,n,this.extent,this._keys,this._values)}};function Mi(e,t,n){t&&n&&(e===15?t.version=n.readVarint():e===1?t.name=n.readString():e===5?t.extent=n.readVarint():e===2?t._features.push(n.pos):e===3?t._keys.push(n.readString()):e===4&&t._values.push(Ui(n)))}function Ui(e){let t=null,n=e.readVarint()+e.pos;for(;e.pos<n;){let r=e.readVarint()>>3;t=r===1?e.readString():r===2?e.readFloat():r===3?e.readDouble():r===4?e.readVarint64():r===5?e.readVarint():r===6?e.readSVarint():r===7?e.readBoolean():null}return t}var de=class{layers;constructor(t,n){this.layers=t.readFields(Li,{},n)}};function Li(e,t,n){if(e===3&&n){let r=new he(n,n.readVarint()+n.pos);r.length&&t&&(t[r.name]=r)}}function un(e){let t=e.indices.length,n="Polygon";if(t<=1)return{type:n,data:e.data,areas:[[j(e.data)]],indices:[e.indices]};let r=[],i=[],o=[],s=[],a,l=0;for(let c,f=0,u;f<t;f++){u=e.indices[f]-l,c=e.indices[f+1]-l||e.data.length;let h=e.data.slice(u,c),d=j(h);if(d===0){let p=e.data.slice(0,u),m=e.data.slice(c);e.data=p.concat(m),l+=c-u;continue}a===void 0&&(a=d<0),a===d<0?(s.length&&(r.push(o),i.push(s)),s=[u],o=[d]):(o.push(d),s.push(u))}return o&&r.push(o),s.length&&i.push(s),{type:n,areas:r,indices:i,data:e.data}}function hn(e,t,n,r){for(let i=0,o=e.length;i<o;i+=2){e[i]=(e[i]+t)*360/r-180;let s=180-(e[i+1]+n)*360/r;e[i+1]=360/Math.PI*Math.atan(Math.exp(s*Math.PI/180))-90}}function dn(e,t,n){t&&n&&(e===1?t.id=n.readVarint():e===2?ki(n,t):e===3?t.type=n.readVarint():e===4&&(t._geometry=n.pos))}function ki(e,t){let n=e.readVarint()+e.pos;for(;e.pos<n;){let r=t._keys[e.readVarint()],i=t._values[e.readVarint()];t.properties[r]=i}}var pn,J,ut,Ce,ht,dt,pe;var ge=class{properties;extent;type;id;_pbf;_geometry;_keys;_values;_geometryInfo;constructor(t,n,r,i,o,s){this.properties={},this.extent=r,this.type=0,this.id=null,this._pbf=t,this._geometry=-1,this._keys=i,this._values=o,this._geometryInfo=s,t.readFields(dn,this,n)}loadGeometry(){let t=this._pbf;t.pos=this._geometry,pn=t.readVarint()+t.pos,J=1,Ce=0,ht=0,dt=0,pe=0;let n=[],r=[];for(;t.pos<pn;)if(Ce<=0&&(ut=t.readVarint(),J=ut&7,Ce=ut>>3),Ce--,J===1||J===2)ht+=t.readSVarint(),dt+=t.readSVarint(),J===1&&n.push(pe),r.push(ht,dt),pe+=2;else if(J===7){if(pe>0){let i=n[n.length-1];r.push(r[i],r[i+1]),pe+=2}}else throw new Error(`unknown command ${J}`);return{data:r,indices:n}}_toBinaryCoordinates(t){let n=this.loadGeometry(),r;t(n.data,this);let i=2;switch(this.type){case 1:this._geometryInfo.pointFeaturesCount++,this._geometryInfo.pointPositionsCount+=n.indices.length,r={type:"Point",...n};break;case 2:this._geometryInfo.lineFeaturesCount++,this._geometryInfo.linePathsCount+=n.indices.length,this._geometryInfo.linePositionsCount+=n.data.length/i,r={type:"LineString",...n};break;case 3:r=un(n),this._geometryInfo.polygonFeaturesCount++,this._geometryInfo.polygonObjectsCount+=r.indices.length;for(let s of r.indices)this._geometryInfo.polygonRingsCount+=s.length;this._geometryInfo.polygonPositionsCount+=r.data.length/i;break;default:throw new Error(`Invalid geometry type: ${this.type}`)}let o={type:"Feature",geometry:r,properties:this.properties};return this.id!==null&&(o.id=this.id),o}toBinaryCoordinates(t){if(typeof t=="function")return this._toBinaryCoordinates(t);let{x:n,y:r,z:i}=t,o=this.extent*Math.pow(2,i),s=this.extent*n,a=this.extent*r;return this._toBinaryCoordinates(l=>hn(l,s,a,o))}};var ye=class{version;name;extent;length;_pbf;_keys;_values;_features;constructor(t,n){this.version=1,this.name="",this.extent=4096,this.length=0,this._pbf=t,this._keys=[],this._values=[],this._features=[],t.readFields(Ci,this,n),this.length=this._features.length}feature(t,n){if(t<0||t>=this._features.length)throw new Error("feature index out of bounds");this._pbf.pos=this._features[t];let r=this._pbf.readVarint()+this._pbf.pos;return new ge(this._pbf,r,this.extent,this._keys,this._values,n)}};function Ci(e,t,n){t&&n&&(e===15?t.version=n.readVarint():e===1?t.name=n.readString():e===5?t.extent=n.readVarint():e===2?t._features.push(n.pos):e===3?t._keys.push(n.readString()):e===4&&t._values.push(Oi(n)))}function Oi(e){let t=null,n=e.readVarint()+e.pos;for(;e.pos<n;){let r=e.readVarint()>>3;t=r===1?e.readString():r===2?e.readFloat():r===3?e.readDouble():r===4?e.readVarint64():r===5?e.readVarint():r===6?e.readSVarint():r===7?e.readBoolean():null}return t}var me=class{layers;constructor(t,n){this.layers=t.readFields(Ni,{},n)}};function Ni(e,t,n){if(e===3&&n){let r=new ye(n,n.readVarint()+n.pos);r.length&&t&&(t[r.name]=r)}}function Oe(e,t){let n=Zi(t),r=t?.gis?.format||t?.mvt?.shape||t?.shape;switch(r){case"columnar-table":return{shape:"columnar-table",data:pt(e,n)};case"geojson-table":return{shape:"geojson-table",type:"FeatureCollection",features:gn(e,n)};case"geojson":return gn(e,n);case"binary-geometry":return pt(e,n);case"binary":return pt(e,n);default:throw new Error(r||"undefined shape")}}function pt(e,t){let[n,r]=zi(e,t),i=at(n,r);return i.byteLength=e.byteLength,i}function zi(e,t){let n=[],r={coordLength:2,pointPositionsCount:0,pointFeaturesCount:0,linePositionsCount:0,linePathsCount:0,lineFeaturesCount:0,polygonPositionsCount:0,polygonObjectsCount:0,polygonRingsCount:0,polygonFeaturesCount:0};if(e.byteLength<=0)return[n,r];let i=new me(new gt.default(e));return(t&&Array.isArray(t.layers)?t.layers:Object.keys(i.layers)).forEach(s=>{let a=i.layers[s];if(a)for(let l=0;l<a.length;l++){let c=a.feature(l,r),f=ji(c,t,s);n.push(f)}}),[n,r]}function gn(e,t){if(e.byteLength<=0)return[];let n=[],r=new de(new gt.default(e));return(Array.isArray(t.layers)?t.layers:Object.keys(r.layers)).forEach(o=>{let s=r.layers[o];if(s)for(let a=0;a<s.length;a++){let l=s.feature(a),c=Ri(l,t,o);n.push(c)}}),n}function Zi(e){if(!e?.mvt)throw new Error("mvt options required");let t=e.mvt?.coordinates==="wgs84",{tileIndex:n}=e.mvt,r=n&&Number.isFinite(n.x)&&Number.isFinite(n.y)&&Number.isFinite(n.z);if(t&&!r)throw new Error("MVT Loader: WGS84 coordinates need tileIndex property");return e.mvt}function Ri(e,t,n){let r=e.toGeoJSON(t.coordinates==="wgs84"?t.tileIndex:Gi);return t.layerProperty&&(r.properties[t.layerProperty]=n),r}function ji(e,t,n){let r=e.toBinaryCoordinates(t.coordinates==="wgs84"?t.tileIndex:Hi);return t.layerProperty&&r.properties&&(r.properties[t.layerProperty]=n),r}function Gi(e,t){let{extent:n}=t;for(let r=0;r<e.length;r++){let i=e[r];i[0]/=n,i[1]/=n}}function Hi(e,t){let{extent:n}=t;for(let r=0,i=e.length;r<i;++r)e[r]/=n}var Ji="4.2.0-alpha.5",yn={name:"Mapbox Vector Tile",id:"mvt",module:"mvt",version:Ji,extensions:["mvt","pbf"],mimeTypes:["application/vnd.mapbox-vector-tile","application/x-protobuf"],worker:!0,category:"geometry",options:{mvt:{shape:"geojson",coordinates:"local",layerProperty:"layerName",layers:void 0,tileIndex:null}}},yt={...yn,parse:async(e,t)=>Oe(e,t),parseSync:Oe,binary:!0};var vn=e=>e!==null&&typeof e=="object";function mt(e,t){if(!e||!vn(e))return null;let n={name:e.name||"",description:e.description||""};if(typeof e.generator=="string"&&(n.generator=e.generator),typeof e.generator_options=="string"&&(n.generatorOptions=e.generator_options),n.boundingBox=mn(e.bounds)||mn(e.antimeridian_adjusted_bounds),n.center=Qi(e.center),n.maxZoom=xn(e.maxzoom),n.minZoom=xn(e.minzoom),typeof e?.json=="string")try{n.metaJson=JSON.parse(e.json)}catch(a){console.warn("Failed to parse tilejson.json field",a)}let r=e.tilestats||n.metaJson?.tilestats,i=Ki(r,t),o=Wi(e.vector_layers),s=Yi(o,i);return n={...n,layers:s},n.maxZoom===null&&s.length>0&&(n.maxZoom=s[0].maxZoom||null),n.minZoom===null&&s.length>0&&(n.minZoom=s[0].minZoom||null),n}function Wi(e){return Array.isArray(e)?e.map(t=>$i(t)):[]}function $i(e){let t=Object.entries(e.fields||[]).map(([r,i])=>({name:r,...Tn(String(i))})),n={...e};return delete n.fields,{name:e.id||"",...n,fields:t}}function Ki(e,t){return vn(e)&&Array.isArray(e.layers)?e.layers.map(n=>Xi(n,t)):[]}function Xi(e,t){let n=[],r={},i=e.attributes||[];for(let o of i){let s=o.attribute;if(typeof s=="string")if(s.split("|").length>1){let a=s.split("|")[0];r[a]=r[a]||[],r[a].push(o),console.warn("ignoring tilestats indexed field",a)}else n[s]||n.push(eo(o,t))}return{name:e.layer||"",dominantGeometry:e.geometry,fields:n}}function Yi(e,t){return e.map(n=>{let r=t.find(s=>s.name===n.name),i=r?.fields||[],o={...n};return delete o.fields,{...o,...r,fields:i}})}function mn(e){let t=In(e);if(Array.isArray(t)&&t.length===4&&[t[0],t[2]].every(Fn)&&[t[1],t[3]].every(Pn))return[[t[0],t[1]],[t[2],t[3]]]}function Qi(e){let t=In(e);return Array.isArray(t)&&t.length===3&&Fn(t[0])&&Pn(t[1])&&qi(t[2])?t:null}function xn(e){let t=typeof e=="string"?parseFloat(e):typeof e=="number"?e:null;return t===null||isNaN(t)?null:t}function Pn(e){return Number.isFinite(e)&&e<=90&&e>=-90}function Fn(e){return Number.isFinite(e)&&e<=180&&e>=-180}function qi(e){return Number.isFinite(e)&&e>=0&&e<=22}function In(e){return typeof e=="string"?e.split(",").map(parseFloat):Array.isArray(e)?e:null}var wn={number:{type:"float32"},numeric:{type:"float32"},string:{type:"utf8"},vachar:{type:"utf8"},float:{type:"float32"},int:{type:"int32"},int4:{type:"int32"},boolean:{type:"boolean"},bool:{type:"boolean"}};function eo(e={},t){let n=Tn(e.type),r={name:e.attribute,...n};return typeof e.min=="number"&&(r.min=e.min),typeof e.max=="number"&&(r.max=e.max),typeof e.count=="number"&&(r.uniqueValueCount=e.count),e.values&&(r.values=e.values),r.values&&typeof t.maxValues=="number"&&(r.values=r.values?.slice(0,t.maxValues)),r}function Tn(e){let t=e.toLowerCase();return!t||wn[t],wn[t]||{type:"string"}}var to="4.2.0-alpha.5",xe={name:"TileJSON",id:"tilejson",module:"pmtiles",version:to,worker:!0,extensions:["json"],mimeTypes:["application/json"],text:!0,options:{tilejson:{maxValues:void 0}},parse:async(e,t)=>{let n=new TextDecoder().decode(e),r=JSON.parse(n),i={...xe.options.tilejson,...t?.tilejson};return mt(r,i)},parseTextSync:(e,t)=>{let n=JSON.parse(e),r={...xe.options.tilejson,...t?.tilejson};return mt(n,r)}};var Fe={};Mt(Fe,{Compression:()=>Zn,EtagMismatch:()=>ze,FetchSource:()=>Gn,FileSource:()=>ko,PMTiles:()=>Ft,Protocol:()=>Bo,ResolvedValueCache:()=>Oo,SharedPromiseCache:()=>Kn,TileType:()=>Rn,bytesToHeader:()=>Hn,findTile:()=>jn,getUint64:()=>E,leafletRasterLayer:()=>bo,readVarint:()=>ee,tileIdToZxy:()=>Uo,zxyToTileId:()=>zn});var W=Math.pow,I=(e,t,n)=>new Promise((r,i)=>{var o=l=>{try{a(n.next(l))}catch(c){i(c)}},s=l=>{try{a(n.throw(l))}catch(c){i(c)}},a=l=>l.done?r(l.value):Promise.resolve(l.value).then(o,s);a((n=n.apply(e,t)).next())}),D=Uint8Array,te=Uint16Array,no=Int32Array,Vn=new D([0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0,0,0,0]),bn=new D([0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13,0,0]),ro=new D([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]),An=function(e,t){for(var n=new te(31),r=0;r<31;++r)n[r]=t+=1<<e[r-1];for(var i=new no(n[30]),r=1;r<30;++r)for(var o=n[r];o<n[r+1];++o)i[o]=o-n[r]<<5|r;return{b:n,r:i}},Bn=An(Vn,2),En=Bn.b,io=Bn.r;En[28]=258,io[258]=28;var _n=An(bn,0),oo=_n.b,Qa=_n.r,vt=new te(32768);for(w=0;w<32768;++w)Z=(w&43690)>>1|(w&21845)<<1,Z=(Z&52428)>>2|(Z&13107)<<2,Z=(Z&61680)>>4|(Z&3855)<<4,vt[w]=((Z&65280)>>8|(Z&255)<<8)>>1;var Z,w,ve=function(e,t,n){for(var r=e.length,i=0,o=new te(t);i<r;++i)e[i]&&++o[e[i]-1];var s=new te(t);for(i=1;i<t;++i)s[i]=s[i-1]+o[i-1]<<1;var a;if(n){a=new te(1<<t);var l=15-t;for(i=0;i<r;++i)if(e[i])for(var c=i<<4|e[i],f=t-e[i],u=s[e[i]-1]++<<f,h=u|(1<<f)-1;u<=h;++u)a[vt[u]>>l]=c}else for(a=new te(r),i=0;i<r;++i)e[i]&&(a[i]=vt[s[e[i]-1]++]>>15-e[i]);return a},Pe=new D(288);for(w=0;w<144;++w)Pe[w]=8;var w;for(w=144;w<256;++w)Pe[w]=9;var w;for(w=256;w<280;++w)Pe[w]=7;var w;for(w=280;w<288;++w)Pe[w]=8;var w,Mn=new D(32);for(w=0;w<32;++w)Mn[w]=5;var w,so=ve(Pe,9,1),ao=ve(Mn,5,1),xt=function(e){for(var t=e[0],n=1;n<e.length;++n)e[n]>t&&(t=e[n]);return t},k=function(e,t,n){var r=t/8|0;return(e[r]|e[r+1]<<8)>>(t&7)&n},wt=function(e,t){var n=t/8|0;return(e[n]|e[n+1]<<8|e[n+2]<<16)>>(t&7)},lo=function(e){return(e+7)/8|0},co=function(e,t,n){(t==null||t<0)&&(t=0),(n==null||n>e.length)&&(n=e.length);var r=new D(n-t);return r.set(e.subarray(t,n)),r},fo=["unexpected EOF","invalid block type","invalid length/literal","invalid distance","stream finished","no stream handler",,"no callback","invalid UTF-8 data","extra field too long","date not in range 1980-2099","filename too long","stream finishing","invalid zip data"],S=function(e,t,n){var r=new Error(t||fo[e]);if(r.code=e,Error.captureStackTrace&&Error.captureStackTrace(r,S),!n)throw r;return r},It=function(e,t,n,r){var i=e.length,o=r?r.length:0;if(!i||t.f&&!t.l)return n||new D(0);var s=!n||t.i!=2,a=t.i;n||(n=new D(i*3));var l=function(Bt){var Et=n.length;if(Bt>Et){var _t=new D(Math.max(Et*2,Bt));_t.set(n),n=_t}},c=t.f||0,f=t.p||0,u=t.b||0,h=t.l,d=t.d,p=t.m,m=t.n,F=i*8;do{if(!h){c=k(e,f,1);var _=k(e,f+1,3);if(f+=3,_)if(_==1)h=so,d=ao,p=9,m=5;else if(_==2){var V=k(e,f,31)+257,C=k(e,f+10,15)+4,M=V+k(e,f+5,31)+1;f+=14;for(var T=new D(M),b=new D(19),A=0;A<C;++A)b[ro[A]]=k(e,f+A*3,7);f+=C*3;for(var St=xt(b),Yn=(1<<St)-1,Qn=ve(b,St,1),A=0;A<M;){var Dt=Qn[k(e,f,Yn)];f+=Dt&15;var v=Dt>>4;if(v<16)T[A++]=v;else{var $=0,Se=0;for(v==16?(Se=3+k(e,f,3),f+=2,$=T[A-1]):v==17?(Se=3+k(e,f,7),f+=3):v==18&&(Se=11+k(e,f,127),f+=7);Se--;)T[A++]=$}}var Vt=T.subarray(0,V),U=T.subarray(V);p=xt(Vt),m=xt(U),h=ve(Vt,p,1),d=ve(U,m,1)}else S(1);else{var v=lo(f)+4,y=e[v-4]|e[v-3]<<8,g=v+y;if(g>i){a&&S(0);break}s&&l(u+y),n.set(e.subarray(v,g),u),t.b=u+=y,t.p=f=g*8,t.f=c;continue}if(f>F){a&&S(0);break}}s&&l(u+131072);for(var qn=(1<<p)-1,er=(1<<m)-1,je=f;;je=f){var $=h[wt(e,f)&qn],K=$>>4;if(f+=$&15,f>F){a&&S(0);break}if($||S(2),K<256)n[u++]=K;else if(K==256){je=f,h=null;break}else{var bt=K-254;if(K>264){var A=K-257,ne=Vn[A];bt=k(e,f,(1<<ne)-1)+En[A],f+=ne}var Ge=d[wt(e,f)&er],He=Ge>>4;Ge||S(3),f+=Ge&15;var U=oo[He];if(He>3){var ne=bn[He];U+=wt(e,f)&(1<<ne)-1,f+=ne}if(f>F){a&&S(0);break}s&&l(u+131072);var Je=u+bt;if(u<U){var At=o-U,tr=Math.min(U,Je);for(At+u<0&&S(3);u<tr;++u)n[u]=r[At+u]}for(;u<Je;u+=4)n[u]=n[u-U],n[u+1]=n[u+1-U],n[u+2]=n[u+2-U],n[u+3]=n[u+3-U];u=Je}}t.l=h,t.p=je,t.b=u,t.f=c,h&&(c=1,t.m=p,t.d=d,t.n=m)}while(!c);return u==n.length?n:co(n,0,u)},uo=new D(0),ho=function(e){(e[0]!=31||e[1]!=139||e[2]!=8)&&S(6,"invalid gzip data");var t=e[3],n=10;t&4&&(n+=(e[10]|e[11]<<8)+2);for(var r=(t>>3&1)+(t>>4&1);r>0;r-=!e[n++]);return n+(t&2)},po=function(e){var t=e.length;return(e[t-4]|e[t-3]<<8|e[t-2]<<16|e[t-1]<<24)>>>0},go=function(e,t){return((e[0]&15)!=8||e[0]>>4>7||(e[0]<<8|e[1])%31)&&S(6,"invalid zlib data"),(e[1]>>5&1)==+!t&&S(6,"invalid zlib data: "+(e[1]&32?"need":"unexpected")+" dictionary"),(e[1]>>3&4)+2};function yo(e,t){return It(e,{i:2},t&&t.out,t&&t.dictionary)}function mo(e,t){var n=ho(e);return n+8>e.length&&S(6,"invalid gzip data"),It(e.subarray(n,-8),{i:2},t&&t.out||new D(po(e)),t&&t.dictionary)}function xo(e,t){return It(e.subarray(go(e,t&&t.dictionary),-4),{i:2},t&&t.out,t&&t.dictionary)}function Pt(e,t){return e[0]==31&&e[1]==139&&e[2]==8?mo(e,t):(e[0]&15)!=8||e[0]>>4>7||(e[0]<<8|e[1])%31?yo(e,t):xo(e,t)}var wo=typeof TextDecoder<"u"&&new TextDecoder,vo=0;try{wo.decode(uo,{stream:!0}),vo=1}catch{}var Un=(e,t)=>e*W(2,t),we=(e,t)=>Math.floor(e/W(2,t)),Ne=(e,t)=>Un(e.getUint16(t+1,!0),8)+e.getUint8(t),Ln=(e,t)=>Un(e.getUint32(t+2,!0),16)+e.getUint16(t,!0),Po=(e,t,n,r,i)=>{if(e!==r.getUint8(i))return e-r.getUint8(i);let o=Ne(r,i+1);if(t!==o)return t-o;let s=Ne(r,i+4);return n!==s?n-s:0},Fo=(e,t,n,r)=>{let i=kn(e,t|128,n,r);return i?{z:t,x:n,y:r,offset:i[0],length:i[1],isDir:!0}:null},Sn=(e,t,n,r)=>{let i=kn(e,t,n,r);return i?{z:t,x:n,y:r,offset:i[0],length:i[1],isDir:!1}:null},kn=(e,t,n,r)=>{let i=0,o=e.byteLength/17-1;for(;i<=o;){let s=o+i>>1,a=Po(t,n,r,e,s*17);if(a>0)i=s+1;else if(a<0)o=s-1;else return[Ln(e,s*17+7),e.getUint32(s*17+13,!0)]}return null},Io=(e,t)=>e.isDir&&!t.isDir?1:!e.isDir&&t.isDir?-1:e.z!==t.z?e.z-t.z:e.x!==t.x?e.x-t.x:e.y-t.y,Cn=(e,t)=>{let n=e.getUint8(t*17);return{z:n&127,x:Ne(e,t*17+1),y:Ne(e,t*17+4),offset:Ln(e,t*17+7),length:e.getUint32(t*17+13,!0),isDir:n>>7===1}},Dn=e=>{let t=[],n=new DataView(e);for(let r=0;r<n.byteLength/17;r++)t.push(Cn(n,r));return To(t)},To=e=>{e.sort(Io);let t=new ArrayBuffer(17*e.length),n=new Uint8Array(t);for(let r=0;r<e.length;r++){let i=e[r],o=i.z;i.isDir&&(o=o|128),n[r*17]=o,n[r*17+1]=i.x&255,n[r*17+2]=i.x>>8&255,n[r*17+3]=i.x>>16&255,n[r*17+4]=i.y&255,n[r*17+5]=i.y>>8&255,n[r*17+6]=i.y>>16&255,n[r*17+7]=i.offset&255,n[r*17+8]=we(i.offset,8)&255,n[r*17+9]=we(i.offset,16)&255,n[r*17+10]=we(i.offset,24)&255,n[r*17+11]=we(i.offset,32)&255,n[r*17+12]=we(i.offset,48)&255,n[r*17+13]=i.length&255,n[r*17+14]=i.length>>8&255,n[r*17+15]=i.length>>16&255,n[r*17+16]=i.length>>24&255}return t},So=(e,t)=>{if(e.byteLength<17)return null;let n=e.byteLength/17,r=Cn(e,n-1);if(r.isDir){let i=r.z,o=t.z-i,s=Math.trunc(t.x/(1<<o)),a=Math.trunc(t.y/(1<<o));return{z:i,x:s,y:a}}return null};function Do(e){return I(this,null,function*(){let t=yield e.getBytes(0,512e3),n=new DataView(t.data),r=n.getUint32(4,!0),i=n.getUint16(8,!0),o=new TextDecoder("utf-8"),s=JSON.parse(o.decode(new DataView(t.data,10,r))),a=0;s.compression==="gzip"&&(a=2);let l=0;"minzoom"in s&&(l=+s.minzoom);let c=0;"maxzoom"in s&&(c=+s.maxzoom);let f=0,u=0,h=0,d=-180,p=-85,m=180,F=85;if(s.bounds){let v=s.bounds.split(",");d=+v[0],p=+v[1],m=+v[2],F=+v[3]}if(s.center){let v=s.center.split(",");f=+v[0],u=+v[1],h=+v[2]}return{specVersion:n.getUint16(2,!0),rootDirectoryOffset:10+r,rootDirectoryLength:i*17,jsonMetadataOffset:10,jsonMetadataLength:r,leafDirectoryOffset:0,leafDirectoryLength:void 0,tileDataOffset:0,tileDataLength:void 0,numAddressedTiles:0,numTileEntries:0,numTileContents:0,clustered:!1,internalCompression:1,tileCompression:a,tileType:1,minZoom:l,maxZoom:c,minLon:d,minLat:p,maxLon:m,maxLat:F,centerZoom:h,centerLon:f,centerLat:u,etag:t.etag}})}function Vo(e,t,n,r,i,o,s){return I(this,null,function*(){let a=yield n.getArrayBuffer(t,e.rootDirectoryOffset,e.rootDirectoryLength,e);e.specVersion===1&&(a=Dn(a));let l=Sn(new DataView(a),r,i,o);if(l){let u=(yield t.getBytes(l.offset,l.length,s)).data,h=new DataView(u);return h.getUint8(0)===31&&h.getUint8(1)===139&&(u=Pt(new Uint8Array(u))),{data:u}}let c=So(new DataView(a),{z:r,x:i,y:o});if(c){let f=Fo(new DataView(a),c.z,c.x,c.y);if(f){let u=yield n.getArrayBuffer(t,f.offset,f.length,e);e.specVersion===1&&(u=Dn(u));let h=Sn(new DataView(u),r,i,o);if(h){let p=(yield t.getBytes(h.offset,h.length,s)).data,m=new DataView(p);return m.getUint8(0)===31&&m.getUint8(1)===139&&(p=Pt(new Uint8Array(p))),{data:p}}}}})}var On={getHeader:Do,getZxy:Vo},bo=(e,t)=>{let n=!1,r="",i=L.GridLayer.extend({createTile:(o,s)=>{let a=document.createElement("img"),l=new AbortController,c=l.signal;return a.cancel=()=>{l.abort()},n||(e.getHeader().then(f=>{f.tileType===1?console.error("Error: archive contains MVT vector tiles, but leafletRasterLayer is for displaying raster tiles. See https://github.com/protomaps/PMTiles/tree/main/js for details."):f.tileType===2?r="image/png":f.tileType===3?r="image/jpeg":f.tileType===4?r="image/webp":f.tileType===5&&(r="image/avif")}),n=!0),e.getZxy(o.z,o.x,o.y,c).then(f=>{if(f){let u=new Blob([f.data],{type:r}),h=window.URL.createObjectURL(u);a.src=h,a.cancel=void 0,s(void 0,a)}}).catch(f=>{if(f.name!=="AbortError")throw f}),a},_removeTile:function(o){let s=this._tiles[o];s&&(s.el.cancel&&s.el.cancel(),s.el.width=0,s.el.height=0,s.el.deleted=!0,L.DomUtil.remove(s.el),delete this._tiles[o],this.fire("tileunload",{tile:s.el,coords:this._keyToTileCoords(o)}))}});return new i(t)},Ao=e=>(t,n)=>{if(n instanceof AbortController)return e(t,n);let r=new AbortController;return e(t,r).then(i=>n(void 0,i.data,i.cacheControl||"",i.expires||""),i=>n(i)).catch(i=>n(i)),{cancel:()=>r.abort()}},Bo=class{constructor(){this.tilev4=(e,t)=>I(this,null,function*(){if(e.type==="json"){let u=e.url.substr(10),h=this.tiles.get(u);h||(h=new Ft(u),this.tiles.set(u,h));let d=yield h.getHeader();return{data:{tiles:[`${e.url}/{z}/{x}/{y}`],minzoom:d.minZoom,maxzoom:d.maxZoom,bounds:[d.minLon,d.minLat,d.maxLon,d.maxLat]}}}let n=new RegExp(/pmtiles:\/\/(.+)\/(\d+)\/(\d+)\/(\d+)/),r=e.url.match(n);if(!r)throw new Error("Invalid PMTiles protocol URL");let i=r[1],o=this.tiles.get(i);o||(o=new Ft(i),this.tiles.set(i,o));let s=r[2],a=r[3],l=r[4],c=yield o.getHeader(),f=yield o?.getZxy(+s,+a,+l,t.signal);return f?{data:new Uint8Array(f.data),cacheControl:f.cacheControl,expires:f.expires}:c.tileType===1?{data:new Uint8Array}:{data:null}}),this.tile=Ao(this.tilev4),this.tiles=new Map}add(e){this.tiles.set(e.source.getKey(),e)}get(e){return this.tiles.get(e)}};function q(e,t){return(t>>>0)*4294967296+(e>>>0)}function Eo(e,t){let n=t.buf,r=n[t.pos++],i=(r&112)>>4;if(r<128||(r=n[t.pos++],i|=(r&127)<<3,r<128)||(r=n[t.pos++],i|=(r&127)<<10,r<128)||(r=n[t.pos++],i|=(r&127)<<17,r<128)||(r=n[t.pos++],i|=(r&127)<<24,r<128)||(r=n[t.pos++],i|=(r&1)<<31,r<128))return q(e,i);throw new Error("Expected varint not more than 10 bytes")}function ee(e){let t=e.buf,n=t[e.pos++],r=n&127;return n<128||(n=t[e.pos++],r|=(n&127)<<7,n<128)||(n=t[e.pos++],r|=(n&127)<<14,n<128)||(n=t[e.pos++],r|=(n&127)<<21,n<128)?r:(n=t[e.pos],r|=(n&15)<<28,Eo(r,e))}function Nn(e,t,n,r){if(r===0){n===1&&(t[0]=e-1-t[0],t[1]=e-1-t[1]);let i=t[0];t[0]=t[1],t[1]=i}}function _o(e,t){let n=W(2,e),r=t,i=t,o=t,s=[0,0],a=1;for(;a<n;)r=1&o/2,i=1&(o^r),Nn(a,s,r,i),s[0]+=a*r,s[1]+=a*i,o=o/4,a*=2;return[e,s[0],s[1]]}var Mo=[0,1,5,21,85,341,1365,5461,21845,87381,349525,1398101,5592405,22369621,89478485,357913941,1431655765,5726623061,22906492245,91625968981,366503875925,1466015503701,5864062014805,23456248059221,93824992236885,375299968947541,0x5555555555555];function zn(e,t,n){if(e>26)throw Error("Tile zoom level exceeds max safe number limit (26)");if(t>W(2,e)-1||n>W(2,e)-1)throw Error("tile x/y outside zoom level bounds");let r=Mo[e],i=W(2,e),o=0,s=0,a=0,l=[t,n],c=i/2;for(;c>0;)o=(l[0]&c)>0?1:0,s=(l[1]&c)>0?1:0,a+=c*c*(3*o^s),Nn(c,l,o,s),c=c/2;return r+a}function Uo(e){let t=0,n=0;for(let r=0;r<27;r++){let i=(1<<r)*(1<<r);if(t+i>e)return _o(r,e-t);t+=i}throw Error("Tile zoom level exceeds max safe number limit (26)")}var Zn=(e=>(e[e.Unknown=0]="Unknown",e[e.None=1]="None",e[e.Gzip=2]="Gzip",e[e.Brotli=3]="Brotli",e[e.Zstd=4]="Zstd",e))(Zn||{});function Tt(e,t){return I(this,null,function*(){if(t===1||t===0)return e;if(t===2){if(typeof globalThis.DecompressionStream>"u")return Pt(new Uint8Array(e));let n=new Response(e).body;if(!n)throw Error("Failed to read response stream");let r=n.pipeThrough(new globalThis.DecompressionStream("gzip"));return new Response(r).arrayBuffer()}throw Error("Compression method not supported")})}var Rn=(e=>(e[e.Unknown=0]="Unknown",e[e.Mvt=1]="Mvt",e[e.Png=2]="Png",e[e.Jpeg=3]="Jpeg",e[e.Webp=4]="Webp",e[e.Avif=5]="Avif",e))(Rn||{}),Lo=127;function jn(e,t){let n=0,r=e.length-1;for(;n<=r;){let i=r+n>>1,o=t-e[i].tileId;if(o>0)n=i+1;else if(o<0)r=i-1;else return e[i]}return r>=0&&(e[r].runLength===0||t-e[r].tileId<e[r].runLength)?e[r]:null}var ko=class{constructor(e){this.file=e}getKey(){return this.file.name}getBytes(e,t){return I(this,null,function*(){return{data:yield this.file.slice(e,e+t).arrayBuffer()}})}},Gn=class{constructor(e,t=new Headers){this.url=e,this.customHeaders=t,this.mustReload=!1}getKey(){return this.url}setHeaders(e){this.customHeaders=e}getBytes(e,t,n,r){return I(this,null,function*(){let i,o;n?o=n:(i=new AbortController,o=i.signal);let s=new Headers(this.customHeaders);s.set("range",`bytes=${e}-${e+t-1}`);let a;this.mustReload&&(a="reload");let l=yield fetch(this.url,{signal:o,cache:a,headers:s});if(e===0&&l.status===416){let h=l.headers.get("Content-Range");if(!h||!h.startsWith("bytes */"))throw Error("Missing content-length on 416 response");let d=+h.substr(8);l=yield fetch(this.url,{signal:o,cache:"reload",headers:{range:`bytes=0-${d-1}`}})}let c=l.headers.get("Etag");if(c?.startsWith("W/")&&(c=null),l.status===416||r&&c&&c!==r)throw this.mustReload=!0,new ze(r);if(l.status>=300)throw Error(`Bad response code: ${l.status}`);let f=l.headers.get("Content-Length");if(l.status===200&&(!f||+f>t))throw i&&i.abort(),Error("Server returned no content-length header or content-length exceeding request. Check that your storage backend supports HTTP Byte Serving.");return{data:yield l.arrayBuffer(),etag:c||void 0,cacheControl:l.headers.get("Cache-Control")||void 0,expires:l.headers.get("Expires")||void 0}})}};function E(e,t){let n=e.getUint32(t+4,!0),r=e.getUint32(t+0,!0);return n*W(2,32)+r}function Hn(e,t){let n=new DataView(e),r=n.getUint8(7);if(r>3)throw Error(`Archive is spec version ${r} but this library supports up to spec version 3`);return{specVersion:r,rootDirectoryOffset:E(n,8),rootDirectoryLength:E(n,16),jsonMetadataOffset:E(n,24),jsonMetadataLength:E(n,32),leafDirectoryOffset:E(n,40),leafDirectoryLength:E(n,48),tileDataOffset:E(n,56),tileDataLength:E(n,64),numAddressedTiles:E(n,72),numTileEntries:E(n,80),numTileContents:E(n,88),clustered:n.getUint8(96)===1,internalCompression:n.getUint8(97),tileCompression:n.getUint8(98),tileType:n.getUint8(99),minZoom:n.getUint8(100),maxZoom:n.getUint8(101),minLon:n.getInt32(102,!0)/1e7,minLat:n.getInt32(106,!0)/1e7,maxLon:n.getInt32(110,!0)/1e7,maxLat:n.getInt32(114,!0)/1e7,centerZoom:n.getUint8(118),centerLon:n.getInt32(119,!0)/1e7,centerLat:n.getInt32(123,!0)/1e7,etag:t}}function Jn(e){let t={buf:new Uint8Array(e),pos:0},n=ee(t),r=[],i=0;for(let o=0;o<n;o++){let s=ee(t);r.push({tileId:i+s,offset:0,length:0,runLength:1}),i+=s}for(let o=0;o<n;o++)r[o].runLength=ee(t);for(let o=0;o<n;o++)r[o].length=ee(t);for(let o=0;o<n;o++){let s=ee(t);s===0&&o>0?r[o].offset=r[o-1].offset+r[o-1].length:r[o].offset=s-1}return r}function Co(e){let t=new DataView(e);return t.getUint16(2,!0)===2?(console.warn("PMTiles spec version 2 has been deprecated; please see github.com/protomaps/PMTiles for tools to upgrade"),2):t.getUint16(2,!0)===1?(console.warn("PMTiles spec version 1 has been deprecated; please see github.com/protomaps/PMTiles for tools to upgrade"),1):3}var ze=class extends Error{};function Wn(e,t){return I(this,null,function*(){let n=yield e.getBytes(0,16384);if(new DataView(n.data).getUint16(0,!0)!==19792)throw new Error("Wrong magic number for PMTiles archive");if(Co(n.data)<3)return[yield On.getHeader(e)];let i=n.data.slice(0,Lo),o=Hn(i,n.etag),s=n.data.slice(o.rootDirectoryOffset,o.rootDirectoryOffset+o.rootDirectoryLength),a=`${e.getKey()}|${o.etag||""}|${o.rootDirectoryOffset}|${o.rootDirectoryLength}`,l=Jn(yield t(s,o.internalCompression));return[o,[a,l.length,l]]})}function $n(e,t,n,r,i){return I(this,null,function*(){let o=yield e.getBytes(n,r,void 0,i.etag),s=yield t(o.data,i.internalCompression),a=Jn(s);if(a.length===0)throw new Error("Empty directory is invalid");return a})}var Oo=class{constructor(e=100,t=!0,n=Tt){this.cache=new Map,this.maxCacheEntries=e,this.counter=1,this.decompress=n}getHeader(e){return I(this,null,function*(){let t=e.getKey(),n=this.cache.get(t);if(n)return n.lastUsed=this.counter++,n.data;let r=yield Wn(e,this.decompress);return r[1]&&this.cache.set(r[1][0],{lastUsed:this.counter++,data:r[1][2]}),this.cache.set(t,{lastUsed:this.counter++,data:r[0]}),this.prune(),r[0]})}getDirectory(e,t,n,r){return I(this,null,function*(){let i=`${e.getKey()}|${r.etag||""}|${t}|${n}`,o=this.cache.get(i);if(o)return o.lastUsed=this.counter++,o.data;let s=yield $n(e,this.decompress,t,n,r);return this.cache.set(i,{lastUsed:this.counter++,data:s}),this.prune(),s})}getArrayBuffer(e,t,n,r){return I(this,null,function*(){let i=`${e.getKey()}|${r.etag||""}|${t}|${n}`,o=this.cache.get(i);if(o)return o.lastUsed=this.counter++,yield o.data;let s=yield e.getBytes(t,n,void 0,r.etag);return this.cache.set(i,{lastUsed:this.counter++,data:s.data}),this.prune(),s.data})}prune(){if(this.cache.size>this.maxCacheEntries){let e=1/0,t;this.cache.forEach((n,r)=>{n.lastUsed<e&&(e=n.lastUsed,t=r)}),t&&this.cache.delete(t)}}invalidate(e){return I(this,null,function*(){this.cache.delete(e.getKey())})}},Kn=class{constructor(e=100,t=!0,n=Tt){this.cache=new Map,this.invalidations=new Map,this.maxCacheEntries=e,this.counter=1,this.decompress=n}getHeader(e){return I(this,null,function*(){let t=e.getKey(),n=this.cache.get(t);if(n)return n.lastUsed=this.counter++,yield n.data;let r=new Promise((i,o)=>{Wn(e,this.decompress).then(s=>{s[1]&&this.cache.set(s[1][0],{lastUsed:this.counter++,data:Promise.resolve(s[1][2])}),i(s[0]),this.prune()}).catch(s=>{o(s)})});return this.cache.set(t,{lastUsed:this.counter++,data:r}),r})}getDirectory(e,t,n,r){return I(this,null,function*(){let i=`${e.getKey()}|${r.etag||""}|${t}|${n}`,o=this.cache.get(i);if(o)return o.lastUsed=this.counter++,yield o.data;let s=new Promise((a,l)=>{$n(e,this.decompress,t,n,r).then(c=>{a(c),this.prune()}).catch(c=>{l(c)})});return this.cache.set(i,{lastUsed:this.counter++,data:s}),s})}getArrayBuffer(e,t,n,r){return I(this,null,function*(){let i=`${e.getKey()}|${r.etag||""}|${t}|${n}`,o=this.cache.get(i);if(o)return o.lastUsed=this.counter++,yield o.data;let s=new Promise((a,l)=>{e.getBytes(t,n,void 0,r.etag).then(c=>{a(c.data),this.cache.has(i),this.prune()}).catch(c=>{l(c)})});return this.cache.set(i,{lastUsed:this.counter++,data:s}),s})}prune(){if(this.cache.size>=this.maxCacheEntries){let e=1/0,t;this.cache.forEach((n,r)=>{n.lastUsed<e&&(e=n.lastUsed,t=r)}),t&&this.cache.delete(t)}}invalidate(e){return I(this,null,function*(){let t=e.getKey();if(this.invalidations.get(t))return yield this.invalidations.get(t);this.cache.delete(e.getKey());let n=new Promise((r,i)=>{this.getHeader(e).then(o=>{r(),this.invalidations.delete(t)}).catch(o=>{i(o)})});this.invalidations.set(t,n)})}},Ft=class{constructor(e,t,n){typeof e=="string"?this.source=new Gn(e):this.source=e,n?this.decompress=n:this.decompress=Tt,t?this.cache=t:this.cache=new Kn}getHeader(){return I(this,null,function*(){return yield this.cache.getHeader(this.source)})}getZxyAttempt(e,t,n,r){return I(this,null,function*(){let i=zn(e,t,n),o=yield this.cache.getHeader(this.source);if(o.specVersion<3)return On.getZxy(o,this.source,this.cache,e,t,n,r);if(e<o.minZoom||e>o.maxZoom)return;let s=o.rootDirectoryOffset,a=o.rootDirectoryLength;for(let l=0;l<=3;l++){let c=yield this.cache.getDirectory(this.source,s,a,o),f=jn(c,i);if(f){if(f.runLength>0){let u=yield this.source.getBytes(o.tileDataOffset+f.offset,f.length,r,o.etag);return{data:yield this.decompress(u.data,o.tileCompression),cacheControl:u.cacheControl,expires:u.expires}}s=o.leafDirectoryOffset+f.offset,a=f.length}else return}throw Error("Maximum directory depth exceeded")})}getZxy(e,t,n,r){return I(this,null,function*(){try{return yield this.getZxyAttempt(e,t,n,r)}catch(i){if(i instanceof ze)return this.cache.invalidate(this.source),yield this.getZxyAttempt(e,t,n,r);throw i}})}getMetadataAttempt(){return I(this,null,function*(){let e=yield this.cache.getHeader(this.source),t=yield this.source.getBytes(e.jsonMetadataOffset,e.jsonMetadataLength,void 0,e.etag),n=yield this.decompress(t.data,e.internalCompression),r=new TextDecoder("utf-8");return JSON.parse(r.decode(n))})}getMetadata(){return I(this,null,function*(){try{return yield this.getMetadataAttempt()}catch(e){if(e instanceof ze)return this.cache.invalidate(this.source),yield this.getMetadataAttempt();throw e}})}};var{TileType:Ie}=Fe;function Xn(e,t,n,r){let i=t,o=null;if(i)try{let l=JSON.stringify(i);o=xe.parseTextSync?.(l,r)||null}catch(l){console.warn("PMTiles metadata could not be interpreted as TileJSON",l)}let s={};typeof o?.name=="string"&&(s.name=o.name),typeof o?.htmlAttribution=="string"&&(s.attributions=[o.htmlAttribution]);let a={...s,format:"pmtiles",formatVersion:e.specVersion,attributions:[],tileMIMEType:No(e.tileType),minZoom:e.minZoom,maxZoom:e.maxZoom,boundingBox:[[e.minLon,e.minLat],[e.maxLon,e.maxLat]],center:[e.centerLon,e.centerLat],centerZoom:e.centerZoom,etag:e.etag};return o&&(a.tilejson=o),n?.includeFormatHeader&&(a.formatHeader=e,a.formatMetadata=a),a}function No(e){switch(e){case Ie.Mvt:return"application/vnd.mapbox-vector-tile";case Ie.Png:return"image/png";case Ie.Jpeg:return"image/jpeg";case Ie.Webp:return"image/webp";case Ie.Avif:return"image/avif";default:return"application/octet-stream"}}var Ze=class{blob;key;constructor(t,n){this.blob=t,this.key=n}getKey(){return this.blob.url||""}async getBytes(t,n,r){return{data:await this.blob.slice(t,t+n).arrayBuffer()}}};var{PMTiles:zo}=Fe;var Re=class extends ie{data;props;mimeType=null;pmtiles;metadata;constructor(t){super(t),this.props=t;let n=typeof t.url=="string"?Ye(t.url):new Ze(t.url,"pmtiles");this.data=t.url,this.pmtiles=new zo(n),this.getTileData=this.getTileData.bind(this),this.metadata=this.getMetadata()}async getMetadata(){let t=await this.pmtiles.getHeader(),n=await this.pmtiles.getMetadata(),r=Xn(t,n,{includeFormatHeader:!1},this.loadOptions);return this.props.attributions&&(r.attributions=[...this.props.attributions,...r.attributions||[]]),r?.tileMIMEType&&(this.mimeType=r?.tileMIMEType),r}async getTile(t){let{x:n,y:r,zoom:i}=t,s=(await this.pmtiles.getZxy(i,n,r))?.data;return s||null}async getTileData(t){let{x:n,y:r,z:i}=t.index;switch((await this.metadata).tileMIMEType){case"application/vnd.mapbox-vector-tile":return await this.getVectorTile({x:n,y:r,zoom:i,layers:[]});default:return await this.getImageTile({x:n,y:r,zoom:i,layers:[]})}}async getImageTile(t){let n=await this.getTile(t);return n?await nt.parse(n,this.loadOptions):null}async getVectorTile(t){let n=await this.getTile(t),r={shape:"geojson-table",mvt:{coordinates:"wgs84",tileIndex:{x:t.x,y:t.y,z:t.zoom},...this.loadOptions?.mvt},...this.loadOptions};return n?await yt.parse(n,r):null}};return ar(Te);})();
|
|
8
|
+
/*! Bundled license information:
|
|
9
|
+
|
|
10
|
+
ieee754/index.js:
|
|
11
|
+
(*! ieee754. BSD-3-Clause License. Feross Aboukhadijeh <https://feross.org/opensource> *)
|
|
12
|
+
*/
|
|
13
|
+
return __exports__;
|
|
14
|
+
});
|
package/dist/index.cjs
CHANGED
|
@@ -27,25 +27,26 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
27
27
|
));
|
|
28
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
29
|
|
|
30
|
-
//
|
|
31
|
-
var
|
|
32
|
-
__export(
|
|
30
|
+
// dist/index.js
|
|
31
|
+
var dist_exports = {};
|
|
32
|
+
__export(dist_exports, {
|
|
33
33
|
PMTilesSource: () => PMTilesSource
|
|
34
34
|
});
|
|
35
|
-
module.exports = __toCommonJS(
|
|
35
|
+
module.exports = __toCommonJS(dist_exports);
|
|
36
36
|
|
|
37
|
-
//
|
|
37
|
+
// dist/pmtiles-source.js
|
|
38
38
|
var import_loader_utils = require("@loaders.gl/loader-utils");
|
|
39
39
|
var import_images = require("@loaders.gl/images");
|
|
40
40
|
var import_mvt2 = require("@loaders.gl/mvt");
|
|
41
41
|
var pmtiles2 = __toESM(require("pmtiles"), 1);
|
|
42
42
|
|
|
43
|
-
//
|
|
43
|
+
// dist/lib/parse-pmtiles.js
|
|
44
44
|
var import_mvt = require("@loaders.gl/mvt");
|
|
45
45
|
var pmtiles = __toESM(require("pmtiles"), 1);
|
|
46
46
|
var { TileType } = pmtiles;
|
|
47
|
-
function parsePMTilesHeader(header,
|
|
47
|
+
function parsePMTilesHeader(header, pmmetadata, options, loadOptions) {
|
|
48
48
|
var _a, _b;
|
|
49
|
+
const pmtilesMetadata = pmmetadata;
|
|
49
50
|
let tilejson = null;
|
|
50
51
|
if (pmtilesMetadata) {
|
|
51
52
|
try {
|
|
@@ -104,8 +105,10 @@ function decodeTileType(tileType) {
|
|
|
104
105
|
}
|
|
105
106
|
}
|
|
106
107
|
|
|
107
|
-
//
|
|
108
|
+
// dist/lib/blob-source.js
|
|
108
109
|
var BlobSource = class {
|
|
110
|
+
blob;
|
|
111
|
+
key;
|
|
109
112
|
constructor(blob, key) {
|
|
110
113
|
this.blob = blob;
|
|
111
114
|
this.key = key;
|
|
@@ -126,12 +129,16 @@ var BlobSource = class {
|
|
|
126
129
|
}
|
|
127
130
|
};
|
|
128
131
|
|
|
129
|
-
//
|
|
132
|
+
// dist/pmtiles-source.js
|
|
130
133
|
var { PMTiles } = pmtiles2;
|
|
131
134
|
var PMTilesSource = class extends import_loader_utils.DataSource {
|
|
135
|
+
data;
|
|
136
|
+
props;
|
|
137
|
+
mimeType = null;
|
|
138
|
+
pmtiles;
|
|
139
|
+
metadata;
|
|
132
140
|
constructor(props) {
|
|
133
141
|
super(props);
|
|
134
|
-
this.mimeType = null;
|
|
135
142
|
this.props = props;
|
|
136
143
|
const url = typeof props.url === "string" ? (0, import_loader_utils.resolvePath)(props.url) : new BlobSource(props.url, "pmtiles");
|
|
137
144
|
this.data = props.url;
|
|
@@ -142,12 +149,7 @@ var PMTilesSource = class extends import_loader_utils.DataSource {
|
|
|
142
149
|
async getMetadata() {
|
|
143
150
|
const pmtilesHeader = await this.pmtiles.getHeader();
|
|
144
151
|
const pmtilesMetadata = await this.pmtiles.getMetadata();
|
|
145
|
-
const metadata = parsePMTilesHeader(
|
|
146
|
-
pmtilesHeader,
|
|
147
|
-
pmtilesMetadata,
|
|
148
|
-
{ includeFormatHeader: false },
|
|
149
|
-
this.loadOptions
|
|
150
|
-
);
|
|
152
|
+
const metadata = parsePMTilesHeader(pmtilesHeader, pmtilesMetadata, { includeFormatHeader: false }, this.loadOptions);
|
|
151
153
|
if (this.props.attributions) {
|
|
152
154
|
metadata.attributions = [...this.props.attributions, ...metadata.attributions || []];
|
|
153
155
|
}
|
|
@@ -198,3 +200,4 @@ var PMTilesSource = class extends import_loader_utils.DataSource {
|
|
|
198
200
|
return arrayBuffer ? await import_mvt2.MVTLoader.parse(arrayBuffer, loadOptions) : null;
|
|
199
201
|
}
|
|
200
202
|
};
|
|
203
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["index.js", "pmtiles-source.js", "lib/parse-pmtiles.js", "lib/blob-source.js"],
|
|
4
|
+
"sourcesContent": ["// loaders.gl\n// SPDX-License-Identifier: MIT\n// Copyright (c) vis.gl contributors\nexport { PMTilesSource } from \"./pmtiles-source.js\";\n", "// loaders.gl\n// SPDX-License-Identifier: MIT\n// Copyright (c) vis.gl contributors\nimport { DataSource, resolvePath } from '@loaders.gl/loader-utils';\nimport { ImageLoader } from '@loaders.gl/images';\nimport { MVTLoader } from '@loaders.gl/mvt';\nimport * as pmtiles from 'pmtiles';\nconst { PMTiles } = pmtiles;\nimport { parsePMTilesHeader } from \"./lib/parse-pmtiles.js\";\nimport { BlobSource } from \"./lib/blob-source.js\";\nconst VERSION = '1.0.0';\nexport const PMTilesService = {\n name: 'PMTiles',\n id: 'pmtiles',\n module: 'pmtiles',\n version: VERSION,\n extensions: ['pmtiles'],\n mimeTypes: ['application/octet-stream'],\n options: {\n pmtiles: {}\n },\n createSource: (props) => new PMTilesSource(props)\n};\n/**\n * A PMTiles data source\n * @note Can be either a raster or vector tile source depending on the contents of the PMTiles file.\n */\nexport class PMTilesSource extends DataSource {\n data;\n props;\n mimeType = null;\n pmtiles;\n metadata;\n constructor(props) {\n super(props);\n this.props = props;\n const url = typeof props.url === 'string' ? resolvePath(props.url) : new BlobSource(props.url, 'pmtiles');\n this.data = props.url;\n this.pmtiles = new PMTiles(url);\n this.getTileData = this.getTileData.bind(this);\n this.metadata = this.getMetadata();\n }\n async getMetadata() {\n const pmtilesHeader = await this.pmtiles.getHeader();\n const pmtilesMetadata = await this.pmtiles.getMetadata();\n const metadata = parsePMTilesHeader(pmtilesHeader, pmtilesMetadata, { includeFormatHeader: false }, this.loadOptions);\n // Add additional attribution if necessary\n if (this.props.attributions) {\n metadata.attributions = [...this.props.attributions, ...(metadata.attributions || [])];\n }\n if (metadata?.tileMIMEType) {\n this.mimeType = metadata?.tileMIMEType;\n }\n // TODO - do we need to allow tileSize to be overridden? Some PMTiles examples seem to suggest it.\n return metadata;\n }\n async getTile(tileParams) {\n const { x, y, zoom: z } = tileParams;\n const rangeResponse = await this.pmtiles.getZxy(z, x, y);\n const arrayBuffer = rangeResponse?.data;\n if (!arrayBuffer) {\n // console.error('No arrayBuffer', tileParams);\n return null;\n }\n return arrayBuffer;\n }\n // Tile Source interface implementation: deck.gl compatible API\n // TODO - currently only handles image tiles, not vector tiles\n async getTileData(tileParams) {\n const { x, y, z } = tileParams.index;\n const metadata = await this.metadata;\n switch (metadata.tileMIMEType) {\n case 'application/vnd.mapbox-vector-tile':\n return await this.getVectorTile({ x, y, zoom: z, layers: [] });\n default:\n return await this.getImageTile({ x, y, zoom: z, layers: [] });\n }\n }\n // ImageTileSource interface implementation\n async getImageTile(tileParams) {\n const arrayBuffer = await this.getTile(tileParams);\n return arrayBuffer ? await ImageLoader.parse(arrayBuffer, this.loadOptions) : null;\n }\n // VectorTileSource interface implementation\n async getVectorTile(tileParams) {\n const arrayBuffer = await this.getTile(tileParams);\n const loadOptions = {\n shape: 'geojson-table',\n mvt: {\n coordinates: 'wgs84',\n tileIndex: { x: tileParams.x, y: tileParams.y, z: tileParams.zoom },\n ...this.loadOptions?.mvt\n },\n ...this.loadOptions\n };\n return arrayBuffer ? await MVTLoader.parse(arrayBuffer, loadOptions) : null;\n }\n}\n", "// loaders.gl\n// SPDX-License-Identifier: MIT\n// Copyright (c) vis.gl contributors\nimport { TileJSONLoader } from '@loaders.gl/mvt';\n// import {Source, PMTiles, Header, TileType} from 'pmtiles';\nimport * as pmtiles from 'pmtiles';\nconst { TileType } = pmtiles;\n/**\n * Parse PMTiles metdata from a PMTiles file\n * @param header\n * @param tilejsonMetadata\n * @param options\n * @param loadOptions\n * @returns\n */\nexport function parsePMTilesHeader(header, pmmetadata, options, loadOptions) {\n const pmtilesMetadata = pmmetadata;\n // Ironically, to use the TileJSON loader we need to stringify the metadata again.\n // This is the price of integrating with the existing pmtiles library.\n // TODO - provide a non-standard TileJSONLoader parsers that accepts a JSON object?\n let tilejson = null;\n if (pmtilesMetadata) {\n try {\n const string = JSON.stringify(pmtilesMetadata);\n tilejson = TileJSONLoader.parseTextSync?.(string, loadOptions) || null;\n }\n catch (error) {\n // eslint-disable-next-line no-console\n console.warn('PMTiles metadata could not be interpreted as TileJSON', error);\n }\n }\n const partialMetadata = {};\n if (typeof tilejson?.name === 'string') {\n partialMetadata.name = tilejson.name;\n }\n if (typeof tilejson?.htmlAttribution === 'string') {\n partialMetadata.attributions = [tilejson.htmlAttribution];\n }\n const metadata = {\n ...partialMetadata,\n format: 'pmtiles',\n formatVersion: header.specVersion,\n attributions: [],\n tileMIMEType: decodeTileType(header.tileType),\n minZoom: header.minZoom,\n maxZoom: header.maxZoom,\n boundingBox: [\n [header.minLon, header.minLat],\n [header.maxLon, header.maxLat]\n ],\n center: [header.centerLon, header.centerLat],\n centerZoom: header.centerZoom,\n etag: header.etag\n };\n if (tilejson) {\n metadata.tilejson = tilejson;\n }\n // Application can optionally include the raw header and metadata.\n if (options?.includeFormatHeader) {\n metadata.formatHeader = header;\n metadata.formatMetadata = metadata;\n }\n return metadata;\n}\n/** Extract a MIME type for tiles from vector tile header */\nfunction decodeTileType(tileType) {\n switch (tileType) {\n case TileType.Mvt:\n return 'application/vnd.mapbox-vector-tile';\n case TileType.Png:\n return 'image/png';\n case TileType.Jpeg:\n return 'image/jpeg';\n case TileType.Webp:\n return 'image/webp';\n case TileType.Avif:\n return 'image/avif';\n default:\n return 'application/octet-stream';\n }\n}\n", "// loaders.gl\n// SPDX-License-Identifier: MIT\n// Copyright (c) vis.gl contributors\n/**\n * A PMTiles library compatible source that reads from blobs\n * @deprecated TODO - reimplement as ReadableFileSource\n * Use loaders.gl HTTP range requests instead\n */\nexport class BlobSource {\n blob;\n key;\n constructor(blob, key) {\n this.blob = blob;\n this.key = key;\n }\n // TODO - how is this used?\n getKey() {\n // @ts-expect-error url is only defined on File subclass\n return this.blob.url || '';\n }\n async getBytes(offset, length, signal) {\n const slice = this.blob.slice(offset, offset + length);\n const data = await slice.arrayBuffer();\n return {\n data\n // etag: response.headers.get('ETag') || undefined,\n // cacheControl: response.headers.get('Cache-Control') || undefined,\n // expires: response.headers.get('Expires') || undefined\n };\n }\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACGA,0BAAwC;AACxC,oBAA4B;AAC5B,IAAAA,cAA0B;AAC1B,IAAAC,WAAyB;;;ACHzB,iBAA+B;AAE/B,cAAyB;AACzB,IAAM,EAAE,SAAS,IAAI;AASd,SAAS,mBAAmB,QAAQ,YAAY,SAAS,aAAa;AAf7E;AAgBI,QAAM,kBAAkB;AAIxB,MAAI,WAAW;AACf,MAAI,iBAAiB;AACjB,QAAI;AACA,YAAM,SAAS,KAAK,UAAU,eAAe;AAC7C,mBAAW,sCAAe,kBAAf,4BAA+B,QAAQ,iBAAgB;AAAA,IACtE,SACO,OAAP;AAEI,cAAQ,KAAK,yDAAyD,KAAK;AAAA,IAC/E;AAAA,EACJ;AACA,QAAM,kBAAkB,CAAC;AACzB,MAAI,QAAO,qCAAU,UAAS,UAAU;AACpC,oBAAgB,OAAO,SAAS;AAAA,EACpC;AACA,MAAI,QAAO,qCAAU,qBAAoB,UAAU;AAC/C,oBAAgB,eAAe,CAAC,SAAS,eAAe;AAAA,EAC5D;AACA,QAAM,WAAW;AAAA,IACb,GAAG;AAAA,IACH,QAAQ;AAAA,IACR,eAAe,OAAO;AAAA,IACtB,cAAc,CAAC;AAAA,IACf,cAAc,eAAe,OAAO,QAAQ;AAAA,IAC5C,SAAS,OAAO;AAAA,IAChB,SAAS,OAAO;AAAA,IAChB,aAAa;AAAA,MACT,CAAC,OAAO,QAAQ,OAAO,MAAM;AAAA,MAC7B,CAAC,OAAO,QAAQ,OAAO,MAAM;AAAA,IACjC;AAAA,IACA,QAAQ,CAAC,OAAO,WAAW,OAAO,SAAS;AAAA,IAC3C,YAAY,OAAO;AAAA,IACnB,MAAM,OAAO;AAAA,EACjB;AACA,MAAI,UAAU;AACV,aAAS,WAAW;AAAA,EACxB;AAEA,MAAI,mCAAS,qBAAqB;AAC9B,aAAS,eAAe;AACxB,aAAS,iBAAiB;AAAA,EAC9B;AACA,SAAO;AACX;AAEA,SAAS,eAAe,UAAU;AAC9B,UAAQ,UAAU;AAAA,IACd,KAAK,SAAS;AACV,aAAO;AAAA,IACX,KAAK,SAAS;AACV,aAAO;AAAA,IACX,KAAK,SAAS;AACV,aAAO;AAAA,IACX,KAAK,SAAS;AACV,aAAO;AAAA,IACX,KAAK,SAAS;AACV,aAAO;AAAA,IACX;AACI,aAAO;AAAA,EACf;AACJ;;;ACxEO,IAAM,aAAN,MAAiB;AAAA,EACpB;AAAA,EACA;AAAA,EACA,YAAY,MAAM,KAAK;AACnB,SAAK,OAAO;AACZ,SAAK,MAAM;AAAA,EACf;AAAA;AAAA,EAEA,SAAS;AAEL,WAAO,KAAK,KAAK,OAAO;AAAA,EAC5B;AAAA,EACA,MAAM,SAAS,QAAQ,QAAQ,QAAQ;AACnC,UAAM,QAAQ,KAAK,KAAK,MAAM,QAAQ,SAAS,MAAM;AACrD,UAAM,OAAO,MAAM,MAAM,YAAY;AACrC,WAAO;AAAA,MACH;AAAA;AAAA;AAAA;AAAA,IAIJ;AAAA,EACJ;AACJ;;;AFvBA,IAAM,EAAE,QAAQ,IAAIC;AAoBb,IAAM,gBAAN,cAA4B,+BAAW;AAAA,EAC1C;AAAA,EACA;AAAA,EACA,WAAW;AAAA,EACX;AAAA,EACA;AAAA,EACA,YAAY,OAAO;AACf,UAAM,KAAK;AACX,SAAK,QAAQ;AACb,UAAM,MAAM,OAAO,MAAM,QAAQ,eAAW,iCAAY,MAAM,GAAG,IAAI,IAAI,WAAW,MAAM,KAAK,SAAS;AACxG,SAAK,OAAO,MAAM;AAClB,SAAK,UAAU,IAAI,QAAQ,GAAG;AAC9B,SAAK,cAAc,KAAK,YAAY,KAAK,IAAI;AAC7C,SAAK,WAAW,KAAK,YAAY;AAAA,EACrC;AAAA,EACA,MAAM,cAAc;AAChB,UAAM,gBAAgB,MAAM,KAAK,QAAQ,UAAU;AACnD,UAAM,kBAAkB,MAAM,KAAK,QAAQ,YAAY;AACvD,UAAM,WAAW,mBAAmB,eAAe,iBAAiB,EAAE,qBAAqB,MAAM,GAAG,KAAK,WAAW;AAEpH,QAAI,KAAK,MAAM,cAAc;AACzB,eAAS,eAAe,CAAC,GAAG,KAAK,MAAM,cAAc,GAAI,SAAS,gBAAgB,CAAC,CAAE;AAAA,IACzF;AACA,QAAI,qCAAU,cAAc;AACxB,WAAK,WAAW,qCAAU;AAAA,IAC9B;AAEA,WAAO;AAAA,EACX;AAAA,EACA,MAAM,QAAQ,YAAY;AACtB,UAAM,EAAE,GAAG,GAAG,MAAM,EAAE,IAAI;AAC1B,UAAM,gBAAgB,MAAM,KAAK,QAAQ,OAAO,GAAG,GAAG,CAAC;AACvD,UAAM,cAAc,+CAAe;AACnC,QAAI,CAAC,aAAa;AAEd,aAAO;AAAA,IACX;AACA,WAAO;AAAA,EACX;AAAA;AAAA;AAAA,EAGA,MAAM,YAAY,YAAY;AAC1B,UAAM,EAAE,GAAG,GAAG,EAAE,IAAI,WAAW;AAC/B,UAAM,WAAW,MAAM,KAAK;AAC5B,YAAQ,SAAS,cAAc;AAAA,MAC3B,KAAK;AACD,eAAO,MAAM,KAAK,cAAc,EAAE,GAAG,GAAG,MAAM,GAAG,QAAQ,CAAC,EAAE,CAAC;AAAA,MACjE;AACI,eAAO,MAAM,KAAK,aAAa,EAAE,GAAG,GAAG,MAAM,GAAG,QAAQ,CAAC,EAAE,CAAC;AAAA,IACpE;AAAA,EACJ;AAAA;AAAA,EAEA,MAAM,aAAa,YAAY;AAC3B,UAAM,cAAc,MAAM,KAAK,QAAQ,UAAU;AACjD,WAAO,cAAc,MAAM,0BAAY,MAAM,aAAa,KAAK,WAAW,IAAI;AAAA,EAClF;AAAA;AAAA,EAEA,MAAM,cAAc,YAAY;AApFpC;AAqFQ,UAAM,cAAc,MAAM,KAAK,QAAQ,UAAU;AACjD,UAAM,cAAc;AAAA,MAChB,OAAO;AAAA,MACP,KAAK;AAAA,QACD,aAAa;AAAA,QACb,WAAW,EAAE,GAAG,WAAW,GAAG,GAAG,WAAW,GAAG,GAAG,WAAW,KAAK;AAAA,QAClE,IAAG,UAAK,gBAAL,mBAAkB;AAAA,MACzB;AAAA,MACA,GAAG,KAAK;AAAA,IACZ;AACA,WAAO,cAAc,MAAM,sBAAU,MAAM,aAAa,WAAW,IAAI;AAAA,EAC3E;AACJ;",
|
|
6
|
+
"names": ["import_mvt", "pmtiles", "pmtiles"]
|
|
7
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export type { PMTilesMetadata } from
|
|
2
|
-
export type { PMTilesSourceProps } from
|
|
3
|
-
export { PMTilesSource } from
|
|
1
|
+
export type { PMTilesMetadata } from "./lib/parse-pmtiles.js";
|
|
2
|
+
export type { PMTilesSourceProps } from "./pmtiles-source.js";
|
|
3
|
+
export { PMTilesSource } from "./pmtiles-source.js";
|
|
4
4
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAIA,YAAY,EAAC,eAAe,EAAC
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAIA,YAAY,EAAC,eAAe,EAAC,+BAA4B;AACzD,YAAY,EAAC,kBAAkB,EAAC,4BAAyB;AACzD,OAAO,EAAC,aAAa,EAAC,4BAAyB"}
|
package/dist/index.js
CHANGED
package/dist/lib/blob-source.js
CHANGED
|
@@ -1,19 +1,31 @@
|
|
|
1
|
+
// loaders.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// Copyright (c) vis.gl contributors
|
|
4
|
+
/**
|
|
5
|
+
* A PMTiles library compatible source that reads from blobs
|
|
6
|
+
* @deprecated TODO - reimplement as ReadableFileSource
|
|
7
|
+
* Use loaders.gl HTTP range requests instead
|
|
8
|
+
*/
|
|
1
9
|
export class BlobSource {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
10
|
+
blob;
|
|
11
|
+
key;
|
|
12
|
+
constructor(blob, key) {
|
|
13
|
+
this.blob = blob;
|
|
14
|
+
this.key = key;
|
|
15
|
+
}
|
|
16
|
+
// TODO - how is this used?
|
|
17
|
+
getKey() {
|
|
18
|
+
// @ts-expect-error url is only defined on File subclass
|
|
19
|
+
return this.blob.url || '';
|
|
20
|
+
}
|
|
21
|
+
async getBytes(offset, length, signal) {
|
|
22
|
+
const slice = this.blob.slice(offset, offset + length);
|
|
23
|
+
const data = await slice.arrayBuffer();
|
|
24
|
+
return {
|
|
25
|
+
data
|
|
26
|
+
// etag: response.headers.get('ETag') || undefined,
|
|
27
|
+
// cacheControl: response.headers.get('Cache-Control') || undefined,
|
|
28
|
+
// expires: response.headers.get('Expires') || undefined
|
|
29
|
+
};
|
|
30
|
+
}
|
|
18
31
|
}
|
|
19
|
-
//# sourceMappingURL=blob-source.js.map
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { LoaderOptions } from '@loaders.gl/loader-utils';
|
|
1
|
+
import type { LoaderOptions } from '@loaders.gl/loader-utils';
|
|
2
2
|
import type { TileJSON } from '@loaders.gl/mvt';
|
|
3
3
|
import * as pmtiles from 'pmtiles';
|
|
4
4
|
/** Metadata describing a PMTiles file */
|
|
@@ -39,7 +39,7 @@ export type PMTilesMetadata = {
|
|
|
39
39
|
* @param loadOptions
|
|
40
40
|
* @returns
|
|
41
41
|
*/
|
|
42
|
-
export declare function parsePMTilesHeader(header: pmtiles.Header,
|
|
42
|
+
export declare function parsePMTilesHeader(header: pmtiles.Header, pmmetadata: unknown, options?: {
|
|
43
43
|
includeFormatHeader?: boolean;
|
|
44
44
|
}, loadOptions?: LoaderOptions): PMTilesMetadata;
|
|
45
45
|
//# sourceMappingURL=parse-pmtiles.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parse-pmtiles.d.ts","sourceRoot":"","sources":["../../src/lib/parse-pmtiles.ts"],"names":[],"mappings":"AAIA,OAAO,EAAC,aAAa,EAAC,MAAM,0BAA0B,CAAC;
|
|
1
|
+
{"version":3,"file":"parse-pmtiles.d.ts","sourceRoot":"","sources":["../../src/lib/parse-pmtiles.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAC,aAAa,EAAC,MAAM,0BAA0B,CAAC;AAC5D,OAAO,KAAK,EAAC,QAAQ,EAAC,MAAM,iBAAiB,CAAC;AAG9C,OAAO,KAAK,OAAO,MAAM,SAAS,CAAC;AAGnC,yCAAyC;AACzC,MAAM,MAAM,eAAe,GAAG;IAC5B,MAAM,EAAE,SAAS,CAAC;IAClB,sDAAsD;IACtD,aAAa,EAAE,MAAM,CAAC;IAEtB,4FAA4F;IAC5F,YAAY,EACR,oCAAoC,GACpC,WAAW,GACX,YAAY,GACZ,YAAY,GACZ,YAAY,GACZ,0BAA0B,CAAC;IAE/B,sEAAsE;IACtE,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,qEAAqE;IACrE,YAAY,CAAC,EAAE,MAAM,EAAE,CAAC;IAExB,kDAAkD;IAClD,OAAO,EAAE,MAAM,CAAC;IAChB,kDAAkD;IAClD,OAAO,EAAE,MAAM,CAAC;IAChB,gEAAgE;IAChE,WAAW,EAAE,CAAC,GAAG,EAAE,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,CAAC,EAAE,GAAG,EAAE,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,CAAC,CAAC,CAAC;IACxE,uCAAuC;IACvC,MAAM,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACzB,wCAAwC;IACxC,UAAU,EAAE,MAAM,CAAC;IACnB,gBAAgB;IAChB,IAAI,CAAC,EAAE,MAAM,CAAC;IAEd,qDAAqD;IACrD,QAAQ,CAAC,EAAE,QAAQ,CAAC;IAEpB,iDAAiD;IACjD,YAAY,CAAC,EAAE,OAAO,CAAC,MAAM,CAAC;IAC9B,2GAA2G;IAC3G,cAAc,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAC1C,CAAC;AAEF;;;;;;;GAOG;AACH,wBAAgB,kBAAkB,CAChC,MAAM,EAAE,OAAO,CAAC,MAAM,EACtB,UAAU,EAAE,OAAO,EACnB,OAAO,CAAC,EAAE;IAAC,mBAAmB,CAAC,EAAE,OAAO,CAAA;CAAC,EACzC,WAAW,CAAC,EAAE,aAAa,GAC1B,eAAe,CAuDjB"}
|
|
@@ -1,63 +1,81 @@
|
|
|
1
|
+
// loaders.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// Copyright (c) vis.gl contributors
|
|
1
4
|
import { TileJSONLoader } from '@loaders.gl/mvt';
|
|
5
|
+
// import {Source, PMTiles, Header, TileType} from 'pmtiles';
|
|
2
6
|
import * as pmtiles from 'pmtiles';
|
|
3
|
-
const {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
7
|
+
const { TileType } = pmtiles;
|
|
8
|
+
/**
|
|
9
|
+
* Parse PMTiles metdata from a PMTiles file
|
|
10
|
+
* @param header
|
|
11
|
+
* @param tilejsonMetadata
|
|
12
|
+
* @param options
|
|
13
|
+
* @param loadOptions
|
|
14
|
+
* @returns
|
|
15
|
+
*/
|
|
16
|
+
export function parsePMTilesHeader(header, pmmetadata, options, loadOptions) {
|
|
17
|
+
const pmtilesMetadata = pmmetadata;
|
|
18
|
+
// Ironically, to use the TileJSON loader we need to stringify the metadata again.
|
|
19
|
+
// This is the price of integrating with the existing pmtiles library.
|
|
20
|
+
// TODO - provide a non-standard TileJSONLoader parsers that accepts a JSON object?
|
|
21
|
+
let tilejson = null;
|
|
22
|
+
if (pmtilesMetadata) {
|
|
23
|
+
try {
|
|
24
|
+
const string = JSON.stringify(pmtilesMetadata);
|
|
25
|
+
tilejson = TileJSONLoader.parseTextSync?.(string, loadOptions) || null;
|
|
26
|
+
}
|
|
27
|
+
catch (error) {
|
|
28
|
+
// eslint-disable-next-line no-console
|
|
29
|
+
console.warn('PMTiles metadata could not be interpreted as TileJSON', error);
|
|
30
|
+
}
|
|
16
31
|
}
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
32
|
+
const partialMetadata = {};
|
|
33
|
+
if (typeof tilejson?.name === 'string') {
|
|
34
|
+
partialMetadata.name = tilejson.name;
|
|
35
|
+
}
|
|
36
|
+
if (typeof tilejson?.htmlAttribution === 'string') {
|
|
37
|
+
partialMetadata.attributions = [tilejson.htmlAttribution];
|
|
38
|
+
}
|
|
39
|
+
const metadata = {
|
|
40
|
+
...partialMetadata,
|
|
41
|
+
format: 'pmtiles',
|
|
42
|
+
formatVersion: header.specVersion,
|
|
43
|
+
attributions: [],
|
|
44
|
+
tileMIMEType: decodeTileType(header.tileType),
|
|
45
|
+
minZoom: header.minZoom,
|
|
46
|
+
maxZoom: header.maxZoom,
|
|
47
|
+
boundingBox: [
|
|
48
|
+
[header.minLon, header.minLat],
|
|
49
|
+
[header.maxLon, header.maxLat]
|
|
50
|
+
],
|
|
51
|
+
center: [header.centerLon, header.centerLat],
|
|
52
|
+
centerZoom: header.centerZoom,
|
|
53
|
+
etag: header.etag
|
|
54
|
+
};
|
|
55
|
+
if (tilejson) {
|
|
56
|
+
metadata.tilejson = tilejson;
|
|
57
|
+
}
|
|
58
|
+
// Application can optionally include the raw header and metadata.
|
|
59
|
+
if (options?.includeFormatHeader) {
|
|
60
|
+
metadata.formatHeader = header;
|
|
61
|
+
metadata.formatMetadata = metadata;
|
|
62
|
+
}
|
|
63
|
+
return metadata;
|
|
46
64
|
}
|
|
65
|
+
/** Extract a MIME type for tiles from vector tile header */
|
|
47
66
|
function decodeTileType(tileType) {
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
67
|
+
switch (tileType) {
|
|
68
|
+
case TileType.Mvt:
|
|
69
|
+
return 'application/vnd.mapbox-vector-tile';
|
|
70
|
+
case TileType.Png:
|
|
71
|
+
return 'image/png';
|
|
72
|
+
case TileType.Jpeg:
|
|
73
|
+
return 'image/jpeg';
|
|
74
|
+
case TileType.Webp:
|
|
75
|
+
return 'image/webp';
|
|
76
|
+
case TileType.Avif:
|
|
77
|
+
return 'image/avif';
|
|
78
|
+
default:
|
|
79
|
+
return 'application/octet-stream';
|
|
80
|
+
}
|
|
62
81
|
}
|
|
63
|
-
//# sourceMappingURL=parse-pmtiles.js.map
|
package/dist/pmtiles-source.d.ts
CHANGED
|
@@ -5,7 +5,7 @@ import { DataSource } from '@loaders.gl/loader-utils';
|
|
|
5
5
|
import { ImageLoaderOptions } from '@loaders.gl/images';
|
|
6
6
|
import { MVTLoaderOptions, TileJSONLoaderOptions } from '@loaders.gl/mvt';
|
|
7
7
|
import * as pmtiles from 'pmtiles';
|
|
8
|
-
import type { PMTilesMetadata } from
|
|
8
|
+
import type { PMTilesMetadata } from "./lib/parse-pmtiles.js";
|
|
9
9
|
export type Service = {
|
|
10
10
|
name: string;
|
|
11
11
|
id: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pmtiles-source.d.ts","sourceRoot":"","sources":["../src/pmtiles-source.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAC,kBAAkB,EAAE,iBAAiB,EAAC,MAAM,0BAA0B,CAAC;AACpF,OAAO,KAAK,EAAC,SAAS,EAAE,eAAe,EAAC,MAAM,0BAA0B,CAAC;AACzE,OAAO,KAAK,EAAC,eAAe,EAAE,gBAAgB,EAAC,MAAM,0BAA0B,CAAC;AAChF,OAAO,EAAC,UAAU,EAAc,MAAM,0BAA0B,CAAC;AACjE,OAAO,EAAc,kBAAkB,EAAC,MAAM,oBAAoB,CAAC;AACnE,OAAO,EAAY,gBAAgB,EAAE,qBAAqB,EAAC,MAAM,iBAAiB,CAAC;AAEnF,OAAO,KAAK,OAAO,MAAM,SAAS,CAAC;AAGnC,OAAO,KAAK,EAAC,eAAe,EAAC
|
|
1
|
+
{"version":3,"file":"pmtiles-source.d.ts","sourceRoot":"","sources":["../src/pmtiles-source.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAC,kBAAkB,EAAE,iBAAiB,EAAC,MAAM,0BAA0B,CAAC;AACpF,OAAO,KAAK,EAAC,SAAS,EAAE,eAAe,EAAC,MAAM,0BAA0B,CAAC;AACzE,OAAO,KAAK,EAAC,eAAe,EAAE,gBAAgB,EAAC,MAAM,0BAA0B,CAAC;AAChF,OAAO,EAAC,UAAU,EAAc,MAAM,0BAA0B,CAAC;AACjE,OAAO,EAAc,kBAAkB,EAAC,MAAM,oBAAoB,CAAC;AACnE,OAAO,EAAY,gBAAgB,EAAE,qBAAqB,EAAC,MAAM,iBAAiB,CAAC;AAEnF,OAAO,KAAK,OAAO,MAAM,SAAS,CAAC;AAGnC,OAAO,KAAK,EAAC,eAAe,EAAC,+BAA4B;AAMzD,MAAM,MAAM,OAAO,GAAG;IACpB,IAAI,EAAE,MAAM,CAAC;IACb,EAAE,EAAE,MAAM,CAAC;IACX,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,EAAE,MAAM,EAAE,CAAC;IACrB,SAAS,EAAE,MAAM,EAAE,CAAC;IACpB,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAClC,CAAC;AAEF,MAAM,MAAM,iBAAiB,CAAC,OAAO,EAAE,YAAY,IAAI,OAAO,GAAG;IAC/D,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,YAAY,CAAC,EAAE,YAAY,CAAC;IAC5B,YAAY,EAAE,CAAC,KAAK,EAAE,YAAY,KAAK,OAAO,CAAC;CAChD,CAAC;AAEF,eAAO,MAAM,cAAc,EAAE,iBAAiB,CAAC,aAAa,EAAE,kBAAkB,CAW/E,CAAC;AAEF,MAAM,MAAM,kBAAkB,GAAG,eAAe,GAAG;IACjD,GAAG,EAAE,MAAM,GAAG,IAAI,CAAC;IACnB,YAAY,CAAC,EAAE,MAAM,EAAE,CAAC;IACxB,WAAW,CAAC,EAAE,qBAAqB,GAAG,gBAAgB,GAAG,kBAAkB,CAAC;CAC7E,CAAC;AAEF;;;GAGG;AACH,qBAAa,aAAc,SAAQ,UAAW,YAAW,eAAe,EAAE,gBAAgB;IACxF,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IACpB,KAAK,EAAE,kBAAkB,CAAC;IAC1B,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAQ;IAC/B,OAAO,EAAE,OAAO,CAAC,OAAO,CAAC;IACzB,QAAQ,EAAE,OAAO,CAAC,eAAe,CAAC,CAAC;gBAEvB,KAAK,EAAE,kBAAkB;IAW/B,WAAW,IAAI,OAAO,CAAC,eAAe,CAAC;IAoBvC,OAAO,CAAC,UAAU,EAAE,iBAAiB,GAAG,OAAO,CAAC,WAAW,GAAG,IAAI,CAAC;IAcnE,WAAW,CAAC,UAAU,EAAE,kBAAkB,GAAG,OAAO,CAAC,OAAO,GAAG,IAAI,CAAC;IAapE,YAAY,CAAC,UAAU,EAAE,iBAAiB,GAAG,OAAO,CAAC,SAAS,GAAG,IAAI,CAAC;IAOtE,aAAa,CAAC,UAAU,EAAE,iBAAiB,GAAG,OAAO,CAAC,OAAO,GAAG,IAAI,CAAC;CAc5E"}
|