Skip to content

Commit

Permalink
implement symbol-sort
Browse files Browse the repository at this point in the history
  • Loading branch information
ansis committed Apr 7, 2015
1 parent 2ea1b1c commit 5bf094f
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions js/data/symbol_bucket.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ function SymbolBucket(buffers, layoutProperties, collision, overscaling, collisi
this.collision = collision;
this.overscaling = overscaling;
this.collisionDebug = collisionDebug;
this.sortedAngle = undefined;

this.symbolInstances = [];

Expand Down Expand Up @@ -191,6 +192,22 @@ SymbolBucket.prototype.placeFeatures = function(buffers, collisionDebug) {
var textAlongLine = layout['text-rotation-alignment'] === 'map' && layout['symbol-placement'] === 'line';
var iconAlongLine = layout['icon-rotation-alignment'] === 'map' && layout['symbol-placement'] === 'line';

if (layout['symbol-sort'] !== undefined && this.sortedAngle !== this.collision.angle) {

var sortAngle = layout['symbol-sort'] / 180 * Math.PI;
var angle = this.collision.angle - sortAngle;
var sin = Math.sin(angle),
cos = Math.cos(angle);

this.symbolInstances.sort(function(a, b) {
var aRotated = sin * a.x + cos * a.y;
var bRotated = sin * b.x + cos * b.y;
return bRotated - aRotated;
});

this.sortedAngle = this.collision.angle;
}

for (var p = 0; p < this.symbolInstances.length; p++) {
var symbolInstance = this.symbolInstances[p];
var hasText = symbolInstance.hasText;
Expand Down Expand Up @@ -397,6 +414,9 @@ function SymbolInstance(anchor, line, shapedText, shapedIcon, layout, inside,
textBoxScale, textPadding, textAlongLine,
iconBoxScale, iconPadding, iconAlongLine) {

this.x = anchor.x;
this.y = anchor.y;

this.hasText = !!shapedText;
this.hasIcon = !!shapedIcon;

Expand All @@ -409,4 +429,5 @@ function SymbolInstance(anchor, line, shapedText, shapedIcon, layout, inside,
this.iconQuads = inside ? getIconQuads(anchor, shapedIcon, iconBoxScale, line, layout, iconAlongLine) : [];
this.iconCollisionFeature = new CollisionFeature(line, anchor, shapedIcon, iconBoxScale, iconPadding, iconAlongLine);
}

}

0 comments on commit 5bf094f

Please sign in to comment.