Skip to content

Commit e097d5a

Browse files
authored
some tweaks (#2184)
* some tweaks * restore GlobalConfig.js * remove WorkerPool.broadcastMessage
1 parent 90ad2be commit e097d5a

File tree

7 files changed

+16
-135
lines changed

7 files changed

+16
-135
lines changed

src/globalConfig.js renamed to src/GlobalConfig.js

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,16 @@
22
* global config
33
* idle/worker etc
44
*/
5-
const globalConfig = {
6-
//dev env
7-
dev: false,
8-
//test env
9-
test: false,
5+
const GlobalConfig = {
106
//idle logging
117
idleLog: false,
128
//idle 时间阈值
139
idleTimeRemaining: 8,
1410
//idle 超时阈值
1511
idleTimeout: 1000,
1612
//worker 数量
17-
workerCount: 0,
18-
//worker 通信并发数量
19-
workerConcurrencyCount: 5
13+
workerCount: window.MAPTALKS_WORKER_COUNT || 0,
14+
//每个Worker Message中封装的task message数量
15+
taskCountPerWorkerMessage: 5
2016
};
21-
export default globalConfig;
17+
export default GlobalConfig;

src/core/MicroTask.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { requestAnimFrame } from './util';
33
import { isFunction, isNil, isNumber } from './util/common';
44
import { getGlobalWorkerPool } from './worker/WorkerPool';
55
import Browser from './Browser';
6-
import globalConfig from '../globalConfig';
6+
import GlobalConfig from '../GlobalConfig';
77

88
let tasks = [];
99

@@ -88,7 +88,7 @@ function loop() {
8888
}
8989

9090
function frameLoop(deadline) {
91-
const { idleTimeRemaining, idleLog, idleTimeout } = globalConfig;
91+
const { idleTimeRemaining, idleLog, idleTimeout } = GlobalConfig;
9292
if (Browser.requestIdleCallback) {
9393
if (deadline && deadline.timeRemaining) {
9494
const t = deadline.timeRemaining();
@@ -118,7 +118,7 @@ export function startTasks() {
118118
return;
119119
}
120120
started = true;
121-
const { idleTimeout } = globalConfig;
121+
const { idleTimeout } = GlobalConfig;
122122
if (Browser.requestIdleCallback) {
123123
requestIdleCallback(frameLoop, { timeout: idleTimeout });
124124
} else {

src/core/util/pick.js

Lines changed: 0 additions & 98 deletions
This file was deleted.

src/core/worker/WorkerPool.js

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
// import { requestAnimFrame } from '../util';
22
import { setWorkerPool, setWorkersCreated } from './CoreWorkers';
33
import { getWorkerSourcePath } from './Worker';
4-
import globalConfig from '../../globalConfig';
4+
import GlobalConfig from '../../GlobalConfig';
55

66
const hardwareConcurrency = typeof window !== 'undefined' ? (window.navigator.hardwareConcurrency || 4) : 0;
7-
const workerCount = Math.max(Math.floor(hardwareConcurrency / 2), 1);
7+
const hardwareWorkerCount = Math.max(Math.floor(hardwareConcurrency / 2), 1);
88

99
class MessageBatch {
1010
constructor(limit = 50) {
@@ -43,7 +43,7 @@ class MessageBatch {
4343
export default class WorkerPool {
4444
constructor() {
4545
this.active = {};
46-
this.workerCount = typeof window !== 'undefined' ? (globalConfig.workerCount || window.MAPTALKS_WORKER_COUNT || workerCount) : 0;
46+
this.workerCount = typeof window !== 'undefined' ? (GlobalConfig.workerCount || hardwareWorkerCount) : 0;
4747
this._messages = [];
4848
this._messageBuffers = [];
4949
}
@@ -107,19 +107,14 @@ export default class WorkerPool {
107107
return this.workers || [];
108108
}
109109

110-
broadcastMessage(message) {
110+
broadcastIdleMessage() {
111111
const workers = this.getWorkers();
112112
workers.forEach(worker => {
113-
worker.postMessage({ messageType: message, messageCount: globalConfig.workerConcurrencyCount });
113+
worker.postMessage({ messageType: 'idle', messageCount: GlobalConfig.taskCountPerWorkerMessage });
114114
});
115115
return this;
116116
}
117117

118-
broadcastIdleMessage() {
119-
this.broadcastMessage('idle');
120-
return this;
121-
}
122-
123118
}
124119

125120
let globalWorkerPool;

src/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { version } from '../package.json';
2-
export { default as globalconfig } from './globalConfig';
2+
export { default as Globalconfig } from './GlobalConfig';
33
export * from './core/Constants';
44
export { default as Browser } from './core/Browser';
55
import * as Util from './core/util';

src/map/Map.Topo.js

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { INTERNAL_LAYER_PREFIX } from '../core/Constants';
22
import { isNil, isString, isArrayHasData, pushIn, isFunction } from '../core/util';
3-
import { isGLRenderLayer, layerIsBlankInPoint } from '../core/util/pick';
43
import Coordinate from '../geo/Coordinate';
54
import Point from '../geo/Point';
65
import Map from './Map';
@@ -108,17 +107,12 @@ Map.include(/** @lends Map.prototype */ {
108107
opts.tolerance = opts.tolerance || 0;
109108
opts.tolerance += layer.options.geometryEventTolerance;
110109
}
111-
//only gllayer,exclude canvas layer
112-
const isGLLayer = isGLRenderLayer(layer);
113-
const isBlank = isGLLayer && layerIsBlankInPoint(layer, containerPoint, opts.tolerance);
114-
if (!isBlank && layer._hasGeoListeners && isMapGeometryEvent && opts.eventTypes.indexOf('mousemove') >= 0) {
110+
if (layer._hasGeoListeners && isMapGeometryEvent && opts.eventTypes.indexOf('mousemove') >= 0) {
115111
if (!layer._hasGeoListeners(opts.eventTypes)) {
116112
return [];
117113
}
118114
}
119-
if (isBlank) {
120-
result = [];
121-
} else if (layer.identifyAtPoint) {
115+
if (layer.identifyAtPoint) {
122116
result = layer.identifyAtPoint(containerPoint, opts);
123117
} else if (coordinate && layer.identify) {
124118
result = layer.identify(coordinate, opts);

src/renderer/layer/vectorlayer/VectorLayerCanvasRenderer.js

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -552,12 +552,6 @@ class VectorLayerRenderer extends OverlayLayerCanvasRenderer {
552552
return this.constructor === VectorLayerRenderer;
553553
}
554554

555-
_alwaysDraw() {
556-
if (this.canvas && this.isProgressiveRender()) {
557-
this.canvas._drawn = true;
558-
}
559-
}
560-
561555
isProgressiveRender() {
562556
const layer = this.layer;
563557
if (!layer) {

0 commit comments

Comments
 (0)