@mapwhit/style-expressions
Version:
Process expressions in map style.
37 lines (30 loc) • 801 B
JavaScript
import { Color } from './values.js';
const geometryTypes = ['Unknown', 'Point', 'LineString', 'Polygon'];
export default class EvaluationContext {
constructor() {
this.globals = null;
this.feature = null;
this.featureState = null;
this._parseColorCache = {};
}
id() {
return this.feature && 'id' in this.feature ? this.feature.id : null;
}
geometryType() {
return this.feature
? typeof this.feature.type === 'number'
? geometryTypes[this.feature.type]
: this.feature.type
: null;
}
properties() {
return this.feature?.properties || {};
}
parseColor(input) {
let cached = this._parseColorCache[input];
if (!cached) {
cached = this._parseColorCache[input] = Color.parse(input);
}
return cached;
}
}