@2gis/general
Advanced tools
Comparing version 1.1.0 to 2.0.0
@@ -1,2 +0,2 @@ | ||
!function(r,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.General=e():r.General=e()}(window,function(){return function(r){var e={};function n(t){if(e[t])return e[t].exports;var o=e[t]={i:t,l:!1,exports:{}};return r[t].call(o.exports,o,o.exports,n),o.l=!0,o.exports}return n.m=r,n.c=e,n.d=function(r,e,t){n.o(r,e)||Object.defineProperty(r,e,{enumerable:!0,get:t})},n.r=function(r){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(r,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(r,"__esModule",{value:!0})},n.t=function(r,e){if(1&e&&(r=n(r)),8&e)return r;if(4&e&&"object"==typeof r&&r&&r.__esModule)return r;var t=Object.create(null);if(n.r(t),Object.defineProperty(t,"default",{enumerable:!0,value:r}),2&e&&"string"!=typeof r)for(var o in r)n.d(t,o,function(e){return r[e]}.bind(null,o));return t},n.n=function(r){var e=r&&r.__esModule?function(){return r.default}:function(){return r};return n.d(e,"a",e),e},n.o=function(r,e){return Object.prototype.hasOwnProperty.call(r,e)},n.p="/dist/",n(n.s=3)}([function(r,e,n){"use strict";n.d(e,"a",function(){return o}),n.d(e,"c",function(){return i}),n.d(e,"b",function(){return a}),n.d(e,"d",function(){return u});var t=0,o={pixelPositionX:t++,pixelPositionY:t++,groupIndex:t++,iconIndex:t++,priority:t++},i=Object.keys(o).length;function a(r,e){for(var n=0,t=0;n<e.length;n++,t+=i){var a=e[n];r[t+o.pixelPositionX]=a.pixelPosition[0],r[t+o.pixelPositionY]=a.pixelPosition[1],r[t+o.groupIndex]=a.groupIndex,r[t+o.iconIndex]=a.iconIndex,r[t+o.priority]=Boolean(a.priority)?1:0}}function u(r,e){for(var n=0,t=0;n<r.length;n++,t+=i)r[n].iconIndex=e[t+o.iconIndex]}},function(r,e,n){"use strict";n.d(e,"a",function(){return o}),n.d(e,"c",function(){return i}),n.d(e,"b",function(){return a}),n.d(e,"d",function(){return u});var t=0,o={markerIndex:t++,offsetX:t++,offsetY:t++,width:t++,height:t++,display:t++},i=6;function a(r,e,n){for(var t=0,a=0;a<e.length;a++){var u=e[a].htmlLabel;void 0!==u&&(r[t+o.markerIndex]=a,r[t+o.offsetX]=u.offset[0]*n,r[t+o.offsetY]=u.offset[1]*n,r[t+o.width]=u.width*n,r[t+o.height]=u.height*n,r[t+o.display]=u.display?1:0,t+=i)}}function u(r,e){for(var n=0,t=0,a=r;t<a.length;t++){var u=a[t].htmlLabel;void 0!==u&&(u.display=1===e[n+o.display],n+=i)}}},function(r,e,n){function t(r){var e={};function n(t){if(e[t])return e[t].exports;var o=e[t]={i:t,l:!1,exports:{}};return r[t].call(o.exports,o,o.exports,n),o.l=!0,o.exports}n.m=r,n.c=e,n.i=function(r){return r},n.d=function(r,e,t){n.o(r,e)||Object.defineProperty(r,e,{configurable:!1,enumerable:!0,get:t})},n.r=function(r){Object.defineProperty(r,"__esModule",{value:!0})},n.n=function(r){var e=r&&r.__esModule?function(){return r.default}:function(){return r};return n.d(e,"a",e),e},n.o=function(r,e){return Object.prototype.hasOwnProperty.call(r,e)},n.p="/",n.oe=function(r){throw console.error(r),r};var t=n(n.s=ENTRY_MODULE);return t.default||t}var o="[\\.|\\-|\\+|\\w|/|@]+",i="\\(\\s*(/\\*.*?\\*/)?\\s*.*?("+o+").*?\\)";function a(r){return(r+"").replace(/[.?*+^$[\]\\(){}|-]/g,"\\$&")}function u(r,e,t){var u={};u[t]=[];var f=e.toString(),c=f.match(/^function\s?\w*\(\w+,\s*\w+,\s*(\w+)\)/);if(!c)return u;for(var s,l=c[1],d=new RegExp("(\\\\n|\\W)"+a(l)+i,"g");s=d.exec(f);)"dll-reference"!==s[3]&&u[t].push(s[3]);for(d=new RegExp("\\("+a(l)+'\\("(dll-reference\\s('+o+'))"\\)\\)'+i,"g");s=d.exec(f);)r[s[2]]||(u[t].push(s[1]),r[s[2]]=n(s[1]).m),u[s[2]]=u[s[2]]||[],u[s[2]].push(s[4]);for(var m,p=Object.keys(u),y=0;y<p.length;y++)for(var v=0;v<u[p[y]].length;v++)m=u[p[y]][v],isNaN(1*m)||(u[p[y]][v]=1*u[p[y]][v]);return u}function f(r){return Object.keys(r).reduce(function(e,n){return e||r[n].length>0},!1)}r.exports=function(r,e){e=e||{};var o={main:n.m},i=e.all?{main:Object.keys(o.main)}:function(r,e){for(var n={main:[e]},t={main:[]},o={main:{}};f(n);)for(var i=Object.keys(n),a=0;a<i.length;a++){var c=i[a],s=n[c].pop();if(o[c]=o[c]||{},!o[c][s]&&r[c][s]){o[c][s]=!0,t[c]=t[c]||[],t[c].push(s);for(var l=u(r,r[c][s],c),d=Object.keys(l),m=0;m<d.length;m++)n[d[m]]=n[d[m]]||[],n[d[m]]=n[d[m]].concat(l[d[m]])}}return t}(o,r),a="";Object.keys(i).filter(function(r){return"main"!==r}).forEach(function(r){for(var e=0;i[r][e];)e++;i[r].push(e),o[r][e]="(function(module, exports, __webpack_require__) { module.exports = __webpack_require__; })",a=a+"var "+r+" = ("+t.toString().replace("ENTRY_MODULE",JSON.stringify(e))+")({"+i[r].map(function(e){return JSON.stringify(e)+": "+o[r][e].toString()}).join(",")+"});\n"}),a=a+"new (("+t.toString().replace("ENTRY_MODULE",JSON.stringify(r))+")({"+i.main.map(function(r){return JSON.stringify(r)+": "+o.main[r].toString()}).join(",")+"}))(self);";var c=new window.Blob([a],{type:"text/javascript"});if(e.bare)return c;var s=(window.URL||window.webkitURL||window.mozURL||window.msURL).createObjectURL(c),l=new window.Worker(s);return l.objectURL=s,l}},function(r,e,n){"use strict";n.r(e);var t=n(0),o=n(1),i=n(2),a=n.n(i),u=function(){function r(){var r=this;this.worker=a()(4),this.queue=[],this.currentJob=void 0,this.markerArray=new Float32Array(1e3*t.c),this.labelArray=new Float32Array(1e3*o.c),this.worker.onmessage=function(e){if(void 0!==r.currentJob){var n=r.currentJob,i=n.markers,a=n.resolve,u=e.data;t.d(i,u.markerArray),o.d(i,u.labelArray),r.markerArray=u.markerArray,r.labelArray=u.labelArray,r.currentJob=void 0,r.dequeue(),a()}}}return r.prototype.generalize=function(r,e,n,t){var o=this,i={bounds:r,priorityGroups:e,sprites:n},a=t.length,u=t.filter(function(r){return void 0!==r.htmlLabel}).length;return new Promise(function(r){o.queue.push({message:i,markers:t,resolve:r,markerCount:a,labelCount:u}),o.dequeue()})},r.prototype.clear=function(){this.queue=[]},r.prototype.pack=function(r,e,n){e*t.c>this.markerArray.length&&(this.markerArray=new Float32Array(e*t.c)),n*o.c>this.labelArray.length&&(this.labelArray=new Float32Array(n*o.c)),t.b(this.markerArray,r),o.b(this.labelArray,r,window.devicePixelRatio)},r.prototype.dequeue=function(){if(void 0===this.currentJob){var r=this.queue.shift();if(void 0!==r){this.pack(r.markers,r.markerCount,r.labelCount);var e=r.message;e.markers=this.markerArray,e.markerCount=r.markerCount,e.labels=this.labelArray,e.labelCount=r.labelCount,this.worker.postMessage(e,[e.markers.buffer,e.labels.buffer]),this.currentJob=r}}},r}();n.d(e,"General",function(){return u})},function(r,e,n){"use strict";n.r(e);var t=n(0),o=n(1),i={minX:0,minY:0,maxX:0,maxY:0},a={minX:0,minY:0,maxX:0,maxY:0},u={minX:0,minY:0,maxX:0,maxY:0},f={minX:0,minY:0,maxX:0,maxY:0};function c(r){for(var e=r.bounds,n=r.priorityGroups,i=r.markers,a=r.markerCount,u=r.labels,f=r.labelCount,c=1+(e.maxX-e.minX>>3)<<3,l=e.maxY-e.minY,d=c*l+8>>3,m=new Uint8Array(d),p=new Uint8Array(d),y=[],v=0;v<n.length;v++)y[v]=new Uint8Array(d);var b=new Int8Array(a);for(v=0;v<a;v++){var x=v*t.c+t.a.iconIndex;b[v]=i[x],i[x]=-1}var h=new Uint8Array(f);for(v=0;v<f;v++){x=v*o.c+o.a.display;h[v]=u[x],u[x]=0}s(r,m,p,y,c,l,b,h,!0,!0),s(r,m,p,y,c,l,b,h,!1,!0),s(r,m,p,y,c,l,b,h,!0,!1),s(r,m,p,y,c,l,b,h,!1,!1)}function s(r,e,n,i,a,u,f,c,s,m){for(var p=r.bounds,y=r.priorityGroups,v=r.sprites,b=r.markers,x=r.markerCount,h=r.labels,g=r.labelCount,w=0;w<y.length;w++){if(v[y[w].iconIndex])for(var k=0!==w?i[w-1]:void 0,Y=w!==y.length-1?i[w]:void 0,A=0;A<x;A++){var X=-1!==f[A],O=1===b[t.c*A+t.a.priority],j=m&&O||!m&&!O;(s&&X||!s&&!X)&&j&&l(b,y,v,p,k,Y,e,n,a,u,w,A)}}for(w=0;w<g;w++){var _=h[w*o.c+o.a.markerIndex];X=1===c[w],O=1===b[_*t.c+t.a.priority],j=m&&O||!m&&!O;(s&&X||!s&&!X)&&j&&d(b,h,p,e,n,a,u,w)}}function l(r,e,n,o,c,s,l,d,b,x,h,g){var w=e[h],k=w.safeZone,Y=w.iconIndex,A=w.margin,X=w.degradation,O=n[Y],j=O.size,_=O.anchor,P=t.c,I=t.a,S=g*P,U=r[S+I.groupIndex],C=r[S+I.pixelPositionX]-o.minX,L=r[S+I.pixelPositionY]-o.minY;U>h||(v(a,b,x,j,_,C,L,A),y(a)||U===h&&c&&m(c,b,a)||(v(i,b,x,j,_,C,L,k),y(i)||m(l,b,i)||(v(u,b,x,j,_,C,L,X),p(l,b,a),v(f,b,x,j,_,C,L,0),p(d,b,f),s&&p(s,b,u),r[S+I.iconIndex]=Y)))}function d(r,e,n,i,a,u,c,s){var l=o.c,d=o.a,b=s*l,x=e[b+d.markerIndex]*t.c;if(-1!==r[x+t.a.iconIndex]){var h=r[x+t.a.pixelPositionX]-n.minX,g=r[x+t.a.pixelPositionY]-n.minY,w=[e[b+d.width],e[b+d.height]],k=[-e[b+d.offsetX]/w[0],-e[b+d.offsetY]/w[1]];v(f,u,c,w,k,h,g,0),y(f)||m(a,u,f)||(p(i,u,f),p(a,u,f),e[b+d.display]=1)}}function m(r,e,n){for(var t=n.minX,o=n.minY,i=n.maxX,a=n.maxY,u=o;u<a;u++){var f=u*e+t>>3,c=u*e+i>>3,s=0;if(f===c)s=r[f]&255>>(7&t)&255<<8-(7&i);else{s=r[f]&255>>(7&t);for(var l=f+1;l<c;l++)s=r[l]|s;s=r[c]&255<<8-(7&i)|s}if(0!==s)return!0}return!1}function p(r,e,n){for(var t=n.minX,o=n.minY,i=n.maxX,a=n.maxY,u=o;u<a;u++){var f=u*e+t>>3,c=u*e+i>>3;if(f===c)r[f]=r[f]|255>>(7&t)&255<<8-(7&i);else{r[f]=r[f]|255>>(7&t);for(var s=f+1;s<c;s++)r[s]=255;r[c]=r[c]|255<<8-(7&i)}}}function y(r){return r.minX===r.maxX||r.minY===r.maxY}function v(r,e,n,t,o,i,a,u){var f=i-t[0]*o[0]-u|0,c=a-t[1]*o[1]-u|0,s=i+t[0]*(1-o[0])+u|0,l=a+t[1]*(1-o[1])+u|0;r.minX=f>0?f<e?f:e:0,r.minY=c>0?c<n?c:n:0,r.maxX=s>0?s<e?s:e:0,r.maxY=l>0?l<n?l:n:0}e.default=function(r){r.onmessage=function(e){c(e.data);var n=e.data,t=n.markers,o=n.labels;r.postMessage({markerArray:t,labelArray:o},[t.buffer,o.buffer])}}}])}); | ||
!function(r,n){"object"==typeof exports&&"object"==typeof module?module.exports=n():"function"==typeof define&&define.amd?define([],n):"object"==typeof exports?exports.General=n():r.General=n()}(window,function(){return function(r){var n={};function e(t){if(n[t])return n[t].exports;var o=n[t]={i:t,l:!1,exports:{}};return r[t].call(o.exports,o,o.exports,e),o.l=!0,o.exports}return e.m=r,e.c=n,e.d=function(r,n,t){e.o(r,n)||Object.defineProperty(r,n,{enumerable:!0,get:t})},e.r=function(r){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(r,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(r,"__esModule",{value:!0})},e.t=function(r,n){if(1&n&&(r=e(r)),8&n)return r;if(4&n&&"object"==typeof r&&r&&r.__esModule)return r;var t=Object.create(null);if(e.r(t),Object.defineProperty(t,"default",{enumerable:!0,value:r}),2&n&&"string"!=typeof r)for(var o in r)e.d(t,o,function(n){return r[n]}.bind(null,o));return t},e.n=function(r){var n=r&&r.__esModule?function(){return r.default}:function(){return r};return e.d(n,"a",n),n},e.o=function(r,n){return Object.prototype.hasOwnProperty.call(r,n)},e.p="/dist/",e(e.s=4)}([function(r,n,e){"use strict";e.d(n,"a",function(){return o}),e.d(n,"c",function(){return i}),e.d(n,"b",function(){return a}),e.d(n,"d",function(){return u});var t=0,o={pixelPositionX:t++,pixelPositionY:t++,groupIndex:t++,iconIndex:t++,priority:t++},i=Object.keys(o).length;function a(r,n){for(var e=0,t=0;e<n.length;e++,t+=i){var a=n[e];r[t+o.pixelPositionX]=a.pixelPosition[0],r[t+o.pixelPositionY]=a.pixelPosition[1],r[t+o.groupIndex]=a.groupIndex,r[t+o.iconIndex]=a.iconIndex,r[t+o.priority]=Boolean(a.priority)?1:0}}function u(r,n){for(var e=0,t=0;e<r.length;e++,t+=i)r[e].iconIndex=n[t+o.iconIndex]}},function(r,n,e){"use strict";e.d(n,"a",function(){return o}),e.d(n,"c",function(){return i}),e.d(n,"b",function(){return a}),e.d(n,"d",function(){return u});var t=0,o={markerIndex:t++,offsetX:t++,offsetY:t++,width:t++,height:t++,display:t++,minZoom:t++},i=7;function a(r,n,e){for(var t=0,a=0;a<n.length;a++){var u=n[a].htmlLabel;void 0!==u&&(r[t+o.markerIndex]=a,r[t+o.offsetX]=u.offset[0]*e,r[t+o.offsetY]=u.offset[1]*e,r[t+o.width]=u.width*e,r[t+o.height]=u.height*e,r[t+o.display]=u.display?1:0,r[t+o.minZoom]=u.minZoom,t+=i)}}function u(r,n){for(var e=0,t=0,a=r;t<a.length;t++){var u=a[t].htmlLabel;void 0!==u&&(u.display=1===n[e+o.display],u.minZoom=n[e+o.minZoom],e+=i)}}},function(r,n,e){function t(r){var n={};function e(t){if(n[t])return n[t].exports;var o=n[t]={i:t,l:!1,exports:{}};return r[t].call(o.exports,o,o.exports,e),o.l=!0,o.exports}e.m=r,e.c=n,e.i=function(r){return r},e.d=function(r,n,t){e.o(r,n)||Object.defineProperty(r,n,{configurable:!1,enumerable:!0,get:t})},e.r=function(r){Object.defineProperty(r,"__esModule",{value:!0})},e.n=function(r){var n=r&&r.__esModule?function(){return r.default}:function(){return r};return e.d(n,"a",n),n},e.o=function(r,n){return Object.prototype.hasOwnProperty.call(r,n)},e.p="/",e.oe=function(r){throw console.error(r),r};var t=e(e.s=ENTRY_MODULE);return t.default||t}var o="[\\.|\\-|\\+|\\w|/|@]+",i="\\(\\s*(/\\*.*?\\*/)?\\s*.*?("+o+").*?\\)";function a(r){return(r+"").replace(/[.?*+^$[\]\\(){}|-]/g,"\\$&")}function u(r,n,t){var u={};u[t]=[];var f=n.toString(),c=f.match(/^function\s?\w*\(\w+,\s*\w+,\s*(\w+)\)/);if(!c)return u;for(var m,s=c[1],l=new RegExp("(\\\\n|\\W)"+a(s)+i,"g");m=l.exec(f);)"dll-reference"!==m[3]&&u[t].push(m[3]);for(l=new RegExp("\\("+a(s)+'\\("(dll-reference\\s('+o+'))"\\)\\)'+i,"g");m=l.exec(f);)r[m[2]]||(u[t].push(m[1]),r[m[2]]=e(m[1]).m),u[m[2]]=u[m[2]]||[],u[m[2]].push(m[4]);for(var d,p=Object.keys(u),x=0;x<p.length;x++)for(var v=0;v<u[p[x]].length;v++)d=u[p[x]][v],isNaN(1*d)||(u[p[x]][v]=1*u[p[x]][v]);return u}function f(r){return Object.keys(r).reduce(function(n,e){return n||r[e].length>0},!1)}r.exports=function(r,n){n=n||{};var o={main:e.m},i=n.all?{main:Object.keys(o.main)}:function(r,n){for(var e={main:[n]},t={main:[]},o={main:{}};f(e);)for(var i=Object.keys(e),a=0;a<i.length;a++){var c=i[a],m=e[c].pop();if(o[c]=o[c]||{},!o[c][m]&&r[c][m]){o[c][m]=!0,t[c]=t[c]||[],t[c].push(m);for(var s=u(r,r[c][m],c),l=Object.keys(s),d=0;d<l.length;d++)e[l[d]]=e[l[d]]||[],e[l[d]]=e[l[d]].concat(s[l[d]])}}return t}(o,r),a="";Object.keys(i).filter(function(r){return"main"!==r}).forEach(function(r){for(var n=0;i[r][n];)n++;i[r].push(n),o[r][n]="(function(module, exports, __webpack_require__) { module.exports = __webpack_require__; })",a=a+"var "+r+" = ("+t.toString().replace("ENTRY_MODULE",JSON.stringify(n))+")({"+i[r].map(function(n){return JSON.stringify(n)+": "+o[r][n].toString()}).join(",")+"});\n"}),a=a+"new (("+t.toString().replace("ENTRY_MODULE",JSON.stringify(r))+")({"+i.main.map(function(r){return JSON.stringify(r)+": "+o.main[r].toString()}).join(",")+"}))(self);";var c=new window.Blob([a],{type:"text/javascript"});if(n.bare)return c;var m=(window.URL||window.webkitURL||window.mozURL||window.msURL).createObjectURL(c),s=new window.Worker(m);return s.objectURL=m,s}},function(r,n,e){"use strict";e.r(n);var t={min:-1/0,max:1/0},o={min:-1/0,max:1/0},i={min:-1/0,max:1/0},a={min:0,max:1/0};function u(r,n,e){var u,c,m,s,l=n.anchorX-r.anchorX,d=n.anchorY-r.anchorY;return f(t,r.minX,r.maxX,n.minX,n.maxX,l),f(o,r.minY,r.maxY,n.minY,n.maxY,d),c=t,m=o,s=a,(u=i).min=Math.max(c.min,m.min,s.min),u.max=Math.min(c.max,m.max,s.max),i.min>=i.max?-1/0:e+Math.log(i.max)/Math.log(2)}function f(r,n,e,t,o,i){var a=i>0?n-o:t-e,u=i>0?e-t:o-n;r.min=a/Math.abs(i),r.max=u/Math.abs(i)}var c=e(0),m=e(1),s={minX:0,minY:0,maxX:0,maxY:0},l={minX:0,minY:0,maxX:0,maxY:0},d={minX:0,minY:0,maxX:0,maxY:0},p={minX:0,minY:0,maxX:0,maxY:0},x=[];function v(r){for(var n=r.bounds,e=r.priorityGroups,t=r.markers,o=r.markerCount,i=r.labels,a=r.labelCount,u=1+(n.maxX-n.minX>>3)<<3,f=n.maxY-n.minY,s=u*f+8>>3,l=new Uint8Array(s),d=new Uint8Array(s),p=[],v=0;v<e.length;v++)p[v]=new Uint8Array(s);var y=new Int8Array(o);for(v=0;v<o;v++){var b=v*c.c+c.a.iconIndex;y[v]=t[b],t[b]=-1}var g=new Uint8Array(a),w=new Float32Array(a);for(v=0;v<a;v++){var k=v*m.c+m.a.display,Y=v*m.c+m.a.minZoom;g[v]=i[k],w[v]=i[Y],i[k]=0,i[Y]=-1/0}x=[],h(r,l,d,p,u,f,y,g,w,!0,!0),h(r,l,d,p,u,f,y,g,w,!1,!0),h(r,l,d,p,u,f,y,g,w,!0,!1),h(r,l,d,p,u,f,y,g,w,!1,!1)}function h(r,n,e,t,o,i,a,u,f,s,l){for(var d=r.bounds,p=r.priorityGroups,x=r.sprites,v=r.markers,h=r.markerCount,g=r.labels,w=r.labelCount,k=r.currentZoom,Y=0;Y<p.length;Y++){if(x[p[Y].iconIndex])for(var X=0!==Y?t[Y-1]:void 0,A=Y!==p.length-1?t[Y]:void 0,O=0;O<h;O++){var j=-1!==a[O],_=1===v[c.c*O+c.a.priority],P=l&&_||!l&&!_;(s&&j||!s&&!j)&&P&&y(v,p,x,d,X,A,n,e,o,i,Y,O)}}for(Y=0;Y<w;Y++){var I=g[Y*m.c+m.a.markerIndex];j=1===u[Y]&&k>=f[Y],_=1===v[I*c.c+c.a.priority],P=l&&_||!l&&!_;(s&&j||!s&&!j)&&P&&b(v,g,d,n,e,o,i,k,Y)}}function y(r,n,e,t,o,i,a,u,f,m,x,v){var h=n[x],y=h.safeZone,b=h.iconIndex,X=h.margin,A=h.degradation,O=e[b],j=O.size,_=O.anchor,P=c.c,I=c.a,M=v*P,Z=r[M+I.groupIndex],S=r[M+I.pixelPositionX]-t.minX,U=r[M+I.pixelPositionY]-t.minY;Z>x||(Y(l,f,m,j,_,S,U,X),k(l)||Z===x&&o&&g(o,f,l)||(Y(s,f,m,j,_,S,U,y),k(s)||g(a,f,s)||(Y(d,f,m,j,_,S,U,A),w(a,f,l),Y(p,f,m,j,_,S,U,0),w(u,f,p),i&&w(i,f,d),r[M+I.iconIndex]=b)))}function b(r,n,e,t,o,i,a,f,s){var l=m.c,d=m.a,v=s*l,h=n[v+d.markerIndex]*c.c;if(-1!==r[h+c.a.iconIndex]){var y=r[h+c.a.pixelPositionX]-e.minX,b=r[h+c.a.pixelPositionY]-e.minY,X=[n[v+d.width],n[v+d.height]],A=[-n[v+d.offsetX]/X[0],-n[v+d.offsetY]/X[1]];if(Y(p,i,a,X,A,y,b,0),!k(p)&&!g(o,i,p)){w(t,i,p),n[v+d.display]=1;for(var O={anchorX:y,anchorY:b,minX:-X[0]*A[0],minY:-X[1]*A[1],maxX:X[0]*(1-A[0]),maxY:X[1]*(1-A[1]),minZoom:-1/0},j=0,_=x;j<_.length;j++){var P=_[j],I=u(P,O,f);I>O.minZoom&&I>P.minZoom&&(O.minZoom=I)}n[v+d.minZoom]=O.minZoom,x.push(O)}}}function g(r,n,e){for(var t=e.minX,o=e.minY,i=e.maxX,a=e.maxY,u=o;u<a;u++){var f=u*n+t>>3,c=u*n+i>>3,m=0;if(f===c)m=r[f]&255>>(7&t)&255<<8-(7&i);else{m=r[f]&255>>(7&t);for(var s=f+1;s<c;s++)m=r[s]|m;m=r[c]&255<<8-(7&i)|m}if(0!==m)return!0}return!1}function w(r,n,e){for(var t=e.minX,o=e.minY,i=e.maxX,a=e.maxY,u=o;u<a;u++){var f=u*n+t>>3,c=u*n+i>>3;if(f===c)r[f]=r[f]|255>>(7&t)&255<<8-(7&i);else{r[f]=r[f]|255>>(7&t);for(var m=f+1;m<c;m++)r[m]=255;r[c]=r[c]|255<<8-(7&i)}}}function k(r){return r.minX===r.maxX||r.minY===r.maxY}function Y(r,n,e,t,o,i,a,u){var f=i-t[0]*o[0]-u|0,c=a-t[1]*o[1]-u|0,m=i+t[0]*(1-o[0])+u|0,s=a+t[1]*(1-o[1])+u|0;r.minX=f>0?f<n?f:n:0,r.minY=c>0?c<e?c:e:0,r.maxX=m>0?m<n?m:n:0,r.maxY=s>0?s<e?s:e:0}n.default=function(r){r.onmessage=function(n){v(n.data);var e=n.data,t=e.markers,o=e.labels;r.postMessage({markerArray:t,labelArray:o},[t.buffer,o.buffer])}}},function(r,n,e){"use strict";e.r(n);var t=e(0),o=e(1),i=e(2),a=e.n(i),u=function(){function r(){var r=this;this.worker=a()(3),this.queue=[],this.currentJob=void 0,this.markerArray=new Float32Array(1e3*t.c),this.labelArray=new Float32Array(1e3*o.c),this.worker.onmessage=function(n){if(void 0!==r.currentJob){var e=r.currentJob,i=e.markers,a=e.resolve,u=n.data;t.d(i,u.markerArray),o.d(i,u.labelArray),r.markerArray=u.markerArray,r.labelArray=u.labelArray,r.currentJob=void 0,r.dequeue(),a()}}}return r.prototype.generalize=function(r,n,e,t,o){var i=this,a={bounds:r,priorityGroups:n,sprites:e,currentZoom:o},u=t.length,f=t.filter(function(r){return void 0!==r.htmlLabel}).length;return new Promise(function(r){i.queue.push({message:a,markers:t,resolve:r,markerCount:u,labelCount:f}),i.dequeue()})},r.prototype.clear=function(){this.queue=[]},r.prototype.pack=function(r,n,e){n*t.c>this.markerArray.length&&(this.markerArray=new Float32Array(n*t.c)),e*o.c>this.labelArray.length&&(this.labelArray=new Float32Array(e*o.c)),t.b(this.markerArray,r),o.b(this.labelArray,r,window.devicePixelRatio)},r.prototype.dequeue=function(){if(void 0===this.currentJob){var r=this.queue.shift();if(void 0!==r){this.pack(r.markers,r.markerCount,r.labelCount);var n=r.message;n.markers=this.markerArray,n.markerCount=r.markerCount,n.labels=this.labelArray,n.labelCount=r.labelCount,this.worker.postMessage(n,[n.markers.buffer,n.labels.buffer]),this.currentJob=r}}},r}();e.d(n,"General",function(){return u})}])}); | ||
//# sourceMappingURL=general.js.map |
@@ -9,3 +9,3 @@ import { BBox, PriorityGroup, Sprite, Marker } from './types'; | ||
constructor(); | ||
generalize(bounds: BBox, priorityGroups: PriorityGroup[], sprites: Sprite[], markers: Marker[]): Promise<void>; | ||
generalize(bounds: BBox, priorityGroups: PriorityGroup[], sprites: Sprite[], markers: Marker[], currentZoom: number): Promise<void>; | ||
clear(): void; | ||
@@ -12,0 +12,0 @@ private pack; |
@@ -9,2 +9,3 @@ import { Marker } from './types'; | ||
display: number; | ||
minZoom: number; | ||
}; | ||
@@ -11,0 +12,0 @@ export declare const stride: number; |
@@ -25,2 +25,3 @@ export declare type Vec2 = [number, number] | Float64Array | number[]; | ||
display: boolean; | ||
minZoom: number; | ||
} | ||
@@ -43,2 +44,7 @@ export interface PriorityGroup { | ||
} | ||
export declare type LabelBBox = BBox & { | ||
anchorX: number; | ||
anchorY: number; | ||
minZoom: number; | ||
}; | ||
export interface JobMessage { | ||
@@ -48,2 +54,3 @@ bounds: BBox; | ||
sprites: Sprite[]; | ||
currentZoom: number; | ||
} | ||
@@ -58,2 +65,3 @@ export interface WorkerMessage { | ||
labels: Float32Array; | ||
currentZoom: number; | ||
} | ||
@@ -60,0 +68,0 @@ export interface Job { |
{ | ||
"name": "@2gis/general", | ||
"version": "1.1.0", | ||
"version": "2.0.0", | ||
"description": "Fast marker generalization algorithm", | ||
@@ -5,0 +5,0 @@ "contributors": [ |
@@ -117,2 +117,3 @@ # General [![Build Status](https://travis-ci.org/2gis/general.svg?branch=master)](https://travis-ci.org/2gis/general) | ||
- `display: boolean` - флаг, означающий, нужно ли отображать подпись. Выставляется в процессе генерализации. | ||
- `minZoom: number` — минимальный зум, на котором можно отображать подпись без пересечения с другими подписями. Выставляется в процессе генерализации. | ||
@@ -119,0 +120,0 @@ Метод `generalize` **не возвращает** новый массив маркеров, он мутирует старый. |
@@ -54,2 +54,3 @@ import * as markerArray from './markerArray'; | ||
markers: Marker[], | ||
currentZoom: number, | ||
): Promise<void> { | ||
@@ -60,2 +61,3 @@ const message: JobMessage = { | ||
sprites, | ||
currentZoom, | ||
}; | ||
@@ -62,0 +64,0 @@ |
@@ -11,2 +11,3 @@ import { Marker } from './types'; | ||
display: i++, | ||
minZoom: i++, | ||
}; | ||
@@ -35,2 +36,3 @@ | ||
labelArray[labelOffset + offsets.display] = label.display ? 1 : 0; | ||
labelArray[labelOffset + offsets.minZoom] = label.minZoom; | ||
@@ -55,2 +57,3 @@ labelOffset += stride; | ||
label.display = labelArray[labelOffset + offsets.display] === 1; | ||
label.minZoom = labelArray[labelOffset + offsets.minZoom]; | ||
@@ -57,0 +60,0 @@ labelOffset += stride; |
@@ -28,2 +28,3 @@ export type Vec2 = [number, number] | Float64Array | number[]; | ||
display: boolean; | ||
minZoom: number; | ||
} | ||
@@ -49,2 +50,8 @@ | ||
export type LabelBBox = BBox & { | ||
anchorX: number; | ||
anchorY: number; | ||
minZoom: number; | ||
}; | ||
export interface JobMessage { | ||
@@ -54,2 +61,3 @@ bounds: BBox; | ||
sprites: Sprite[]; | ||
currentZoom: number; | ||
} | ||
@@ -65,2 +73,3 @@ | ||
labels: Float32Array; | ||
currentZoom: number; | ||
} | ||
@@ -67,0 +76,0 @@ |
@@ -1,2 +0,3 @@ | ||
import { BBox, Vec2, WorkerMessage, PriorityGroup, Sprite } from '../types'; | ||
import { BBox, Vec2, WorkerMessage, PriorityGroup, Sprite, LabelBBox } from '../types'; | ||
import { getIntersectionZoom } from './minZoom'; | ||
import * as markerArray from '../markerArray'; | ||
@@ -10,2 +11,4 @@ import * as labelArray from '../labelArray'; | ||
let survivedLabelBoxes: LabelBBox[] = []; | ||
export function generalize(data: WorkerMessage) { | ||
@@ -59,12 +62,18 @@ const { bounds, priorityGroups, markers, markerCount, labels, labelCount } = data; | ||
const prevLabelState = new Uint8Array(labelCount); | ||
const prevLabelMinZoom = new Float32Array(labelCount); | ||
for (let i = 0; i < labelCount; i++) { | ||
const index = i * labelArray.stride + labelArray.offsets.display; | ||
const displayIndex = i * labelArray.stride + labelArray.offsets.display; | ||
const minZoomIndex = i * labelArray.stride + labelArray.offsets.minZoom; | ||
// Сохраняем предыдущее состояние лейблов | ||
prevLabelState[i] = labels[index]; | ||
prevLabelState[i] = labels[displayIndex]; | ||
prevLabelMinZoom[i] = labels[minZoomIndex]; | ||
// Сбрасываем состояние лейблов | ||
labels[index] = 0; | ||
labels[displayIndex] = 0; | ||
labels[minZoomIndex] = -Infinity; | ||
} | ||
survivedLabelBoxes = []; | ||
// Здесь начинает работу основной алгоритм генерализации | ||
@@ -78,17 +87,16 @@ // Генерализуем в таком порядке: | ||
data, plane, noMarginPlane, degradationPlanes, planeWidth, planeHeight, | ||
prevIconIndices, prevLabelState, true, true, | ||
prevIconIndices, prevLabelState, prevLabelMinZoom, true, true, | ||
); | ||
generalizePart( | ||
data, plane, noMarginPlane, degradationPlanes, planeWidth, planeHeight, | ||
prevIconIndices, prevLabelState, false, true, | ||
prevIconIndices, prevLabelState, prevLabelMinZoom, false, true, | ||
); | ||
generalizePart( | ||
data, plane, noMarginPlane, degradationPlanes, planeWidth, planeHeight, | ||
prevIconIndices, prevLabelState, true, false, | ||
prevIconIndices, prevLabelState, prevLabelMinZoom, true, false, | ||
); | ||
generalizePart( | ||
data, plane, noMarginPlane, degradationPlanes, planeWidth, planeHeight, | ||
prevIconIndices, prevLabelState, false, false, | ||
prevIconIndices, prevLabelState, prevLabelMinZoom, false, false, | ||
); | ||
} | ||
@@ -105,7 +113,7 @@ | ||
prevLabelState: Uint8Array, | ||
prevLabelMinZoom: Float32Array, | ||
processVisible: boolean, | ||
processPriority: boolean, | ||
): void { | ||
const { bounds, priorityGroups, sprites, markers, markerCount, labels, labelCount } = data; | ||
const { bounds, priorityGroups, sprites, markers, markerCount, labels, labelCount, currentZoom } = data; | ||
@@ -150,3 +158,3 @@ for (let i = 0; i < priorityGroups.length; i++) { | ||
const isVisible = prevLabelState[i] === 1; | ||
const isVisible = prevLabelState[i] === 1 && currentZoom >= prevLabelMinZoom[i]; | ||
const isPriority = markers[markerIndex * markerArray.stride + markerArray.offsets.priority] === 1; | ||
@@ -158,3 +166,3 @@ | ||
if (visibilityOk && priorityOk) { | ||
generalizeLabel(markers, labels, bounds, plane, noMarginPlane, planeWidth, planeHeight, i); | ||
generalizeLabel(markers, labels, bounds, plane, noMarginPlane, planeWidth, planeHeight, currentZoom, i); | ||
} | ||
@@ -234,2 +242,3 @@ } | ||
planeHeight: number, | ||
currentZoom: number, | ||
labelIndex: number, | ||
@@ -268,4 +277,25 @@ ): void { | ||
putToArray(plane, planeWidth, noMarginBBox); | ||
putToArray(noMarginPlane, planeWidth, noMarginBBox); | ||
labels[labelOffset + offsets.display] = 1; | ||
const labelBox: LabelBBox = { | ||
anchorX: pixelPositionX, | ||
anchorY: pixelPositionY, | ||
minX: -size[0] * anchor[0], | ||
minY: -size[1] * anchor[1], | ||
maxX: size[0] * (1 - anchor[0]), | ||
maxY: size[1] * (1 - anchor[1]), | ||
minZoom: -Infinity, | ||
}; | ||
for (const existingBox of survivedLabelBoxes) { | ||
const minZoom = getIntersectionZoom(existingBox, labelBox, currentZoom); | ||
if (minZoom > labelBox.minZoom && minZoom > existingBox.minZoom) { | ||
labelBox.minZoom = minZoom; | ||
} | ||
} | ||
labels[labelOffset + offsets.minZoom] = labelBox.minZoom; | ||
survivedLabelBoxes.push(labelBox); | ||
} | ||
@@ -272,0 +302,0 @@ } |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
125294
26
1055
128
0