Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable property functions for text-field, text-transform #4074

Merged
merged 6 commits into from
Feb 2, 2017
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions js/data/bucket/symbol_bucket.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,11 +119,10 @@ class SymbolBucket {

populate(features, options) {
const layout = this.layers[0].layout;
const textField = layout['text-field'];
const textFont = layout['text-font'];
const iconImage = layout['icon-image'];

const hasText = textField && textFont;
const hasText = layout['text-field'] && textFont;
const hasIcon = iconImage;

this.features = [];
Expand All @@ -144,10 +143,9 @@ class SymbolBucket {

let text;
if (hasText) {
text = resolveText(this.layers[0], {zoom: this.zoom}, feature.properties);
if (rtlTextPlugin.applyArabicShaping) {
text = rtlTextPlugin.applyArabicShaping(resolveText(feature, layout));
} else {
text = resolveText(feature, layout);
text = rtlTextPlugin.applyArabicShaping(text);
}
}

Expand Down
4 changes: 3 additions & 1 deletion js/style-spec/reference/v8.json
Original file line number Diff line number Diff line change
Expand Up @@ -1082,9 +1082,10 @@
"type": "string",
"function": "piecewise-constant",
"zoom-function": true,
"property-function": true,
"default": "",
"tokens": true,
"doc": "Value to use for a text label. Feature properties are specified using tokens like {field_name}.",
"doc": "Value to use for a text label. Feature properties are specified using tokens like {field_name}. (Token replacement is only supported for literal text-field values--not for data-driven property functions.)",
"sdk-support": {
"basic functionality": {
"js": "0.10.0",
Expand Down Expand Up @@ -1369,6 +1370,7 @@
"type": "enum",
"function": "piecewise-constant",
"zoom-function": true,
"property-function": true,
"values": {
"none": {
"doc": "The text is not altered."
Expand Down
9 changes: 6 additions & 3 deletions js/symbol/resolve_text.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,17 @@

const resolveTokens = require('../util/token');

module.exports = function resolveText(feature, layout) {
let text = resolveTokens(feature.properties, layout['text-field']);
module.exports = function resolveText(layer, globalProperties, featureProperties) {
let text = layer.getLayoutValue('text-field', globalProperties, featureProperties);
if (layer.isLayoutValueFeatureConstant('text-field')) {
text = resolveTokens(featureProperties, text);
}
if (!text) {
return;
}
text = text.toString();

const transform = layout['text-transform'];
const transform = layer.getLayoutValue('text-transform', globalProperties, featureProperties);
if (transform === 'uppercase') {
text = text.toLocaleUpperCase();
} else if (transform === 'lowercase') {
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
56 changes: 56 additions & 0 deletions test/integration/render-tests/text-field/literal/style.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
{
"version": 8,
"metadata": {
"test": {
"height": 256
}
},
"center": [
13.418056,
52.499167
],
"zoom": 14,
"sources": {
"point": {
"type": "geojson",
"data": {
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"properties": {},
"geometry": {
"type": "Point",
"coordinates": [
13.418056,
52.499167
]
}
}
]
}
}
},
"glyphs": "local://glyphs/{fontstack}/{range}.pbf",
"layers": [
{
"id": "background",
"type": "background",
"paint": {
"background-color": "white"
}
},
{
"id": "text",
"type": "symbol",
"source": "point",
"layout": {
"text-field": "Test",
"text-font": [
"Open Sans Semibold",
"Arial Unicode MS Bold"
]
}
}
]
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
{
"version": 8,
"metadata": {
"test": {
"height": 256,
"skipped": {
"native": "needs issue"
}
}
},
"center": [
13.418056,
52.499167
],
"zoom": 14,
"sources": {
"point": {
"type": "geojson",
"data": {
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"properties": { "x": 1 },
"geometry": {
"type": "Point",
"coordinates": [
13.413056,
52.499167
]
}
},
{
"type": "Feature",
"properties": { "x": 0 },
"geometry": {
"type": "Point",
"coordinates": [
13.423056,
52.499167
]
}
}
]
}
}
},
"glyphs": "local://glyphs/{fontstack}/{range}.pbf",
"layers": [
{
"id": "background",
"type": "background",
"paint": {
"background-color": "white"
}
},
{
"id": "text",
"type": "symbol",
"source": "point",
"layout": {
"text-field": {
"type": "categorical",
"property": "x",
"stops": [
[0, "Zero"],
[1, "One"]
]
},
"text-font": [
"Open Sans Semibold",
"Arial Unicode MS Bold"
]
}
}
]
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
67 changes: 67 additions & 0 deletions test/integration/render-tests/text-field/token/style.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
{
"version": 8,
"metadata": {
"test": {
"height": 256
}
},
"center": [
13.418056,
52.499167
],
"zoom": 14,
"sources": {
"point": {
"type": "geojson",
"data": {
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"properties": { "x": 1 },
"geometry": {
"type": "Point",
"coordinates": [
13.413056,
52.499167
]
}
},
{
"type": "Feature",
"properties": { "x": 0 },
"geometry": {
"type": "Point",
"coordinates": [
13.423056,
52.499167
]
}
}
]
}
}
},
"glyphs": "local://glyphs/{fontstack}/{range}.pbf",
"layers": [
{
"id": "background",
"type": "background",
"paint": {
"background-color": "white"
}
},
{
"id": "text",
"type": "symbol",
"source": "point",
"layout": {
"text-field": "Test {x}",
"text-font": [
"Open Sans Semibold",
"Arial Unicode MS Bold"
]
}
}
]
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
{
"version": 8,
"metadata": {
"test": {
"height": 256,
"skipped": {
"native": "needs issue"
}
}
},
"center": [
13.418056,
52.499167
],
"zoom": 14,
"sources": {
"point": {
"type": "geojson",
"data": {
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"properties": { "x": 0 },
"geometry": {
"type": "Point",
"coordinates": [
13.413056,
52.499167
]
}
},
{
"type": "Feature",
"properties": { "x": 1 },
"geometry": {
"type": "Point",
"coordinates": [
13.423056,
52.499167
]
}
}
]
}
}
},
"glyphs": "local://glyphs/{fontstack}/{range}.pbf",
"layers": [
{
"id": "background",
"type": "background",
"paint": {
"background-color": "white"
}
},
{
"id": "text",
"type": "symbol",
"source": "point",
"layout": {
"text-field": "hello",
"text-transform": {
"type": "categorical",
"property": "x",
"stops": [
[0, "uppercase"],
[1, "lowercase"]
]
},
"text-font": [
"Open Sans Semibold",
"Arial Unicode MS Bold"
]
}
}
]
}
Loading