Skip to content

Commit

Permalink
Fix depth picking from GeoJSON layer for binary features (#7817)
Browse files Browse the repository at this point in the history
Co-authored-by: Xiaoji Chen <Pessimistress@users.noreply.github.com>
  • Loading branch information
gabeboning and Pessimistress committed Apr 26, 2023
1 parent 7927265 commit c695825
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 5 deletions.
33 changes: 30 additions & 3 deletions modules/core/src/lib/layer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,9 @@ import type {PickingInfo, GetPickingInfoParams} from './picking/pick-info';
import type Viewport from '../viewports/viewport';
import type {NumericArray} from '../types/types';
import type {DefaultProps} from '../lifecycle/prop-types';
import type {LayerProps} from '../types/layer-props';
import type {LayerData, LayerProps} from '../types/layer-props';
import type {LayerContext} from './layer-manager';
import type {BinaryAttribute} from './attribute/attribute';

const TRACE_CHANGE_FLAG = 'layer.changeFlag';
const TRACE_INITIALIZE = 'layer.initialize';
Expand Down Expand Up @@ -745,8 +746,34 @@ export default abstract class Layer<PropsT extends {} = {}> extends Component<

/** (Internal) Sets the picking color at the specified index to null picking color. Used for multi-depth picking.
This method may be overriden by layer implementations */
disablePickingIndex(objectIndex: number): void {
this._disablePickingIndex(objectIndex);
disablePickingIndex(objectIndex: number) {
const data = this.props.data as LayerData<any>;
if (!('attributes' in data)) {
this._disablePickingIndex(objectIndex);
return;
}

// @ts-ignore (TS2531) this method is only called internally with attributeManager defined
const {pickingColors, instancePickingColors} = this.getAttributeManager().attributes;
const colors = pickingColors || instancePickingColors;
const externalColorAttribute =
colors && data.attributes && (data.attributes[colors.id] as BinaryAttribute);
if (externalColorAttribute && externalColorAttribute.value) {
const values = externalColorAttribute.value;
const objectColor = this.encodePickingColor(objectIndex);
for (let index = 0; index < data.length; index++) {
const i = colors.getVertexOffset(index);
if (
values[i] === objectColor[0] &&
values[i + 1] === objectColor[1] &&
values[i + 2] === objectColor[2]
) {
this._disablePickingIndex(index);
}
}
} else {
this._disablePickingIndex(objectIndex);
}
}

// TODO - simplify subclassing interface
Expand Down
2 changes: 1 addition & 1 deletion modules/layers/src/path-layer/path-layer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ export default class PathLayer<DataT = any, ExtraPropsT extends {} = {}> extends
}
}
} else {
this._disablePickingIndex(objectIndex);
super.disablePickingIndex(objectIndex);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ export default class SolidPolygonLayer<DataT = any, ExtraPropsT extends {} = {}>
}
}
} else {
this._disablePickingIndex(objectIndex);
super.disablePickingIndex(objectIndex);
}
}

Expand Down

0 comments on commit c695825

Please # to comment.