!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).geojsonvt={})}(this,(function(t){"use strict";function e(t,o,s,i){let r=i;const a=o+(s-o>>1);let u,c=s-o;const l=t[o],h=t[o+1],d=t[s],p=t[s+1];for(let e=o+3;er)u=e,r=o;else if(o===r){const t=Math.abs(e-a);ti&&(u-o>3&&e(t,o,u,i),t[u+2]=r,s-u>3&&e(t,u,s,i))}function n(t,e,n,o,s,i){let r=s-n,a=i-o;if(0!==r||0!==a){const u=((t-n)*r+(e-o)*a)/(r*r+a*a);u>1?(n=s,o=i):u>0&&(n+=r*u,o+=a*u)}return r=t-n,a=e-o,r*r+a*a}function o(t,e,n,o){const i={type:e,geom:n},r={id:null==t?null:t,type:i.type,geometry:i.geom,tags:o,minX:1/0,minY:1/0,maxX:-1/0,maxY:-1/0};switch(i.type){case"Point":case"MultiPoint":case"LineString":s(r,i.geom);break;case"Polygon":s(r,i.geom[0]);break;case"MultiLineString":for(const t of i.geom)s(r,t);break;case"MultiPolygon":for(const t of i.geom)s(r,t[0])}return r}function s(t,e){for(let n=0;n0&&(a+=s?(i*u-o*r)/2:Math.sqrt(Math.pow(o-i,2)+Math.pow(u-r,2))),i=o,r=u}const u=n.length-3;n[2]=1,o>0&&e(n,0,u,o),n[u+2]=1,n.size=Math.abs(a),n.start=0,n.end=n.size}function u(t,e,n,o){for(let s=0;s1?1:n}function h(t){const e={type:"Feature",geometry:d(t),properties:t.tags};return null!=t.id&&(e.id=t.id),e}function d(t){const{type:e,geometry:n}=t;switch(e){case"Point":return{type:e,coordinates:f(n[0],n[1])};case"MultiPoint":case"LineString":return{type:e,coordinates:p(n)};case"MultiLineString":case"Polygon":return{type:e,coordinates:n.map((t=>p(t)))};case"MultiPolygon":return{type:e,coordinates:n.map((t=>t.map((t=>p(t)))))}}}function p(t){const e=[];for(let n=0;n=(n/=e)&&r=o)return null;const u=[];for(const e of t){const t=s===y.X?e.minX:e.minY,i=s===y.X?e.maxX:e.maxY;if(t>=n&&i=o))switch(e.type){case"Point":case"MultiPoint":M(e,u,n,o,s);continue;case"LineString":w(e,u,n,o,s,a);continue;case"MultiLineString":P(e,u,n,o,s);continue;case"Polygon":I(e,u,n,o,s);continue;case"MultiPolygon":v(e,u,n,o,s);continue}}return u.length?u:null}function M(t,e,n,s,i){const r=[];if(function(t,e,n,o,s){for(let i=0;i=n&&r<=o&&A(e,t[i],t[i+1],t[i+2])}}(t.geometry,r,n,s,i),!r.length)return;const a=3===r.length?"Point":"MultiPoint";e.push(o(t.id,a,r,t.tags))}function w(t,e,n,s,i,r){const a=[];if(b(t.geometry,a,n,s,i,!1,r.lineMetrics),a.length)if(r.lineMetrics)for(const n of a)e.push(o(t.id,"LineString",n,t.tags));else a.length>1?e.push(o(t.id,"MultiLineString",a,t.tags)):e.push(o(t.id,"LineString",a[0],t.tags))}function P(t,e,n,s,i){const r=[];z(t.geometry,r,n,s,i,!1),r.length&&(1!==r.length?e.push(o(t.id,"MultiLineString",r,t.tags)):e.push(o(t.id,"LineString",r[0],t.tags)))}function I(t,e,n,s,i){const r=[];z(t.geometry,r,n,s,i,!0),r.length&&e.push(o(t.id,"Polygon",r,t.tags))}function v(t,e,n,s,i){const r=[];for(const e of t.geometry){const t=[];z(e,t,n,s,i,!0),t.length&&r.push(t)}r.length&&e.push(o(t.id,"MultiPolygon",r,t.tags))}function b(t,e,n,o,s,i,r){let a=S(t);const u=s===y.X?E:T;let c,l,h=t.start;for(let d=0;dn&&(l=u(a,p,f,m,x,n),r&&(a.start=h+c*l)):M>o?w=n&&(l=u(a,p,f,m,x,n),P=!0),w>o&&M<=o&&(l=u(a,p,f,m,x,o),P=!0),!i&&P&&(r&&(a.end=h+c*l),e.push(a),a=S(t)),r&&(h+=c)}let d=t.length-3;const p=t[d],f=t[d+1],g=t[d+2],m=s===y.X?p:f;m>=n&&m<=o&&A(a,p,f,g),d=a.length-3,i&&d>=3&&(a[d]!==a[0]||a[d+1]!==a[1])&&A(a,a[0],a[1],a[2]),a.length&&e.push(a)}function S(t){const e=[];return e.size=t.size,e.start=t.start,e.end=t.end,e}function z(t,e,n,o,s,i){for(const r of t)b(r,e,n,o,s,i,!1)}function A(t,e,n,o){t.push(e,n,o)}function E(t,e,n,o,s,i){const r=(i-e)/(o-e);return A(t,i,n+(s-n)*r,1),r}function T(t,e,n,o,s,i){const r=(i-n)/(s-n);return A(t,e+(o-e)*r,i,1),r}function X(t,e){const n=e.buffer/e.extent;let o=t;const s=x(t,1,-1-n,n,y.X,-1,2,e),i=x(t,1,1-n,2+n,y.X,-1,2,e);return s||i?(o=x(t,1,-n,1+n,y.X,-1,2,e)||[],s&&(o=Y(s,1).concat(o)),i&&(o=o.concat(Y(i,-1))),o):o}function Y(t,e){const n=[];for(const s of t)switch(s.type){case"Point":case"MultiPoint":case"LineString":{const t=L(s.geometry,e);n.push(o(s.id,s.type,t,s.tags));continue}case"MultiLineString":case"Polygon":{const t=[];for(const n of s.geometry)t.push(L(n,e));n.push(o(s.id,s.type,t,s.tags));continue}case"MultiPolygon":{const t=[];for(const n of s.geometry){const o=[];for(const t of n)o.push(L(t,e));t.push(o)}n.push(o(s.id,s.type,t,s.tags));continue}}return n}function L(t,e){const n=[];n.size=t.size,void 0!==t.start&&(n.start=t.start,n.end=t.end);for(let o=0;o[t.id,t]))),update:new Map(t.update?.map((t=>[t.id,t])))};return e}(e);let s=[];if(o.removeAll&&(s=t,t=[]),o.remove.size||o.add.size){const e=[];for(const n of t)(o.remove.has(n.id)||o.add.has(n.id))&&e.push(n);if(e.length){s.push(...e);const n=new Set(e.map((t=>t.id)));t=t.filter((t=>!n.has(t.id)))}if(o.add.size){let e=i({type:"FeatureCollection",features:Array.from(o.add.values())},n);e=X(e,n),s.push(...e),t.push(...e)}}if(o.update.size)for(const[e,i]of o.update){const o=[],r=[];for(const n of t)n.id===e?o.push(n):r.push(n);if(!o.length)continue;const a=C(o,i,n);a.length&&(s.push(...o,...a),r.push(...a),t=r)}return{affected:s,source:t}}function C(t,e,n){const o=!!e.newGeometry,s=e.removeAllProperties||e.removeProperties?.length>0||e.addOrUpdateProperties?.length>0;if(o){const o=t[0];let r=i({type:"FeatureCollection",features:[{type:"Feature",id:o.id,geometry:e.newGeometry,properties:s?_(o.tags,e):o.tags}]},n);return r=X(r,n),r}if(s){const n=[];for(const o of t){const t={...o};t.tags=_(t.tags,e),n.push(t)}return n}return[]}function _(t,e){if(e.removeAllProperties)return{};const n={...t||{}};if(e.removeProperties)for(const t of e.removeProperties)delete n[t];if(e.addOrUpdateProperties)for(const{key:t,value:o}of e.addOrUpdateProperties)n[t]=o;return n}!function(t){t[t.X=0]="X",t[t.Y=1]="Y"}(y||(y={}));const Z=[Int8Array,Uint8Array,Uint8ClampedArray,Int16Array,Uint16Array,Int32Array,Uint32Array,Float32Array,Float64Array];class F{static from(t){if(!(t instanceof ArrayBuffer))throw new Error("Data must be an instance of ArrayBuffer.");const[e,n]=new Uint8Array(t,0,2);if(219!==e)throw new Error("Data does not appear to be in a KDBush format.");const o=n>>4;if(1!==o)throw new Error(`Got v${o} data when expected v1.`);const s=Z[15&n];if(!s)throw new Error("Unrecognized array type.");const[i]=new Uint16Array(t,2,1),[r]=new Uint32Array(t,4,1);return new F(r,i,s,t)}constructor(t,e=64,n=Float64Array,o){if(isNaN(t)||t<0)throw new Error(`Unpexpected numItems value: ${t}.`);this.numItems=+t,this.nodeSize=Math.min(Math.max(+e,2),65535),this.ArrayType=n,this.IndexArrayType=t<65536?Uint16Array:Uint32Array;const s=Z.indexOf(this.ArrayType),i=2*t*this.ArrayType.BYTES_PER_ELEMENT,r=t*this.IndexArrayType.BYTES_PER_ELEMENT,a=(8-r%8)%8;if(s<0)throw new Error(`Unexpected typed array class: ${n}.`);o&&o instanceof ArrayBuffer?(this.data=o,this.ids=new this.IndexArrayType(this.data,8,t),this.coords=new this.ArrayType(this.data,8+r+a,2*t),this._pos=2*t,this._finished=!0):(this.data=new ArrayBuffer(8+i+r+a),this.ids=new this.IndexArrayType(this.data,8,t),this.coords=new this.ArrayType(this.data,8+r+a,2*t),this._pos=0,this._finished=!1,new Uint8Array(this.data,0,2).set([219,16+s]),new Uint16Array(this.data,2,1)[0]=e,new Uint32Array(this.data,4,1)[0]=t)}add(t,e){const n=this._pos>>1;return this.ids[n]=n,this.coords[this._pos++]=t,this.coords[this._pos++]=e,n}finish(){const t=this._pos>>1;if(t!==this.numItems)throw new Error(`Added ${t} items when expected ${this.numItems}.`);return U(this.ids,this.coords,this.nodeSize,0,this.numItems-1,0),this._finished=!0,this}range(t,e,n,o){if(!this._finished)throw new Error("Data not yet indexed - call index.finish().");const{ids:s,coords:i,nodeSize:r}=this,a=[0,s.length-1,0],u=[];for(;a.length;){const c=a.pop()||0,l=a.pop()||0,h=a.pop()||0;if(l-h<=r){for(let r=h;r<=l;r++){const a=i[2*r],c=i[2*r+1];a>=t&&a<=n&&c>=e&&c<=o&&u.push(s[r])}continue}const d=h+l>>1,p=i[2*d],f=i[2*d+1];p>=t&&p<=n&&f>=e&&f<=o&&u.push(s[d]),(0===c?t<=p:e<=f)&&(a.push(h),a.push(d-1),a.push(1-c)),(0===c?n>=p:o>=f)&&(a.push(d+1),a.push(l),a.push(1-c))}return u}within(t,e,n){if(!this._finished)throw new Error("Data not yet indexed - call index.finish().");const{ids:o,coords:s,nodeSize:i}=this,r=[0,o.length-1,0],a=[],u=n*n;for(;r.length;){const c=r.pop()||0,l=r.pop()||0,h=r.pop()||0;if(l-h<=i){for(let n=h;n<=l;n++)k(s[2*n],s[2*n+1],t,e)<=u&&a.push(o[n]);continue}const d=h+l>>1,p=s[2*d],f=s[2*d+1];k(p,f,t,e)<=u&&a.push(o[d]),(0===c?t-n<=p:e-n<=f)&&(r.push(h),r.push(d-1),r.push(1-c)),(0===c?t+n>=p:e+n>=f)&&(r.push(d+1),r.push(l),r.push(1-c))}return a}}function U(t,e,n,o,s,i){if(s-o<=n)return;const r=o+s>>1;D(t,e,r,o,s,i),U(t,e,n,o,r-1,1-i),U(t,e,n,r+1,s,1-i)}function D(t,e,n,o,s,i){for(;s>o;){if(s-o>600){const r=s-o+1,a=n-o+1,u=Math.log(r),c=.5*Math.exp(2*u/3),l=.5*Math.sqrt(u*c*(r-c)/r)*(a-r/2<0?-1:1);D(t,e,n,Math.max(o,Math.floor(n-a*c/r+l)),Math.min(s,Math.floor(n+(r-a)*c/r+l)),i)}const r=e[2*n+i];let a=o,u=s;for(j(t,e,o,n),e[2*s+i]>r&&j(t,e,o,s);ar;)u--}e[2*o+i]===r?j(t,e,o,u):(u++,j(t,e,u,s)),u<=n&&(o=u+1),n<=u&&(s=u-1)}}function j(t,e,n,o){N(t,n,o),N(e,2*n,2*o),N(e,2*n+1,2*o+1)}function N(t,e,n){const o=t[e];t[e]=t[n],t[n]=o}function k(t,e,n,o){const s=t-n,i=e-o;return s*s+i*i}const $={minZoom:0,maxZoom:16,minPoints:2,radius:40,extent:512,nodeSize:64,log:!1,generateId:!1,reduce:null,map:t=>t},G=3,B=5,J=6;class q{constructor(t){this.options=Object.assign(Object.create($),t),this.trees=new Array(this.options.maxZoom+1),this.stride=this.options.reduce?7:6,this.clusterProps=[],this.points=[]}load(t){const e=[];for(const n of t){if(!n.geometry)continue;const[t,o]=n.geometry.coordinates,[s,i]=[c(t),l(o)],r={id:n.id,type:"Point",geometry:[s,i],tags:n.properties};e.push(r)}this.createIndex(e)}initialize(t){const e=[];for(const n of t)"Point"===n.type&&e.push(n);this.createIndex(e)}updateIndex(t,e,n){this.options=Object.assign(Object.create($),n.clusterOptions),this.initialize(t)}createIndex(t){const{log:e,minZoom:n,maxZoom:o}=this.options;e&&console.time("total time");const s=`prepare ${t.length} points`;e&&console.time(s),this.points=t;const i=[];for(let e=0;e=n;t--){const n=Date.now();r=this.trees[t]=this.createTree(this.cluster(r,t)),e&&console.log("z%d: %d clusters in %dms",t,r.numItems,Date.now()-n)}e&&console.timeEnd("total time")}getClusters(t,e){return this.getClustersInternal(t,e).map((t=>h(t)))}getClustersInternal(t,e){let n=((t[0]+180)%360+360)%360-180;const o=Math.max(-90,Math.min(90,t[1]));let s=180===t[2]?180:((t[2]+180)%360+360)%360-180;const i=Math.max(-90,Math.min(90,t[3]));if(t[2]-t[0]>=360)n=-180,s=180;else if(n>s){const t=this.getClustersInternal([n,o,180,i],e),r=this.getClustersInternal([-180,o,s,i],e);return t.concat(r)}const r=this.trees[this.limitZoom(e)],a=r.range(c(n),l(i),c(s),l(o)),u=r.flatData,h=[];for(const t of a){const e=this.stride*t;h.push(u[e+B]>1?R(u,e,this.clusterProps):this.points[u[e+G]])}return h}getChildren(t){const e=this.getOriginId(t),n=this.getOriginZoom(t),o=new Error("No cluster with the specified id: "+t),s=this.trees[n];if(!s)throw o;const i=s.flatData;if(e*this.stride>=i.length)throw o;const r=this.options.radius/(this.options.extent*Math.pow(2,n-1)),a=i[e*this.stride],u=i[e*this.stride+1],c=s.within(a,u,r),l=[];for(const e of c){const n=e*this.stride;i[n+4]===t&&l.push(i[n+B]>1?V(i,n,this.clusterProps):h(this.points[i[n+G]]))}if(0===l.length)throw o;return l}getLeaves(t,e,n){e=e||10,n=n||0;const o=[];return this.appendLeaves(o,t,e,n,0),o}getTile(t,e,n){const o=this.trees[this.limitZoom(t)];if(!o)return null;const s=Math.pow(2,t),{extent:i,radius:r}=this.options,a=r/i,u=(n-a)/s,c=(n+1+a)/s,l={transformed:!0,features:[],source:null,x:e,y:n,z:t};return this.addTileFeatures(o.range((e-a)/s,u,(e+1+a)/s,c),o.flatData,e,n,s,l),0===e&&this.addTileFeatures(o.range(1-a/s,u,1,c),o.flatData,s,n,s,l),e===s-1&&this.addTileFeatures(o.range(0,u,a/s,c),o.flatData,-1,n,s,l),l}getClusterExpansionZoom(t){return this.getOriginZoom(t)}appendLeaves(t,e,n,o,s){const i=this.getChildren(e);for(const e of i){const i=e.properties;if(i?.cluster?s+i.point_count<=o?s+=i.point_count:s=this.appendLeaves(t,i.cluster_id,n,o,s):s1;let u,c,l;if(a)u=K(e,t,this.clusterProps),c=e[t],l=e[t+1];else{const n=this.points[e[t+G]];u=n.tags,[c,l]=n.geometry}const h={type:1,geometry:[[Math.round(this.options.extent*(c*s-n)),Math.round(this.options.extent*(l*s-o))]],tags:u};let d;d=a||this.options.generateId?e[t+G]:this.points[e[t+G]].id,void 0!==d&&(h.id=d),i.features.push(h)}}limitZoom(t){return Math.max(this.options.minZoom,Math.min(Math.floor(+t),this.options.maxZoom+1))}cluster(t,e){const{radius:n,extent:o,reduce:s,minPoints:i}=this.options,r=n/(o*Math.pow(2,e)),a=t.flatData,u=[],c=this.stride;for(let n=0;ne&&(p+=a[n+B])}if(p>d&&p>=i){let t,i=o*d,r=l*d,f=-1;const g=(n/c<<5)+(e+1)+this.points.length;for(const o of h){const u=o*c;if(a[u+2]<=e)continue;a[u+2]=e;const l=a[u+B];i+=a[u]*l,r+=a[u+1]*l,a[u+4]=g,s&&(t||(t=this.map(a,n,!0),f=this.clusterProps.length,this.clusterProps.push(t)),s(t,this.map(a,u)))}a[n+4]=g,u.push(i/p,r/p,1/0,g,-1,p),s&&u.push(f)}else{for(let t=0;t1)for(const t of h){const n=t*c;if(!(a[n+2]<=e)){a[n+2]=e;for(let t=0;t>5}getOriginZoom(t){return(t-this.points.length)%32}map(t,e,n){if(t[e+B]>1){const o=this.clusterProps[t[e+J]];return n?Object.assign({},o):o}const o=this.points[t[e+G]].tags,s=this.options.map(o);return n&&s===o?Object.assign({},s):s}}function R(t,e,n){return{id:t[e+G],type:"Point",tags:K(t,e,n),geometry:[t[e],t[e+1]]}}function V(t,e,n){return{type:"Feature",id:t[e+G],properties:K(t,e,n),geometry:{type:"Point",coordinates:[g(t[e]),m(t[e+1])]}}}function K(t,e,n){const o=t[e+B],s=o>=1e4?`${Math.round(o/1e3)}k`:o>=1e3?Math.round(o/100)/10+"k":o,i=t[e+J],r=-1===i?{}:Object.assign({},n[i]);return Object.assign(r,{cluster:!0,cluster_id:t[e+G],point_count:o,point_count_abbreviated:s})}const H="geojsonvt_clip_start",Q="geojsonvt_clip_end";function W(t,e,n,o,s){const i=e===s.maxZoom?0:s.tolerance/((1<0&&e.size<(s?r:o))return void(n.numPoints+=e.length/3);const a=[];for(let t=0;tr)&&(n.numSimplified++,a.push(e[t],e[t+1])),n.numPoints++;s&&function(t,e){let n=0;for(let e=0,o=t.length,s=o-2;e0!==e)return;for(let e=0,n=t.length;e1&&(console.log("invalidating tiles"),console.time("invalidating")),this.invalidateTiles(e),n.debug>1&&console.timeEnd("invalidating");const[o,s,i]=[0,0,0],r=W(t,o,s,i,n);r.source=t;const a=at(o,s,i);if(this.tiles[a]=r,this.tileCoords.push({z:o,x:s,y:i,id:a}),n.debug){const t=`z${o}`;this.stats[t]=(this.stats[t]||0)+1,this.total++}}getClusterExpansionZoom(t){return null}getChildren(t){return null}getLeaves(t,e,n){return null}getTile(t,e,n){const{extent:o,debug:s}=this.options,i=1<1&&console.log("drilling down to z%d-%d-%d",t,e,n);let a,u=t,c=e,l=n;for(;!a&&u>0;)u--,c>>=1,l>>=1,a=this.tiles[at(u,c,l)];return a?.source?(s>1&&(console.log("found parent tile z%d-%d-%d",u,c,l),console.time("drilling down")),this.splitTile(a.source,u,c,l,t,e,n),s>1&&console.timeEnd("drilling down"),this.tiles[r]?nt(this.tiles[r],o):null):null}splitTile(t,e,n,o,s,i,r){const a=[t,e,n,o],u=this.options,c=u.debug;for(;a.length;){o=a.pop(),n=a.pop(),e=a.pop(),t=a.pop();const l=1<1&&console.time("creation"),d=this.tiles[h]=W(t,e,n,o,u),this.tileCoords.push({z:e,x:n,y:o,id:h}),c)){c>1&&(console.log("tile z%d-%d-%d (features: %d, points: %d, simplified: %d)",e,n,o,d.numFeatures,d.numPoints,d.numSimplified),console.timeEnd("creation"));const t=`z${e}`;this.stats[t]=(this.stats[t]||0)+1,this.total++}if(d.source=t,null==s){if(e===u.indexMaxZoom||d.numPoints<=u.indexMaxPoints)continue}else{if(e===u.maxZoom||e===s)continue;if(null!=s){const t=s-e;if(n!==i>>t||o!==r>>t)continue}}if(d.source=null,!t.length)continue;c>1&&console.time("clipping");const p=.5*u.buffer/u.extent,f=.5-p,g=.5+p,m=1+p;let M=null,w=null,P=null,I=null;const v=x(t,l,n-p,n+g,y.X,d.minX,d.maxX,u),b=x(t,l,n+f,n+m,y.X,d.minX,d.maxX,u);v&&(M=x(v,l,o-p,o+g,y.Y,d.minY,d.maxY,u),w=x(v,l,o+f,o+m,y.Y,d.minY,d.maxY,u)),b&&(P=x(b,l,o-p,o+g,y.Y,d.minY,d.maxY,u),I=x(b,l,o+f,o+m,y.Y,d.minY,d.maxY,u)),c>1&&console.timeEnd("clipping"),a.push(M||[],e+1,2*n,2*o),a.push(w||[],e+1,2*n,2*o+1),a.push(P||[],e+1,2*n+1,2*o),a.push(I||[],e+1,2*n+1,2*o+1)}}invalidateTiles(t){if(!t.length)return;const e=this.options,{debug:n}=e;let o=1/0,s=-1/0,i=1/0,r=-1/0;for(const e of t)o=Math.min(o,e.minX),s=Math.max(s,e.maxX),i=Math.min(i,e.minY),r=Math.max(r,e.maxY);const a=e.buffer/e.extent,u=new Set;for(const e in this.tiles){const c=this.tiles[e],l=1<=d||r=f)continue;let g=!1;for(const e of t)if(e.maxX>=h&&e.minX=p&&e.minY1&&console.log("invalidate tile z%d-%d-%d (features: %d, points: %d, simplified: %d)",c.z,c.x,c.y,c.numFeatures,c.numPoints,c.numSimplified);const t=`z${c.z}`;this.stats[t]=(this.stats[t]||0)-1,this.total--}delete this.tiles[e],u.add(e)}}u.size&&(this.tileCoords=this.tileCoords.filter((t=>!u.has(t.id))))}}function at(t,e,n){return 32*((1<24)throw new Error("maxZoom should be in the 0-24 range");if(e.promoteId&&e.generateId)throw new Error("promoteId and generateId cannot be used together.");let o=i(t,e);n&&(console.timeEnd("preprocess data"),console.log("index: maxZoom: %d, maxPoints: %d",e.indexMaxZoom,e.indexMaxPoints),console.time("generate tiles")),o=X(o,e),e.updateable&&(this.source=o),this.initializeIndex(o,e)}initializeIndex(t,e){this.tileIndex=e.cluster?new q(e.clusterOptions):new rt(e),t.length&&this.tileIndex.initialize(t)}getTile(t,e,n){return e=+e,n=+n,(t=+t)<0||t>24?null:this.tileIndex.getTile(t,e,n)}updateData(t,e){const n=this.options;if(!n.updateable)throw new Error("to update tile geojson `updateable` option must be set to true");let{affected:o,source:s}=O(this.source,t,n);e&&({affected:o,source:s}=this.filterUpdate(s,o,e)),o.length&&(this.source=s,this.tileIndex.updateIndex(s,o,n))}filterUpdate(t,e,n){const o=new Set;for(const s of t)null!=s.id&&(n(h(s))||(e.push(s),o.add(s.id)));return{affected:e,source:t=t.filter((t=>!o.has(t.id)))}}getData(){if(!this.options.updateable)throw new Error("to retrieve data the `updateable` option must be set to true");return{type:"FeatureCollection",features:this.source.map((t=>h(t)))}}updateClusterOptions(t,e){const n=this.options.cluster;this.options.cluster=t,this.options.clusterOptions=e,n!=t?this.initializeIndex(this.source,this.options):this.tileIndex.updateIndex(this.source,[],this.options)}getClusterExpansionZoom(t){return this.tileIndex.getClusterExpansionZoom(t)}getClusterChildren(t){return this.tileIndex.getChildren(t)}getClusterLeaves(t,e,n){return this.tileIndex.getLeaves(t,e,n)}},t.Supercluster=q,t.geoJSONToTile=function(t,e,n,o,s={}){s={...ut,...s};const{wrap:r=!1,clip:a=!1}=s;let u=i(t,s);if(r&&(u=X(u,s)),a||s.lineMetrics){const t=1<