From d744fb2ace194cc65106027e1c14c1a6729906af Mon Sep 17 00:00:00 2001 From: Ansis Brammanis Date: Mon, 9 Mar 2015 12:00:08 -0700 Subject: [PATCH] more placement cleanup --- js/data/symbol_bucket.js | 46 +++++++++++++++++++-------------------- js/source/tile_pyramid.js | 1 + js/source/worker_tile.js | 2 ++ js/symbol/glyph_source.js | 5 ++--- shaders/icon.vertex.glsl | 3 --- shaders/sdf.vertex.glsl | 3 --- 6 files changed, 27 insertions(+), 33 deletions(-) diff --git a/js/data/symbol_bucket.js b/js/data/symbol_bucket.js index a63477e570e..7b758234abb 100644 --- a/js/data/symbol_bucket.js +++ b/js/data/symbol_bucket.js @@ -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; @@ -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) { @@ -293,7 +295,7 @@ 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; } }; @@ -301,39 +303,38 @@ SymbolBucket.prototype.getDependencies = function(tile, actor, callback) { 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', { @@ -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(); diff --git a/js/source/tile_pyramid.js b/js/source/tile_pyramid.js index 8aa8c9144fd..092d8132bfd 100644 --- a/js/source/tile_pyramid.js +++ b/js/source/tile_pyramid.js @@ -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; var i; var id; var tile; diff --git a/js/source/worker_tile.js b/js/source/worker_tile.js index d3d7000651b..cc197286ddf 100644 --- a/js/source/worker_tile.js +++ b/js/source/worker_tile.js @@ -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'; } diff --git a/js/symbol/glyph_source.js b/js/symbol/glyph_source.js index 41c9b17c5cb..4f8d254d5f0 100644 --- a/js/symbol/glyph_source.js +++ b/js/symbol/glyph_source.js @@ -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; @@ -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 @@ -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) { diff --git a/shaders/icon.vertex.glsl b/shaders/icon.vertex.glsl index 49af0a24f41..019b40f612e 100644 --- a/shaders/icon.vertex.glsl +++ b/shaders/icon.vertex.glsl @@ -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)); diff --git a/shaders/sdf.vertex.glsl b/shaders/sdf.vertex.glsl index 93842f6657a..741334f2277 100644 --- a/shaders/sdf.vertex.glsl +++ b/shaders/sdf.vertex.glsl @@ -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));