Skip to content

Commit

Permalink
Support multiple symbol placements. Also inadvertently supports dupli…
Browse files Browse the repository at this point in the history
…cate feature IDs :(
  • Loading branch information
Asheem Mamoowala committed Mar 9, 2018
1 parent b9e457f commit d1cd559
Showing 1 changed file with 24 additions and 19 deletions.
43 changes: 24 additions & 19 deletions src/data/program_configuration.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ import type {PossiblyEvaluated} from '../style/properties';
import type {FeatureStates} from '../source/source_state';

type FeaturePaintBufferMap = {
[feature_id: string]: {
[feature_id: string]: Array<{
index: number,
start: number,
length: number
}
}>
};

function packColor(color: Color): [number, number] {
Expand Down Expand Up @@ -377,11 +377,13 @@ class ProgramConfiguration {
}

if (feature.id && index) {
this._idMap[feature.id] = {
const featureId = String(feature.id);
this._idMap[featureId] = this._idMap[featureId] || [];
this._idMap[featureId].push({
index: index,
start: this._bufferPos,
length: length
};
});
}

this._bufferPos = length;
Expand All @@ -390,21 +392,24 @@ class ProgramConfiguration {
updatePaintArrays(featureStates: FeatureStates, vtLayer: VectorTileLayer, layer: TypedStyleLayer): boolean {
let dirty: boolean = false;
for (const id in featureStates) {
const pos = this._idMap[id];

if (pos) {
const feature: any = vtLayer.feature(pos.index);
feature.state = featureStates[id];

for (const property in this.binders) {
const binder: Binder<any> = this.binders[property];
if (binder instanceof ConstantBinder) continue;
if ((binder: any).expression.isStateDependent === true) {
//AHM: Remove after https://github.com/mapbox/mapbox-gl-js/issues/6255
const value = layer.paint.get(property);
(binder: any).expression = value.value;
binder.updatePaintArray(pos.start, pos.length, feature);
dirty = true;
const posArray = this._idMap[id];

if (posArray) {
for (let i = 0; i < posArray.length; i++) {
const pos = posArray[i];
const feature: any = vtLayer.feature(pos.index);
feature.state = featureStates[id];

for (const property in this.binders) {
const binder: Binder<any> = this.binders[property];
if (binder instanceof ConstantBinder) continue;
if ((binder: any).expression.isStateDependent === true) {
//AHM: Remove after https://github.com/mapbox/mapbox-gl-js/issues/6255
const value = layer.paint.get(property);
(binder: any).expression = value.value;
binder.updatePaintArray(pos.start, pos.length, feature);
dirty = true;
}
}
}
}
Expand Down

0 comments on commit d1cd559

Please sign in to comment.