@2gis/general
Advanced tools
Comparing version 0.0.1 to 0.0.2
@@ -13,3 +13,3 @@ import * as DG from '2gis-maps'; | ||
Marker as DrawMarker, | ||
} from 'markerdrawer'; | ||
} from '@2gis/markerdrawer'; | ||
import { | ||
@@ -16,0 +16,0 @@ BBox, |
@@ -1,2 +0,2 @@ | ||
import { Atlas } from 'markerdrawer'; | ||
import { Atlas } from '@2gis/markerdrawer'; | ||
@@ -3,0 +3,0 @@ const R = 6378137; |
@@ -1,2 +0,2 @@ | ||
import { Atlas } from 'markerdrawer'; | ||
import { Atlas } from '@2gis/markerdrawer'; | ||
export declare function lngLatToZoomPoint(lngLat: [number, number], zoom: number): [number, number]; | ||
@@ -3,0 +3,0 @@ export declare function mapPointToZoomPoint(point: [number, number], zoom: any): [number, number]; |
@@ -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()}(this,function(){return function(r){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}var n={};return 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.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,e){return Object.prototype.hasOwnProperty.call(r,e)},e.p="/dist/",e(e.s=1)}([function(r,e,n){"use strict";var t=n(2);n.d(e,"a",function(){return i});var o=n(4),i=function(){function r(){var r=this;this.worker=new o,this.queue=[],this.currentJob=void 0,this.markerArray=new Float32Array(1e3*t.a),this.worker.onmessage=function(e){if(void 0!==r.currentJob){var n=r.currentJob,t=n.markers,o=n.resolve;r.recordResult(t,e.data),r.markerArray=e.data,r.currentJob=void 0,r.dequeue(),o()}}}return r.prototype.generalize=function(r,e,n,t,o){var i=this,u={bounds:r,pixelRatio:e,priorityGroups:n,markerCount:o.length,sprites:t.sprites,markers:this.pack(o)};return new Promise(function(r){i.queue.push({message:u,markers:o,resolve:r}),i.dequeue()})},r.prototype.clear=function(){this.queue=[]},r.prototype.pack=function(r){r.length*t.a>this.markerArray.length&&(this.markerArray=new Float32Array(r.length*t.a));for(var e=this.markerArray,n=0,o=0;n<r.length;n++,o+=t.a){var i=r[n],u=i.iconIndex,a=i.prevGroupIndex;this.markerArray[o+t.b.pixelPositionX]=i.pixelPosition[0],this.markerArray[o+t.b.pixelPositionY]=i.pixelPosition[1],e[o+t.b.groupIndex]=i.groupIndex,e[o+t.b.iconIndex]=void 0!==u?u:NaN,e[o+t.b.prevGroupIndex]=void 0!==a?a:NaN}return e},r.prototype.dequeue=function(){if(void 0===this.currentJob){var r=this.queue.shift();if(void 0!==r){var e=r.message;this.worker.postMessage(e,[e.markers.buffer]),this.currentJob=r}}},r.prototype.recordResult=function(r,e){for(var n=0,o=0;n<r.length;n++,o+=t.a){var i=e[o+t.b.iconIndex],u=e[o+t.b.prevGroupIndex];r[n].iconIndex=i!==i?void 0:i,r[n].prevGroupIndex=u!==u?void 0:u}},r}()},function(r,e,n){"use strict";Object.defineProperty(e,"__esModule",{value:!0});var t=n(0);n.d(e,"General",function(){return t.a})},function(r,e,n){"use strict";n.d(e,"a",function(){return o}),n.d(e,"b",function(){return i});var t=["pixelPositionX","pixelPositionY","groupIndex","iconIndex","prevGroupIndex"],o=t.length,i=t.reduce(function(r,e,n){return r[e]=n,r},{})},function(r,e){var n=window.URL||window.webkitURL;r.exports=function(r,e){try{try{var t;try{t=new(window.BlobBuilder||window.WebKitBlobBuilder||window.MozBlobBuilder||window.MSBlobBuilder),t.append(r),t=t.getBlob()}catch(e){t=new Blob([r])}return new Worker(n.createObjectURL(t))}catch(e){return new Worker("data:application/javascript,"+encodeURIComponent(r))}}catch(r){if(!e)throw Error("Inline worker is not supported");return new Worker(e)}}},function(r,e,n){r.exports=function(){return n(3)('!function(n){function r(i){if(e[i])return e[i].exports;var o=e[i]={i:i,l:!1,exports:{}};return n[i].call(o.exports,o,o.exports,r),o.l=!0,o.exports}var e={};r.m=n,r.c=e,r.i=function(n){return n},r.d=function(n,e,i){r.o(n,e)||Object.defineProperty(n,e,{configurable:!1,enumerable:!0,get:i})},r.n=function(n){var e=n&&n.__esModule?function(){return n.default}:function(){return n};return r.d(e,"a",e),e},r.o=function(n,r){return Object.prototype.hasOwnProperty.call(n,r)},r.p="/dist/",r(r.s=1)}([function(n,r,e){"use strict";e.d(r,"a",function(){return o}),e.d(r,"b",function(){return t});var i=["pixelPositionX","pixelPositionY","groupIndex","iconIndex","prevGroupIndex"],o=i.length,t=i.reduce(function(n,r,e){return n[r]=e,n},{})},function(n,r,e){"use strict";function i(n,r,e){for(var i=e.minX,o=e.minY,t=e.maxX,a=e.maxY,u=o;u<a;u++){var x=u*r+i>>3,m=u*r+t>>3,f=0;if(x===m)f=n[x]&255>>(7&i)&255<<8-(7&t);else{f=n[x]&255>>(7&i);for(var s=x+1;s<m;s++)f=n[s]|f;f=n[m]&255<<8-(7&t)|f}if(0!==f)return!0}return!1}function o(n,r,e){for(var i=e.minX,o=e.minY,t=e.maxX,a=e.maxY,u=o;u<a;u++){var x=u*r+i>>3,m=u*r+t>>3;if(x===m)n[x]=n[x]|255>>(7&i)&255<<8-(7&t);else{n[x]=n[x]|255>>(7&i);for(var f=x+1;f<m;f++)n[f]=255;n[m]=n[m]|255<<8-(7&t)}}}function t(n){return n!==n}function a(n){return n.minX===n.maxX||n.minY===n.maxY}function u(n,r,e,i,o,t,a,u,x,m){var f=i/a,s=u*i-o[0]*f*t[0]-m|0,c=x*i-o[1]*f*t[1]-m|0,p=u*i+o[0]*f*(1-t[0])+m|0,d=x*i+o[1]*f*(1-t[1])+m|0;n.minX=s>0?s<r?s:r:0,n.minY=c>0?c<e?c:e:0,n.maxX=p>0?p<r?p:r:0,n.maxY=d>0?d<e?d:e:0}Object.defineProperty(r,"__esModule",{value:!0});var x=e(0),m={minX:0,minY:0,maxX:0,maxY:0},f={minX:0,minY:0,maxX:0,maxY:0},s={minX:0,minY:0,maxX:0,maxY:0};onmessage=function(n){for(var r=n.data,e=r.bounds,c=r.pixelRatio,p=r.priorityGroups,d=r.sprites,v=r.markers,l=r.markerCount,X=1+(e.maxX-e.minX>>3)<<3,Y=e.maxY-e.minY,b=X*Y+8>>3,g=new Uint8Array(b),y=new Uint8Array(b),I=new Uint8Array(b),P=0;P<l;P++){var h=v[P*x.a+x.b.prevGroupIndex],G=v[P*x.a+x.b.pixelPositionX],w=v[P*x.a+x.b.pixelPositionY];if(!t(h)){var O=p[h],_=O.iconIndex,j=O.margin,A=O.degradation,M=d[_];if(!M)continue;var U=M.size,k=M.anchor,z=M.pixelDensity;u(f,X,Y,c,U,k,z,G,w,j),a(f)||o(g,X,f),u(s,X,Y,c,U,k,z,G,w,A),a(s)||o(I,X,s)}}for(var P=0;P<p.length;P++){var D=p[P],C=D.safeZone,_=D.iconIndex,j=D.margin,A=D.degradation,M=d[_];if(M){var U=M.size,k=M.anchor,z=M.pixelDensity;y.set(I);for(var R=0;R<l;R++){var Z=R*x.a,q=v[Z+x.b.groupIndex],h=v[Z+x.b.prevGroupIndex],G=v[Z+x.b.pixelPositionX],w=v[Z+x.b.pixelPositionY];q>P||!t(h)||(u(f,X,Y,c,U,k,z,G,w,j),a(f)||q===P&&i(y,X,f)||(u(m,X,Y,c,U,k,z,G,w,C),a(m)||i(g,X,m)||(u(s,X,Y,c,U,k,z,G,w,A),o(g,X,f),o(I,X,s),v[Z+x.b.iconIndex]=_,v[Z+x.b.prevGroupIndex]=P)))}}}postMessage(v)}}]);\n//# sourceMappingURL=6d0ff04c83ecb1dd4d04.worker.js.map',null)}}])}); | ||
!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()}(this,function(){return function(r){function e(t){if(n[t])return n[t].exports;var i=n[t]={i:t,l:!1,exports:{}};return r[t].call(i.exports,i,i.exports,e),i.l=!0,i.exports}var n={};return 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.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,e){return Object.prototype.hasOwnProperty.call(r,e)},e.p="/dist/",e(e.s=1)}([function(r,e,n){"use strict";var t=n(2);n.d(e,"a",function(){return o});var i=n(4),o=function(){function r(){var r=this;this.worker=new i,this.queue=[],this.currentJob=void 0,this.markerArray=new Float32Array(1e3*t.a),this.worker.onmessage=function(e){if(void 0!==r.currentJob){var n=r.currentJob,t=n.markers,i=n.resolve;r.recordResult(t,e.data),r.markerArray=e.data,r.currentJob=void 0,r.dequeue(),i()}}}return r.prototype.generalize=function(r,e,n,t,i){var o=this,a={bounds:r,pixelRatio:e,priorityGroups:n,sprites:t.sprites};return new Promise(function(r){o.queue.push({message:a,markers:i,resolve:r}),o.dequeue()})},r.prototype.clear=function(){this.queue=[]},r.prototype.pack=function(r){r.length*t.a>this.markerArray.length&&(this.markerArray=new Float32Array(r.length*t.a));for(var e=this.markerArray,n=0,i=0;n<r.length;n++,i+=t.a){var o=r[n],a=o.iconIndex,u=o.prevGroupIndex;this.markerArray[i+t.b.pixelPositionX]=o.pixelPosition[0],this.markerArray[i+t.b.pixelPositionY]=o.pixelPosition[1],e[i+t.b.groupIndex]=o.groupIndex,e[i+t.b.iconIndex]=void 0!==a?a:NaN,e[i+t.b.prevGroupIndex]=void 0!==u?u:NaN}},r.prototype.dequeue=function(){if(void 0===this.currentJob){var r=this.queue.shift();if(void 0!==r){this.pack(r.markers);var e=r.message;e.markers=this.markerArray,e.markerCount=r.markers.length,this.worker.postMessage(e,[e.markers.buffer]),this.currentJob=r}}},r.prototype.recordResult=function(r,e){for(var n=0,i=0;n<r.length;n++,i+=t.a){var o=e[i+t.b.iconIndex],a=e[i+t.b.prevGroupIndex];r[n].iconIndex=o!==o?void 0:o,r[n].prevGroupIndex=a!==a?void 0:a}},r}()},function(r,e,n){"use strict";Object.defineProperty(e,"__esModule",{value:!0});var t=n(0);n.d(e,"General",function(){return t.a})},function(r,e,n){"use strict";n.d(e,"b",function(){return t}),n.d(e,"a",function(){return i});var t={pixelPositionX:0,pixelPositionY:1,groupIndex:2,iconIndex:3,prevGroupIndex:4},i=Object.keys(t).length},function(r,e){var n=window.URL||window.webkitURL;r.exports=function(r,e){try{try{var t;try{var i=window.BlobBuilder||window.WebKitBlobBuilder||window.MozBlobBuilder||window.MSBlobBuilder;t=new i,t.append(r),t=t.getBlob()}catch(e){t=new Blob([r])}return new Worker(n.createObjectURL(t))}catch(e){return new Worker("data:application/javascript,"+encodeURIComponent(r))}}catch(r){if(!e)throw Error("Inline worker is not supported");return new Worker(e)}}},function(r,e,n){r.exports=function(){return n(3)('!function(n){function r(i){if(e[i])return e[i].exports;var t=e[i]={i:i,l:!1,exports:{}};return n[i].call(t.exports,t,t.exports,r),t.l=!0,t.exports}var e={};r.m=n,r.c=e,r.i=function(n){return n},r.d=function(n,e,i){r.o(n,e)||Object.defineProperty(n,e,{configurable:!1,enumerable:!0,get:i})},r.n=function(n){var e=n&&n.__esModule?function(){return n.default}:function(){return n};return r.d(e,"a",e),e},r.o=function(n,r){return Object.prototype.hasOwnProperty.call(n,r)},r.p="/dist/",r(r.s=1)}([function(n,r,e){"use strict";function i(n){for(var r=n.bounds,e=n.pixelRatio,i=n.priorityGroups,p=n.sprites,v=n.markers,d=n.markerCount,l=1+(r.maxX-r.minX>>3)<<3,X=r.maxY-r.minY,Y=l*X+8>>3,b=new Uint8Array(Y),g=new Uint8Array(Y),y=new Uint8Array(Y),I=0;I<d;I++){var P=v[I*m.a+m.b.prevGroupIndex],h=v[I*m.a+m.b.pixelPositionX],G=v[I*m.a+m.b.pixelPositionY];if(!a(P)){var O=i[P],j=O.iconIndex,k=O.margin,w=O.degradation,_=p[j];if(!_)continue;var A=_.size,M=_.anchor,U=_.pixelDensity;s(f,l,X,e,A,M,U,h,G,k),u(f)||o(b,l,f),s(c,l,X,e,A,M,U,h,G,w),u(c)||o(y,l,c)}}for(var I=0;I<i.length;I++){var z=i[I],D=z.safeZone,j=z.iconIndex,k=z.margin,w=z.degradation,_=p[j];if(_){var A=_.size,M=_.anchor,U=_.pixelDensity;g.set(y);for(var C=0;C<d;C++){var R=C*m.a,Z=v[R+m.b.groupIndex],P=v[R+m.b.prevGroupIndex],h=v[R+m.b.pixelPositionX],G=v[R+m.b.pixelPositionY];Z>I||!a(P)||(s(f,l,X,e,A,M,U,h,G,k),u(f)||Z===I&&t(g,l,f)||(s(x,l,X,e,A,M,U,h,G,D),u(x)||t(b,l,x)||(s(c,l,X,e,A,M,U,h,G,w),o(b,l,f),o(y,l,c),v[R+m.b.iconIndex]=j,v[R+m.b.prevGroupIndex]=I)))}}}}function t(n,r,e){for(var i=e.minX,t=e.minY,o=e.maxX,a=e.maxY,u=t;u<a;u++){var s=u*r+i>>3,m=u*r+o>>3,x=0;if(s===m)x=n[s]&255>>(7&i)&255<<8-(7&o);else{x=n[s]&255>>(7&i);for(var f=s+1;f<m;f++)x=n[f]|x;x=n[m]&255<<8-(7&o)|x}if(0!==x)return!0}return!1}function o(n,r,e){for(var i=e.minX,t=e.minY,o=e.maxX,a=e.maxY,u=t;u<a;u++){var s=u*r+i>>3,m=u*r+o>>3;if(s===m)n[s]=n[s]|255>>(7&i)&255<<8-(7&o);else{n[s]=n[s]|255>>(7&i);for(var x=s+1;x<m;x++)n[x]=255;n[m]=n[m]|255<<8-(7&o)}}}function a(n){return n!==n}function u(n){return n.minX===n.maxX||n.minY===n.maxY}function s(n,r,e,i,t,o,a,u,s,m){var x=i/a,f=u*i-t[0]*x*o[0]-m|0,c=s*i-t[1]*x*o[1]-m|0,p=u*i+t[0]*x*(1-o[0])+m|0,v=s*i+t[1]*x*(1-o[1])+m|0;n.minX=f>0?f<r?f:r:0,n.minY=c>0?c<e?c:e:0,n.maxX=p>0?p<r?p:r:0,n.maxY=v>0?v<e?v:e:0}var m=e(2);r.a=i;var x={minX:0,minY:0,maxX:0,maxY:0},f={minX:0,minY:0,maxX:0,maxY:0},c={minX:0,minY:0,maxX:0,maxY:0}},function(n,r,e){"use strict";Object.defineProperty(r,"__esModule",{value:!0});var i=e(0);onmessage=function(n){var r=n.data;e.i(i.a)(r),postMessage(r.markers)}},function(n,r,e){"use strict";e.d(r,"b",function(){return i}),e.d(r,"a",function(){return t});var i={pixelPositionX:0,pixelPositionY:1,groupIndex:2,iconIndex:3,prevGroupIndex:4},t=Object.keys(i).length}]);\n//# sourceMappingURL=dde090990a6feb572c38.worker.js.map',null)}}])}); | ||
//# sourceMappingURL=general.js.map |
@@ -10,5 +10,11 @@ import { BBox, PriorityGroup, Atlas, Marker } from './types'; | ||
clear(): void; | ||
/** | ||
* Запаковывает переданный массив маркеров в типизированный массив для быстрой передачи в воркер | ||
*/ | ||
private pack(markers); | ||
private dequeue(); | ||
/** | ||
* Вынимает значения из запакованного типизированного массива в массив маркеров | ||
*/ | ||
private recordResult(markers, workerMessage); | ||
} |
@@ -1,4 +0,8 @@ | ||
export declare const stride: number; | ||
export declare const offsets: { | ||
[key: string]: number; | ||
pixelPositionX: number; | ||
pixelPositionY: number; | ||
groupIndex: number; | ||
iconIndex: number; | ||
prevGroupIndex: number; | ||
}; | ||
export declare const stride: number; |
@@ -1,2 +0,2 @@ | ||
export declare type Vec2 = [number, number] | Float64Array; | ||
export declare type Vec2 = [number, number] | Float64Array | number[]; | ||
export interface Sprite { | ||
@@ -28,2 +28,8 @@ size: Vec2; | ||
} | ||
export interface JobMessage { | ||
bounds: BBox; | ||
pixelRatio: number; | ||
priorityGroups: PriorityGroup[]; | ||
sprites: Sprite[]; | ||
} | ||
export interface WorkerMessage { | ||
@@ -38,5 +44,5 @@ bounds: BBox; | ||
export interface Job { | ||
message: WorkerMessage; | ||
message: JobMessage; | ||
markers: Marker[]; | ||
resolve: () => void; | ||
} |
{ | ||
"name": "@2gis/general", | ||
"version": "0.0.1", | ||
"version": "0.0.2", | ||
"description": "Fast marker generalization algorithm", | ||
@@ -24,19 +24,24 @@ "contributors": [ | ||
"start": "npm run dev", | ||
"test": "npm run lint", | ||
"test": "npm run lint && npm run unit", | ||
"dev": "webpack-dev-server", | ||
"build": "NODE_ENV=production webpack", | ||
"builddemo": "NODE_ENV=demo webpack", | ||
"lint": "tslint src/**/*.ts demo/**/*.ts" | ||
"unit": "TS_NODE_COMPILER_OPTIONS='{\"module\":\"commonjs\"}' mocha --compilers ts:ts-node/register test/**/*.spec.ts", | ||
"unit-dev": "TS_NODE_COMPILER_OPTIONS='{\"module\":\"commonjs\"}' mocha -w --compilers ts:ts-node/register test/**/*.spec.ts", | ||
"lint": "tslint src/**/*.ts demo/**/*.ts test/**/*.ts" | ||
}, | ||
"devDependencies": { | ||
"2gis-maps": "^3.2.0", | ||
"@2gis/markerdrawer": "^0.0.2", | ||
"@types/leaflet": "^1.0.56", | ||
"@types/mocha": "^2.2.41", | ||
"@types/node": "^7.0.12", | ||
"@types/rbush": "^2.0.2", | ||
"markerdrawer": "https://github.com/2gis/markerdrawer.git#8ef4d5dbfe325a03dbbb321f7f5aa2b6cc23aa96", | ||
"mocha": "^3.3.0", | ||
"rbush": "^2.0.1", | ||
"ts-loader": "^2.0.3", | ||
"ts-node": "^3.0.2", | ||
"tslib": "^1.6.0", | ||
"tslint": "^4.5.1", | ||
"tslint-eslint-rules": "^3.5.1", | ||
"tslint": "^5.2.0", | ||
"tslint-eslint-rules": "^4.0.0", | ||
"typescript": "^2.2.1", | ||
@@ -43,0 +48,0 @@ "webpack": "^2.3.1", |
@@ -68,5 +68,5 @@ # General [![Build Status](https://travis-ci.org/2gis/general.svg?branch=master)](https://travis-ci.org/2gis/general) | ||
## Установка ## | ||
Собранные версии библиотеки лежат в репозитории в ветке [build](https://github.com/2gis/general/tree/build): | ||
С помощью `npm`: | ||
```bash | ||
npm install https://github.com/2gis/general.git#build | ||
npm install @2gis/general | ||
``` | ||
@@ -116,2 +116,2 @@ Можно подключить через `script` использовать через глобальную переменную `General`: | ||
Также, генерализация выставляет маркерам дополнительный параметр `prevGroupIndex`, чтобы при повторной генерализации, обрабатывать только новые маркера. Это помогает избежать моментов, когда при добавление новых маркеров, старые маркеры генерализуются в новых условиях по-новому. | ||
Также, генерализация выставляет маркерам дополнительный параметр `prevGroupIndex`, чтобы при повторной генерализации, обрабатывать только новые маркера. Это помогает избежать моментов, когда при добавление новых маркеров, старые маркеры генерализуются в новых условиях по-новому. |
@@ -9,2 +9,3 @@ import { stride, offsets } from './markerArray'; | ||
Job, | ||
JobMessage, | ||
} from './types'; | ||
@@ -15,8 +16,13 @@ | ||
export class General { | ||
private worker = new Worker(); | ||
private queue: Job[] = []; | ||
private currentJob: Job | undefined = undefined; | ||
private markerArray = new Float32Array(1000 * stride); | ||
private worker: Worker; | ||
private queue: Job[]; | ||
private currentJob: Job | undefined; | ||
private markerArray: Float32Array; | ||
constructor() { | ||
this.worker = new Worker(); | ||
this.queue = []; | ||
this.currentJob = undefined; | ||
this.markerArray = new Float32Array(1000 * stride); | ||
this.worker.onmessage = (event) => { | ||
@@ -44,9 +50,7 @@ if (this.currentJob === undefined) { | ||
): Promise<{}> { | ||
const message: WorkerMessage = { | ||
const message: JobMessage = { | ||
bounds, | ||
pixelRatio, | ||
priorityGroups, | ||
markerCount: markers.length, | ||
sprites: atlas.sprites, | ||
markers: this.pack(markers), | ||
}; | ||
@@ -64,3 +68,6 @@ | ||
private pack(markers: Marker[]): Float32Array { | ||
/** | ||
* Запаковывает переданный массив маркеров в типизированный массив для быстрой передачи в воркер | ||
*/ | ||
private pack(markers: Marker[]) { | ||
if (markers.length * stride > this.markerArray.length) { | ||
@@ -86,4 +93,2 @@ this.markerArray = new Float32Array(markers.length * stride); | ||
} | ||
return markerArray; | ||
} | ||
@@ -102,3 +107,8 @@ | ||
const message = job.message; | ||
this.pack(job.markers); | ||
let message = job.message as WorkerMessage; | ||
message.markers = this.markerArray; | ||
message.markerCount = job.markers.length; | ||
this.worker.postMessage(message, [message.markers.buffer]); | ||
@@ -109,2 +119,5 @@ | ||
/** | ||
* Вынимает значения из запакованного типизированного массива в массив маркеров | ||
*/ | ||
private recordResult(markers: Marker[], workerMessage: Float32Array) { | ||
@@ -111,0 +124,0 @@ for (let i = 0, markerOffset = 0; i < markers.length; i++, markerOffset = markerOffset + stride) { |
@@ -1,13 +0,10 @@ | ||
const members = [ | ||
'pixelPositionX', | ||
'pixelPositionY', | ||
'groupIndex', | ||
'iconIndex', | ||
'prevGroupIndex', | ||
]; | ||
// Оффсеты должны быть пронумерованы по порядку | ||
export const offsets = { | ||
pixelPositionX: 0, | ||
pixelPositionY: 1, | ||
groupIndex: 2, | ||
iconIndex: 3, | ||
prevGroupIndex: 4, | ||
}; | ||
export const stride = members.length; | ||
export const offsets: {[key: string]: number} = members.reduce((offsets, member, index) => { | ||
offsets[member] = index; | ||
return offsets; | ||
}, {}); | ||
export const stride = Object.keys(offsets).length; |
@@ -1,2 +0,2 @@ | ||
export type Vec2 = [number, number] | Float64Array; | ||
export type Vec2 = [number, number] | Float64Array | number[]; | ||
@@ -35,2 +35,9 @@ export interface Sprite { | ||
export interface JobMessage { | ||
bounds: BBox; | ||
pixelRatio: number; | ||
priorityGroups: PriorityGroup[]; | ||
sprites: Sprite[]; | ||
} | ||
export interface WorkerMessage { | ||
@@ -46,5 +53,5 @@ bounds: BBox; | ||
export interface Job { | ||
message: WorkerMessage; | ||
message: JobMessage; | ||
markers: Marker[]; | ||
resolve: () => void; | ||
} |
Sorry, the diff of this file is not supported yet
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
4484397
52
1292
116
17