Skip to content

Commit 1be9af6

Browse files
authored
feat: add map.options.tileBackgroundLimitPerFrame to control how many background tileLayers to draw per frame (#2626)
1 parent 83d1cd0 commit 1be9af6

File tree

2 files changed

+21
-5
lines changed

2 files changed

+21
-5
lines changed

packages/maptalks/src/map/Map.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,12 +107,14 @@ const options: MapOptionsType = {
107107
'maxPitch': 80,
108108
'centerCross': false,
109109

110+
'zoomable': true,
110111
'zoomInCenter': false,
111112
'zoomOrigin': null,
112113
'zoomAnimation': (function () {
113114
return !IS_NODE;
114115
})(),
115116
'zoomAnimationDuration': 330,
117+
'tileBackgroundLimitPerFrame': 3,
116118

117119
'panAnimation': (function () {
118120
return !IS_NODE;
@@ -125,7 +127,7 @@ const options: MapOptionsType = {
125127
return !IS_NODE;
126128
})(),
127129

128-
'zoomable': true,
130+
129131
'enableInfoWindow': true,
130132

131133
'hitDetect': (function () {
@@ -2822,15 +2824,18 @@ export type MapOptionsType = {
28222824
maxVisualPitch?: number;
28232825
maxPitch?: number;
28242826
centerCross?: boolean;
2827+
2828+
zoomable?: boolean;
28252829
zoomInCenter?: boolean;
28262830
zoomOrigin?: Array<number>;
28272831
zoomAnimation?: boolean;
28282832
zoomAnimationDuration?: number;
2833+
tileBackgroundLimitPerFrame?: number;
28292834
panAnimation?: boolean;
28302835
panAnimationDuration?: number;
28312836
rotateAnimation?: boolean;
28322837
rotateAnimationDuration?: number;
2833-
zoomable?: boolean;
2838+
28342839
enableInfoWindow?: boolean;
28352840
hitDetect?: boolean;
28362841
hitDetectLimit?: number;

packages/maptalks/src/renderer/layer/tilelayer/TileLayerRendererable.ts

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -471,14 +471,25 @@ const TileLayerRenderable = function <T extends MixinConstructor>(Base: T) {
471471
this._childTiles.sort(this._compareTiles);
472472
}
473473

474+
const map = this.getMap();
475+
const mapCanvas = map.getRenderer().canvas;
474476
let drawBackground = true;
475-
const backgroundTimestamp = this.canvas._parentTileTimestamp;
477+
let frameTileState = mapCanvas._frameTileState;
478+
if (!frameTileState) {
479+
frameTileState = mapCanvas._frameTileState = { timestamp: 0, count: 0 };
480+
}
476481
if (this.layer.constructor === TileLayer || this.layer.constructor === WMSTileLayer) {
482+
477483
// background tiles are only painted once for TileLayer and WMSTileLayer per frame.
478-
if (this._renderTimestamp === backgroundTimestamp) {
484+
if (this._renderTimestamp === frameTileState.timestamp && frameTileState.count > map.options['tileBackgroundLimitPerFrame']) {
479485
drawBackground = false;
480486
} else {
481-
this.canvas._parentTileTimestamp = this._renderTimestamp;
487+
if (this._renderTimestamp !== frameTileState.timestamp) {
488+
frameTileState.timestamp = this._renderTimestamp;
489+
frameTileState.count = 1;
490+
} else {
491+
frameTileState.count++;
492+
}
482493
}
483494
}
484495

0 commit comments

Comments
 (0)