Skip to content

Commit

Permalink
optimize line dash recalculation
Browse files Browse the repository at this point in the history
  • Loading branch information
mourner committed Mar 4, 2016
1 parent c369202 commit 61ca1c8
Showing 1 changed file with 11 additions and 12 deletions.
23 changes: 11 additions & 12 deletions js/style/style_layer/line_style_layer.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,21 @@ module.exports = LineStyleLayer;
LineStyleLayer.prototype = util.inherit(StyleLayer, {

getPaintValue: function(name, zoom, zoomHistory) {
var output = StyleLayer.prototype.getPaintValue.call(this, name, zoom, zoomHistory);
var value = StyleLayer.prototype.getPaintValue.call(this, name, zoom, zoomHistory);

// If the line is dashed, scale the dash lengths by the line
// width at the previous round zoom level.
if (output && name === 'line-dasharray') {
var lineWidth = this.getPaintValue('line-width', Math.floor(zoom), Infinity);
output.fromScale *= lineWidth;
output.toScale *= lineWidth;
if (value && name === 'line-dasharray') {
var flooredZoom = Math.floor(zoom);
if (this._flooredZoom !== flooredZoom) {
this._flooredZoom = flooredZoom;
this._flooredLineWidth = this.getPaintValue('line-width', flooredZoom, Infinity);
}

value.fromScale *= this._flooredLineWidth;
value.toScale *= this._flooredLineWidth;
}

return output;
},

recalculate: function(zoom, zoomHistory) {
StyleLayer.prototype.recalculate.call(this, zoom, zoomHistory);
var key = 'line-dasharray';
if (this._paintTransitions[key]) this.paint[key] = this.getPaintValue(key, zoom, zoomHistory);
return value;
}
});

0 comments on commit 61ca1c8

Please sign in to comment.