translate as a text bucket property

When used, text is translated before being checked for collisions.
This commit is contained in:
Ansis Brammanis
2014-05-30 03:50:25 -04:00
parent 41c310c762
commit 7c653895c6
4 changed files with 21 additions and 13 deletions

View File

@@ -765,8 +765,7 @@ module.exports = {
"path": "horizontal",
"font": "Open Sans Semibold, Arial Unicode MS Bold",
"fontSize": 18,
"maxWidth": 2,
"lineHeight": 1.4,
"maxWidth": 6,
"feature_type": "point",
"type": "text"
},
@@ -880,6 +879,9 @@ module.exports = {
"text_field": "name",
"path": "horizontal",
"padding": 2,
"maxWidth": 8,
"verticalAlignment": "top",
"translate": [0, -1],
"font": "Open Sans Semibold, Arial Unicode MS Bold",
"fontSize": 11,
"feature_type": "point",
@@ -893,6 +895,9 @@ module.exports = {
"text_field": "name",
"path": "horizontal",
"padding": 2,
"maxWidth": 8,
"verticalAlignment": "top",
"translate": [0, -1],
"font": "Open Sans Semibold, Arial Unicode MS Bold",
"fontSize": 10,
"feature_type": "point",
@@ -906,6 +911,9 @@ module.exports = {
"text_field": "name",
"path": "horizontal",
"padding": 2,
"maxWidth": 8,
"verticalAlignment": "top",
"translate": [0, -1],
"font": "Open Sans Semibold, Arial Unicode MS Bold",
"fontSize": 10,
"feature_type": "point",
@@ -2417,7 +2425,6 @@ module.exports = {
"stroke": "land",
"strokeWidth": 0.3,
"strokeBlur": 1,
"translate": [0, 14]
},
"poi_label_3": {
"color": "#444",
@@ -2425,7 +2432,6 @@ module.exports = {
"stroke": "land",
"strokeWidth": 0.3,
"strokeBlur": 1,
"translate": [0, 14],
"opacity": [
"stops",
{"z": 16.5, "val": 0},
@@ -2443,7 +2449,6 @@ module.exports = {
"stroke": "land",
"strokeWidth": 0.3,
"strokeBlur": 1,
"translate": [0, 14]
},
"poi_aerodrome": {
"opacity": ["stops",
@@ -3169,7 +3174,6 @@ module.exports = {
"stroke": "text2_stroke_night",
"strokeWidth": 0.3,
"strokeBlur": 1,
"translate": [0, 14]
},
"poi_label_3": {
"color": "#fff",
@@ -3177,7 +3181,6 @@ module.exports = {
"stroke": "text2_stroke_night",
"strokeWidth": 0.3,
"strokeBlur": 1,
"translate": [0, 14],
"opacity": [
"stops",
{"z": 16.5, "val": 0},
@@ -3195,7 +3198,6 @@ module.exports = {
"stroke": "text2_stroke_night",
"strokeWidth": 0.3,
"strokeBlur": 1,
"translate": [0, 14]
},
"poi_aerodrome": {
"opacity": ["stops",

View File

@@ -6,6 +6,7 @@
#include <cmath>
#include "value.hpp"
#include "../util/vec.hpp"
namespace llmr {
@@ -95,6 +96,7 @@ public:
float vertical_alignment = 0.5;
float line_height = 1.2 * 24;
float max_width = 15.0f * 24;
vec2<float> translate {0, 0};
float padding = 2.0f;
float textMinDistance = 250.0f;
float rotate = 0.0f; // what is this?

View File

@@ -108,11 +108,18 @@ BucketDescription StyleParser::parseBucket(JSVal value) {
} else {
throw Style::exception("alignment must be a string");
}
} else if (name == "translate") {
if (value.IsArray()) {
bucket.geometry.translate.x = value[(rapidjson::SizeType)0].GetDouble() * 24;
bucket.geometry.translate.y = value[(rapidjson::SizeType)1].GetDouble() * -24;
} else {
throw Style::exception("translate must be a string");
}
} else if (name == "verticalAlignment") {
if (value.IsString()) {
bucket.geometry.vertical_alignment = verticalAlignmentType({ value.GetString(), value.GetStringLength() });
} else {
throw Style::exception("alignment must be a string");
throw Style::exception("verticalAlignment must be a string");
}
} else if (name == "lineHeight") {
if (value.IsNumber()) {

View File

@@ -260,9 +260,6 @@ void Placement::addFeature(TextBucket& bucket,
Anchors anchors;
// TODO: figure out correct ascender height.
vec2<float> origin{0, 0};
if (line.size() == 1) {
// Point labels
anchors = Anchors{{Anchor{
@@ -282,7 +279,7 @@ void Placement::addFeature(TextBucket& bucket,
PlacedGlyphs glyphs;
GlyphBoxes boxes;
getGlyphs(glyphs, boxes, anchor, origin, shaping, face, fontScale, horizontal,
getGlyphs(glyphs, boxes, anchor, info.translate, shaping, face, fontScale, horizontal,
line, maxAngleDelta, rotate);
PlacementProperty place =
collision.place(boxes, anchor, anchor.scale, maxPlacementScale,