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

Introduce within expression #9352

Merged
merged 14 commits into from
Mar 11, 2020
Merged
3 changes: 2 additions & 1 deletion bench/benchmarks/symbol_layout.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ export default class SymbolLayout extends Layout {
tileResult.glyphPositions,
tileResult.iconMap,
tileResult.imageAtlas.iconPositions,
false);
false,
tileResult.tileID.canonical);
}
}
});
Expand Down
3 changes: 2 additions & 1 deletion src/data/bucket.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import type FeatureIndex from './feature_index';
import type Context from '../gl/context';
import type {FeatureStates} from '../source/source_state';
import type {ImagePosition} from '../render/image_atlas';
import type {CanonicalTileID} from '../source/tile_id';

export type BucketParameters<Layer: TypedStyleLayer> = {
index: number,
Expand Down Expand Up @@ -74,7 +75,7 @@ export interface Bucket {
+layers: Array<any>;
+stateDependentLayers: Array<any>;
+stateDependentLayerIds: Array<string>;
populate(features: Array<IndexedFeature>, options: PopulateParameters): void;
populate(features: Array<IndexedFeature>, options: PopulateParameters, canonical: CanonicalTileID): void;
update(states: FeatureStates, vtLayer: VectorTileLayer, imagePositions: {[_: string]: ImagePosition}): void;
isEmpty(): boolean;

Expand Down
54 changes: 31 additions & 23 deletions src/data/bucket/circle_bucket.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import EXTENT from '../extent';
import {register} from '../../util/web_worker_transfer';
import EvaluationParameters from '../../style/evaluation_parameters';

import type {CanonicalTileID} from '../../source/tile_id';
import type {
Bucket,
BucketParameters,
Expand Down Expand Up @@ -75,7 +76,7 @@ class CircleBucket<Layer: CircleStyleLayer | HeatmapStyleLayer> implements Bucke
this.stateDependentLayerIds = this.layers.filter((l) => l.isStateDependent()).map((l) => l.id);
}

populate(features: Array<IndexedFeature>, options: PopulateParameters) {
populate(features: Array<IndexedFeature>, options: PopulateParameters, canonical: CanonicalTileID) {
const styleLayer = this.layers[0];
const bucketFeatures = [];
let circleSortKey = null;
Expand All @@ -86,25 +87,32 @@ class CircleBucket<Layer: CircleStyleLayer | HeatmapStyleLayer> implements Bucke
}

for (const {feature, id, index, sourceLayerIndex} of features) {
if (this.layers[0]._featureFilter(new EvaluationParameters(this.zoom), feature)) {
const geometry = loadGeometry(feature);
const sortKey = circleSortKey ?
circleSortKey.evaluate(feature, {}) :
undefined;

const bucketFeature: BucketFeature = {
id,
properties: feature.properties,
type: feature.type,
sourceLayerIndex,
index,
geometry,
patterns: {},
sortKey
};

bucketFeatures.push(bucketFeature);
}
const needGeometry = this.layers[0]._featureFilter.needGeometry;
const evaluationFeature = {type: feature.type,
id,
properties: feature.properties,
geometry: needGeometry ? loadGeometry(feature) : []};
zmiao marked this conversation as resolved.
Show resolved Hide resolved

if (!this.layers[0]._featureFilter.filter(new EvaluationParameters(this.zoom), evaluationFeature, canonical)) continue;

if (!needGeometry) evaluationFeature.geometry = loadGeometry(feature);
const sortKey = circleSortKey ?
circleSortKey.evaluate(evaluationFeature, {}, canonical) :
undefined;

const bucketFeature: BucketFeature = {
id,
properties: feature.properties,
type: feature.type,
sourceLayerIndex,
index,
geometry : evaluationFeature.geometry,
patterns: {},
sortKey
};

bucketFeatures.push(bucketFeature);

}

if (circleSortKey) {
Expand All @@ -118,7 +126,7 @@ class CircleBucket<Layer: CircleStyleLayer | HeatmapStyleLayer> implements Bucke
const {geometry, index, sourceLayerIndex} = bucketFeature;
const feature = features[index].feature;

this.addFeature(bucketFeature, geometry, index);
this.addFeature(bucketFeature, geometry, index, canonical);
options.featureIndex.insert(feature, geometry, index, sourceLayerIndex, this.index);
}
}
Expand Down Expand Up @@ -153,7 +161,7 @@ class CircleBucket<Layer: CircleStyleLayer | HeatmapStyleLayer> implements Bucke
this.segments.destroy();
}

addFeature(feature: BucketFeature, geometry: Array<Array<Point>>, index: number) {
addFeature(feature: BucketFeature, geometry: Array<Array<Point>>, index: number, canonical: CanonicalTileID) {
for (const ring of geometry) {
for (const point of ring) {
const x = point.x;
Expand Down Expand Up @@ -187,7 +195,7 @@ class CircleBucket<Layer: CircleStyleLayer | HeatmapStyleLayer> implements Bucke
}
}

this.programConfigurations.populatePaintArrays(this.layoutVertexArray.length, feature, index, {});
this.programConfigurations.populatePaintArrays(this.layoutVertexArray.length, feature, index, {}, canonical);
}
}

Expand Down
28 changes: 18 additions & 10 deletions src/data/bucket/fill_bucket.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {hasPattern, addPatternDependencies} from './pattern_bucket_features';
import loadGeometry from '../load_geometry';
import EvaluationParameters from '../../style/evaluation_parameters';

import type {CanonicalTileID} from '../../source/tile_id';
import type {
Bucket,
BucketParameters,
Expand Down Expand Up @@ -73,17 +74,24 @@ class FillBucket implements Bucket {
this.stateDependentLayerIds = this.layers.filter((l) => l.isStateDependent()).map((l) => l.id);
}

populate(features: Array<IndexedFeature>, options: PopulateParameters) {
populate(features: Array<IndexedFeature>, options: PopulateParameters, canonical: CanonicalTileID) {
this.hasPattern = hasPattern('fill', this.layers, options);
const fillSortKey = this.layers[0].layout.get('fill-sort-key');
const bucketFeatures = [];

for (const {feature, id, index, sourceLayerIndex} of features) {
if (!this.layers[0]._featureFilter(new EvaluationParameters(this.zoom), feature)) continue;
const needGeometry = this.layers[0]._featureFilter.needGeometry;
const evaluationFeature = {type: feature.type,
id,
properties: feature.properties,
geometry: needGeometry ? loadGeometry(feature) : []};

if (!this.layers[0]._featureFilter.filter(new EvaluationParameters(this.zoom), evaluationFeature, canonical)) continue;

if (!needGeometry) evaluationFeature.geometry = loadGeometry(feature);

const geometry = loadGeometry(feature);
const sortKey = fillSortKey ?
fillSortKey.evaluate(feature, {}, options.availableImages) :
fillSortKey.evaluate(evaluationFeature, {}, canonical, options.availableImages) :
undefined;

const bucketFeature: BucketFeature = {
Expand All @@ -92,7 +100,7 @@ class FillBucket implements Bucket {
type: feature.type,
sourceLayerIndex,
index,
geometry,
geometry: evaluationFeature.geometry,
patterns: {},
sortKey
};
Expand All @@ -116,7 +124,7 @@ class FillBucket implements Bucket {
// so are stored during populate until later updated with positions by tile worker in addFeatures
this.patternFeatures.push(patternFeature);
} else {
this.addFeature(bucketFeature, geometry, index, {});
this.addFeature(bucketFeature, geometry, index, canonical, {});
}

const feature = features[index].feature;
Expand All @@ -129,9 +137,9 @@ class FillBucket implements Bucket {
this.programConfigurations.updatePaintArrays(states, vtLayer, this.stateDependentLayers, imagePositions);
}

addFeatures(options: PopulateParameters, imagePositions: {[_: string]: ImagePosition}) {
addFeatures(options: PopulateParameters, canonical: CanonicalTileID, imagePositions: {[_: string]: ImagePosition}) {
for (const feature of this.patternFeatures) {
this.addFeature(feature, feature.geometry, feature.index, imagePositions);
this.addFeature(feature, feature.geometry, feature.index, canonical, imagePositions);
}
}

Expand Down Expand Up @@ -162,7 +170,7 @@ class FillBucket implements Bucket {
this.segments2.destroy();
}

addFeature(feature: BucketFeature, geometry: Array<Array<Point>>, index: number, imagePositions: {[_: string]: ImagePosition}) {
addFeature(feature: BucketFeature, geometry: Array<Array<Point>>, index: number, canonical: CanonicalTileID, imagePositions: {[_: string]: ImagePosition}) {
for (const polygon of classifyRings(geometry, EARCUT_MAX_RINGS)) {
let numVertices = 0;
for (const ring of polygon) {
Expand Down Expand Up @@ -216,7 +224,7 @@ class FillBucket implements Bucket {
triangleSegment.vertexLength += numVertices;
triangleSegment.primitiveLength += indices.length / 3;
}
this.programConfigurations.populatePaintArrays(this.layoutVertexArray.length, feature, index, imagePositions);
this.programConfigurations.populatePaintArrays(this.layoutVertexArray.length, feature, index, imagePositions, canonical);
}
}

Expand Down
25 changes: 15 additions & 10 deletions src/data/bucket/fill_extrusion_bucket.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {hasPattern, addPatternDependencies} from './pattern_bucket_features';
import loadGeometry from '../load_geometry';
import EvaluationParameters from '../../style/evaluation_parameters';

import type {CanonicalTileID} from '../../source/tile_id';
import type {
Bucket,
BucketParameters,
Expand Down Expand Up @@ -87,20 +88,24 @@ class FillExtrusionBucket implements Bucket {

}

populate(features: Array<IndexedFeature>, options: PopulateParameters) {
populate(features: Array<IndexedFeature>, options: PopulateParameters, canonical: CanonicalTileID) {
this.features = [];
this.hasPattern = hasPattern('fill-extrusion', this.layers, options);

for (const {feature, id, index, sourceLayerIndex} of features) {
if (!this.layers[0]._featureFilter(new EvaluationParameters(this.zoom), feature)) continue;
const needGeometry = this.layers[0]._featureFilter.needGeometry;
const evaluationFeature = {type: feature.type,
id,
properties: feature.properties,
geometry: needGeometry ? loadGeometry(feature) : []};

const geometry = loadGeometry(feature);
if (!this.layers[0]._featureFilter.filter(new EvaluationParameters(this.zoom), evaluationFeature, canonical)) continue;

const patternFeature: BucketFeature = {
id,
sourceLayerIndex,
index,
geometry,
geometry: needGeometry ? evaluationFeature.geometry : loadGeometry(feature),
properties: feature.properties,
type: feature.type,
patterns: {}
Expand All @@ -113,17 +118,17 @@ class FillExtrusionBucket implements Bucket {
if (this.hasPattern) {
this.features.push(addPatternDependencies('fill-extrusion', this.layers, patternFeature, this.zoom, options));
} else {
this.addFeature(patternFeature, geometry, index, {});
this.addFeature(patternFeature, patternFeature.geometry, index, canonical, {});
}

options.featureIndex.insert(feature, geometry, index, sourceLayerIndex, this.index, true);
options.featureIndex.insert(feature, patternFeature.geometry, index, sourceLayerIndex, this.index, true);
}
}

addFeatures(options: PopulateParameters, imagePositions: {[_: string]: ImagePosition}) {
addFeatures(options: PopulateParameters, canonical: CanonicalTileID, imagePositions: {[_: string]: ImagePosition}) {
for (const feature of this.features) {
const {geometry} = feature;
this.addFeature(feature, geometry, feature.index, imagePositions);
this.addFeature(feature, geometry, feature.index, canonical, imagePositions);
}
}

Expand Down Expand Up @@ -157,7 +162,7 @@ class FillExtrusionBucket implements Bucket {
this.segments.destroy();
}

addFeature(feature: BucketFeature, geometry: Array<Array<Point>>, index: number, imagePositions: {[_: string]: ImagePosition}) {
addFeature(feature: BucketFeature, geometry: Array<Array<Point>>, index: number, canonical: CanonicalTileID, imagePositions: {[_: string]: ImagePosition}) {
for (const polygon of classifyRings(geometry, EARCUT_MAX_RINGS)) {
let numVertices = 0;
for (const ring of polygon) {
Expand Down Expand Up @@ -263,7 +268,7 @@ class FillExtrusionBucket implements Bucket {
segment.vertexLength += numVertices;
}

this.programConfigurations.populatePaintArrays(this.layoutVertexArray.length, feature, index, imagePositions);
this.programConfigurations.populatePaintArrays(this.layoutVertexArray.length, feature, index, imagePositions, canonical);
}
}

Expand Down
32 changes: 20 additions & 12 deletions src/data/bucket/line_bucket.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {hasPattern, addPatternDependencies} from './pattern_bucket_features';
import loadGeometry from '../load_geometry';
import EvaluationParameters from '../../style/evaluation_parameters';

import type {CanonicalTileID} from '../../source/tile_id';
import type {
Bucket,
BucketParameters,
Expand Down Expand Up @@ -116,17 +117,24 @@ class LineBucket implements Bucket {
this.stateDependentLayerIds = this.layers.filter((l) => l.isStateDependent()).map((l) => l.id);
}

populate(features: Array<IndexedFeature>, options: PopulateParameters) {
populate(features: Array<IndexedFeature>, options: PopulateParameters, canonical: CanonicalTileID) {
this.hasPattern = hasPattern('line', this.layers, options);
const lineSortKey = this.layers[0].layout.get('line-sort-key');
const bucketFeatures = [];

for (const {feature, id, index, sourceLayerIndex} of features) {
if (!this.layers[0]._featureFilter(new EvaluationParameters(this.zoom), feature)) continue;
const needGeometry = this.layers[0]._featureFilter.needGeometry;
const evaluationFeature = {type: feature.type,
id,
properties: feature.properties,
geometry: needGeometry ? loadGeometry(feature) : []};

if (!this.layers[0]._featureFilter.filter(new EvaluationParameters(this.zoom), evaluationFeature, canonical)) continue;

if (!needGeometry) evaluationFeature.geometry = loadGeometry(feature);

const geometry = loadGeometry(feature);
const sortKey = lineSortKey ?
lineSortKey.evaluate(feature, {}) :
lineSortKey.evaluate(evaluationFeature, {}, canonical) :
undefined;

const bucketFeature: BucketFeature = {
Expand All @@ -135,7 +143,7 @@ class LineBucket implements Bucket {
type: feature.type,
sourceLayerIndex,
index,
geometry,
geometry: evaluationFeature.geometry,
patterns: {},
sortKey
};
Expand All @@ -159,7 +167,7 @@ class LineBucket implements Bucket {
// so are stored during populate until later updated with positions by tile worker in addFeatures
this.patternFeatures.push(patternBucketFeature);
} else {
this.addFeature(bucketFeature, geometry, index, {});
this.addFeature(bucketFeature, geometry, index, canonical, {});
}

const feature = features[index].feature;
Expand All @@ -172,9 +180,9 @@ class LineBucket implements Bucket {
this.programConfigurations.updatePaintArrays(states, vtLayer, this.stateDependentLayers, imagePositions);
}

addFeatures(options: PopulateParameters, imagePositions: {[_: string]: ImagePosition}) {
addFeatures(options: PopulateParameters, canonical: CanonicalTileID, imagePositions: {[_: string]: ImagePosition}) {
for (const feature of this.patternFeatures) {
this.addFeature(feature, feature.geometry, feature.index, imagePositions);
this.addFeature(feature, feature.geometry, feature.index, canonical, imagePositions);
}
}

Expand Down Expand Up @@ -203,19 +211,19 @@ class LineBucket implements Bucket {
this.segments.destroy();
}

addFeature(feature: BucketFeature, geometry: Array<Array<Point>>, index: number, imagePositions: {[_: string]: ImagePosition}) {
addFeature(feature: BucketFeature, geometry: Array<Array<Point>>, index: number, canonical: CanonicalTileID, imagePositions: {[_: string]: ImagePosition}) {
const layout = this.layers[0].layout;
const join = layout.get('line-join').evaluate(feature, {});
const cap = layout.get('line-cap');
const miterLimit = layout.get('line-miter-limit');
const roundLimit = layout.get('line-round-limit');

for (const line of geometry) {
this.addLine(line, feature, join, cap, miterLimit, roundLimit, index, imagePositions);
this.addLine(line, feature, join, cap, miterLimit, roundLimit, index, canonical, imagePositions);
}
}

addLine(vertices: Array<Point>, feature: BucketFeature, join: string, cap: string, miterLimit: number, roundLimit: number, index: number, imagePositions: {[_: string]: ImagePosition}) {
addLine(vertices: Array<Point>, feature: BucketFeature, join: string, cap: string, miterLimit: number, roundLimit: number, index: number, canonical: CanonicalTileID, imagePositions: {[_: string]: ImagePosition}) {
this.distance = 0;
this.scaledDistance = 0;
this.totalDistance = 0;
Expand Down Expand Up @@ -461,7 +469,7 @@ class LineBucket implements Bucket {
}
}

this.programConfigurations.populatePaintArrays(this.layoutVertexArray.length, feature, index, imagePositions);
this.programConfigurations.populatePaintArrays(this.layoutVertexArray.length, feature, index, imagePositions, canonical);
}

/**
Expand Down
Loading