Speed up rendering by not using alpha
This commit is contained in:
@@ -62,7 +62,10 @@ export function createHitDetectionImageData(size, transforms, features, styleFun
|
||||
const image = originalStyle.getImage();
|
||||
if (image) {
|
||||
const imgSize = image.getImageSize();
|
||||
const imgContext = createCanvasContext2D(imgSize[0], imgSize[1]);
|
||||
const canvas = document.createElement('canvas');
|
||||
canvas.width = imgSize[0];
|
||||
canvas.height = imgSize[1];
|
||||
const imgContext = canvas.getContext('2d', {alpha: false});
|
||||
imgContext.fillStyle = color;
|
||||
const img = imgContext.canvas;
|
||||
imgContext.fillRect(0, 0, img.width, img.height);
|
||||
@@ -133,14 +136,11 @@ export function hitDetect(pixel, features, imageData) {
|
||||
const r = imageData.data[index];
|
||||
const g = imageData.data[index + 1];
|
||||
const b = imageData.data[index + 2];
|
||||
const a = imageData.data[index + 3];
|
||||
if (a === 255) {
|
||||
const i = b + (256 * (g + (256 * r)));
|
||||
const indexFactor = Math.ceil((256 * 256 * 256) / features.length);
|
||||
if (i % indexFactor === 0) {
|
||||
resultFeatures.push(features[i / indexFactor]);
|
||||
}
|
||||
}
|
||||
}
|
||||
return resultFeatures;
|
||||
}
|
||||
|
||||
@@ -430,10 +430,9 @@ class CanvasVectorTileLayerRenderer extends CanvasTileLayerRenderer {
|
||||
}
|
||||
const extent = tileGrid.getTileCoordExtent(tile.wrappedTileCoord);
|
||||
const corner = getTopLeft(extent);
|
||||
const renderScale = tileGrid.getResolution(tileCoord[0]) / resolution;
|
||||
const tilePixel = [
|
||||
(coordinate[0] - corner[0]) / resolution / renderScale,
|
||||
(corner[1] - coordinate[1]) / resolution / renderScale
|
||||
(coordinate[0] - corner[0]) / resolution,
|
||||
(corner[1] - coordinate[1]) / resolution
|
||||
];
|
||||
const features = tile.getSourceTiles().reduce(function(accumulator, sourceTile) {
|
||||
return accumulator.concat(sourceTile.getFeatures());
|
||||
@@ -444,12 +443,13 @@ class CanvasVectorTileLayerRenderer extends CanvasTileLayerRenderer {
|
||||
const rotation = this.renderedRotation_;
|
||||
const transforms = [
|
||||
this.getRenderTransform(tileGrid.getTileCoordCenter(tile.wrappedTileCoord),
|
||||
resolution * renderScale, 0, 0.5, size[0], size[1], 0)
|
||||
resolution, 0, 0.5, size[0], size[1], 0)
|
||||
];
|
||||
requestAnimationFrame(function() {
|
||||
tile.hitDetectionImageData = createHitDetectionImageData(tileSize, transforms,
|
||||
features, layer.getStyleFunction(),
|
||||
tileGrid.getTileCoordExtent(tile.wrappedTileCoord), resolution, rotation);
|
||||
tileGrid.getTileCoordExtent(tile.wrappedTileCoord),
|
||||
tile.getReplayState(layer).renderedResolution, rotation);
|
||||
resolve(hitDetect(tilePixel, features, tile.hitDetectionImageData));
|
||||
});
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user