More code clean up in Renderer

This commit is contained in:
Christian Paul 2017-12-23 00:49:37 -08:00
parent 0c27a79ad6
commit 0353effa67

View File

@ -57,10 +57,10 @@ class Renderer {
}).map((tile) => { }).map((tile) => {
return this._getTileFeatures(tile, zoom); return this._getTileFeatures(tile, zoom);
}).then((tiles) => { }).then((tiles) => {
return this._renderTiles(tiles); this._renderTiles(tiles);
}).then(() => { }).then(() => {
return this._getFrame(); return this._getFrame();
}).catch(function(e) { }).catch((e) => {
return console.log(e); return console.log(e);
}).finally((frame) => { }).finally((frame) => {
this.isDrawing = false; this.isDrawing = false;
@ -98,8 +98,8 @@ class Renderer {
tiles.push({ tiles.push({
xyz: tile, xyz: tile,
zoom: zoom, zoom,
position: position, position,
size: tileSize, size: tileSize,
}); });
} }
@ -159,7 +159,7 @@ class Renderer {
// drawn[feature.id] = true // drawn[feature.id] = true
if (layerId.match(/label/)) { if (layerId.match(/label/)) {
labels.push({ labels.push({
tile: tile, tile,
feature: feature, feature: feature,
scale: layer.scale scale: layer.scale
}); });
@ -169,14 +169,12 @@ class Renderer {
} }
} }
} }
labels.sort(function(a, b) { labels.sort((a, b) => {
return a.feature.sorty - b.feature.sort; return a.feature.sorty - b.feature.sort;
}); });
const results = [];
for (const label of labels) { for (const label of labels) {
results.push(this._drawFeature(label.tile, label.feature, label.scale)); this._drawFeature(label.tile, label.feature, label.scale);
} }
return results;
} }
_getFrame() { _getFrame() {
@ -194,7 +192,7 @@ class Renderer {
} }
_drawFeature(tile, feature, scale) { _drawFeature(tile, feature, scale) {
let points, placed, genericSymbol; let points, placed;
if (feature.style.minzoom && tile.zoom < feature.style.minzoom) { if (feature.style.minzoom && tile.zoom < feature.style.minzoom) {
return false; return false;
} else if (feature.style.maxzoom && tile.zoom > feature.style.maxzoom) { } else if (feature.style.maxzoom && tile.zoom > feature.style.maxzoom) {
@ -222,26 +220,30 @@ class Renderer {
break; break;
} }
case 'symbol': { case 'symbol': {
const text = feature.label || (genericSymbol = config.poiMarker); const genericSymbol = config.poiMarker;
const text = feature.label || config.poiMarker;
if (this._seen[text] && !genericSymbol) { if (this._seen[text] && !genericSymbol) {
return false; return false;
} }
placed = false; placed = false;
const points2 = this._scaleAndReduce(tile, feature, feature.points, scale); const pointsOfInterest = this._scaleAndReduce(tile, feature, feature.points, scale);
for (const point of points2) { for (const point of pointsOfInterest) {
let ref1, ref2;
const x = point.x - text.length; const x = point.x - text.length;
const margin = ((ref1 = config.layers[feature.layer]) != null ? ref1.margin : void 0) || config.labelMargin; const layerMargin = (config.layers[feature.layer] || {}).margin;
const margin = layerMargin || config.labelMargin;
if (this.labelBuffer.writeIfPossible(text, x, point.y, feature, margin)) { if (this.labelBuffer.writeIfPossible(text, x, point.y, feature, margin)) {
this.canvas.text(text, x, point.y, feature.color); this.canvas.text(text, x, point.y, feature.color);
placed = true; placed = true;
break; break;
} else if (((ref2 = config.layers[feature.layer]) != null ? ref2.cluster : void 0) && this.labelBuffer.writeIfPossible(config.poiMarker, point.x, point.y, feature, 3)) { } else {
this.canvas.text(config.poiMarker, point.x, point.y, feature.color); const cluster = (config.layers[feature.layer] || {}).cluster;
placed = true; if (cluster && this.labelBuffer.writeIfPossible(config.poiMarker, point.x, point.y, feature, 3)) {
break; this.canvas.text(config.poiMarker, point.x, point.y, feature.color);
placed = true;
break;
}
} }
} }
if (placed) { if (placed) {