-
Notifications
You must be signed in to change notification settings - Fork 2.2k
/
symbol_style_layer.js
86 lines (70 loc) · 2.9 KB
/
symbol_style_layer.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
// @flow
const StyleLayer = require('../style_layer');
const SymbolBucket = require('../../data/bucket/symbol_bucket');
const resolveTokens = require('../../util/token');
const {isExpression} = require('../../style-spec/expression');
const assert = require('assert');
const properties = require('./symbol_style_layer_properties');
const {
Transitionable,
Transitioning,
Layout,
PossiblyEvaluated
} = require('../properties');
import type {BucketParameters} from '../../data/bucket';
import type {LayoutProps, PaintProps} from './symbol_style_layer_properties';
import type {Feature} from '../../style-spec/expression';
import type EvaluationParameters from '../evaluation_parameters';
class SymbolStyleLayer extends StyleLayer {
_unevaluatedLayout: Layout<LayoutProps>;
layout: PossiblyEvaluated<LayoutProps>;
_transitionablePaint: Transitionable<PaintProps>;
_transitioningPaint: Transitioning<PaintProps>;
paint: PossiblyEvaluated<PaintProps>;
constructor(layer: LayerSpecification) {
super(layer, properties);
}
recalculate(parameters: EvaluationParameters) {
super.recalculate(parameters);
if (this.layout.get('icon-rotation-alignment') === 'auto') {
if (this.layout.get('symbol-placement') === 'line') {
this.layout._values['icon-rotation-alignment'] = 'map';
} else {
this.layout._values['icon-rotation-alignment'] = 'viewport';
}
}
if (this.layout.get('text-rotation-alignment') === 'auto') {
if (this.layout.get('symbol-placement') === 'line') {
this.layout._values['text-rotation-alignment'] = 'map';
} else {
this.layout._values['text-rotation-alignment'] = 'viewport';
}
}
// If unspecified, `*-pitch-alignment` inherits `*-rotation-alignment`
if (this.layout.get('text-pitch-alignment') === 'auto') {
this.layout._values['text-pitch-alignment'] = this.layout.get('text-rotation-alignment');
}
if (this.layout.get('icon-pitch-alignment') === 'auto') {
this.layout._values['icon-pitch-alignment'] = this.layout.get('icon-rotation-alignment');
}
}
getValueAndResolveTokens(name: *, feature: Feature) {
const value = this.layout.get(name).evaluate(feature);
const unevaluated = this._unevaluatedLayout._values[name];
if (!unevaluated.isDataDriven() && !isExpression(unevaluated.value)) {
return resolveTokens(feature.properties, value);
}
return value;
}
createBucket(parameters: BucketParameters<*>) {
return new SymbolBucket(parameters);
}
queryRadius(): number {
return 0;
}
queryIntersectsFeature(): boolean {
assert(false); // Should take a different path in FeatureIndex
return false;
}
}
module.exports = SymbolStyleLayer;