Skip to content

Commit

Permalink
more placement cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
ansis committed Mar 9, 2015
1 parent 6b3b6f0 commit d744fb2
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 33 deletions.
46 changes: 22 additions & 24 deletions js/data/symbol_bucket.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,13 @@ SymbolBucket.prototype.addFeatures = function() {
var fontstack = layout['text-font'];

var geometries = [];

for (var g = 0; g < features.length; g++) {
geometries.push(features[g].loadGeometry());
}

if (layout['symbol-placement'] === 'line') {
// Merge adjacent lines with the same text to improve labelling.
// It's better to place labels on one long line than on many short segments.
var merged = mergeLines(features, textFeatures, geometries);

geometries = merged.geometries;
Expand All @@ -88,15 +89,16 @@ SymbolBucket.prototype.addFeatures = function() {
for (var k = 0; k < features.length; k++) {
if (!geometries[k]) continue;

var shapedText = false;
var shapedText, shapedIcon;

if (textFeatures[k]) {
shapedText = shapeText(textFeatures[k], this.stacks[fontstack].glyphs, maxWidth,
shapedText = shapeText(textFeatures[k], this.stacks[fontstack], maxWidth,
lineHeight, horizontalAlign, verticalAlign, justify, spacing, textOffset);
}

var shapedIcon = false;
if (this.icons && layout['icon-image']) {
var image = this.icons[resolveTokens(features[k].properties, layout['icon-image'])];
if (layout['icon-image']) {
var iconName = resolveTokens(features[k].properties, layout['icon-image']);
var image = this.icons[iconName];
shapedIcon = shapeIcon(image, layout);

if (image) {
Expand Down Expand Up @@ -293,47 +295,46 @@ SymbolBucket.prototype.getDependencies = function(tile, actor, callback) {
this.getTextDependencies(tile, actor, done);
this.getIconDependencies(tile, actor, done);
function done(err) {
if (err || firstdone) callback(err);
if (err || firstdone) return callback(err);
firstdone = true;
}
};

SymbolBucket.prototype.getIconDependencies = function(tile, actor, callback) {
if (this.layoutProperties['icon-image']) {
var features = this.features;
var layoutProperties = this.layoutProperties;
var icons = resolveIcons(features, layoutProperties);
var icons = resolveIcons(features, this.layoutProperties);

if (icons.length) {
actor.send('get icons', {
id: tile.id,
icons: icons
}, function(err, newicons) {
if (err) return callback(err);
this.icons = newicons;
callback();
}.bind(this));
}, setIcons.bind(this));
} else {
callback();
}
} else {
callback();
}

function setIcons(err, newicons) {
if (err) return callback(err);
this.icons = newicons;
callback();
}
};

SymbolBucket.prototype.getTextDependencies = function(tile, actor, callback) {
var features = this.features;
var layoutProperties = this.layoutProperties;
var fontstack = this.layoutProperties['text-font'];

if (tile.stacks === undefined) tile.stacks = {};
var stacks = this.stacks = tile.stacks;
var fontstack = layoutProperties['text-font'];
if (stacks[fontstack] === undefined) {
stacks[fontstack] = { glyphs: {} };
stacks[fontstack] = {};
}
var stack = stacks[fontstack];

var data = resolveText(features, layoutProperties, stack.glyphs);
var data = resolveText(features, this.layoutProperties, stack);
this.textFeatures = data.textFeatures;

actor.send('get glyphs', {
Expand All @@ -343,11 +344,8 @@ SymbolBucket.prototype.getTextDependencies = function(tile, actor, callback) {
}, function(err, newstack) {
if (err) return callback(err);

var newglyphs = newstack.glyphs;
var glyphs = stack.glyphs;

for (var codepoint in newglyphs) {
glyphs[codepoint] = newglyphs[codepoint];
for (var codepoint in newstack) {
stack[codepoint] = newstack[codepoint];
}

callback();
Expand Down
1 change: 1 addition & 0 deletions js/source/tile_pyramid.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ TilePyramid.prototype = {

// Removes tiles that are outside the viewport and adds new tiles that are inside the viewport.
update: function(used, transform, fadeDuration) {
if (window.no) return;

This comment has been minimized.

Copy link
@mourner

mourner Mar 10, 2015

Member

wat?

This comment has been minimized.

Copy link
@ansis

ansis Mar 10, 2015

Author Contributor

Yeah, that snuck into the commit. It was cleaned up in a later commit

var i;
var id;
var tile;
Expand Down
2 changes: 2 additions & 0 deletions js/source/worker_tile.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ function WorkerTile(id, zoom, maxZoom, tileSize, source, overscaling, angle, xhr
this.angle = angle;
this.xhr = xhr;

this.stacks = {};

this.status = 'loading';
}

Expand Down
5 changes: 2 additions & 3 deletions js/symbol/glyph_source.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ GlyphSource.prototype.getSimpleGlyphs = function(fontstack, glyphIDs, tileID, ca
if (this.stacks[fontstack] === undefined) this.stacks[fontstack] = {};

var glyphs = {};
var result = { glyphs: glyphs };

var stack = this.stacks[fontstack];
var glyphAtlas = this.glyphAtlas;
Expand Down Expand Up @@ -48,7 +47,7 @@ GlyphSource.prototype.getSimpleGlyphs = function(fontstack, glyphIDs, tileID, ca
}
}

if (!remaining) callback(undefined, result);
if (!remaining) callback(undefined, glyphs);

var onRangeLoaded = function(err, range, data) {
// TODO not be silent about errors
Expand All @@ -62,7 +61,7 @@ GlyphSource.prototype.getSimpleGlyphs = function(fontstack, glyphIDs, tileID, ca
}
}
remaining--;
if (!remaining) callback(undefined, result);
if (!remaining) callback(undefined, glyphs);
}.bind(this);

for (var r in missing) {
Expand Down
3 changes: 0 additions & 3 deletions shaders/icon.vertex.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,6 @@ void main() {

float a_fadedist = 10.0;

// If the label should be invisible, we move the vertex outside
// of the view plane so that the triangle gets clipped. This makes it easier
// for us to create degenerate triangle strips.
// u_zoom is the current zoom level adjusted for the change in font size
float z = 2.0 - step(a_minzoom, u_zoom) - (1.0 - step(a_maxzoom, u_zoom));

Expand Down
3 changes: 0 additions & 3 deletions shaders/sdf.vertex.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,6 @@ void main() {
float a_minzoom = a_zoom[0];
float a_maxzoom = a_zoom[1];

// If the label should be invisible, we move the vertex outside
// of the view plane so that the triangle gets clipped. This makes it easier
// for us to create degenerate triangle strips.
// u_zoom is the current zoom level adjusted for the change in font size
float z = 2.0 - step(a_minzoom, u_zoom) - (1.0 - step(a_maxzoom, u_zoom));

Expand Down

0 comments on commit d744fb2

Please sign in to comment.