@maplibre/geojson-vt 6.1.0 → 6.1.1

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