1 | import StyleLayer from '../style_layer';
|
2 |
|
3 | import FillBucket from '../../data/bucket/fill_bucket';
|
4 | import {polygonIntersectsMultiPolygon} from '../../util/intersection_tests';
|
5 | import {translateDistance, translate} from '../query_utils';
|
6 | import properties, {FillLayoutPropsPossiblyEvaluated, FillPaintPropsPossiblyEvaluated} from './fill_style_layer_properties.g';
|
7 | import {Transitionable, Transitioning, Layout, PossiblyEvaluated} from '../properties';
|
8 |
|
9 | import type {FeatureState} from '../../style-spec/expression';
|
10 | import type {BucketParameters} from '../../data/bucket';
|
11 | import type Point from '@mapbox/point-geometry';
|
12 | import type {FillLayoutProps, FillPaintProps} from './fill_style_layer_properties.g';
|
13 | import type EvaluationParameters from '../evaluation_parameters';
|
14 | import type Transform from '../../geo/transform';
|
15 | import type {LayerSpecification} from '../../style-spec/types.g';
|
16 | import type {VectorTileFeature} from '@mapbox/vector-tile';
|
17 |
|
18 | class FillStyleLayer extends StyleLayer {
|
19 | _unevaluatedLayout: Layout<FillLayoutProps>;
|
20 | layout: PossiblyEvaluated<FillLayoutProps, FillLayoutPropsPossiblyEvaluated>;
|
21 |
|
22 | _transitionablePaint: Transitionable<FillPaintProps>;
|
23 | _transitioningPaint: Transitioning<FillPaintProps>;
|
24 | paint: PossiblyEvaluated<FillPaintProps, FillPaintPropsPossiblyEvaluated>;
|
25 |
|
26 | constructor(layer: LayerSpecification) {
|
27 | super(layer, properties);
|
28 | }
|
29 |
|
30 | recalculate(parameters: EvaluationParameters, availableImages: Array<string>) {
|
31 | super.recalculate(parameters, availableImages);
|
32 |
|
33 | const outlineColor = this.paint._values['fill-outline-color'];
|
34 | if (outlineColor.value.kind === 'constant' && outlineColor.value.value === undefined) {
|
35 | this.paint._values['fill-outline-color'] = this.paint._values['fill-color'];
|
36 | }
|
37 | }
|
38 |
|
39 | createBucket(parameters: BucketParameters<any>) {
|
40 | return new FillBucket(parameters);
|
41 | }
|
42 |
|
43 | queryRadius(): number {
|
44 | return translateDistance(this.paint.get('fill-translate'));
|
45 | }
|
46 |
|
47 | queryIntersectsFeature(
|
48 | queryGeometry: Array<Point>,
|
49 | feature: VectorTileFeature,
|
50 | featureState: FeatureState,
|
51 | geometry: Array<Array<Point>>,
|
52 | zoom: number,
|
53 | transform: Transform,
|
54 | pixelsToTileUnits: number
|
55 | ): boolean {
|
56 | const translatedPolygon = translate(queryGeometry,
|
57 | this.paint.get('fill-translate'),
|
58 | this.paint.get('fill-translate-anchor'),
|
59 | transform.angle, pixelsToTileUnits);
|
60 | return polygonIntersectsMultiPolygon(translatedPolygon, geometry);
|
61 | }
|
62 |
|
63 | isTileClipped() {
|
64 | return true;
|
65 | }
|
66 | }
|
67 |
|
68 | export default FillStyleLayer;
|