diff --git a/src/layer/tile/TileLayer.js b/src/layer/tile/TileLayer.js index 6aa9f9d86..0623e4710 100644 --- a/src/layer/tile/TileLayer.js +++ b/src/layer/tile/TileLayer.js @@ -145,7 +145,7 @@ const options = { 'tileLimitPerFrame': 0, 'tileStackStartDepth': 7, - 'tileStackDepth': 5, + 'tileStackDepth': 6, 'awareOfTerrain': true, 'bufferPixel': 0.5, @@ -1407,5 +1407,5 @@ function distanceToRect(min, max, xyz) { function sortingTiles(t0, t1) { - return t0.z - t1.z; + return t1.z - t0.z; } diff --git a/src/renderer/layer/tilelayer/TileLayerCanvasRenderer.js b/src/renderer/layer/tilelayer/TileLayerCanvasRenderer.js index 1de84e529..62fbaa063 100644 --- a/src/renderer/layer/tilelayer/TileLayerCanvasRenderer.js +++ b/src/renderer/layer/tilelayer/TileLayerCanvasRenderer.js @@ -185,11 +185,11 @@ class TileLayerCanvasRenderer extends CanvasRenderer { placeholders = [], placeholderKeys = {}; //visit all the tiles const tileQueue = {}; - const preLoadingCount = this.markTiles(), - loadingLimit = this._getLoadLimit(); + const preLoadingCount = this.markTiles(); + const loadingLimit = this._getLoadLimit(); const l = tileGrids.length; - + const isFirstRender = this._tileZoom === undefined; // main tile grid is the last one (draws on top) this._tileZoom = tileGrids[0]['zoom']; @@ -207,7 +207,7 @@ class TileLayerCanvasRenderer extends CanvasRenderer { const gridTiles = tileGrid['tiles']; const parents = tileGrid['parents'] || EMPTY_ARRAY; const parentCount = parents.length; - const allTiles = parents.concat(gridTiles); + const allTiles = isFirstRender ? gridTiles : parents.concat(gridTiles); let placeholder; if (allTiles.length) { @@ -425,6 +425,8 @@ class TileLayerCanvasRenderer extends CanvasRenderer { } } + const renderInGL = this.layer.options.renderer === 'gl' && (!this.isGL || this.isGL()); + const context = { tiles, parentTiles: this._parentTiles, childTiles: this._childTiles, parentContext }; this.onDrawTileStart(context, parentContext); @@ -432,13 +434,15 @@ class TileLayerCanvasRenderer extends CanvasRenderer { this.layer._silentConfig = true; const fadingAnimation = this.layer.options['fadeAnimation']; this.layer.options['fadeAnimation'] = false; - // _hasOwnSR 时,瓦片之间会有重叠,会产生z-fighting,所以背景瓦片要后绘制 - this.drawingChildTiles = true; - this._childTiles.forEach(t => this._drawTile(t.info, t.image, parentContext)); - delete this.drawingChildTiles; - this.drawingParentTiles = true; - this._parentTiles.forEach(t => this._drawTile(t.info, t.image, parentContext)); - delete this.drawingParentTiles; + + if (renderInGL) { + this._drawChildTiles(childTiles, parentContext); + this._drawParentTiles(this._parentTiles, parentContext); + } else { + this._drawParentTiles(this._parentTiles, parentContext); + this._drawChildTiles(childTiles, parentContext); + } + this.layer.options['fadeAnimation'] = fadingAnimation; this.layer._silentConfig = false; } @@ -454,12 +458,15 @@ class TileLayerCanvasRenderer extends CanvasRenderer { this.layer._silentConfig = true; const fadingAnimation = this.layer.options['fadeAnimation']; this.layer.options['fadeAnimation'] = false; - this.drawingChildTiles = true; - this._childTiles.forEach(t => this._drawTile(t.info, t.image, parentContext)); - delete this.drawingChildTiles; - this.drawingParentTiles = true; - this._parentTiles.forEach(t => this._drawTile(t.info, t.image, parentContext)); - delete this.drawingParentTiles; + + if (renderInGL) { + this._drawChildTiles(childTiles, parentContext); + this._drawParentTiles(this._parentTiles, parentContext); + } else { + this._drawParentTiles(this._parentTiles, parentContext); + this._drawChildTiles(childTiles, parentContext); + } + this.layer.options['fadeAnimation'] = fadingAnimation; this.layer._silentConfig = false; } @@ -470,6 +477,19 @@ class TileLayerCanvasRenderer extends CanvasRenderer { } + _drawChildTiles(childTiles, parentContext) { + // _hasOwnSR 时,瓦片之间会有重叠,会产生z-fighting,所以背景瓦片要后绘制 + this.drawingChildTiles = true; + childTiles.forEach(t => this._drawTile(t.info, t.image, parentContext)); + delete this.drawingChildTiles; + } + + _drawParentTiles(parentTiles, parentContext) { + this.drawingParentTiles = true; + this._parentTiles.forEach(t => this._drawTile(t.info, t.image, parentContext)); + delete this.drawingParentTiles; + } + onDrawTileStart() { } onDrawTileEnd() { } @@ -1166,6 +1186,7 @@ class TileLayerCanvasRenderer extends CanvasRenderer { this.clear(); delete this.tileCache; delete this._tilePlaceHolder; + delete this._tileZoom; super.onRemove(); } diff --git a/src/renderer/layer/tilelayer/TileLayerGLRenderer.js b/src/renderer/layer/tilelayer/TileLayerGLRenderer.js index 152b33932..94772c4f2 100644 --- a/src/renderer/layer/tilelayer/TileLayerGLRenderer.js +++ b/src/renderer/layer/tilelayer/TileLayerGLRenderer.js @@ -29,7 +29,7 @@ class TileLayerGLRenderer extends ImageGLRenderable(TileLayerCanvasRenderer) { needToRedraw() { const map = this.getMap(); - if (this._gl() && !map.getPitch() && map.isZooming() && !map.isMoving() && !map.isRotating()) { + if (this.isGL() && !map.getPitch() && map.isZooming() && !map.isMoving() && !map.isRotating()) { return true; } return super.needToRedraw(); @@ -81,7 +81,7 @@ class TileLayerGLRenderer extends ImageGLRenderable(TileLayerCanvasRenderer) { if (tileInfo.cache !== false) { this._bindGLBuffer(tileImage, w, h); } - if (!this._gl()) { + if (!this.isGL()) { // fall back to canvas 2D, which is faster super.drawTile(tileInfo, tileImage); return; @@ -153,7 +153,7 @@ class TileLayerGLRenderer extends ImageGLRenderable(TileLayerCanvasRenderer) { } getCanvasImage() { - if (!this._gl() || !this.canvas2) { + if (!this.isGL() || !this.canvas2) { return super.getCanvasImage(); } const img = super.getCanvasImage(); @@ -165,7 +165,7 @@ class TileLayerGLRenderer extends ImageGLRenderable(TileLayerCanvasRenderer) { // decide whether the layer is renderer with gl. // when map is pitching, or fragmentShader is set in options - _gl() { + isGL() { if (this.canvas.gl && this.canvas.gl.wrap) { //in GroupGLLayer return true;