Skip to content

Commit ad3ba1c

Browse files
authored
fix: always create data for renderPlugin with false symbol.visible, close #2634 (#2647)
* fix: always create data for renderPlugin with false symbol.visible, close #2634 * fixing vt specs * add spec for #2634 * fixing vt specs
1 parent 1799978 commit ad3ba1c

File tree

4 files changed

+127
-25
lines changed

4 files changed

+127
-25
lines changed

packages/vt/src/layer/renderer/VectorTileLayerRenderer.js

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -97,22 +97,31 @@ class VectorTileLayerRenderer extends CanvasCompatible(TileLayerRendererable(Lay
9797
this._groundPainter.update();
9898
}
9999
if (this._workerConn) {
100-
this._styleCounter++;
101-
this._preservePrevTiles();
102-
const style = this.layer._getComputedStyle();
103-
style.styleCounter = this._styleCounter;
104-
this._workersyncing = true;
105-
this._workerConn.updateStyle(style, err => {
106-
this._workersyncing = false;
107-
if (err) throw new Error(err);
108-
this._needRetire = true;
109-
// this.clear();
110-
// this._clearPlugin();
111-
this._initPlugins();
112-
this.setToRedraw();
100+
if (this._workerUpdateTimeout) {
101+
clearTimeout(this._workerUpdateTimeout);
102+
}
103+
this._workerUpdateTimeout = setTimeout(() => {
104+
if (!this.layer) {
105+
// layer is removed from map
106+
return;
107+
}
108+
this._styleCounter++;
109+
this._preservePrevTiles();
110+
const style = this.layer._getComputedStyle();
111+
style.styleCounter = this._styleCounter;
112+
this._workersyncing = true;
113+
this._workerConn.updateStyle(style, err => {
114+
this._workersyncing = false;
115+
if (err) throw new Error(err);
116+
this._needRetire = true;
117+
// this.clear();
118+
// this._clearPlugin();
119+
this._initPlugins();
120+
this.setToRedraw();
113121

114-
this.layer.fire('refreshstyle');
115-
});
122+
this.layer.fire('refreshstyle');
123+
});
124+
}, 10);
116125
} else {
117126
this._initPlugins();
118127
}
@@ -1481,7 +1490,7 @@ class VectorTileLayerRenderer extends CanvasCompatible(TileLayerRendererable(Lay
14811490
const status = plugin.createTile(context);
14821491
if (tileCache[idx].geometry) {
14831492
//插件数据以及经转化为geometry,可以删除原始数据以节省内存
1484-
tileData.data[idx] = 1;
1493+
tileData.data[idx] = 'geometry created';
14851494
}
14861495
if (!this._needRetire && status.retire && plugin.supportRenderMode('taa')) {
14871496
this._needRetire = true;

packages/vt/src/packer/index.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ const SYMBOLS_NEED_REBUILD = {
4747

4848
// 只有vt图层,需要重建mesh的symbol属性
4949
const SYMBOLS_NEED_REBUILD_IN_VT = {
50-
'visible': 1,
5150

5251
'textHorizontalAlignment': 1,
5352
'textVerticalAlignment': 1,

packages/vt/src/worker/layer/BaseLayerWorker.js

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -308,11 +308,6 @@ export default class BaseLayerWorker {
308308
}
309309
// type = 0 是普通 style, type = 1 是 feature style
310310
const targetData = pluginConfig.type === 0 ? data : featureData;
311-
if (pluginConfig.symbol && pluginConfig.symbol.visible === false) {
312-
//数据不存在,则在data中添加个占位的null,不然renderer中featureData与data,对应的plugin会不正确
313-
targetData[typeIndex] = null;
314-
continue;
315-
}
316311
getFnTypeProps(pluginConfig.symbol, fnTypeProps, i);
317312
hasFnTypeProps = hasFnTypeProps || fnTypeProps[i] && fnTypeProps[i].size > 0;
318313

packages/vt/test/specs/update.spec.js

Lines changed: 102 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -605,7 +605,6 @@ describe('update style specs', () => {
605605
}
606606
});
607607
map.setZoom(map.getZoom() + 2);
608-
assert(layer.getRenderer().getStyleCounter() === 2);
609608
}, false, null, 0, 2);
610609
});
611610

@@ -1690,7 +1689,7 @@ describe('update style specs', () => {
16901689
assert.deepEqual(pixel, [36, 40, 44, 255]);
16911690
done();
16921691
}, 1500);
1693-
}, 1500);
1692+
}, 2000);
16941693
}).timeout(5000);
16951694

16961695
it('should can update symbol to lit with AA, maptalks-studio#374', done => {
@@ -2216,7 +2215,7 @@ describe('update style specs', () => {
22162215
assert(styleRefreshed);
22172216
assert.notDeepEqual(pixel, newPixel);
22182217
done();
2219-
}, 800);
2218+
}, 1500);
22202219
});
22212220
layer.on('refreshstyle', () => {
22222221
styleRefreshed = true;
@@ -2297,6 +2296,106 @@ describe('update style specs', () => {
22972296
layer.addTo(map);
22982297
});
22992298

2299+
it('should can update visible, maptalks/maptalks.js#2634', done => {
2300+
const polygons = {
2301+
type: 'FeatureCollection',
2302+
features: [
2303+
{
2304+
type: 'Feature',
2305+
geometry: {
2306+
type: 'Polygon',
2307+
coordinates: [
2308+
[
2309+
[-1., 1.0],
2310+
[1., 1.0],
2311+
[1., -1.0],
2312+
[-1., -1],
2313+
[-1., 1]
2314+
]
2315+
]
2316+
},
2317+
properties: {
2318+
type: 1
2319+
}
2320+
},
2321+
{
2322+
type: 'Feature',
2323+
geometry: {
2324+
type: 'Polygon',
2325+
coordinates: [
2326+
[
2327+
[-0.5, 0.5],
2328+
[0.5, 0.5],
2329+
[0.5, -0.5],
2330+
[-0.5, -0.5],
2331+
[-0.5, 0.5]
2332+
]
2333+
]
2334+
},
2335+
properties: {
2336+
type: 2
2337+
}
2338+
}
2339+
]
2340+
};
2341+
const layer = new GeoJSONVectorTileLayer('gvt', {
2342+
data: polygons,
2343+
style: [
2344+
{
2345+
name: '1',
2346+
filter: ['==', 'type', 1],
2347+
renderPlugin: {
2348+
dataConfig: {
2349+
type: "fill",
2350+
},
2351+
type: "fill",
2352+
},
2353+
symbol: {
2354+
polygonFill: "#f00",
2355+
polygonOpacity: 1,
2356+
},
2357+
},
2358+
{
2359+
name: '2',
2360+
filter: ['==', 'type', 2],
2361+
renderPlugin: {
2362+
dataConfig: {
2363+
type: "fill",
2364+
},
2365+
type: "fill",
2366+
},
2367+
symbol: {
2368+
polygonFill: "#0f0",
2369+
polygonOpacity: 1,
2370+
},
2371+
},
2372+
]
2373+
});
2374+
layer.addTo(map);
2375+
const renderer = map.getRenderer();
2376+
const x = renderer.canvas.width, y = renderer.canvas.height;
2377+
setTimeout(() => {
2378+
const pixel = readPixel(renderer.canvas, x / 2, y / 2);
2379+
assert.deepEqual(pixel, [0, 255, 0, 255]);
2380+
layer.updateSymbol('1', { visible: false });
2381+
layer.updateSymbol('2', { visible: false });
2382+
2383+
setTimeout(() => {
2384+
const pixel = readPixel(renderer.canvas, x / 2, y / 2);
2385+
assert.deepEqual(pixel, [0, 0, 0, 0]);
2386+
layer.updateSymbol('1', { visible: true });
2387+
layer.updateSymbol('2', { visible: true });
2388+
setTimeout(() => {
2389+
const pixel = readPixel(renderer.canvas, x / 2, y / 2);
2390+
assert.deepEqual(pixel, [0, 255, 0, 255]);
2391+
done();
2392+
}, 300);
2393+
}, 300);
2394+
2395+
}, 1500);
2396+
2397+
});
2398+
23002399
function assertChangeStyle(done, expectedColor, changeFun, isSetStyle, style, renderCount, doneRenderCount) {
23012400
style = style || [
23022401
{

0 commit comments

Comments
 (0)