@maplibre/geojson-vt 6.3.1 → 6.3.2

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.
@@ -97,10 +97,10 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
97
97
  type: data.type,
98
98
  geometry: data.geom,
99
99
  tags,
100
- minX: Infinity,
101
- minY: Infinity,
102
- maxX: -Infinity,
103
- maxY: -Infinity
100
+ minX: 1e400,
101
+ minY: 1e400,
102
+ maxX: -1e400,
103
+ maxY: -1e400
104
104
  };
105
105
  switch (data.type) {
106
106
  case "Point":
@@ -1814,14 +1814,51 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
1814
1814
  const transformed = feature;
1815
1815
  const geometry = feature.geometry;
1816
1816
  const nonPoint = [];
1817
- for (const geom of geometry) {
1818
- const ring = [];
1819
- for (let i = 0; i < geom.length; i += 2) ring.push(transformPoint(geom[i], geom[i + 1], extent, z2, tx, ty));
1820
- nonPoint.push(ring);
1817
+ for (const geom of geometry) if (feature.type === 3) nonPoint.push(transformPolygonRing(geom, extent, z2, tx, ty));
1818
+ else {
1819
+ const line = [];
1820
+ for (let i = 0; i < geom.length; i += 2) line.push(transformPoint(geom[i], geom[i + 1], extent, z2, tx, ty));
1821
+ nonPoint.push(line);
1821
1822
  }
1822
1823
  transformed.geometry = nonPoint;
1823
1824
  return transformed;
1824
1825
  }
1826
+ /**
1827
+ * Quantizes a polygon ring while preserving its winding so a hole does not become
1828
+ * a shell, or vice versa. Signed areas use coordinates relative to the first
1829
+ * vertex to reduce cancellation for narrow rings far from the origin.
1830
+ * Zero-area results are left unchanged; other quantization topology changes
1831
+ * are not repaired.
1832
+ */
1833
+ function transformPolygonRing(geometry, extent, z2, tx, ty) {
1834
+ if (!geometry.length) return [];
1835
+ const originX = geometry[0];
1836
+ const originY = geometry[1];
1837
+ const origin = transformPoint(originX, originY, extent, z2, tx, ty);
1838
+ const ring = [origin];
1839
+ let previousX = 0;
1840
+ let previousY = 0;
1841
+ let previousRoundedX = 0;
1842
+ let previousRoundedY = 0;
1843
+ let sourceArea = 0;
1844
+ let roundedArea = 0;
1845
+ for (let i = 2; i < geometry.length; i += 2) {
1846
+ const point = transformPoint(geometry[i], geometry[i + 1], extent, z2, tx, ty);
1847
+ const x = geometry[i] - originX;
1848
+ const y = geometry[i + 1] - originY;
1849
+ const roundedX = point[0] - origin[0];
1850
+ const roundedY = point[1] - origin[1];
1851
+ sourceArea += previousX * y - x * previousY;
1852
+ roundedArea += previousRoundedX * roundedY - roundedX * previousRoundedY;
1853
+ previousX = x;
1854
+ previousY = y;
1855
+ previousRoundedX = roundedX;
1856
+ previousRoundedY = roundedY;
1857
+ ring.push(point);
1858
+ }
1859
+ if (sourceArea * roundedArea < 0) ring.reverse();
1860
+ return ring;
1861
+ }
1825
1862
  function transformPoint(x, y, extent, z2, tx, ty) {
1826
1863
  return [Math.round(extent * (x * z2 - tx)), Math.round(extent * (y * z2 - ty))];
1827
1864
  }
@@ -1926,8 +1963,8 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
1926
1963
  const { wrap, coordinates } = this.options;
1927
1964
  if (wrap && coordinates !== "unitSquare") return features;
1928
1965
  const buffer = this.options.buffer / this.options.extent;
1929
- const inX = wrap ? features : clip(features, 1, -buffer, 1 + buffer, 0, -Infinity, Infinity, this.options) || [];
1930
- return clip(inX, 1, -buffer, 1 + buffer, 1, -Infinity, Infinity, this.options) || [];
1966
+ const inX = wrap ? features : clip(features, 1, -buffer, 1 + buffer, 0, -1e400, 1e400, this.options) || [];
1967
+ return clip(inX, 1, -buffer, 1 + buffer, 1, -1e400, 1e400, this.options) || [];
1931
1968
  }
1932
1969
  /**
1933
1970
  * splits features from a parent tile to sub-tiles.
@@ -2026,10 +2063,10 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2026
2063
  if (!features.length) return;
2027
2064
  const options = this.options;
2028
2065
  const { debug } = options;
2029
- let minX = Infinity;
2030
- let maxX = -Infinity;
2031
- let minY = Infinity;
2032
- let maxY = -Infinity;
2066
+ let minX = 1e400;
2067
+ let maxX = -1e400;
2068
+ let minY = 1e400;
2069
+ let maxY = -1e400;
2033
2070
  for (const feature of features) {
2034
2071
  minX = Math.min(minX, feature.minX);
2035
2072
  maxX = Math.max(maxX, feature.maxX);
@@ -1 +1 @@
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,t,r,i){let a=[t,r];for(;a.length;)r=a.pop(),t=a.pop(),n(e,t,r,i,a)}function n(e,t,n,i,a){let o=i,s=t+(n-t>>1),c=n-t,l,u=e[t],d=e[t+1],f=e[n],p=e[n+1];for(let i=t+3;i<n;i+=3){let t=r(e[i],e[i+1],u,d,f,p);if(t>o)l=i,o=t;else if(t===o){let e=Math.abs(i-s);e<c&&(l=i,c=e)}}o>i&&(e[l+2]=o,l-t>3&&a.push(t,l),n-l>3&&a.push(l,n))}function r(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 i(e,t,n,r){let i={type:t,geom:n},a={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`:o(a,i.geom);break;case`LineString`:o(a,i.geom.points);break;case`Polygon`:o(a,i.geom[0].points);break;case`MultiLineString`:for(let e of i.geom)o(a,e.points);break;case`MultiPolygon`:for(let e of i.geom)o(a,e[0].points)}return a}function a(e){let t=e;e.points.length>64&&(t.points=new Float64Array(e.points))}function o(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])}var s=class{projectX(e){return e/360+.5}projectY(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}unprojectX(e){return(e-.5)*360}unprojectY(e){let t=(180-e*360)*Math.PI/180;return 360*Math.atan(Math.exp(t))/Math.PI-90}},c=class{projectX(e){return e}projectY(e){return e}unprojectX(e){return e}unprojectY(e){return e}};let l=new s,u=new c;function d(e){return e===`unitSquare`?u:l}function f(e,t,n){let r=[];switch(e.type){case`FeatureCollection`:for(let i=0;i<e.features.length;i++)p(r,e.features[i],t,n,i);break;case`Feature`:p(r,e,t,n);break;default:p(r,{type:`Feature`,geometry:e,properties:void 0},t,n)}return r}function p(e,t,n,r,i){let a=e.length;if(m(e,t,n,i),!r)return;let o=h(t,n,i);o!=null&&(e.length>a?r.delete(o):r.set(o,{...t,id:o}))}function m(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`){g(e,t,t.geometry,n,r,i+1);return}if(!t.geometry.coordinates?.length)return;let a=h(t,n,r),o=(n.tolerance/((1<<n.maxZoom)*n.extent))**2,s=d(n.coordinates);switch(t.geometry.type){case`Point`:_(e,a,t.geometry,s,t.properties);return;case`MultiPoint`:v(e,a,t.geometry,s,t.properties);return;case`LineString`:y(e,a,t.geometry,o,s,t.properties);return;case`MultiLineString`:b(e,a,t.geometry,o,s,n,t.properties);return;case`Polygon`:x(e,a,t.geometry,o,s,t.properties);return;case`MultiPolygon`:S(e,a,t.geometry,o,s,t.properties);return;default:throw Error(`Input data is not a valid GeoJSON object.`)}}function h(e,t,n){return t.promoteId?e.properties?.[t.promoteId]:t.generateId?n||0:e.id}function g(e,t,n,r,i,a=0){for(let o of n.geometries)m(e,{id:t.id,type:`Feature`,geometry:o,properties:t.properties},r,i,a)}function _(e,t,n,r,a){let o=[];o.push(r.projectX(n.coordinates[0]),r.projectY(n.coordinates[1]),0),e.push(i(t,`Point`,o,a))}function v(e,t,n,r,a){let o=[];for(let e of n.coordinates)o.push(r.projectX(e[0]),r.projectY(e[1]),0);e.push(i(t,`MultiPoint`,o,a))}function y(e,t,n,r,a,o){let s={points:[]};C(n.coordinates,s,r,!1,a),e.push(i(t,`LineString`,s,o))}function b(e,t,n,r,a,o,s){if(o.lineMetrics)for(let o of n.coordinates){let n={points:[]};C(o,n,r,!1,a),e.push(i(t,`LineString`,n,s))}else{let o=[];w(n.coordinates,o,r,!1,a),e.push(i(t,`MultiLineString`,o,s))}}function x(e,t,n,r,a,o){let s=[];w(n.coordinates,s,r,!0,a),e.push(i(t,`Polygon`,s,o))}function S(e,t,n,r,a,o){let s=[];for(let e of n.coordinates){let t=[];w(e,t,r,!0,a),t.length&&s.push(t)}s.length&&e.push(i(t,`MultiPolygon`,s,o))}function C(e,n,r,i,o){let s,c,l=0;for(let t=0;t<e.length;t++){let r=o.projectX(e[t][0]),a=o.projectY(e[t][1]);n.points.push(r,a,0),t>0&&(l+=i?(s*a-r*c)/2:Math.sqrt((r-s)**2+(a-c)**2)),s=r,c=a}let u=n.points.length-3;n.points[2]=1,r>0&&t(n.points,0,u,r),n.points[u+2]=1,a(n),n.size=Math.abs(l),n.start=0,n.end=n.size}function w(e,t,n,r,i){for(let a=0;a<e.length;a++){let o={points:[]};C(e[a],o,n,r,i),t.push(o)}}function ee(e,t=l){return{type:`FeatureCollection`,features:e.map(e=>T(e,t))}}function T(e,t=l){let n={type:`Feature`,geometry:te(e,t),properties:e.tags};return e.id!=null&&(n.id=e.id),n}function te(e,t){let{type:n,geometry:r}=e;switch(n){case`Point`:return{type:n,coordinates:ne(r[0],r[1],t)};case`MultiPoint`:return{type:n,coordinates:E(r,t)};case`LineString`:return{type:n,coordinates:E(r.points,t)};case`MultiLineString`:case`Polygon`:return{type:n,coordinates:r.map(e=>E(e.points,t))};case`MultiPolygon`:return{type:n,coordinates:r.map(e=>e.map(e=>E(e.points,t)))}}}function E(e,t=l){let n=[];for(let r=0;r<e.length;r+=3)n.push(ne(e[r],e[r+1],t));return n}function ne(e,t,n){return[n.unprojectX(e),n.unprojectY(t)]}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);else if(!(a<n||e>=r))switch(t.type){case`MultiPoint`:re(t,c,n,r,i);continue;case`LineString`:ie(t,c,n,r,i,s);continue;case`MultiLineString`:ae(t,c,n,r,i);continue;case`Polygon`:oe(t,c,n,r,i);continue;case`MultiPolygon`:se(t,c,n,r,i);continue}}return c.length?c:null}function re(e,t,n,r,a){let o=[];if(ce(e.geometry,o,n,r,a),!o.length)return;let s=o.length===3?`Point`:`MultiPoint`;t.push(i(e.id,s,o,e.tags))}function ie(e,t,n,r,a,o){let s=[];if(O(e.geometry,s,n,r,a,!1,o.lineMetrics),s.length){if(o.lineMetrics)for(let n of s)t.push(i(e.id,`LineString`,n,e.tags));else s.length>1?t.push(i(e.id,`MultiLineString`,s,e.tags)):t.push(i(e.id,`LineString`,s[0],e.tags))}}function ae(e,t,n,r,a){let o=[];k(e.geometry,o,n,r,a,!1),o.length&&(o.length===1?t.push(i(e.id,`LineString`,o[0],e.tags)):t.push(i(e.id,`MultiLineString`,o,e.tags)))}function oe(e,t,n,r,a){let o=[];k(e.geometry,o,n,r,a,!0),o.length&&t.push(i(e.id,`Polygon`,o,e.tags))}function se(e,t,n,r,a){let o=[];for(let t of e.geometry){let e=[];k(t,e,n,r,a,!0),e.length&&o.push(e)}o.length&&t.push(i(e.id,`MultiPolygon`,o,e.tags))}function ce(e,t,n,r,i){for(let a=0;a<e.length;a+=3){let o=e[a+i];o>=n&&o<=r&&A(t,e[a],e[a+1],e[a+2])}}function O(e,t,n,r,i,o,s){let c=le(e),l=i===0?ue:de,u=e.start,d,f;for(let a=0;a<e.points.length-3;a+=3){let p=e.points[a],m=e.points[a+1],h=e.points[a+2],g=e.points[a+3],_=e.points[a+4],v=i===0?p:m,y=i===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)):A(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=le(e)),s&&(u+=d)}let p=e.points.length-3,m=e.points[p],h=e.points[p+1],g=e.points[p+2],_=i===0?m:h;_>=n&&_<=r&&A(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])&&A(c.points,c.points[0],c.points[1],c.points[2]),c.points.length&&(a(c),t.push(c))}function le(e){return{points:[],size:e.size,start:e.start,end:e.end}}function k(e,t,n,r,i,a){for(let o of e)O(o,t,n,r,i,a,!1)}function A(e,t,n,r){e.push(t,n,r)}function ue(e,t,n,r,i,a){let o=(a-t)/(r-t);return A(e.points,a,n+(i-n)*o,1),o}function de(e,t,n,r,i,a){let o=(a-n)/(i-n);return A(e.points,t+(r-t)*o,a,1),o}function j(e,t){if(!t.wrap)return e;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=D(e,1,-n,1+n,0,-1,2,t)||[],i&&(r=M(i,1).concat(r)),a&&(r=r.concat(M(a,-1)))),r}function M(e,t){let n=[];for(let r of e)switch(r.type){case`Point`:case`MultiPoint`:{let e=fe(r.geometry,t);n.push(i(r.id,r.type,e,r.tags));continue}case`LineString`:{let e=N(r.geometry,t);n.push(i(r.id,r.type,e,r.tags));continue}case`MultiLineString`:case`Polygon`:{let e=[];for(let n of r.geometry)e.push(N(n,t));n.push(i(r.id,r.type,e,r.tags));continue}case`MultiPolygon`:{let e=[];for(let n of r.geometry){let r=[];for(let e of n)r.push(N(e,t));e.push(r)}n.push(i(r.id,r.type,e,r.tags));continue}}return n}function fe(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 N(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 a(n),n}function pe(e,t,n,r){let i=ge(t,n),a=[];if(i.removeAll&&(a=e,e=[],r?.clear()),i.remove.size||i.add.size){for(let e of i.remove)r?.delete(e);let t=[];for(let n of e)(i.remove.has(n.id)||i.add.has(n.id))&&t.push(n);if(t.length){a=a.concat(t);let n=new Set(t.map(e=>e.id));e=e.filter(e=>!n.has(e.id))}if(i.add.size){let t=f({type:`FeatureCollection`,features:Array.from(i.add.values())},{...n,generateId:!1},r);t=j(t,n),a=a.concat(t),e=e.concat(t)}}if(i.update.size){let t=/* @__PURE__ */ new Map,o=[];for(let n of e)i.update.has(n.id)?t.set(n.id,[...t.get(n.id)||[],n]):o.push(n);for(let[e,s]of i.update){let i=t.get(e);if(!i||i.length===0){if(!r?.has(e))continue;let t=he(e,s,n,r);a=a.concat(t),o=o.concat(t);continue}let c=me(i,s,n,r);a=a.concat(i,c),o=o.concat(c)}e=o}return{affected:a,source:e}}function me(e,t,n,r){let i=!!t.newGeometry,a=F(t);if(i){let i=e[0],o=a?I(i.tags,t):i.tags;return P(i.id,t.newGeometry,o,n,r)}if(a){let n=[];for(let r of e){let e={...r};e.tags=I(e.tags,t),n.push(e)}return n}return e}function he(e,t,n,r){let i=r.get(e),a=F(t)?I(i.properties,t):i.properties;return t.newGeometry?P(e,t.newGeometry,a,n,r):(r.set(e,{...i,properties:a}),[])}function P(e,t,n,r,i){return j(f({type:`FeatureCollection`,features:[{type:`Feature`,id:e,geometry:t,properties:n}]},{...r,promoteId:void 0,generateId:!1},i),r)}function F(e){return e.removeAllProperties||e.removeProperties?.length>0||e.addOrUpdateProperties?.length>0}function I(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 ge(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:/* @__PURE__ */ new Set,add:/* @__PURE__ */ new Map,update:/* @__PURE__ */ new Map}}let L=[Int8Array,Uint8Array,Uint8ClampedArray,Int16Array,Uint16Array,Int32Array,Uint32Array,Float32Array,Float64Array],R=/* @__PURE__ */ new Uint32Array(96);var _e=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=L[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=L.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 z(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;R[0]=0,R[1]=i.length-1,R[2]=0;let s=3,c=[];for(;s>0;){let l=R[--s],u=R[--s],d=R[--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)&&(R[s++]=d,R[s++]=f-1,R[s++]=1-l),(l===0?n>=p:r>=m)&&(R[s++]=f+1,R[s++]=u,R[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;R[0]=0,R[1]=i.length-1,R[2]=0;let s=3,c=0,l=n*n;for(;s>0;){let u=R[--s],d=R[--s],f=R[--s];if(d-f<=o){for(let n=f;n<=d;n++)U(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];U(m,h,e,t)<=l&&(r[c++]=i[p]),(u===0?e-n<=m:t-n<=h)&&(R[s++]=f,R[s++]=p-1,R[s++]=1-u),(u===0?e+n>=m:t+n>=h)&&(R[s++]=p+1,R[s++]=d,R[s++]=1-u)}return c}};function z(e,t,n,r,i,a){if(i-r<=n)return;let o=r+i>>1;B(e,t,o,r,i,a),z(e,t,n,r,o-1,1-a),z(e,t,n,o+1,i,1-a)}function B(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);B(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(V(e,t,r,n),t[2*i+a]>o&&V(e,t,r,i);s<c;){for(V(e,t,s,c),s++,c--;t[2*s+a]<o;)s++;for(;t[2*c+a]>o;)c--}t[2*r+a]===o?V(e,t,r,c):(c++,V(e,t,c,i)),c<=n&&(r=c+1),n<=c&&(i=c-1)}}function V(e,t,n,r){H(e,n,r),H(t,2*n,2*r),H(t,2*n+1,2*r+1)}function H(e,t,n){let r=e[t];e[t]=e[n],e[n]=r}function U(e,t,n,r){let i=e-n,a=t-r;return i*i+a*a}let ve={minZoom:0,maxZoom:16,minPoints:2,radius:40,extent:512,nodeSize:64,log:!1,generateId:!1,reduce:null,map:e=>e,coordinates:`lngLat`,wrap:!0},W=1073741824;function G(e){return(e-.5)*W}function K(e){return e/W+.5}function ye(e){return Math.abs(G(e))<2147483647}var be=class{constructor(e){this.options=xe(e),this.worldCoordinateHelper=d(this.options.coordinates),this.trees=Array(this.options.maxZoom+1),this.stride=this.options.reduce?5:4,this.clusterProps=[],this.points=[]}load(e){let t=[];for(let n of e){if(!n.geometry)continue;let e=n.geometry.type===`MultiPoint`?n.geometry.coordinates:[n.geometry.coordinates];for(let[r,i]of e){let[e,a]=[this.worldCoordinateHelper.projectX(r),this.worldCoordinateHelper.projectY(i)];if(!this.options.wrap&&!J([e,a]))continue;let o={id:n.id,type:`Point`,geometry:[e,a],tags:n.properties};t.push(o)}}this.createIndex(t)}initialize(e){let t=[];for(let n of e)if(n.type===`Point`){if(!this.options.wrap&&!J(n.geometry))continue;t.push(n)}else if(n.type===`MultiPoint`)for(let e=0;e<n.geometry.length;e+=3){let r=[n.geometry[e],n.geometry[e+1]];(this.options.wrap||J(r))&&t.push({id:n.id,type:`Point`,geometry:r,tags:n.tags})}this.createIndex(t)}updateIndex(e,t,n){this.options=xe({...n.clusterOptions,coordinates:this.options.coordinates,wrap:this.options.wrap}),this.initialize(e)}createIndex(e){let{log:t,minZoom:n,maxZoom:r}=this.options;this.trees=Array(r+1),this.stride=this.options.reduce?5:4,this.clusterProps=[],t&&console.time(`total time`);let i=`prepare ${e.length} points`;t&&console.time(i),this.points=e;let a=this.stride,o=r+1,s=new Int32Array(e.length*2),c=new Int32Array(e.length*a),l=0;for(let t=0;t<e.length;t++){let n=e[t];if(!n?.geometry||!ye(n.geometry[0])||!ye(n.geometry[1]))continue;s[l*2]=Math.round(G(n.geometry[0])),s[l*2+1]=Math.round(G(n.geometry[1]));let r=l*a;c[r+0]=o,c[r+1]=t,c[r+2]=-1,c[r+3]=1,l++}let u=this.trees[r+1]=this.createTree(s,c,l);t&&console.timeEnd(i);let d=new Int32Array(l*2),f=new Int32Array(l*a);for(let e=r;e>=n;e--){let n=Date.now(),r=this.cluster(u,e,d,f);this.isSameAsTree(u,f,r)||(u=this.createTree(d.slice(0,r*2),f.slice(0,r*a),r)),this.trees[e]=u,t&&console.log(`z%d: %d clusters in %dms`,e,u.numItems,Date.now()-n)}t&&console.timeEnd(`total time`)}getClusters(e,t){return(this.options.wrap?this.options.coordinates===`unitSquare`?this.getClustersAcrossEdge(e,t):this.getClustersInternal(e,t):this.getClustersInWorld(e,t)).map(e=>T(e,this.worldCoordinateHelper))}getClustersInWorld(e,t){let n=this.options.coordinates!==`unitSquare`,r=this.worldCoordinateHelper.projectY(n?Math.max(-90,Math.min(90,e[1])):e[1]),i=this.worldCoordinateHelper.projectY(n?Math.max(-90,Math.min(90,e[3])):e[3]),a=Math.max(0,this.worldCoordinateHelper.projectX(e[0])),o=Math.min(1,this.worldCoordinateHelper.projectX(e[2]));return a>o?[]:this.getClustersInRange([a,Math.min(r,i),o,Math.max(r,i)],t)}getClustersAcrossEdge([e,t,n,r],i){if(n<e&&(n+=1),n-e>=1)return this.getClustersInRange([0,t,1,r],i);let a=Math.floor(e),o=e-a,s=n-a;return s<=1?this.getClustersInRange([o,t,s,r],i):this.getClustersInRange([o,t,1,r],i).concat(this.getClustersInRange([0,t,s-1,r],i))}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)}return this.getClustersInRange([this.worldCoordinateHelper.projectX(n),this.worldCoordinateHelper.projectY(a),this.worldCoordinateHelper.projectX(i),this.worldCoordinateHelper.projectY(r)],t)}getClustersInRange([e,t,n,r],i){let a=this.trees[this.limitZoom(i)],o=a.range(G(e),G(t),G(n),G(r)),s=a.flatCoords,c=a.flatData,l=[];for(let e of o){let t=this.stride*e;l.push(c[t+3]>1?Se(s,e,c,t,this.clusterProps):this.points[c[t+1]])}return l}getChildren(e){let t=this.getOriginId(e),n=this.getOriginZoom(e),r=/* @__PURE__ */ Error(`No cluster with the specified id: `+e),i=this.trees[n];if(!i)throw r;let a=i.flatCoords,o=i.flatData;if(t>=i.numItems)throw r;let s=this.options.radius/(this.options.extent*2**(n-1))*W,c=a[t*2],l=a[t*2+1],u=i.within(c,l,s),d=[];for(let t of u){let n=t*this.stride;o[n+2]===e&&d.push(o[n+3]>1?Ce(a,t,o,n,this.clusterProps,this.worldCoordinateHelper):T(this.points[o[n+1]],this.worldCoordinateHelper))}if(d.length===0)throw r;return d}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;if(!this.options.wrap&&(t<0||t>=i||n<0||n>=i))return null;let{extent:a,radius:o}=this.options,s=o/a,c=G((n-s)/i),l=G((n+1+s)/i),u={transformed:!0,features:[],source:null,x:t,y:n,z:e};return this.addTileFeatures(r.range(G((t-s)/i),c,G((t+1+s)/i),l),r,t,n,i,u),this.options.wrap&&t===0&&this.addTileFeatures(r.range(G(1-s/i),c,G(1),l),r,i,n,i,u),this.options.wrap&&t===i-1&&this.addTileFeatures(r.range(G(0),c,G(s/i),l),r,-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,t,n){let r=new _e(n,this.options.nodeSize,Int32Array);for(let t=0;t<n;t++)r.add(e[t*2],e[t*2+1]);return r.finish(),r.flatCoords=e,r.flatData=t,r.data=null,r}isSameAsTree(e,t,n){if(n!==e.numItems)return!1;let r=e.flatData;for(let e=1;e<n*this.stride;e+=this.stride)if(t[e]!==r[e])return!1;return!0}addTileFeatures(e,t,n,r,i,a){let o=t.flatCoords,s=t.flatData;for(let t of e){let e=t*this.stride,c=s[e+3]>1,l,u,d;if(c)l=q(s,e,this.clusterProps),u=K(o[t*2]),d=K(o[t*2+1]);else{let t=this.points[s[e+1]];l=t.tags,[u,d]=t.geometry}let f={type:1,geometry:[[Math.round(this.options.extent*(u*i-n)),Math.round(this.options.extent*(d*i-r))]],tags:l},p;p=c||this.options.generateId?s[e+1]:this.points[s[e+1]].id,p!==void 0&&(f.id=p),a.features.push(f)}}limitZoom(e){return Math.max(this.options.minZoom,Math.min(Math.floor(+e),this.options.maxZoom+1))}cluster(e,t,n,r){let{radius:i,extent:a,reduce:o,minPoints:s,maxZoom:c}=this.options,l=i/(a*2**t)*W,u=c+1,d=e.flatCoords,f=e.flatData,p=this.stride,m=new Uint32Array(e.numItems),h=0;for(let i=0;i<e.numItems;i++){let a=i*p;if(f[a+0]<=t)continue;f[a+0]=t;let c=d[i*2],g=d[i*2+1],_=e.withinInto(c,g,l,m),v=f[a+3],y=v;for(let e=0;e<_;e++){let n=m[e]*p;f[n+0]>t&&(y+=f[n+3])}if(y>v&&y>=s){let e=c*v,s=g*v,l,b=-1,x=(i<<5)+(t+1)+this.points.length;for(let n=0;n<_;n++){let r=m[n],i=r*p;if(f[i+0]<=t)continue;f[i+0]=t;let c=f[i+3];e+=d[r*2]*c,s+=d[r*2+1]*c,f[i+2]=x,o&&(l||(l=this.map(f,a,!0),b=this.clusterProps.length,this.clusterProps.push(l)),o(l,this.map(f,i)))}f[a+2]=x,n[h*2]=Math.round(e/y),n[h*2+1]=Math.round(s/y);let S=h*p;r[S+0]=u,r[S+1]=x,r[S+2]=-1,r[S+3]=y,o&&(r[S+4]=b),h++}else{n[h*2]=c,n[h*2+1]=g;for(let e=0;e<p;e++)r[h*p+e]=f[a+e];if(h++,y>1)for(let e=0;e<_;e++){let i=m[e],a=i*p;if(!(f[a+0]<=t)){f[a+0]=t,n[h*2]=d[i*2],n[h*2+1]=d[i*2+1];for(let e=0;e<p;e++)r[h*p+e]=f[a+e];h++}}}}return h}getOriginId(e){return e-this.points.length>>5}getOriginZoom(e){return(e-this.points.length)%32}map(e,t,n){if(e[t+3]>1){let r=this.clusterProps[e[t+4]];return n?Object.assign({},r):r}let r=this.points[e[t+1]].tags,i=this.options.map(r);return n&&i===r?Object.assign({},i):i}};function xe(e){let t=Object.assign(Object.create(ve),e);return t.minZoom=Math.min(t.minZoom,30),t.maxZoom=Math.min(t.maxZoom,30),t}function Se(e,t,n,r,i){return{id:n[r+1],type:`Point`,tags:q(n,r,i),geometry:[K(e[t*2]),K(e[t*2+1])]}}function Ce(e,t,n,r,i,a){return{type:`Feature`,id:n[r+1],properties:q(n,r,i),geometry:{type:`Point`,coordinates:[a.unprojectX(K(e[t*2])),a.unprojectY(K(e[t*2+1]))]}}}function q(e,t,n){let r=e[t+3],i=r>=1e4?`${Math.round(r/1e3)}k`:r>=1e3?`${Math.round(r/100)/10}k`:r,a=e[t+4],o=a===-1?{}:Object.assign({},n[a]);return Object.assign(o,{cluster:!0,cluster_id:e[t+1],point_count:r,point_count_abbreviated:i})}function J(e){return e[0]>=0&&e[0]<=1&&e[1]>=0&&e[1]<=1}let we=`geojsonvt_clip_start`,Te=`geojsonvt_clip_end`;function Y(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)Ee(o,t,a,i);return o}function Ee(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`:De(e,t);return;case`LineString`:Oe(e,t,n,r);return;case`MultiLineString`:case`Polygon`:ke(e,t,n);return;case`MultiPolygon`:Ae(e,t,n);return}}function De(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 Oe(e,t,n,r){let i=[];if(X(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[we]=t.geometry.start/t.geometry.size,a[Te]=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 ke(e,t,n){let r=[];for(let i=0;i<t.geometry.length;i++)X(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 Ae(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++)X(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 X(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&&je(s,a),e.push(s)}function je(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 Z(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?Me(a,t,n,r,i):Ne(a,t,n,r,i);return e.transformed=!0,e}function Me(e,t,n,r,i){let a=e,o=e.geometry,s=[];for(let e=0;e<o.length;e+=2)s.push(Pe(o[e],o[e+1],t,n,r,i));return a.geometry=s,a}function Ne(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(Pe(e[o],e[o+1],t,n,r,i));s.push(a)}return a.geometry=s,a}function Pe(e,t,n,r,i,a){return[Math.round(n*(e*r-i)),Math.round(n*(t*r-a))]}var Fe=class{constructor(e){this.options=e,this.total=0,this.stats={},this.tiles={},this.tileCoords=[],this.stats={},this.total=0}initialize(e){this.splitTile(this.clipToWorld(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=this.clipToWorld(e),s=Y(o,r,i,a,n);s.source=o;let c=Q(r,i,a);if(this.tiles[c]=s,this.tileCoords.push({z:r,x:i,y:a,id:c}),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;if(!this.options.wrap&&(t<0||t>=a))return null;t=t+a&a-1;let o=Q(e,t,n);if(this.tiles[o])return Z(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:Z(this.tiles[o],r)}clipToWorld(e){let{wrap:t,coordinates:n}=this.options;if(t&&n!==`unitSquare`)return e;let r=this.options.buffer/this.options.extent;return D(t?e:D(e,1,-r,1+r,0,-1/0,1/0,this.options)||[],1,-r,1+r,1,-1/0,1/0,this.options)||[]}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]=Y(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=/* @__PURE__ */ 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:ve,debug:0,coordinates:`lngLat`,wrap:!0};var Ie=class{constructor(e,t){t=this.options=Object.assign({},$,t),this.worldCoordinateHelper=d(t.coordinates);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.`);t.updateable&&(this.unlocated=/* @__PURE__ */ new Map),this.nextId=e.type===`FeatureCollection`?e.features.length:1;let r=f(e,t,this.unlocated);n&&(console.timeEnd(`preprocess data`),console.log(`index: maxZoom: %d, maxPoints: %d`,t.indexMaxZoom,t.indexMaxPoints),console.time(`generate tiles`)),r=j(r,t),t.updateable&&(this.source=r),this.initializeIndex(r,t)}initializeIndex(e,t){this.tileIndex=t.cluster?new be({...t.clusterOptions,coordinates:t.coordinates,wrap:t.wrap}):new Fe(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");n.generateId&&e.add&&(e={...e,add:e.add.map(e=>({...e,id:this.nextId++}))});let{affected:r,source:i}=pe(this.source,e,n,this.unlocated);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=/* @__PURE__ */ new Set;for(let i of e)i.id!=null&&(n(T(i,this.worldCoordinateHelper))||(t.push(i),r.add(i.id)));e=e.filter(e=>!r.has(e.id));for(let[e,t]of this.unlocated??[])t.geometry&&!n(t)&&this.unlocated.delete(e);return{affected:t,source:e}}getData(){if(!this.options.updateable)throw Error("to retrieve data the `updateable` option must be set to true");return ee(this.source,this.worldCoordinateHelper)}updateClusterOptions(e,t){let n=this.options.cluster;this.options.cluster=e,this.options.clusterOptions=t,n==e?this.tileIndex.updateIndex(this.source,[],this.options):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 Le(e,t,n,r,i={}){i={...$,wrap:!1,...i};let{wrap:a,clip:o=!1}=i,s=f(e,i);if(a&&(s=j(s,i)),o||i.lineMetrics){let e=1<<t,a=i.buffer/i.extent;s=D(D(s,e,n-a,n+1+a,0,-1,2,i)||[],e,r-a,r+1+a,1,-1,2,i)}return Z(Y(s??[],t,n,r,i),i.extent)}e.GEOJSONVT_CLIP_END=Te,e.GEOJSONVT_CLIP_START=we,e.GeoJSONVT=Ie,e.Supercluster=be,e.geoJSONToTile=Le});
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,t,r,i){let a=[t,r];for(;a.length;)r=a.pop(),t=a.pop(),n(e,t,r,i,a)}function n(e,t,n,i,a){let o=i,s=t+(n-t>>1),c=n-t,l,u=e[t],d=e[t+1],f=e[n],p=e[n+1];for(let i=t+3;i<n;i+=3){let t=r(e[i],e[i+1],u,d,f,p);if(t>o)l=i,o=t;else if(t===o){let e=Math.abs(i-s);e<c&&(l=i,c=e)}}o>i&&(e[l+2]=o,l-t>3&&a.push(t,l),n-l>3&&a.push(l,n))}function r(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 i(e,t,n,r){let i={type:t,geom:n},a={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`:o(a,i.geom);break;case`LineString`:o(a,i.geom.points);break;case`Polygon`:o(a,i.geom[0].points);break;case`MultiLineString`:for(let e of i.geom)o(a,e.points);break;case`MultiPolygon`:for(let e of i.geom)o(a,e[0].points)}return a}function a(e){let t=e;e.points.length>64&&(t.points=new Float64Array(e.points))}function o(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])}var s=class{projectX(e){return e/360+.5}projectY(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}unprojectX(e){return(e-.5)*360}unprojectY(e){let t=(180-e*360)*Math.PI/180;return 360*Math.atan(Math.exp(t))/Math.PI-90}},c=class{projectX(e){return e}projectY(e){return e}unprojectX(e){return e}unprojectY(e){return e}};let l=new s,u=new c;function d(e){return e===`unitSquare`?u:l}function f(e,t,n){let r=[];switch(e.type){case`FeatureCollection`:for(let i=0;i<e.features.length;i++)p(r,e.features[i],t,n,i);break;case`Feature`:p(r,e,t,n);break;default:p(r,{type:`Feature`,geometry:e,properties:void 0},t,n)}return r}function p(e,t,n,r,i){let a=e.length;if(m(e,t,n,i),!r)return;let o=h(t,n,i);o!=null&&(e.length>a?r.delete(o):r.set(o,{...t,id:o}))}function m(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`){g(e,t,t.geometry,n,r,i+1);return}if(!t.geometry.coordinates?.length)return;let a=h(t,n,r),o=(n.tolerance/((1<<n.maxZoom)*n.extent))**2,s=d(n.coordinates);switch(t.geometry.type){case`Point`:_(e,a,t.geometry,s,t.properties);return;case`MultiPoint`:v(e,a,t.geometry,s,t.properties);return;case`LineString`:y(e,a,t.geometry,o,s,t.properties);return;case`MultiLineString`:b(e,a,t.geometry,o,s,n,t.properties);return;case`Polygon`:x(e,a,t.geometry,o,s,t.properties);return;case`MultiPolygon`:S(e,a,t.geometry,o,s,t.properties);return;default:throw Error(`Input data is not a valid GeoJSON object.`)}}function h(e,t,n){return t.promoteId?e.properties?.[t.promoteId]:t.generateId?n||0:e.id}function g(e,t,n,r,i,a=0){for(let o of n.geometries)m(e,{id:t.id,type:`Feature`,geometry:o,properties:t.properties},r,i,a)}function _(e,t,n,r,a){let o=[];o.push(r.projectX(n.coordinates[0]),r.projectY(n.coordinates[1]),0),e.push(i(t,`Point`,o,a))}function v(e,t,n,r,a){let o=[];for(let e of n.coordinates)o.push(r.projectX(e[0]),r.projectY(e[1]),0);e.push(i(t,`MultiPoint`,o,a))}function y(e,t,n,r,a,o){let s={points:[]};C(n.coordinates,s,r,!1,a),e.push(i(t,`LineString`,s,o))}function b(e,t,n,r,a,o,s){if(o.lineMetrics)for(let o of n.coordinates){let n={points:[]};C(o,n,r,!1,a),e.push(i(t,`LineString`,n,s))}else{let o=[];w(n.coordinates,o,r,!1,a),e.push(i(t,`MultiLineString`,o,s))}}function x(e,t,n,r,a,o){let s=[];w(n.coordinates,s,r,!0,a),e.push(i(t,`Polygon`,s,o))}function S(e,t,n,r,a,o){let s=[];for(let e of n.coordinates){let t=[];w(e,t,r,!0,a),t.length&&s.push(t)}s.length&&e.push(i(t,`MultiPolygon`,s,o))}function C(e,n,r,i,o){let s,c,l=0;for(let t=0;t<e.length;t++){let r=o.projectX(e[t][0]),a=o.projectY(e[t][1]);n.points.push(r,a,0),t>0&&(l+=i?(s*a-r*c)/2:Math.sqrt((r-s)**2+(a-c)**2)),s=r,c=a}let u=n.points.length-3;n.points[2]=1,r>0&&t(n.points,0,u,r),n.points[u+2]=1,a(n),n.size=Math.abs(l),n.start=0,n.end=n.size}function w(e,t,n,r,i){for(let a=0;a<e.length;a++){let o={points:[]};C(e[a],o,n,r,i),t.push(o)}}function ee(e,t=l){return{type:`FeatureCollection`,features:e.map(e=>T(e,t))}}function T(e,t=l){let n={type:`Feature`,geometry:te(e,t),properties:e.tags};return e.id!=null&&(n.id=e.id),n}function te(e,t){let{type:n,geometry:r}=e;switch(n){case`Point`:return{type:n,coordinates:ne(r[0],r[1],t)};case`MultiPoint`:return{type:n,coordinates:E(r,t)};case`LineString`:return{type:n,coordinates:E(r.points,t)};case`MultiLineString`:case`Polygon`:return{type:n,coordinates:r.map(e=>E(e.points,t))};case`MultiPolygon`:return{type:n,coordinates:r.map(e=>e.map(e=>E(e.points,t)))}}}function E(e,t=l){let n=[];for(let r=0;r<e.length;r+=3)n.push(ne(e[r],e[r+1],t));return n}function ne(e,t,n){return[n.unprojectX(e),n.unprojectY(t)]}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);else if(!(a<n||e>=r))switch(t.type){case`MultiPoint`:re(t,c,n,r,i);continue;case`LineString`:ie(t,c,n,r,i,s);continue;case`MultiLineString`:ae(t,c,n,r,i);continue;case`Polygon`:oe(t,c,n,r,i);continue;case`MultiPolygon`:se(t,c,n,r,i);continue}}return c.length?c:null}function re(e,t,n,r,a){let o=[];if(ce(e.geometry,o,n,r,a),!o.length)return;let s=o.length===3?`Point`:`MultiPoint`;t.push(i(e.id,s,o,e.tags))}function ie(e,t,n,r,a,o){let s=[];if(O(e.geometry,s,n,r,a,!1,o.lineMetrics),s.length){if(o.lineMetrics)for(let n of s)t.push(i(e.id,`LineString`,n,e.tags));else s.length>1?t.push(i(e.id,`MultiLineString`,s,e.tags)):t.push(i(e.id,`LineString`,s[0],e.tags))}}function ae(e,t,n,r,a){let o=[];k(e.geometry,o,n,r,a,!1),o.length&&(o.length===1?t.push(i(e.id,`LineString`,o[0],e.tags)):t.push(i(e.id,`MultiLineString`,o,e.tags)))}function oe(e,t,n,r,a){let o=[];k(e.geometry,o,n,r,a,!0),o.length&&t.push(i(e.id,`Polygon`,o,e.tags))}function se(e,t,n,r,a){let o=[];for(let t of e.geometry){let e=[];k(t,e,n,r,a,!0),e.length&&o.push(e)}o.length&&t.push(i(e.id,`MultiPolygon`,o,e.tags))}function ce(e,t,n,r,i){for(let a=0;a<e.length;a+=3){let o=e[a+i];o>=n&&o<=r&&A(t,e[a],e[a+1],e[a+2])}}function O(e,t,n,r,i,o,s){let c=le(e),l=i===0?ue:de,u=e.start,d,f;for(let a=0;a<e.points.length-3;a+=3){let p=e.points[a],m=e.points[a+1],h=e.points[a+2],g=e.points[a+3],_=e.points[a+4],v=i===0?p:m,y=i===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)):A(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=le(e)),s&&(u+=d)}let p=e.points.length-3,m=e.points[p],h=e.points[p+1],g=e.points[p+2],_=i===0?m:h;_>=n&&_<=r&&A(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])&&A(c.points,c.points[0],c.points[1],c.points[2]),c.points.length&&(a(c),t.push(c))}function le(e){return{points:[],size:e.size,start:e.start,end:e.end}}function k(e,t,n,r,i,a){for(let o of e)O(o,t,n,r,i,a,!1)}function A(e,t,n,r){e.push(t,n,r)}function ue(e,t,n,r,i,a){let o=(a-t)/(r-t);return A(e.points,a,n+(i-n)*o,1),o}function de(e,t,n,r,i,a){let o=(a-n)/(i-n);return A(e.points,t+(r-t)*o,a,1),o}function j(e,t){if(!t.wrap)return e;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=D(e,1,-n,1+n,0,-1,2,t)||[],i&&(r=M(i,1).concat(r)),a&&(r=r.concat(M(a,-1)))),r}function M(e,t){let n=[];for(let r of e)switch(r.type){case`Point`:case`MultiPoint`:{let e=fe(r.geometry,t);n.push(i(r.id,r.type,e,r.tags));continue}case`LineString`:{let e=N(r.geometry,t);n.push(i(r.id,r.type,e,r.tags));continue}case`MultiLineString`:case`Polygon`:{let e=[];for(let n of r.geometry)e.push(N(n,t));n.push(i(r.id,r.type,e,r.tags));continue}case`MultiPolygon`:{let e=[];for(let n of r.geometry){let r=[];for(let e of n)r.push(N(e,t));e.push(r)}n.push(i(r.id,r.type,e,r.tags));continue}}return n}function fe(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 N(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 a(n),n}function pe(e,t,n,r){let i=ge(t,n),a=[];if(i.removeAll&&(a=e,e=[],r?.clear()),i.remove.size||i.add.size){for(let e of i.remove)r?.delete(e);let t=[];for(let n of e)(i.remove.has(n.id)||i.add.has(n.id))&&t.push(n);if(t.length){a=a.concat(t);let n=new Set(t.map(e=>e.id));e=e.filter(e=>!n.has(e.id))}if(i.add.size){let t=f({type:`FeatureCollection`,features:Array.from(i.add.values())},{...n,generateId:!1},r);t=j(t,n),a=a.concat(t),e=e.concat(t)}}if(i.update.size){let t=/* @__PURE__ */ new Map,o=[];for(let n of e)i.update.has(n.id)?t.set(n.id,[...t.get(n.id)||[],n]):o.push(n);for(let[e,s]of i.update){let i=t.get(e);if(!i||i.length===0){if(!r?.has(e))continue;let t=he(e,s,n,r);a=a.concat(t),o=o.concat(t);continue}let c=me(i,s,n,r);a=a.concat(i,c),o=o.concat(c)}e=o}return{affected:a,source:e}}function me(e,t,n,r){let i=!!t.newGeometry,a=F(t);if(i){let i=e[0],o=a?I(i.tags,t):i.tags;return P(i.id,t.newGeometry,o,n,r)}if(a){let n=[];for(let r of e){let e={...r};e.tags=I(e.tags,t),n.push(e)}return n}return e}function he(e,t,n,r){let i=r.get(e),a=F(t)?I(i.properties,t):i.properties;return t.newGeometry?P(e,t.newGeometry,a,n,r):(r.set(e,{...i,properties:a}),[])}function P(e,t,n,r,i){return j(f({type:`FeatureCollection`,features:[{type:`Feature`,id:e,geometry:t,properties:n}]},{...r,promoteId:void 0,generateId:!1},i),r)}function F(e){return e.removeAllProperties||e.removeProperties?.length>0||e.addOrUpdateProperties?.length>0}function I(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 ge(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:/* @__PURE__ */ new Set,add:/* @__PURE__ */ new Map,update:/* @__PURE__ */ new Map}}let L=[Int8Array,Uint8Array,Uint8ClampedArray,Int16Array,Uint16Array,Int32Array,Uint32Array,Float32Array,Float64Array],R=/* @__PURE__ */ new Uint32Array(96);var _e=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=L[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=L.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 z(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;R[0]=0,R[1]=i.length-1,R[2]=0;let s=3,c=[];for(;s>0;){let l=R[--s],u=R[--s],d=R[--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)&&(R[s++]=d,R[s++]=f-1,R[s++]=1-l),(l===0?n>=p:r>=m)&&(R[s++]=f+1,R[s++]=u,R[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;R[0]=0,R[1]=i.length-1,R[2]=0;let s=3,c=0,l=n*n;for(;s>0;){let u=R[--s],d=R[--s],f=R[--s];if(d-f<=o){for(let n=f;n<=d;n++)ve(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];ve(m,h,e,t)<=l&&(r[c++]=i[p]),(u===0?e-n<=m:t-n<=h)&&(R[s++]=f,R[s++]=p-1,R[s++]=1-u),(u===0?e+n>=m:t+n>=h)&&(R[s++]=p+1,R[s++]=d,R[s++]=1-u)}return c}};function z(e,t,n,r,i,a){if(i-r<=n)return;let o=r+i>>1;B(e,t,o,r,i,a),z(e,t,n,r,o-1,1-a),z(e,t,n,o+1,i,1-a)}function B(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);B(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(V(e,t,r,n),t[2*i+a]>o&&V(e,t,r,i);s<c;){for(V(e,t,s,c),s++,c--;t[2*s+a]<o;)s++;for(;t[2*c+a]>o;)c--}t[2*r+a]===o?V(e,t,r,c):(c++,V(e,t,c,i)),c<=n&&(r=c+1),n<=c&&(i=c-1)}}function V(e,t,n,r){H(e,n,r),H(t,2*n,2*r),H(t,2*n+1,2*r+1)}function H(e,t,n){let r=e[t];e[t]=e[n],e[n]=r}function ve(e,t,n,r){let i=e-n,a=t-r;return i*i+a*a}let ye={minZoom:0,maxZoom:16,minPoints:2,radius:40,extent:512,nodeSize:64,log:!1,generateId:!1,reduce:null,map:e=>e,coordinates:`lngLat`,wrap:!0},U=1073741824;function W(e){return(e-.5)*U}function G(e){return e/U+.5}function be(e){return Math.abs(W(e))<2147483647}var xe=class{constructor(e){this.options=Se(e),this.worldCoordinateHelper=d(this.options.coordinates),this.trees=Array(this.options.maxZoom+1),this.stride=this.options.reduce?5:4,this.clusterProps=[],this.points=[]}load(e){let t=[];for(let n of e){if(!n.geometry)continue;let e=n.geometry.type===`MultiPoint`?n.geometry.coordinates:[n.geometry.coordinates];for(let[r,i]of e){let[e,a]=[this.worldCoordinateHelper.projectX(r),this.worldCoordinateHelper.projectY(i)];if(!this.options.wrap&&!q([e,a]))continue;let o={id:n.id,type:`Point`,geometry:[e,a],tags:n.properties};t.push(o)}}this.createIndex(t)}initialize(e){let t=[];for(let n of e)if(n.type===`Point`){if(!this.options.wrap&&!q(n.geometry))continue;t.push(n)}else if(n.type===`MultiPoint`)for(let e=0;e<n.geometry.length;e+=3){let r=[n.geometry[e],n.geometry[e+1]];(this.options.wrap||q(r))&&t.push({id:n.id,type:`Point`,geometry:r,tags:n.tags})}this.createIndex(t)}updateIndex(e,t,n){this.options=Se({...n.clusterOptions,coordinates:this.options.coordinates,wrap:this.options.wrap}),this.initialize(e)}createIndex(e){let{log:t,minZoom:n,maxZoom:r}=this.options;this.trees=Array(r+1),this.stride=this.options.reduce?5:4,this.clusterProps=[],t&&console.time(`total time`);let i=`prepare ${e.length} points`;t&&console.time(i),this.points=e;let a=this.stride,o=r+1,s=new Int32Array(e.length*2),c=new Int32Array(e.length*a),l=0;for(let t=0;t<e.length;t++){let n=e[t];if(!n?.geometry||!be(n.geometry[0])||!be(n.geometry[1]))continue;s[l*2]=Math.round(W(n.geometry[0])),s[l*2+1]=Math.round(W(n.geometry[1]));let r=l*a;c[r+0]=o,c[r+1]=t,c[r+2]=-1,c[r+3]=1,l++}let u=this.trees[r+1]=this.createTree(s,c,l);t&&console.timeEnd(i);let d=new Int32Array(l*2),f=new Int32Array(l*a);for(let e=r;e>=n;e--){let n=Date.now(),r=this.cluster(u,e,d,f);this.isSameAsTree(u,f,r)||(u=this.createTree(d.slice(0,r*2),f.slice(0,r*a),r)),this.trees[e]=u,t&&console.log(`z%d: %d clusters in %dms`,e,u.numItems,Date.now()-n)}t&&console.timeEnd(`total time`)}getClusters(e,t){return(this.options.wrap?this.options.coordinates===`unitSquare`?this.getClustersAcrossEdge(e,t):this.getClustersInternal(e,t):this.getClustersInWorld(e,t)).map(e=>T(e,this.worldCoordinateHelper))}getClustersInWorld(e,t){let n=this.options.coordinates!==`unitSquare`,r=this.worldCoordinateHelper.projectY(n?Math.max(-90,Math.min(90,e[1])):e[1]),i=this.worldCoordinateHelper.projectY(n?Math.max(-90,Math.min(90,e[3])):e[3]),a=Math.max(0,this.worldCoordinateHelper.projectX(e[0])),o=Math.min(1,this.worldCoordinateHelper.projectX(e[2]));return a>o?[]:this.getClustersInRange([a,Math.min(r,i),o,Math.max(r,i)],t)}getClustersAcrossEdge([e,t,n,r],i){if(n<e&&(n+=1),n-e>=1)return this.getClustersInRange([0,t,1,r],i);let a=Math.floor(e),o=e-a,s=n-a;return s<=1?this.getClustersInRange([o,t,s,r],i):this.getClustersInRange([o,t,1,r],i).concat(this.getClustersInRange([0,t,s-1,r],i))}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)}return this.getClustersInRange([this.worldCoordinateHelper.projectX(n),this.worldCoordinateHelper.projectY(a),this.worldCoordinateHelper.projectX(i),this.worldCoordinateHelper.projectY(r)],t)}getClustersInRange([e,t,n,r],i){let a=this.trees[this.limitZoom(i)],o=a.range(W(e),W(t),W(n),W(r)),s=a.flatCoords,c=a.flatData,l=[];for(let e of o){let t=this.stride*e;l.push(c[t+3]>1?Ce(s,e,c,t,this.clusterProps):this.points[c[t+1]])}return l}getChildren(e){let t=this.getOriginId(e),n=this.getOriginZoom(e),r=/* @__PURE__ */ Error(`No cluster with the specified id: `+e),i=this.trees[n];if(!i)throw r;let a=i.flatCoords,o=i.flatData;if(t>=i.numItems)throw r;let s=this.options.radius/(this.options.extent*2**(n-1))*U,c=a[t*2],l=a[t*2+1],u=i.within(c,l,s),d=[];for(let t of u){let n=t*this.stride;o[n+2]===e&&d.push(o[n+3]>1?we(a,t,o,n,this.clusterProps,this.worldCoordinateHelper):T(this.points[o[n+1]],this.worldCoordinateHelper))}if(d.length===0)throw r;return d}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;if(!this.options.wrap&&(t<0||t>=i||n<0||n>=i))return null;let{extent:a,radius:o}=this.options,s=o/a,c=W((n-s)/i),l=W((n+1+s)/i),u={transformed:!0,features:[],source:null,x:t,y:n,z:e};return this.addTileFeatures(r.range(W((t-s)/i),c,W((t+1+s)/i),l),r,t,n,i,u),this.options.wrap&&t===0&&this.addTileFeatures(r.range(W(1-s/i),c,W(1),l),r,i,n,i,u),this.options.wrap&&t===i-1&&this.addTileFeatures(r.range(W(0),c,W(s/i),l),r,-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,t,n){let r=new _e(n,this.options.nodeSize,Int32Array);for(let t=0;t<n;t++)r.add(e[t*2],e[t*2+1]);return r.finish(),r.flatCoords=e,r.flatData=t,r.data=null,r}isSameAsTree(e,t,n){if(n!==e.numItems)return!1;let r=e.flatData;for(let e=1;e<n*this.stride;e+=this.stride)if(t[e]!==r[e])return!1;return!0}addTileFeatures(e,t,n,r,i,a){let o=t.flatCoords,s=t.flatData;for(let t of e){let e=t*this.stride,c=s[e+3]>1,l,u,d;if(c)l=K(s,e,this.clusterProps),u=G(o[t*2]),d=G(o[t*2+1]);else{let t=this.points[s[e+1]];l=t.tags,[u,d]=t.geometry}let f={type:1,geometry:[[Math.round(this.options.extent*(u*i-n)),Math.round(this.options.extent*(d*i-r))]],tags:l},p;p=c||this.options.generateId?s[e+1]:this.points[s[e+1]].id,p!==void 0&&(f.id=p),a.features.push(f)}}limitZoom(e){return Math.max(this.options.minZoom,Math.min(Math.floor(+e),this.options.maxZoom+1))}cluster(e,t,n,r){let{radius:i,extent:a,reduce:o,minPoints:s,maxZoom:c}=this.options,l=i/(a*2**t)*U,u=c+1,d=e.flatCoords,f=e.flatData,p=this.stride,m=new Uint32Array(e.numItems),h=0;for(let i=0;i<e.numItems;i++){let a=i*p;if(f[a+0]<=t)continue;f[a+0]=t;let c=d[i*2],g=d[i*2+1],_=e.withinInto(c,g,l,m),v=f[a+3],y=v;for(let e=0;e<_;e++){let n=m[e]*p;f[n+0]>t&&(y+=f[n+3])}if(y>v&&y>=s){let e=c*v,s=g*v,l,b=-1,x=(i<<5)+(t+1)+this.points.length;for(let n=0;n<_;n++){let r=m[n],i=r*p;if(f[i+0]<=t)continue;f[i+0]=t;let c=f[i+3];e+=d[r*2]*c,s+=d[r*2+1]*c,f[i+2]=x,o&&(l||(l=this.map(f,a,!0),b=this.clusterProps.length,this.clusterProps.push(l)),o(l,this.map(f,i)))}f[a+2]=x,n[h*2]=Math.round(e/y),n[h*2+1]=Math.round(s/y);let S=h*p;r[S+0]=u,r[S+1]=x,r[S+2]=-1,r[S+3]=y,o&&(r[S+4]=b),h++}else{n[h*2]=c,n[h*2+1]=g;for(let e=0;e<p;e++)r[h*p+e]=f[a+e];if(h++,y>1)for(let e=0;e<_;e++){let i=m[e],a=i*p;if(!(f[a+0]<=t)){f[a+0]=t,n[h*2]=d[i*2],n[h*2+1]=d[i*2+1];for(let e=0;e<p;e++)r[h*p+e]=f[a+e];h++}}}}return h}getOriginId(e){return e-this.points.length>>5}getOriginZoom(e){return(e-this.points.length)%32}map(e,t,n){if(e[t+3]>1){let r=this.clusterProps[e[t+4]];return n?Object.assign({},r):r}let r=this.points[e[t+1]].tags,i=this.options.map(r);return n&&i===r?Object.assign({},i):i}};function Se(e){let t=Object.assign(Object.create(ye),e);return t.minZoom=Math.min(t.minZoom,30),t.maxZoom=Math.min(t.maxZoom,30),t}function Ce(e,t,n,r,i){return{id:n[r+1],type:`Point`,tags:K(n,r,i),geometry:[G(e[t*2]),G(e[t*2+1])]}}function we(e,t,n,r,i,a){return{type:`Feature`,id:n[r+1],properties:K(n,r,i),geometry:{type:`Point`,coordinates:[a.unprojectX(G(e[t*2])),a.unprojectY(G(e[t*2+1]))]}}}function K(e,t,n){let r=e[t+3],i=r>=1e4?`${Math.round(r/1e3)}k`:r>=1e3?`${Math.round(r/100)/10}k`:r,a=e[t+4],o=a===-1?{}:Object.assign({},n[a]);return Object.assign(o,{cluster:!0,cluster_id:e[t+1],point_count:r,point_count_abbreviated:i})}function q(e){return e[0]>=0&&e[0]<=1&&e[1]>=0&&e[1]<=1}let Te=`geojsonvt_clip_start`,Ee=`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)De(o,t,a,i);return o}function De(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`:Oe(e,t);return;case`LineString`:ke(e,t,n,r);return;case`MultiLineString`:case`Polygon`:Ae(e,t,n);return;case`MultiPolygon`:je(e,t,n);return}}function Oe(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 ke(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[Te]=t.geometry.start/t.geometry.size,a[Ee]=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 Ae(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 je(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&&Me(s,a),e.push(s)}function Me(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?Ne(a,t,n,r,i):Pe(a,t,n,r,i);return e.transformed=!0,e}function Ne(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 Pe(e,t,n,r,i){let a=e,o=e.geometry,s=[];for(let a of o)if(e.type===3)s.push(Fe(a,t,n,r,i));else{let e=[];for(let o=0;o<a.length;o+=2)e.push(Z(a[o],a[o+1],t,n,r,i));s.push(e)}return a.geometry=s,a}function Fe(e,t,n,r,i){if(!e.length)return[];let a=e[0],o=e[1],s=Z(a,o,t,n,r,i),c=[s],l=0,u=0,d=0,f=0,p=0,m=0;for(let h=2;h<e.length;h+=2){let g=Z(e[h],e[h+1],t,n,r,i),_=e[h]-a,v=e[h+1]-o,y=g[0]-s[0],b=g[1]-s[1];p+=l*v-_*u,m+=d*b-y*f,l=_,u=v,d=y,f=b,c.push(g)}return p*m<0&&c.reverse(),c}function Z(e,t,n,r,i,a){return[Math.round(n*(e*r-i)),Math.round(n*(t*r-a))]}var Ie=class{constructor(e){this.options=e,this.total=0,this.stats={},this.tiles={},this.tileCoords=[],this.stats={},this.total=0}initialize(e){this.splitTile(this.clipToWorld(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=this.clipToWorld(e),s=J(o,r,i,a,n);s.source=o;let c=Q(r,i,a);if(this.tiles[c]=s,this.tileCoords.push({z:r,x:i,y:a,id:c}),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;if(!this.options.wrap&&(t<0||t>=a))return null;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)}clipToWorld(e){let{wrap:t,coordinates:n}=this.options;if(t&&n!==`unitSquare`)return e;let r=this.options.buffer/this.options.extent;return D(t?e:D(e,1,-r,1+r,0,-1/0,1/0,this.options)||[],1,-r,1+r,1,-1/0,1/0,this.options)||[]}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=/* @__PURE__ */ 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:ye,debug:0,coordinates:`lngLat`,wrap:!0};var Le=class{constructor(e,t){t=this.options=Object.assign({},$,t),this.worldCoordinateHelper=d(t.coordinates);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.`);t.updateable&&(this.unlocated=/* @__PURE__ */ new Map),this.nextId=e.type===`FeatureCollection`?e.features.length:1;let r=f(e,t,this.unlocated);n&&(console.timeEnd(`preprocess data`),console.log(`index: maxZoom: %d, maxPoints: %d`,t.indexMaxZoom,t.indexMaxPoints),console.time(`generate tiles`)),r=j(r,t),t.updateable&&(this.source=r),this.initializeIndex(r,t)}initializeIndex(e,t){this.tileIndex=t.cluster?new xe({...t.clusterOptions,coordinates:t.coordinates,wrap:t.wrap}):new Ie(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");n.generateId&&e.add&&(e={...e,add:e.add.map(e=>({...e,id:this.nextId++}))});let{affected:r,source:i}=pe(this.source,e,n,this.unlocated);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=/* @__PURE__ */ new Set;for(let i of e)i.id!=null&&(n(T(i,this.worldCoordinateHelper))||(t.push(i),r.add(i.id)));e=e.filter(e=>!r.has(e.id));for(let[e,t]of this.unlocated??[])t.geometry&&!n(t)&&this.unlocated.delete(e);return{affected:t,source:e}}getData(){if(!this.options.updateable)throw Error("to retrieve data the `updateable` option must be set to true");return ee(this.source,this.worldCoordinateHelper)}updateClusterOptions(e,t){let n=this.options.cluster;this.options.cluster=e,this.options.clusterOptions=t,n==e?this.tileIndex.updateIndex(this.source,[],this.options):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 Re(e,t,n,r,i={}){i={...$,wrap:!1,...i};let{wrap:a,clip:o=!1}=i,s=f(e,i);if(a&&(s=j(s,i)),o||i.lineMetrics){let e=1<<t,a=i.buffer/i.extent;s=D(D(s,e,n-a,n+1+a,0,-1,2,i)||[],e,r-a,r+1+a,1,-1,2,i)}return X(J(s??[],t,n,r,i),i.extent)}e.GEOJSONVT_CLIP_END=Ee,e.GEOJSONVT_CLIP_START=Te,e.GeoJSONVT=Le,e.Supercluster=xe,e.geoJSONToTile=Re});
@@ -90,10 +90,10 @@ function createFeature(id, type, geom, tags) {
90
90
  type: data.type,
91
91
  geometry: data.geom,
92
92
  tags,
93
- minX: Infinity,
94
- minY: Infinity,
95
- maxX: -Infinity,
96
- maxY: -Infinity
93
+ minX: 1e400,
94
+ minY: 1e400,
95
+ maxX: -1e400,
96
+ maxY: -1e400
97
97
  };
98
98
  switch (data.type) {
99
99
  case "Point":
@@ -1796,14 +1796,51 @@ function transformNonPointFeature(feature, extent, z2, tx, ty) {
1796
1796
  const transformed = feature;
1797
1797
  const geometry = feature.geometry;
1798
1798
  const nonPoint = [];
1799
- for (const geom of geometry) {
1800
- const ring = [];
1801
- for (let i = 0; i < geom.length; i += 2) ring.push(transformPoint(geom[i], geom[i + 1], extent, z2, tx, ty));
1802
- nonPoint.push(ring);
1799
+ for (const geom of geometry) if (feature.type === 3) nonPoint.push(transformPolygonRing(geom, extent, z2, tx, ty));
1800
+ else {
1801
+ const line = [];
1802
+ for (let i = 0; i < geom.length; i += 2) line.push(transformPoint(geom[i], geom[i + 1], extent, z2, tx, ty));
1803
+ nonPoint.push(line);
1803
1804
  }
1804
1805
  transformed.geometry = nonPoint;
1805
1806
  return transformed;
1806
1807
  }
1808
+ /**
1809
+ * Quantizes a polygon ring while preserving its winding so a hole does not become
1810
+ * a shell, or vice versa. Signed areas use coordinates relative to the first
1811
+ * vertex to reduce cancellation for narrow rings far from the origin.
1812
+ * Zero-area results are left unchanged; other quantization topology changes
1813
+ * are not repaired.
1814
+ */
1815
+ function transformPolygonRing(geometry, extent, z2, tx, ty) {
1816
+ if (!geometry.length) return [];
1817
+ const originX = geometry[0];
1818
+ const originY = geometry[1];
1819
+ const origin = transformPoint(originX, originY, extent, z2, tx, ty);
1820
+ const ring = [origin];
1821
+ let previousX = 0;
1822
+ let previousY = 0;
1823
+ let previousRoundedX = 0;
1824
+ let previousRoundedY = 0;
1825
+ let sourceArea = 0;
1826
+ let roundedArea = 0;
1827
+ for (let i = 2; i < geometry.length; i += 2) {
1828
+ const point = transformPoint(geometry[i], geometry[i + 1], extent, z2, tx, ty);
1829
+ const x = geometry[i] - originX;
1830
+ const y = geometry[i + 1] - originY;
1831
+ const roundedX = point[0] - origin[0];
1832
+ const roundedY = point[1] - origin[1];
1833
+ sourceArea += previousX * y - x * previousY;
1834
+ roundedArea += previousRoundedX * roundedY - roundedX * previousRoundedY;
1835
+ previousX = x;
1836
+ previousY = y;
1837
+ previousRoundedX = roundedX;
1838
+ previousRoundedY = roundedY;
1839
+ ring.push(point);
1840
+ }
1841
+ if (sourceArea * roundedArea < 0) ring.reverse();
1842
+ return ring;
1843
+ }
1807
1844
  function transformPoint(x, y, extent, z2, tx, ty) {
1808
1845
  return [Math.round(extent * (x * z2 - tx)), Math.round(extent * (y * z2 - ty))];
1809
1846
  }
@@ -1907,7 +1944,7 @@ var TileIndex = class {
1907
1944
  const { wrap, coordinates } = this.options;
1908
1945
  if (wrap && coordinates !== "unitSquare") return features;
1909
1946
  const buffer = this.options.buffer / this.options.extent;
1910
- return clip(wrap ? features : clip(features, 1, -buffer, 1 + buffer, 0, -Infinity, Infinity, this.options) || [], 1, -buffer, 1 + buffer, 1, -Infinity, Infinity, this.options) || [];
1947
+ return clip(wrap ? features : clip(features, 1, -buffer, 1 + buffer, 0, -1e400, 1e400, this.options) || [], 1, -buffer, 1 + buffer, 1, -1e400, 1e400, this.options) || [];
1911
1948
  }
1912
1949
  /**
1913
1950
  * splits features from a parent tile to sub-tiles.
@@ -2006,10 +2043,10 @@ var TileIndex = class {
2006
2043
  if (!features.length) return;
2007
2044
  const options = this.options;
2008
2045
  const { debug } = options;
2009
- let minX = Infinity;
2010
- let maxX = -Infinity;
2011
- let minY = Infinity;
2012
- let maxY = -Infinity;
2046
+ let minX = 1e400;
2047
+ let maxX = -1e400;
2048
+ let minY = 1e400;
2049
+ let maxY = -1e400;
2013
2050
  for (const feature of features) {
2014
2051
  minX = Math.min(minX, feature.minX);
2015
2052
  maxX = Math.max(maxX, feature.maxX);