Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

supercluster

Package Overview
Dependencies
Maintainers
15
Versions
26
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

supercluster - npm Package Compare versions

Comparing version 6.0.2 to 7.0.0

53

dist/supercluster.js

@@ -5,3 +5,3 @@ (function (global, factory) {

(global = global || self, global.Supercluster = factory());
}(this, function () { 'use strict';
}(this, (function () { 'use strict';

@@ -203,2 +203,5 @@ function sortKD(ids, coords, nodeSize, left, right, depth) {

// whether to generate numeric ids for input features that don't have them
generateId: false,
// a reduce function for calculating custom cluster properties

@@ -285,4 +288,4 @@ reduce: null, // (accumulated, props) => { accumulated.sum += props.sum; }

Supercluster.prototype.getChildren = function getChildren (clusterId) {
var originId = clusterId >> 5;
var originZoom = clusterId % 32;
var originId = this._getOriginId(clusterId);
var originZoom = this._getOriginZoom(clusterId);
var errorMsg = 'No cluster with the specified id.';

@@ -356,10 +359,10 @@

Supercluster.prototype.getClusterExpansionZoom = function getClusterExpansionZoom (clusterId) {
var clusterZoom = (clusterId % 32) - 1;
while (clusterZoom <= this.options.maxZoom) {
var expansionZoom = this._getOriginZoom(clusterId) - 1;
while (expansionZoom <= this.options.maxZoom) {
var children = this.getChildren(clusterId);
clusterZoom++;
expansionZoom++;
if (children.length !== 1) { break; }
clusterId = children[0].properties.cluster_id;
}
return clusterZoom;
return expansionZoom;
};

@@ -402,2 +405,3 @@

var c = points[i];
var isCluster = c.numPoints;
var f = {

@@ -409,8 +413,19 @@ type: 1,

]],
tags: c.numPoints ? getClusterProperties(c) : this.points[c.index].properties
tags: isCluster ? getClusterProperties(c) : this.points[c.index].properties
};
var id = c.numPoints ? c.id : this.points[c.index].id;
if (id !== undefined) {
f.id = id;
// assign id
var id = (void 0);
if (isCluster) {
id = c.id;
} else if (this.options.generateId) {
// optionally generate id
id = c.index;
} else if (this.points[c.index].id) {
// keep id if already assigned
id = this.points[c.index].id;
}
if (id !== undefined) { f.id = id; }
tile.features.push(f);

@@ -449,4 +464,4 @@ }

// encode both zoom and point index on which the cluster originated
var id = (i << 5) + (zoom + 1);
// encode both zoom and point index on which the cluster originated -- offset by total length of features
var id = (i << 5) + (zoom + 1) + this.points.length;

@@ -485,2 +500,12 @@ for (var i$1 = 0, list = neighborIds; i$1 < list.length; i$1 += 1) {

// get index of the point from which the cluster originated
Supercluster.prototype._getOriginId = function _getOriginId (clusterId) {
return (clusterId - this.points.length) >> 5;
};
// get zoom of the point from which the cluster originated
Supercluster.prototype._getOriginZoom = function _getOriginZoom (clusterId) {
return (clusterId - this.points.length) % 32;
};
Supercluster.prototype._map = function _map (point, clone) {

@@ -578,2 +603,2 @@ if (point.numPoints) {

}));
})));

@@ -1,1 +0,1 @@

!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t=t||self).Supercluster=e()}(this,function(){"use strict";function t(o,n,r,i,s,a){if(!(s-i<=r)){var p=i+s>>1;!function t(o,n,r,i,s,a){for(;s>i;){if(s-i>600){var p=s-i+1,u=r-i+1,h=Math.log(p),f=.5*Math.exp(2*h/3),d=.5*Math.sqrt(h*f*(p-f)/p)*(u-p/2<0?-1:1),l=Math.max(i,Math.floor(r-u*f/p+d)),c=Math.min(s,Math.floor(r+(p-u)*f/p+d));t(o,n,r,l,c,a)}var m=n[2*r+a],v=i,g=s;for(e(o,n,i,r),n[2*s+a]>m&&e(o,n,i,s);v<g;){for(e(o,n,v,g),v++,g--;n[2*v+a]<m;)v++;for(;n[2*g+a]>m;)g--}n[2*i+a]===m?e(o,n,i,g):e(o,n,++g,s),g<=r&&(i=g+1),r<=g&&(s=g-1)}}(o,n,p,i,s,a%2),t(o,n,r,i,p-1,a+1),t(o,n,r,p+1,s,a+1)}}function e(t,e,n,r){o(t,n,r),o(e,2*n,2*r),o(e,2*n+1,2*r+1)}function o(t,e,o){var n=t[e];t[e]=t[o],t[o]=n}function n(t,e,o,n){var r=t-o,i=e-n;return r*r+i*i}var r=function(t){return t[0]},i=function(t){return t[1]},s=function(e,o,n,s,a){void 0===o&&(o=r),void 0===n&&(n=i),void 0===s&&(s=64),void 0===a&&(a=Float64Array),this.nodeSize=s,this.points=e;for(var p=e.length<65536?Uint16Array:Uint32Array,u=this.ids=new p(e.length),h=this.coords=new a(2*e.length),f=0;f<e.length;f++)u[f]=f,h[2*f]=o(e[f]),h[2*f+1]=n(e[f]);t(u,h,s,0,u.length-1,0)};s.prototype.range=function(t,e,o,n){return function(t,e,o,n,r,i,s){for(var a,p,u=[0,t.length-1,0],h=[];u.length;){var f=u.pop(),d=u.pop(),l=u.pop();if(d-l<=s)for(var c=l;c<=d;c++)a=e[2*c],p=e[2*c+1],a>=o&&a<=r&&p>=n&&p<=i&&h.push(t[c]);else{var m=Math.floor((l+d)/2);a=e[2*m],p=e[2*m+1],a>=o&&a<=r&&p>=n&&p<=i&&h.push(t[m]);var v=(f+1)%2;(0===f?o<=a:n<=p)&&(u.push(l),u.push(m-1),u.push(v)),(0===f?r>=a:i>=p)&&(u.push(m+1),u.push(d),u.push(v))}}return h}(this.ids,this.coords,t,e,o,n,this.nodeSize)},s.prototype.within=function(t,e,o){return function(t,e,o,r,i,s){for(var a=[0,t.length-1,0],p=[],u=i*i;a.length;){var h=a.pop(),f=a.pop(),d=a.pop();if(f-d<=s)for(var l=d;l<=f;l++)n(e[2*l],e[2*l+1],o,r)<=u&&p.push(t[l]);else{var c=Math.floor((d+f)/2),m=e[2*c],v=e[2*c+1];n(m,v,o,r)<=u&&p.push(t[c]);var g=(h+1)%2;(0===h?o-i<=m:r-i<=v)&&(a.push(d),a.push(c-1),a.push(g)),(0===h?o+i>=m:r+i>=v)&&(a.push(c+1),a.push(f),a.push(g))}}return p}(this.ids,this.coords,t,e,o,this.nodeSize)};var a={minZoom:0,maxZoom:16,radius:40,extent:512,nodeSize:64,log:!1,reduce:null,map:function(t){return t}},p=function(t){this.options=m(Object.create(a),t),this.trees=new Array(this.options.maxZoom+1)};function u(t,e,o,n,r){return{x:t,y:e,zoom:1/0,id:o,parentId:-1,numPoints:n,properties:r}}function h(t,e){var o=t.geometry.coordinates,n=o[0],r=o[1];return{x:l(n),y:c(r),zoom:1/0,index:e,parentId:-1}}function f(t){return{type:"Feature",id:t.id,properties:d(t),geometry:{type:"Point",coordinates:[(n=t.x,360*(n-.5)),(e=t.y,o=(180-360*e)*Math.PI/180,360*Math.atan(Math.exp(o))/Math.PI-90)]}};var e,o,n}function d(t){var e=t.numPoints,o=e>=1e4?Math.round(e/1e3)+"k":e>=1e3?Math.round(e/100)/10+"k":e;return m(m({},t.properties),{cluster:!0,cluster_id:t.id,point_count:e,point_count_abbreviated:o})}function l(t){return t/360+.5}function c(t){var e=Math.sin(t*Math.PI/180),o=.5-.25*Math.log((1+e)/(1-e))/Math.PI;return o<0?0:o>1?1:o}function m(t,e){for(var o in e)t[o]=e[o];return t}function v(t){return t.x}function g(t){return t.y}return p.prototype.load=function(t){var e=this.options,o=e.log,n=e.minZoom,r=e.maxZoom,i=e.nodeSize;o&&console.time("total time");var a="prepare "+t.length+" points";o&&console.time(a),this.points=t;for(var p=[],u=0;u<t.length;u++)t[u].geometry&&p.push(h(t[u],u));this.trees[r+1]=new s(p,v,g,i,Float32Array),o&&console.timeEnd(a);for(var f=r;f>=n;f--){var d=+Date.now();p=this._cluster(p,f),this.trees[f]=new s(p,v,g,i,Float32Array),o&&console.log("z%d: %d clusters in %dms",f,p.length,+Date.now()-d)}return o&&console.timeEnd("total time"),this},p.prototype.getClusters=function(t,e){var o=((t[0]+180)%360+360)%360-180,n=Math.max(-90,Math.min(90,t[1])),r=180===t[2]?180:((t[2]+180)%360+360)%360-180,i=Math.max(-90,Math.min(90,t[3]));if(t[2]-t[0]>=360)o=-180,r=180;else if(o>r){var s=this.getClusters([o,n,180,i],e),a=this.getClusters([-180,n,r,i],e);return s.concat(a)}for(var p=this.trees[this._limitZoom(e)],u=[],h=0,d=p.range(l(o),c(i),l(r),c(n));h<d.length;h+=1){var m=d[h],v=p.points[m];u.push(v.numPoints?f(v):this.points[v.index])}return u},p.prototype.getChildren=function(t){var e=t>>5,o=t%32,n="No cluster with the specified id.",r=this.trees[o];if(!r)throw new Error(n);var i=r.points[e];if(!i)throw new Error(n);for(var s=this.options.radius/(this.options.extent*Math.pow(2,o-1)),a=[],p=0,u=r.within(i.x,i.y,s);p<u.length;p+=1){var h=u[p],d=r.points[h];d.parentId===t&&a.push(d.numPoints?f(d):this.points[d.index])}if(0===a.length)throw new Error(n);return a},p.prototype.getLeaves=function(t,e,o){e=e||10,o=o||0;var n=[];return this._appendLeaves(n,t,e,o,0),n},p.prototype.getTile=function(t,e,o){var n=this.trees[this._limitZoom(t)],r=Math.pow(2,t),i=this.options,s=i.extent,a=i.radius/s,p=(o-a)/r,u=(o+1+a)/r,h={features:[]};return this._addTileFeatures(n.range((e-a)/r,p,(e+1+a)/r,u),n.points,e,o,r,h),0===e&&this._addTileFeatures(n.range(1-a/r,p,1,u),n.points,r,o,r,h),e===r-1&&this._addTileFeatures(n.range(0,p,a/r,u),n.points,-1,o,r,h),h.features.length?h:null},p.prototype.getClusterExpansionZoom=function(t){for(var e=t%32-1;e<=this.options.maxZoom;){var o=this.getChildren(t);if(e++,1!==o.length)break;t=o[0].properties.cluster_id}return e},p.prototype._appendLeaves=function(t,e,o,n,r){for(var i=0,s=this.getChildren(e);i<s.length;i+=1){var a=s[i],p=a.properties;if(p&&p.cluster?r+p.point_count<=n?r+=p.point_count:r=this._appendLeaves(t,p.cluster_id,o,n,r):r<n?r++:t.push(a),t.length===o)break}return r},p.prototype._addTileFeatures=function(t,e,o,n,r,i){for(var s=0,a=t;s<a.length;s+=1){var p=e[a[s]],u={type:1,geometry:[[Math.round(this.options.extent*(p.x*r-o)),Math.round(this.options.extent*(p.y*r-n))]],tags:p.numPoints?d(p):this.points[p.index].properties},h=p.numPoints?p.id:this.points[p.index].id;void 0!==h&&(u.id=h),i.features.push(u)}},p.prototype._limitZoom=function(t){return Math.max(this.options.minZoom,Math.min(t,this.options.maxZoom+1))},p.prototype._cluster=function(t,e){for(var o=[],n=this.options,r=n.radius,i=n.extent,s=n.reduce,a=r/(i*Math.pow(2,e)),p=0;p<t.length;p++){var h=t[p];if(!(h.zoom<=e)){h.zoom=e;for(var f=this.trees[e+1],d=f.within(h.x,h.y,a),l=h.numPoints||1,c=h.x*l,m=h.y*l,v=s&&l>1?this._map(h,!0):null,g=(p<<5)+(e+1),y=0,x=d;y<x.length;y+=1){var M=x[y],_=f.points[M];if(!(_.zoom<=e)){_.zoom=e;var w=_.numPoints||1;c+=_.x*w,m+=_.y*w,l+=w,_.parentId=g,s&&(v||(v=this._map(h,!0)),s(v,this._map(_)))}}1===l?o.push(h):(h.parentId=g,o.push(u(c/l,m/l,g,l,v)))}}return o},p.prototype._map=function(t,e){if(t.numPoints)return e?m({},t.properties):t.properties;var o=this.points[t.index].properties,n=this.options.map(o);return e&&n===o?m({},n):n},p});
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t=t||self).Supercluster=e()}(this,function(){"use strict";function t(o,n,r,i,s,a){if(!(s-i<=r)){var p=i+s>>1;!function t(o,n,r,i,s,a){for(;s>i;){if(s-i>600){var p=s-i+1,h=r-i+1,u=Math.log(p),d=.5*Math.exp(2*u/3),f=.5*Math.sqrt(u*d*(p-d)/p)*(h-p/2<0?-1:1),l=Math.max(i,Math.floor(r-h*d/p+f)),c=Math.min(s,Math.floor(r+(p-h)*d/p+f));t(o,n,r,l,c,a)}var m=n[2*r+a],g=i,v=s;for(e(o,n,i,r),n[2*s+a]>m&&e(o,n,i,s);g<v;){for(e(o,n,g,v),g++,v--;n[2*g+a]<m;)g++;for(;n[2*v+a]>m;)v--}n[2*i+a]===m?e(o,n,i,v):e(o,n,++v,s),v<=r&&(i=v+1),r<=v&&(s=v-1)}}(o,n,p,i,s,a%2),t(o,n,r,i,p-1,a+1),t(o,n,r,p+1,s,a+1)}}function e(t,e,n,r){o(t,n,r),o(e,2*n,2*r),o(e,2*n+1,2*r+1)}function o(t,e,o){var n=t[e];t[e]=t[o],t[o]=n}function n(t,e,o,n){var r=t-o,i=e-n;return r*r+i*i}var r=function(t){return t[0]},i=function(t){return t[1]},s=function(e,o,n,s,a){void 0===o&&(o=r),void 0===n&&(n=i),void 0===s&&(s=64),void 0===a&&(a=Float64Array),this.nodeSize=s,this.points=e;for(var p=e.length<65536?Uint16Array:Uint32Array,h=this.ids=new p(e.length),u=this.coords=new a(2*e.length),d=0;d<e.length;d++)h[d]=d,u[2*d]=o(e[d]),u[2*d+1]=n(e[d]);t(h,u,s,0,h.length-1,0)};s.prototype.range=function(t,e,o,n){return function(t,e,o,n,r,i,s){for(var a,p,h=[0,t.length-1,0],u=[];h.length;){var d=h.pop(),f=h.pop(),l=h.pop();if(f-l<=s)for(var c=l;c<=f;c++)a=e[2*c],p=e[2*c+1],a>=o&&a<=r&&p>=n&&p<=i&&u.push(t[c]);else{var m=Math.floor((l+f)/2);a=e[2*m],p=e[2*m+1],a>=o&&a<=r&&p>=n&&p<=i&&u.push(t[m]);var g=(d+1)%2;(0===d?o<=a:n<=p)&&(h.push(l),h.push(m-1),h.push(g)),(0===d?r>=a:i>=p)&&(h.push(m+1),h.push(f),h.push(g))}}return u}(this.ids,this.coords,t,e,o,n,this.nodeSize)},s.prototype.within=function(t,e,o){return function(t,e,o,r,i,s){for(var a=[0,t.length-1,0],p=[],h=i*i;a.length;){var u=a.pop(),d=a.pop(),f=a.pop();if(d-f<=s)for(var l=f;l<=d;l++)n(e[2*l],e[2*l+1],o,r)<=h&&p.push(t[l]);else{var c=Math.floor((f+d)/2),m=e[2*c],g=e[2*c+1];n(m,g,o,r)<=h&&p.push(t[c]);var v=(u+1)%2;(0===u?o-i<=m:r-i<=g)&&(a.push(f),a.push(c-1),a.push(v)),(0===u?o+i>=m:r+i>=g)&&(a.push(c+1),a.push(d),a.push(v))}}return p}(this.ids,this.coords,t,e,o,this.nodeSize)};var a={minZoom:0,maxZoom:16,radius:40,extent:512,nodeSize:64,log:!1,generateId:!1,reduce:null,map:function(t){return t}},p=function(t){this.options=m(Object.create(a),t),this.trees=new Array(this.options.maxZoom+1)};function h(t,e,o,n,r){return{x:t,y:e,zoom:1/0,id:o,parentId:-1,numPoints:n,properties:r}}function u(t,e){var o=t.geometry.coordinates,n=o[0],r=o[1];return{x:l(n),y:c(r),zoom:1/0,index:e,parentId:-1}}function d(t){return{type:"Feature",id:t.id,properties:f(t),geometry:{type:"Point",coordinates:[(n=t.x,360*(n-.5)),(e=t.y,o=(180-360*e)*Math.PI/180,360*Math.atan(Math.exp(o))/Math.PI-90)]}};var e,o,n}function f(t){var e=t.numPoints,o=e>=1e4?Math.round(e/1e3)+"k":e>=1e3?Math.round(e/100)/10+"k":e;return m(m({},t.properties),{cluster:!0,cluster_id:t.id,point_count:e,point_count_abbreviated:o})}function l(t){return t/360+.5}function c(t){var e=Math.sin(t*Math.PI/180),o=.5-.25*Math.log((1+e)/(1-e))/Math.PI;return o<0?0:o>1?1:o}function m(t,e){for(var o in e)t[o]=e[o];return t}function g(t){return t.x}function v(t){return t.y}return p.prototype.load=function(t){var e=this.options,o=e.log,n=e.minZoom,r=e.maxZoom,i=e.nodeSize;o&&console.time("total time");var a="prepare "+t.length+" points";o&&console.time(a),this.points=t;for(var p=[],h=0;h<t.length;h++)t[h].geometry&&p.push(u(t[h],h));this.trees[r+1]=new s(p,g,v,i,Float32Array),o&&console.timeEnd(a);for(var d=r;d>=n;d--){var f=+Date.now();p=this._cluster(p,d),this.trees[d]=new s(p,g,v,i,Float32Array),o&&console.log("z%d: %d clusters in %dms",d,p.length,+Date.now()-f)}return o&&console.timeEnd("total time"),this},p.prototype.getClusters=function(t,e){var o=((t[0]+180)%360+360)%360-180,n=Math.max(-90,Math.min(90,t[1])),r=180===t[2]?180:((t[2]+180)%360+360)%360-180,i=Math.max(-90,Math.min(90,t[3]));if(t[2]-t[0]>=360)o=-180,r=180;else if(o>r){var s=this.getClusters([o,n,180,i],e),a=this.getClusters([-180,n,r,i],e);return s.concat(a)}for(var p=this.trees[this._limitZoom(e)],h=[],u=0,f=p.range(l(o),c(i),l(r),c(n));u<f.length;u+=1){var m=f[u],g=p.points[m];h.push(g.numPoints?d(g):this.points[g.index])}return h},p.prototype.getChildren=function(t){var e=this._getOriginId(t),o=this._getOriginZoom(t),n="No cluster with the specified id.",r=this.trees[o];if(!r)throw new Error(n);var i=r.points[e];if(!i)throw new Error(n);for(var s=this.options.radius/(this.options.extent*Math.pow(2,o-1)),a=[],p=0,h=r.within(i.x,i.y,s);p<h.length;p+=1){var u=h[p],f=r.points[u];f.parentId===t&&a.push(f.numPoints?d(f):this.points[f.index])}if(0===a.length)throw new Error(n);return a},p.prototype.getLeaves=function(t,e,o){e=e||10,o=o||0;var n=[];return this._appendLeaves(n,t,e,o,0),n},p.prototype.getTile=function(t,e,o){var n=this.trees[this._limitZoom(t)],r=Math.pow(2,t),i=this.options,s=i.extent,a=i.radius/s,p=(o-a)/r,h=(o+1+a)/r,u={features:[]};return this._addTileFeatures(n.range((e-a)/r,p,(e+1+a)/r,h),n.points,e,o,r,u),0===e&&this._addTileFeatures(n.range(1-a/r,p,1,h),n.points,r,o,r,u),e===r-1&&this._addTileFeatures(n.range(0,p,a/r,h),n.points,-1,o,r,u),u.features.length?u:null},p.prototype.getClusterExpansionZoom=function(t){for(var e=this._getOriginZoom(t)-1;e<=this.options.maxZoom;){var o=this.getChildren(t);if(e++,1!==o.length)break;t=o[0].properties.cluster_id}return e},p.prototype._appendLeaves=function(t,e,o,n,r){for(var i=0,s=this.getChildren(e);i<s.length;i+=1){var a=s[i],p=a.properties;if(p&&p.cluster?r+p.point_count<=n?r+=p.point_count:r=this._appendLeaves(t,p.cluster_id,o,n,r):r<n?r++:t.push(a),t.length===o)break}return r},p.prototype._addTileFeatures=function(t,e,o,n,r,i){for(var s=0,a=t;s<a.length;s+=1){var p=e[a[s]],h=p.numPoints,u={type:1,geometry:[[Math.round(this.options.extent*(p.x*r-o)),Math.round(this.options.extent*(p.y*r-n))]],tags:h?f(p):this.points[p.index].properties},d=void 0;h?d=p.id:this.options.generateId?d=p.index:this.points[p.index].id&&(d=this.points[p.index].id),void 0!==d&&(u.id=d),i.features.push(u)}},p.prototype._limitZoom=function(t){return Math.max(this.options.minZoom,Math.min(t,this.options.maxZoom+1))},p.prototype._cluster=function(t,e){for(var o=[],n=this.options,r=n.radius,i=n.extent,s=n.reduce,a=r/(i*Math.pow(2,e)),p=0;p<t.length;p++){var u=t[p];if(!(u.zoom<=e)){u.zoom=e;for(var d=this.trees[e+1],f=d.within(u.x,u.y,a),l=u.numPoints||1,c=u.x*l,m=u.y*l,g=s&&l>1?this._map(u,!0):null,v=(p<<5)+(e+1)+this.points.length,y=0,x=f;y<x.length;y+=1){var M=x[y],_=d.points[M];if(!(_.zoom<=e)){_.zoom=e;var w=_.numPoints||1;c+=_.x*w,m+=_.y*w,l+=w,_.parentId=v,s&&(g||(g=this._map(u,!0)),s(g,this._map(_)))}}1===l?o.push(u):(u.parentId=v,o.push(h(c/l,m/l,v,l,g)))}}return o},p.prototype._getOriginId=function(t){return t-this.points.length>>5},p.prototype._getOriginZoom=function(t){return(t-this.points.length)%32},p.prototype._map=function(t,e){if(t.numPoints)return e?m({},t.properties):t.properties;var o=this.points[t.index].properties,n=this.options.map(o);return e&&n===o?m({},n):n},p});

@@ -12,2 +12,5 @@

// whether to generate numeric ids for input features that don't have them
generateId: false,
// a reduce function for calculating custom cluster properties

@@ -89,4 +92,4 @@ reduce: null, // (accumulated, props) => { accumulated.sum += props.sum; }

getChildren(clusterId) {
const originId = clusterId >> 5;
const originZoom = clusterId % 32;
const originId = this._getOriginId(clusterId);
const originZoom = this._getOriginZoom(clusterId);
const errorMsg = 'No cluster with the specified id.';

@@ -156,10 +159,10 @@

getClusterExpansionZoom(clusterId) {
let clusterZoom = (clusterId % 32) - 1;
while (clusterZoom <= this.options.maxZoom) {
let expansionZoom = this._getOriginZoom(clusterId) - 1;
while (expansionZoom <= this.options.maxZoom) {
const children = this.getChildren(clusterId);
clusterZoom++;
expansionZoom++;
if (children.length !== 1) break;
clusterId = children[0].properties.cluster_id;
}
return clusterZoom;
return expansionZoom;
}

@@ -198,2 +201,3 @@

const c = points[i];
const isCluster = c.numPoints;
const f = {

@@ -205,8 +209,19 @@ type: 1,

]],
tags: c.numPoints ? getClusterProperties(c) : this.points[c.index].properties
tags: isCluster ? getClusterProperties(c) : this.points[c.index].properties
};
const id = c.numPoints ? c.id : this.points[c.index].id;
if (id !== undefined) {
f.id = id;
// assign id
let id;
if (isCluster) {
id = c.id;
} else if (this.options.generateId) {
// optionally generate id
id = c.index;
} else if (this.points[c.index].id) {
// keep id if already assigned
id = this.points[c.index].id;
}
if (id !== undefined) f.id = id;
tile.features.push(f);

@@ -242,4 +257,4 @@ }

// encode both zoom and point index on which the cluster originated
const id = (i << 5) + (zoom + 1);
// encode both zoom and point index on which the cluster originated -- offset by total length of features
const id = (i << 5) + (zoom + 1) + this.points.length;

@@ -276,2 +291,12 @@ for (const neighborId of neighborIds) {

// get index of the point from which the cluster originated
_getOriginId(clusterId) {
return (clusterId - this.points.length) >> 5;
}
// get zoom of the point from which the cluster originated
_getOriginZoom(clusterId) {
return (clusterId - this.points.length) % 32;
}
_map(point, clone) {

@@ -278,0 +303,0 @@ if (point.numPoints) {

{
"name": "supercluster",
"version": "6.0.2",
"version": "7.0.0",
"description": "A very fast geospatial point clustering library.",

@@ -37,11 +37,11 @@ "main": "dist/supercluster.js",

"devDependencies": {
"c8": "^5.0.1",
"eslint": "^6.1.0",
"c8": "^6.0.1",
"eslint": "^6.6.0",
"eslint-config-mourner": "^3.0.0",
"esm": "^3.2.25",
"mkdirp": "^0.5.1",
"rollup": "^1.17.0",
"rollup": "^1.26.3",
"rollup-plugin-buble": "^0.19.8",
"rollup-plugin-node-resolve": "^5.2.0",
"rollup-plugin-terser": "^5.1.1",
"rollup-plugin-terser": "^5.1.2",
"tape": "^4.11.0"

@@ -48,0 +48,0 @@ },

@@ -6,3 +6,3 @@ # supercluster [![Simply Awesome](https://img.shields.io/badge/simply-awesome-brightgreen.svg)](https://github.com/mourner/projects) [![Build Status](https://travis-ci.org/mapbox/supercluster.svg?branch=master)](https://travis-ci.org/mapbox/supercluster)

```html
<script src="https://unpkg.com/supercluster@5.0.0/dist/supercluster.min.js"></script>
<script src="https://unpkg.com/supercluster@6.0.2/dist/supercluster.min.js"></script>
```

@@ -38,3 +38,3 @@

```html
<script src="https://unpkg.com/supercluster@5.0.0/dist/supercluster.min.js"></script>
<script src="https://unpkg.com/supercluster@6.0.2/dist/supercluster.min.js"></script>
```

@@ -72,10 +72,11 @@

| Option | Default | Description |
|----------|---------|-------------------------------------------------------------------|
| minZoom | 0 | Minimum zoom level at which clusters are generated. |
| maxZoom | 16 | Maximum zoom level at which clusters are generated. |
| radius | 40 | Cluster radius, in pixels. |
| extent | 512 | (Tiles) Tile extent. Radius is calculated relative to this value. |
| nodeSize | 64 | Size of the KD-tree leaf node. Affects performance. |
| log | false | Whether timing info should be logged. |
| Option | Default | Description |
|------------|---------|-------------------------------------------------------------------|
| minZoom | 0 | Minimum zoom level at which clusters are generated. |
| maxZoom | 16 | Maximum zoom level at which clusters are generated. |
| radius | 40 | Cluster radius, in pixels. |
| extent | 512 | (Tiles) Tile extent. Radius is calculated relative to this value. |
| nodeSize | 64 | Size of the KD-tree leaf node. Affects performance. |
| log | false | Whether timing info should be logged. |
| generateId | false | Whether to generate ids for input features that don't have them. |

@@ -82,0 +83,0 @@ ### Property map/reduce options

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc