Skip to content

Commit

Permalink
fix icon-size for small data-driven values
Browse files Browse the repository at this point in the history
fix #7017
fix #7066
  • Loading branch information
ansis committed Aug 14, 2018
1 parent 3b0a1a9 commit 2284ac9
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 13 deletions.
4 changes: 2 additions & 2 deletions src/shaders/symbol_icon.vertex.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ void main() {

float size;
if (!u_is_size_zoom_constant && !u_is_size_feature_constant) {
size = mix(a_size[0], a_size[1], u_size_t) / 10.0;
size = mix(a_size[0], a_size[1], u_size_t) / 256.0;
} else if (u_is_size_zoom_constant && !u_is_size_feature_constant) {
size = a_size[0] / 10.0;
size = a_size[0] / 256.0;
} else if (!u_is_size_zoom_constant && u_is_size_feature_constant) {
size = u_size;
} else {
Expand Down
4 changes: 2 additions & 2 deletions src/shaders/symbol_sdf.vertex.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ void main() {
float size;

if (!u_is_size_zoom_constant && !u_is_size_feature_constant) {
size = mix(a_size[0], a_size[1], u_size_t) / 10.0;
size = mix(a_size[0], a_size[1], u_size_t) / 256.0;
} else if (u_is_size_zoom_constant && !u_is_size_feature_constant) {
size = a_size[0] / 10.0;
size = a_size[0] / 256.0;
} else if (!u_is_size_zoom_constant && u_is_size_feature_constant) {
size = u_size;
} else {
Expand Down
13 changes: 7 additions & 6 deletions src/symbol/symbol_layout.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import EXTENT from '../data/extent';
import SymbolBucket from '../data/bucket/symbol_bucket';
import EvaluationParameters from '../style/evaluation_parameters';
import {Formatted} from '../style-spec/expression/definitions/formatted';
import {SIZE_PACK_FACTOR} from './symbol_size';

import type {Shaping, PositionedIcon} from './shaping';
import type {CollisionBoxArray} from '../data/array_types';
Expand Down Expand Up @@ -289,12 +290,12 @@ function addTextVertices(bucket: SymbolBucket,

if (sizeData.functionType === 'source') {
textSizeData = [
10 * layer.layout.get('text-size').evaluate(feature, {})
SIZE_PACK_FACTOR * layer.layout.get('text-size').evaluate(feature, {})
];
} else if (sizeData.functionType === 'composite') {
textSizeData = [
10 * sizes.compositeTextSizes[0].evaluate(feature, {}),
10 * sizes.compositeTextSizes[1].evaluate(feature, {})
SIZE_PACK_FACTOR * sizes.compositeTextSizes[0].evaluate(feature, {}),
SIZE_PACK_FACTOR * sizes.compositeTextSizes[1].evaluate(feature, {})
];
}

Expand Down Expand Up @@ -382,12 +383,12 @@ function addSymbol(bucket: SymbolBucket,

if (sizeData.functionType === 'source') {
iconSizeData = [
10 * layer.layout.get('icon-size').evaluate(feature, {})
SIZE_PACK_FACTOR * layer.layout.get('icon-size').evaluate(feature, {})
];
} else if (sizeData.functionType === 'composite') {
iconSizeData = [
10 * sizes.compositeIconSizes[0].evaluate(feature, {}),
10 * sizes.compositeIconSizes[1].evaluate(feature, {})
SIZE_PACK_FACTOR * sizes.compositeIconSizes[0].evaluate(feature, {}),
SIZE_PACK_FACTOR * sizes.compositeIconSizes[1].evaluate(feature, {})
];
}

Expand Down
8 changes: 5 additions & 3 deletions src/symbol/symbol_size.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ import type {Property, PropertyValue, PossiblyEvaluatedPropertyValue} from '../s
import type {CameraExpression, CompositeExpression} from '../style-spec/expression/index';
import type {PropertyValueSpecification} from '../style-spec/types';

export { getSizeData, evaluateSizeForFeature, evaluateSizeForZoom };
const SIZE_PACK_FACTOR = 256;

export { getSizeData, evaluateSizeForFeature, evaluateSizeForZoom, SIZE_PACK_FACTOR };

export type SizeData = {
functionType: 'constant',
Expand Down Expand Up @@ -89,9 +91,9 @@ function evaluateSizeForFeature(sizeData: SizeData,
symbol: { lowerSize: number, upperSize: number}) {
const part = partiallyEvaluatedSize;
if (sizeData.functionType === 'source') {
return symbol.lowerSize / 10;
return symbol.lowerSize / SIZE_PACK_FACTOR;
} else if (sizeData.functionType === 'composite') {
return interpolate(symbol.lowerSize / 10, symbol.upperSize / 10, part.uSizeT);
return interpolate(symbol.lowerSize / SIZE_PACK_FACTOR, symbol.upperSize / SIZE_PACK_FACTOR, part.uSizeT);
} else {
return part.uSize;
}
Expand Down
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,40 @@
{
"version": 8,
"metadata": {
"test": {
"pixelRatio": 10,
"width": 24,
"height": 24
}
},
"sources": {
"geojson": {
"type": "geojson",
"data": {
"type": "Feature",
"properties": {
"size": 0.05
},
"geometry": {
"type": "Point",
"coordinates": [
0,
0
]
}
}
}
},
"sprite": "local://sprites/emerald",
"layers": [
{
"id": "symbol",
"type": "symbol",
"source": "geojson",
"layout": {
"icon-size": ["get", "size"],
"icon-image": "generic_icon"
}
}
]
}

0 comments on commit 2284ac9

Please sign in to comment.