Skip to content

Commit

Permalink
populate paint arrays for all layers with dds line-pattern
Browse files Browse the repository at this point in the history
  • Loading branch information
Molly Lloyd committed Mar 13, 2018
1 parent 5f52312 commit d42aee4
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 27 deletions.
50 changes: 27 additions & 23 deletions src/data/bucket/line_bucket.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { LineLayoutArray } from '../array_types';

import { members as layoutAttributes } from './line_attributes';
import SegmentVector from '../segment';
import { ProgramConfigurationSet, SourceExpressionBinder, CompositeExpressionBinder } from '../program_configuration';
import { ProgramConfigurationSet } from '../program_configuration';
import { TriangleIndexArray } from '../index_array_type';
import loadGeometry from '../load_geometry';
import EXTENT from '../extent';
Expand Down Expand Up @@ -135,16 +135,14 @@ class LineBucket implements Bucket {
this.programConfigurations = new ProgramConfigurationSet(layoutAttributes, options.layers, options.zoom);
this.segments = new SegmentVector();

this.dataDrivenPattern = false;
this.dataDrivenPattern = [];

for (const key in this.programConfigurations) {
const programConfiguration = this.programConfigurations[key];
for (const layer in programConfiguration) {
const binders = programConfiguration[layer].binders;
if (binders && binders['line-pattern'] && binders['line-pattern'].paintVertexArray) {
this.dataDrivenPattern = true;
break;
}

for (let i = 0; i < this.layerIds.length; i++) {
const id = this.layerIds[i];
const programConfiguration = this.programConfigurations.get(id);
if (programConfiguration.binders && programConfiguration.binders['line-pattern'] && programConfiguration.binders['line-pattern'].isDataDriven()) {
this.dataDrivenPattern.push(i);
}
}
}
Expand All @@ -154,18 +152,21 @@ class LineBucket implements Bucket {
this.features = [];
for (const {feature, index, sourceLayerIndex} of features) {
if (!this.layers[0]._featureFilter({zoom: this.zoom}, feature)) continue;
if (this.dataDrivenPattern) {
const layer = this.layers[0];
const linePattern = layer.paint.get('line-pattern');
const image = linePattern.evaluate(feature);
if (image) {
icons[image.min] = true;
icons[image.mid] = true;
icons[image.max] = true;
if (this.dataDrivenPattern.length) {
for (let i = 0; i < this.dataDrivenPattern.length; i++) {
const layerIdx = this.dataDrivenPattern[i];
const layer = this.layers[layerIdx];
const linePattern = layer.paint.get('line-pattern');
const image = linePattern.evaluate(feature);
if (image) {
icons[image.min] = true;
icons[image.mid] = true;
icons[image.max] = true;
}
}

const geometry = loadGeometry(feature);
const lineFeature: LineFeature = {
image: image,
sourceLayerIndex: sourceLayerIndex,
index: index,
geometry: geometry,
Expand Down Expand Up @@ -497,13 +498,16 @@ class LineBucket implements Bucket {
populatePatternPaintArray(length: number, feature: VectorTileFeature | LineFeature) {
for (const layer of this.layers) {
const programConfiguration = this.programConfigurations.get(layer.id);
if (programConfiguration.binders && programConfiguration.binders['line-pattern'] && (programConfiguration.binders['line-pattern'] instanceof SourceExpressionBinder || programConfiguration.binders['line-pattern'] instanceof CompositeExpressionBinder)) {
if (programConfiguration.binders && programConfiguration.binders['line-pattern'] &&
programConfiguration.binders['line-pattern'].isDataDriven()) {

const linePattern = layer.paint.get('line-pattern');
const image = linePattern.evaluate(feature);
const paintArray = programConfiguration.binders['line-pattern'].paintVertexArray;
const start = paintArray.length;

paintArray.reserve(length);
if (feature.image) {
const image = (feature.image: any);
if (image) {
paintArray.reserve(length);
const imageMin = this.imagePositions[image.min];
const imageMid = this.imagePositions[image.mid];
const imageMax = this.imagePositions[image.max];
Expand Down
19 changes: 15 additions & 4 deletions src/data/program_configuration.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ interface Binder<T> {
destroy(): void;

defines(): Array<string>;
isDataDriven(): boolean;

setUniforms(context: Context,
program: Program,
Expand All @@ -84,6 +85,10 @@ class ConstantBinder<T> implements Binder<T> {
return this.names.map(name => `#define HAS_UNIFORM_u_${name}`);
}

isDataDriven() {
return false;
}

populatePaintArray() {}
upload() {}
destroy() {}
Expand Down Expand Up @@ -136,6 +141,10 @@ class SourceExpressionBinder<T> implements Binder<T> {
return [];
}

isDataDriven() {
return true;
}

populatePaintArray(length: number, feature: Feature) {
const paintArray = this.paintVertexArray;

Expand Down Expand Up @@ -211,6 +220,10 @@ class CompositeExpressionBinder<T> implements Binder<T> {
return [];
}

isDataDriven() {
return true;
}

populatePaintArray(length: number, feature: Feature) {
const paintArray = this.paintVertexArray;

Expand Down Expand Up @@ -475,10 +488,8 @@ register('ProgramConfigurationSet', ProgramConfigurationSet);

const exported = {
ProgramConfiguration,
ProgramConfigurationSet,
CompositeExpressionBinder,
SourceExpressionBinder
ProgramConfigurationSet
};

export default exported;
export { ProgramConfiguration, ProgramConfigurationSet, CompositeExpressionBinder, SourceExpressionBinder };
export { ProgramConfiguration, ProgramConfigurationSet };

0 comments on commit d42aee4

Please sign in to comment.