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

[Enhancement] Support elevation in Icon layer #1483

Merged
merged 2 commits into from
May 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 17 additions & 1 deletion src/layers/icon-layer/icon-layer.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,15 @@ const brushingExtension = new BrushingExtension();

export const SVG_ICON_URL = `${CLOUDFRONT}/icons/svg-icons.json`;

export const iconPosAccessor = ({lat, lng}) => d => [d.data[lng.fieldIdx], d.data[lat.fieldIdx]];
export const iconPosAccessor = ({lat, lng, altitude}) => d => [
d.data[lng.fieldIdx],
d.data[lat.fieldIdx],
altitude?.fieldIdx > -1 ? d.data[altitude.fieldIdx] : 0
];
export const iconAccessor = ({icon}) => d => d.data[icon.fieldIdx];

export const iconRequiredColumns = ['lat', 'lng', 'icon'];
export const iconOptionalColumns = ['altitude'];

export const pointVisConfigs = {
radius: 'radius',
Expand Down Expand Up @@ -79,6 +84,10 @@ export default class IconLayer extends Layer {
return iconRequiredColumns;
}

get optionalColumns() {
return iconOptionalColumns;
}

get columnPairs() {
return this.defaultPointColumnPairs;
}
Expand Down Expand Up @@ -274,6 +283,11 @@ export default class IconLayer extends Layer {
];
const hoveredObject = this.hasHoveredObject(objectHovered);

const parameters = {
// icons will be flat on the map when the altitude column is not used
depthTest: this.config.columns.altitude.fieldIdx > -1
};

return !this.iconGeometry
? []
: [
Expand All @@ -282,6 +296,7 @@ export default class IconLayer extends Layer {
...brushingProps,
...layerProps,
...data,
parameters,
getIconGeometry: id => this.iconGeometry[id],

// update triggers
Expand All @@ -295,6 +310,7 @@ export default class IconLayer extends Layer {
...this.getDefaultHoverLayerProps(),
...layerProps,
data: [hoveredObject],
parameters,
getPosition: data.getPosition,
getRadius: data.getRadius,
getFillColor: this.config.highlightColor,
Expand Down
4 changes: 2 additions & 2 deletions test/browser/layer-tests/icon-layer-specs.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ test('#IconLayer -> formatLayerData', t => {
// getPosition
t.deepEqual(
layerData.getPosition(layerData.data[0]),
[testRows[0][2], testRows[0][1]],
[testRows[0][2], testRows[0][1], 0],
'getPosition should return correct position'
);
// getFillColor
Expand Down Expand Up @@ -471,7 +471,7 @@ test('#IconLayer -> renderLayer', t => {

t.deepEqual(
getPosition(layerData.data[0]),
[testRows[0][2], testRows[0][1]],
[testRows[0][2], testRows[0][1], 0],
'Should calculate correct getPosition'
);
t.deepEqual(getColor, DEFAULT_TEXT_LABEL.color, 'Should calculate correct getColor');
Expand Down