Skip to content

Commit 4826743

Browse files
committed
fix cascade tiles when hit minzoom, close #679
1 parent 9467787 commit 4826743

File tree

2 files changed

+43
-9
lines changed

2 files changed

+43
-9
lines changed

src/layer/tile/TileLayer.js

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -126,28 +126,31 @@ class TileLayer extends Layer {
126126
const mapExtent = map.getContainerExtent();
127127
const tileGrids = [];
128128
let count = 0;
129+
const minZoom = this.getMinZoom();
129130
const minPitchToCascade = this.options['minPitchToCascade'];
130-
if (!isNil(z) || !this.options['cascadeTiles'] || map.getPitch() <= minPitchToCascade) {
131-
if (isNil(z)) {
132-
z = this._getTileZoom(map.getZoom());
133-
}
134-
const currentTiles = this._getTiles(z, mapExtent);
131+
const tileZoom = isNil(z) ? this._getTileZoom(map.getZoom()) : z;
132+
if (
133+
!isNil(z) ||
134+
!this.options['cascadeTiles'] ||
135+
map.getPitch() <= minPitchToCascade ||
136+
!isNil(minZoom) && tileZoom <= minZoom
137+
) {
138+
const currentTiles = this._getTiles(tileZoom, mapExtent);
135139
count += currentTiles ? currentTiles.tiles.length : 0;
136140
tileGrids.push(currentTiles);
137141
return {
138142
tileGrids, count
139143
};
140144
}
141145

142-
z = this._getTileZoom(map.getZoom());
143146
const visualHeight = Math.floor(map._getVisualHeight(minPitchToCascade));
144147
const extent0 = new PointExtent(0, map.height - visualHeight, map.width, map.height);
145-
const currentTiles = this._getTiles(z, extent0, 0);
148+
const currentTiles = this._getTiles(tileZoom, extent0, 0);
146149
count += currentTiles ? currentTiles.tiles.length : 0;
147150

148151
const extent1 = new PointExtent(0, mapExtent.ymin, map.width, extent0.ymin);
149152
const d = map.getSpatialReference().getZoomDirection();
150-
const parentTiles = this._getTiles(z - d, extent1, 1);
153+
const parentTiles = this._getTiles(tileZoom - d, extent1, 1);
151154
count += parentTiles ? parentTiles.tiles.length : 0;
152155

153156
tileGrids.push(currentTiles, parentTiles);
@@ -269,7 +272,12 @@ class TileLayer extends Layer {
269272
if (!map || !this.isVisible() || !map.width || !map.height) {
270273
return null;
271274
}
272-
275+
const minZoom = this.getMinZoom(),
276+
maxZoom = this.getMaxZoom();
277+
if (!isNil(minZoom) && z < minZoom ||
278+
!isNil(maxZoom) && z > maxZoom) {
279+
return null;
280+
}
273281
const tileConfig = this._getTileConfig();
274282
if (!tileConfig) {
275283
return null;

test/layer/TileLayerSpec.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,32 @@ describe('TileLayer', function () {
167167
map.setBaseLayer(tile);
168168
});
169169

170+
it('#679, cascade tiles\'s bug on 4326', function (done) {
171+
container = document.createElement('div');
172+
container.style.width = '3px';
173+
container.style.height = '3px';
174+
document.body.appendChild(container);
175+
map = new maptalks.Map(container, {
176+
center: [241.7567321978039, 210.07750904461014],
177+
zoom: 1,
178+
bearing : 153.60000000000036,
179+
pitch : 36,
180+
minZoom:1,
181+
maxZoom:18,
182+
spatialReference:{
183+
projection:'EPSG:4326'
184+
}
185+
});
186+
map.setBaseLayer(new maptalks.TileLayer('base', {
187+
tileSystem : [1, -1, -180, 90],
188+
crossOrigin:'Anonymous',
189+
urlTemplate:'#'
190+
}));
191+
setTimeout(function () {
192+
done();
193+
}, 20);
194+
});
195+
170196
it('baidu', function (done) {
171197
createMap();
172198
map.config({

0 commit comments

Comments
 (0)