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

[feat] H3 Layer separate layer opacity into unique fill opacity and stroke opacity #2261

Merged
merged 2 commits into from
Jun 15, 2023
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
25 changes: 13 additions & 12 deletions src/components/src/side-panel/layer-panel/layer-configurator.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -490,12 +490,12 @@ export default function LayerConfiguratorFactory(
}) {
return (
<StyledLayerVisualConfigurator>
{/* Fill Color */}
{/* Fill */}
<LayerConfigGroup
{...layer.visConfigSettings.filled}
{...visConfiguratorProps}
collapsible
label={'layer.fillColor'}
collapsible
>
{layer.config.colorField ? (
<LayerColorRangeSelector {...visConfiguratorProps} />
Expand All @@ -507,10 +507,15 @@ export default function LayerConfiguratorFactory(
channel={layer.visualChannels.color}
{...layerChannelConfigProps}
/>
<VisConfigSlider
{...layer.visConfigSettings.opacity}
{...visConfiguratorProps}
disabled={!layer.config.visConfig.filled}
/>
</ConfigGroupCollapsibleContent>
</LayerConfigGroup>

{/* Outline Color */}
{/* Outline */}
<LayerConfigGroup
{...layer.visConfigSettings.outline}
{...visConfiguratorProps}
Expand All @@ -530,6 +535,11 @@ export default function LayerConfiguratorFactory(
/>
)}
<ConfigGroupCollapsibleContent>
<VisConfigSlider
{...layer.visConfigSettings.strokeOpacity}
{...visConfiguratorProps}
disabled={!layer.config.visConfig.outline}
/>
<VisConfigSlider
{...layer.visConfigSettings.thickness}
{...visConfiguratorProps}
Expand All @@ -538,15 +548,6 @@ export default function LayerConfiguratorFactory(
</ConfigGroupCollapsibleContent>
</LayerConfigGroup>

{/* Opacity */}
<LayerConfigGroup label={layer.visConfigSettings.opacity.label}>
<VisConfigSlider
{...layer.visConfigSettings.opacity}
{...visConfiguratorProps}
label={false}
/>
</LayerConfigGroup>

{/* Coverage */}
<LayerConfigGroup label={'layer.coverage'} collapsible>
{!layer.config.coverageField ? (
Expand Down
81 changes: 77 additions & 4 deletions src/deckgl-layers/src/column-layer/enhanced-column-layer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

import {ColumnLayer} from '@deck.gl/layers';
import {UNIT} from '@deck.gl/core';
import {ColumnLayer, ColumnLayerProps} from '@deck.gl/layers/typed';
import GL from '@luma.gl/constants';

import {editShader} from '../';

function addInstanceCoverage(vs) {
Expand All @@ -38,8 +41,12 @@ function addInstanceCoverage(vs) {
);
}

type EnhancedColumnLayerProps = ColumnLayerProps<any> & {
strokeOpacity: any;
};

// TODO: export all deck.gl layers from kepler.gl
class EnhancedColumnLayer extends ColumnLayer<any> {
class EnhancedColumnLayer extends ColumnLayer<any, EnhancedColumnLayerProps> {
getShaders() {
const shaders = super.getShaders();

Expand All @@ -50,12 +57,78 @@ class EnhancedColumnLayer extends ColumnLayer<any> {
}

initializeState() {
super.initializeState(undefined);
super.initializeState();

this.getAttributeManager().addInstanced({
this.getAttributeManager()?.addInstanced({
instanceCoverage: {size: 1, accessor: 'getCoverage'}
});
}

draw({uniforms}) {
const {
lineWidthUnits,
lineWidthScale,
lineWidthMinPixels,
lineWidthMaxPixels,
radiusUnits,
elevationScale,
extruded,
filled,
stroked,
strokeOpacity,
wireframe,
offset,
coverage,
radius,
angle
} = this.props;
const {model, fillVertexCount, wireframeVertexCount, edgeDistance} = this.state;

model.setUniforms(uniforms).setUniforms({
radius,
angle: (angle / 180) * Math.PI,
offset,
extruded,
stroked,
coverage,
elevationScale,
edgeDistance,
radiusUnits: UNIT[radiusUnits],
widthUnits: UNIT[lineWidthUnits],
widthScale: lineWidthScale,
widthMinPixels: lineWidthMinPixels,
widthMaxPixels: lineWidthMaxPixels
});

// When drawing 3d: draw wireframe first so it doesn't get occluded by depth test
if (extruded && wireframe) {
model.setProps({isIndexed: true});
model
.setVertexCount(wireframeVertexCount)
.setDrawMode(GL.LINES)
.setUniforms({isStroke: true})
.draw();
}
if (filled) {
model.setProps({isIndexed: false});
model
.setVertexCount(fillVertexCount)
.setDrawMode(GL.TRIANGLE_STRIP)
.setUniforms({isStroke: false})
.draw();
}
// When drawing 2d: draw fill before stroke so that the outline is always on top
if (!extruded && stroked) {
model.setProps({isIndexed: false});
// The width of the stroke is achieved by flattening the side of the cylinder.
// Skip the last 1/3 of the vertices which is the top.
model
.setVertexCount((fillVertexCount * 2) / 3)
.setDrawMode(GL.TRIANGLE_STRIP)
.setUniforms({isStroke: true, opacity: strokeOpacity})
.draw();
}
}
}

EnhancedColumnLayer.layerName = 'EnhancedColumnLayer';
Expand Down
21 changes: 18 additions & 3 deletions src/layers/src/h3-hexagon-layer/h3-hexagon-layer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ export type HexagonIdLayerColumnsConfig = {

export type HexagonIdLayerVisConfigSettings = {
opacity: VisConfigNumber;
strokeOpacity: VisConfigNumber;
colorRange: VisConfigColorRange;
coverage: VisConfigNumber;
enable3d: VisConfigBoolean;
Expand All @@ -81,6 +82,7 @@ export type HexagonIdLayerVisConfigSettings = {

export type HexagonIdLayerVisConfig = {
opacity: number;
strokeOpacity: number;
colorRange: ColorRange;
coverage: number;
enable3d: boolean;
Expand Down Expand Up @@ -115,7 +117,8 @@ export const defaultElevation = 500;
export const defaultCoverage = 1;

export const HexagonIdVisConfigs: {
opacity: 'opacity';
opacity: VisConfigNumber;
strokeOpacity: VisConfigNumber;
colorRange: 'colorRange';
filled: VisConfigBoolean;
outline: 'outline';
Expand All @@ -129,15 +132,26 @@ export const HexagonIdVisConfigs: {
elevationScale: 'elevationScale';
enableElevationZoomFactor: 'enableElevationZoomFactor';
} = {
opacity: 'opacity',
colorRange: 'colorRange',
filled: {
...LAYER_VIS_CONFIGS.filled,
defaultValue: true
},
opacity: {
...LAYER_VIS_CONFIGS.opacity,
label: 'Fill Opacity',
range: [0, 1],
property: 'opacity'
},
outline: 'outline',
strokeColor: 'strokeColor',
strokeColorRange: 'strokeColorRange',
strokeOpacity: {
...LAYER_VIS_CONFIGS.opacity,
label: 'Stroke Opacity',
range: [0, 1],
property: 'strokeOpacity'
},
thickness: 'thickness',
coverage: 'coverage',
enable3d: 'enable3d',
Expand Down Expand Up @@ -432,7 +446,8 @@ export default class HexagonIdLayer extends Layer {
'hexagon-cell': {
type: EnhancedColumnLayer,
getCoverage: data.getCoverage,
updateTriggers: columnLayerTriggers
updateTriggers: columnLayerTriggers,
strokeOpacity: visConfig.strokeOpacity
}
}
}),
Expand Down
1 change: 1 addition & 0 deletions src/localization/src/translations/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -464,6 +464,7 @@ export default {
colorScale: 'Color Scale',
sizeScale: 'Size Scale',
strokeScale: 'Stroke Scale',
strokeColorScale: 'Stroke Color Scale',
scale: 'Scale'
},
fileUploader: {
Expand Down
1 change: 1 addition & 0 deletions test/fixtures/test-hex-id-data.js
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,7 @@ mergedH3Layer.config = {
category: 'Uber',
colors: ['#5A1846', '#900C3F', '#C70039', '#E3611C', '#F1920E', '#FFC300']
},
strokeOpacity: 0.8,
thickness: 2,
coverage: 1,
sizeRange: [0, 500],
Expand Down