1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-08-14 21:23:50 +00:00
seahub/media/js/map/cluster.js

1 line
33 KiB
JavaScript
Raw Normal View History

!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t="undefined"!=typeof globalThis?globalThis:t||self).Cluster=e()}(this,(function(){"use strict";class t{constructor(e){this._hashCode=null!=e?e:t.guid()}getHandlers(t){let e=this._events||(this._events=new Map);return e.has(t)||e.set(t,new Map),e.get(t)}on(e,s){if("function"!=typeof s)return;this.getHandlers(e).set(s,t.guid())}addEventListener(t,e){this.on(t,e)}off(t,e){var s;let i=this.getHandlers(t);e?i.has(e)&&i.delete(e):null===(s=this._events)||void 0===s||s.clear()}removeEventListener(t,e){this.off(t,e)}fire(t,e){let s=Array.from(this.getHandlers(t).entries());for(const[t]of s)t.call(this,e)}dispatchEvent(t,e){this.fire(t,e)}destroy(){var t;null===(t=this._events)||void 0===t||t.clear(),this._events=null}get hashCode(){return this._hashCode}static guid(){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,(function(t){let e=16*Math.random()|0;return("x"==t?e:3&e|8).toString(16)}))}}var e,s,i,r;!function(t){t.CLICK="click",t.MOUSE_OVER="mouseover",t.MOUSE_OUT="mouseout",t.CHANGE="change",t.DESTROY="destroy"}(e||(e={})),function(t){t.DIS_PIXEL="dis-pixel",t.ATTR_REF="attribute",t.GEO_FENCE="geo-fence"}(s||(s={})),function(t){t.DOM="dom",t.WEBGL="webgl"}(i||(i={})),function(t){t.MULTI="multi",t.SINGLE="single"}(r||(r={}));const n=[Int8Array,Uint8Array,Uint8ClampedArray,Int16Array,Uint16Array,Int32Array,Uint32Array,Float32Array,Float64Array];class o{static from(t){if(!(t instanceof ArrayBuffer))throw new Error("Data must be an instance of ArrayBuffer.");const[e,s]=new Uint8Array(t,0,2);if(219!==e)throw new Error("Data does not appear to be in a KDBush format.");const i=s>>4;if(1!==i)throw new Error(`Got v${i} data when expected v1.`);const r=n[15&s];if(!r)throw new Error("Unrecognized array type.");const[l]=new Uint16Array(t,2,1),[h]=new Uint32Array(t,4,1);return new o(h,l,r,t)}constructor(t,e=64,s=Float64Array,i){if(isNaN(t)||t<0)throw new Error(`Unpexpected numItems value: ${t}.`);this.numItems=+t,this.nodeSize=Math.min(Math.max(+e,2),65535),this.ArrayType=s,this.IndexArrayType=t<65536?Uint16Array:Uint32Array;const r=n.indexOf(this.ArrayType),o=2*t*this.ArrayType.BYTES_PER_ELEMENT,l=t*this.IndexArrayType.BYTES_PER_ELEMENT,h=(8-l%8)%8;if(r<0)throw new Error(`Unexpected typed array class: ${s}.`);i&&i instanceof ArrayBuffer?(this.data=i,this.ids=new this.IndexArrayType(this.data,8,t),this.coords=new this.ArrayType(this.data,8+l+h,2*t),this._pos=2*t,this._finished=!0):(this.data=new ArrayBuffer(8+o+l+h),this.ids=new this.IndexArrayType(this.data,8,t),this.coords=new this.ArrayType(this.data,8+l+h,2*t),this._pos=0,this._finished=!1,new Uint8Array(this.data,0,2).set([219,16+r]),new Uint16Array(this.data,2,1)[0]=e,new Uint32Array(this.data,4,1)[0]=t)}add(t,e){const s=this._pos>>1;return this.ids[s]=s,this.coords[this._pos++]=t,this.coords[this._pos++]=e,s}finish(){const t=this._pos>>1;if(t!==this.numItems)throw new Error(`Added ${t} items when expected ${this.numItems}.`);return l(this.ids,this.coords,this.nodeSize,0,this.numItems-1,0),this._finished=!0,this}range(t,e,s,i){if(!this._finished)throw new Error("Data not yet indexed - call index.finish().");const{ids:r,coords:n,nodeSize:o}=this,l=[0,r.length-1,0],h=[];for(;l.length;){const a=l.pop()||0,u=l.pop()||0,p=l.pop()||0;if(u-p<=o){for(let o=p;o<=u;o++){const l=n[2*o],a=n[2*o+1];l>=t&&l<=s&&a>=e&&a<=i&&h.push(r[o])}continue}const c=p+u>>1,g=n[2*c],d=n[2*c+1];g>=t&&g<=s&&d>=e&&d<=i&&h.push(r[c]),(0===a?t<=g:e<=d)&&(l.push(p),l.push(c-1),l.push(1-a)),(0===a?s>=g:i>=d)&&(l.push(c+1),l.push(u),l.push(1-a))}return h}within(t,e,s){if(!this._finished)throw new Error("Data not yet indexed - call index.finish().");const{ids:i,coords:r,nodeSize:n}=this,o=[0,i.length-1,0],l=[],h=s*s;for(;o.length;){const a=o.pop()||0,u=o.pop()||0,c=o.pop()||0;if(u-c<=n){for(let s=c;s<=u;s++)p(r[2*s],r[2*s+1],t,e)<=h&&l.push(i[s]);continue}const g=c+u>>1,d=r[2*g],y=r[2*g+1];p(d,y,t,e)<=h&&l.push(i[g]),(0===a?t-s<=d:e-s<=y)&&(o.push(c),o.push(g-1),o.push(1