Merge pull request #6493 from ahocevar/vectortile-cleanup
Vector tile cleanup
This commit is contained in:
@@ -71,7 +71,7 @@ ol.layer.VectorTile.prototype.createRenderer = function(mapRenderer) {
|
|||||||
* @api
|
* @api
|
||||||
*/
|
*/
|
||||||
ol.layer.VectorTile.prototype.getPreload = function() {
|
ol.layer.VectorTile.prototype.getPreload = function() {
|
||||||
return /** @type {number} */ (this.get(ol.layer.VectorTile.Property_.PRELOAD));
|
return /** @type {number} */ (this.get(ol.layer.TileProperty.PRELOAD));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@@ -91,7 +91,7 @@ ol.layer.VectorTile.prototype.getRenderMode = function() {
|
|||||||
*/
|
*/
|
||||||
ol.layer.VectorTile.prototype.getUseInterimTilesOnError = function() {
|
ol.layer.VectorTile.prototype.getUseInterimTilesOnError = function() {
|
||||||
return /** @type {boolean} */ (
|
return /** @type {boolean} */ (
|
||||||
this.get(ol.layer.VectorTile.Property_.USE_INTERIM_TILES_ON_ERROR));
|
this.get(ol.layer.TileProperty.USE_INTERIM_TILES_ON_ERROR));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@@ -116,13 +116,3 @@ ol.layer.VectorTile.prototype.setUseInterimTilesOnError = function(useInterimTil
|
|||||||
this.set(
|
this.set(
|
||||||
ol.layer.TileProperty.USE_INTERIM_TILES_ON_ERROR, useInterimTilesOnError);
|
ol.layer.TileProperty.USE_INTERIM_TILES_ON_ERROR, useInterimTilesOnError);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @enum {string}
|
|
||||||
* @private
|
|
||||||
*/
|
|
||||||
ol.layer.VectorTile.Property_ = {
|
|
||||||
PRELOAD: 'preload',
|
|
||||||
USE_INTERIM_TILES_ON_ERROR: 'useInterimTilesOnError'
|
|
||||||
};
|
|
||||||
|
|||||||
@@ -29,12 +29,6 @@ ol.renderer.canvas.IntermediateCanvas = function(layer) {
|
|||||||
*/
|
*/
|
||||||
this.hitCanvasContext_ = null;
|
this.hitCanvasContext_ = null;
|
||||||
|
|
||||||
/**
|
|
||||||
* @protected
|
|
||||||
* @type {number}
|
|
||||||
*/
|
|
||||||
this.renderedResolution;
|
|
||||||
|
|
||||||
};
|
};
|
||||||
ol.inherits(ol.renderer.canvas.IntermediateCanvas, ol.renderer.canvas.Layer);
|
ol.inherits(ol.renderer.canvas.IntermediateCanvas, ol.renderer.canvas.Layer);
|
||||||
|
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ ol.renderer.canvas.TileLayer = function(tileLayer) {
|
|||||||
* @protected
|
* @protected
|
||||||
* @type {CanvasRenderingContext2D}
|
* @type {CanvasRenderingContext2D}
|
||||||
*/
|
*/
|
||||||
this.context = ol.dom.createCanvasContext2D();
|
this.context = this.context === null ? null : ol.dom.createCanvasContext2D();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @private
|
* @private
|
||||||
@@ -178,19 +178,20 @@ ol.renderer.canvas.TileLayer.prototype.prepareFrame = function(frameState, layer
|
|||||||
this.renderedRevision != sourceRevision) ||
|
this.renderedRevision != sourceRevision) ||
|
||||||
oversampling != this.oversampling_) {
|
oversampling != this.oversampling_) {
|
||||||
|
|
||||||
var tilePixelSize = tileSource.getTilePixelSize(z, pixelRatio, projection);
|
|
||||||
var width = Math.round(tileRange.getWidth() * tilePixelSize[0] / oversampling);
|
|
||||||
var height = Math.round(tileRange.getHeight() * tilePixelSize[1] / oversampling);
|
|
||||||
var context = this.context;
|
var context = this.context;
|
||||||
var canvas = context.canvas;
|
if (context) {
|
||||||
var opaque = tileSource.getOpaque(projection);
|
var tilePixelSize = tileSource.getTilePixelSize(z, pixelRatio, projection);
|
||||||
if (canvas.width != width || canvas.height != height) {
|
var width = Math.round(tileRange.getWidth() * tilePixelSize[0] / oversampling);
|
||||||
this.oversampling_ = oversampling;
|
var height = Math.round(tileRange.getHeight() * tilePixelSize[1] / oversampling);
|
||||||
canvas.width = width;
|
var canvas = context.canvas;
|
||||||
canvas.height = height;
|
if (canvas.width != width || canvas.height != height) {
|
||||||
} else {
|
this.oversampling_ = oversampling;
|
||||||
context.clearRect(0, 0, width, height);
|
canvas.width = width;
|
||||||
oversampling = this.oversampling_;
|
canvas.height = height;
|
||||||
|
} else {
|
||||||
|
context.clearRect(0, 0, width, height);
|
||||||
|
oversampling = this.oversampling_;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
this.renderedTiles.length = 0;
|
this.renderedTiles.length = 0;
|
||||||
@@ -213,9 +214,6 @@ ol.renderer.canvas.TileLayer.prototype.prepareFrame = function(frameState, layer
|
|||||||
y = (imageExtent[3] - tileExtent[3]) / tileResolution * tilePixelRatio / oversampling;
|
y = (imageExtent[3] - tileExtent[3]) / tileResolution * tilePixelRatio / oversampling;
|
||||||
w = currentTilePixelSize[0] * currentScale / oversampling;
|
w = currentTilePixelSize[0] * currentScale / oversampling;
|
||||||
h = currentTilePixelSize[1] * currentScale / oversampling;
|
h = currentTilePixelSize[1] * currentScale / oversampling;
|
||||||
if (!opaque) {
|
|
||||||
context.clearRect(x, y, w, h);
|
|
||||||
}
|
|
||||||
this.drawTileImage(tile, frameState, layerState, x, y, w, h, tileGutter);
|
this.drawTileImage(tile, frameState, layerState, x, y, w, h, tileGutter);
|
||||||
this.renderedTiles.push(tile);
|
this.renderedTiles.push(tile);
|
||||||
}
|
}
|
||||||
@@ -261,6 +259,9 @@ ol.renderer.canvas.TileLayer.prototype.prepareFrame = function(frameState, layer
|
|||||||
* @param {number} gutter Tile gutter.
|
* @param {number} gutter Tile gutter.
|
||||||
*/
|
*/
|
||||||
ol.renderer.canvas.TileLayer.prototype.drawTileImage = function(tile, frameState, layerState, x, y, w, h, gutter) {
|
ol.renderer.canvas.TileLayer.prototype.drawTileImage = function(tile, frameState, layerState, x, y, w, h, gutter) {
|
||||||
|
if (!this.getLayer().getSource().getOpaque(frameState.viewState.projection)) {
|
||||||
|
this.context.clearRect(x, y, w, h);
|
||||||
|
}
|
||||||
var image = tile.getImage();
|
var image = tile.getImage();
|
||||||
if (image) {
|
if (image) {
|
||||||
this.context.drawImage(image, gutter, gutter,
|
this.context.drawImage(image, gutter, gutter,
|
||||||
@@ -273,7 +274,8 @@ ol.renderer.canvas.TileLayer.prototype.drawTileImage = function(tile, frameState
|
|||||||
* @inheritDoc
|
* @inheritDoc
|
||||||
*/
|
*/
|
||||||
ol.renderer.canvas.TileLayer.prototype.getImage = function() {
|
ol.renderer.canvas.TileLayer.prototype.getImage = function() {
|
||||||
return this.context.canvas;
|
var context = this.context;
|
||||||
|
return context ? context.canvas : null;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
goog.provide('ol.renderer.canvas.VectorTileLayer');
|
goog.provide('ol.renderer.canvas.VectorTileLayer');
|
||||||
|
|
||||||
goog.require('ol');
|
goog.require('ol');
|
||||||
|
goog.require('ol.dom');
|
||||||
goog.require('ol.extent');
|
goog.require('ol.extent');
|
||||||
goog.require('ol.proj');
|
goog.require('ol.proj');
|
||||||
goog.require('ol.proj.Units');
|
goog.require('ol.proj.Units');
|
||||||
@@ -22,6 +23,8 @@ goog.require('ol.transform');
|
|||||||
*/
|
*/
|
||||||
ol.renderer.canvas.VectorTileLayer = function(layer) {
|
ol.renderer.canvas.VectorTileLayer = function(layer) {
|
||||||
|
|
||||||
|
this.context = null;
|
||||||
|
|
||||||
ol.renderer.canvas.TileLayer.call(this, layer);
|
ol.renderer.canvas.TileLayer.call(this, layer);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -74,9 +77,17 @@ ol.renderer.canvas.VectorTileLayer.VECTOR_REPLAYS = {
|
|||||||
* @inheritDoc
|
* @inheritDoc
|
||||||
*/
|
*/
|
||||||
ol.renderer.canvas.VectorTileLayer.prototype.prepareFrame = function(frameState, layerState) {
|
ol.renderer.canvas.VectorTileLayer.prototype.prepareFrame = function(frameState, layerState) {
|
||||||
var layerRevision = this.getLayer().getRevision();
|
var layer = this.getLayer();
|
||||||
|
var layerRevision = layer.getRevision();
|
||||||
if (this.renderedLayerRevision_ != layerRevision) {
|
if (this.renderedLayerRevision_ != layerRevision) {
|
||||||
this.renderedTiles.length = 0;
|
this.renderedTiles.length = 0;
|
||||||
|
var renderMode = layer.getRenderMode();
|
||||||
|
if (!this.context && renderMode != ol.layer.VectorTileRenderType.VECTOR) {
|
||||||
|
this.context = ol.dom.createCanvasContext2D();
|
||||||
|
}
|
||||||
|
if (this.context && renderMode == ol.layer.VectorTileRenderType.VECTOR) {
|
||||||
|
this.context = null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
this.renderedLayerRevision_ = layerRevision;
|
this.renderedLayerRevision_ = layerRevision;
|
||||||
return ol.renderer.canvas.TileLayer.prototype.prepareFrame.apply(this, arguments);
|
return ol.renderer.canvas.TileLayer.prototype.prepareFrame.apply(this, arguments);
|
||||||
@@ -184,11 +195,10 @@ ol.renderer.canvas.VectorTileLayer.prototype.drawTileImage = function(
|
|||||||
tile, frameState, layerState, x, y, w, h, gutter) {
|
tile, frameState, layerState, x, y, w, h, gutter) {
|
||||||
var vectorTile = /** @type {ol.VectorTile} */ (tile);
|
var vectorTile = /** @type {ol.VectorTile} */ (tile);
|
||||||
this.createReplayGroup_(vectorTile, frameState);
|
this.createReplayGroup_(vectorTile, frameState);
|
||||||
var layer = this.getLayer();
|
if (this.context) {
|
||||||
if (layer.getRenderMode() != ol.layer.VectorTileRenderType.VECTOR) {
|
|
||||||
this.renderTileImage_(vectorTile, frameState, layerState);
|
this.renderTileImage_(vectorTile, frameState, layerState);
|
||||||
|
ol.renderer.canvas.TileLayer.prototype.drawTileImage.apply(this, arguments);
|
||||||
}
|
}
|
||||||
ol.renderer.canvas.TileLayer.prototype.drawTileImage.apply(this, arguments);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ ol.VectorTile = function(tileCoord, state, src, format, tileLoadFunction) {
|
|||||||
* @private
|
* @private
|
||||||
* @type {CanvasRenderingContext2D}
|
* @type {CanvasRenderingContext2D}
|
||||||
*/
|
*/
|
||||||
this.context_ = ol.dom.createCanvasContext2D();
|
this.context_ = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @private
|
* @private
|
||||||
@@ -83,6 +83,9 @@ ol.inherits(ol.VectorTile, ol.Tile);
|
|||||||
* @return {CanvasRenderingContext2D} The rendering context.
|
* @return {CanvasRenderingContext2D} The rendering context.
|
||||||
*/
|
*/
|
||||||
ol.VectorTile.prototype.getContext = function() {
|
ol.VectorTile.prototype.getContext = function() {
|
||||||
|
if (!this.context_) {
|
||||||
|
this.context_ = ol.dom.createCanvasContext2D();
|
||||||
|
}
|
||||||
return this.context_;
|
return this.context_;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user