Skip to content

Kepler.gl is a powerful open source geospatial analysis tool for large-scale data sets.

[Feat] Upgrade to Deck.gl v5 (#153)

Shan Heb1ec139c910d
diff --git a/examples/demo-app/package.json b/examples/demo-app/package.json
index 007eda087..92f861f21 100644
--- a/examples/demo-app/package.json
+++ b/examples/demo-app/package.json
@@ -7,7 +7,7 @@
"dependencies": {
"d3-request": "^1.0.6",
"global": "^4.3.0",
- "kepler.gl": "^0.0.27",
+ "kepler.gl": "../..",
"lodash.debounce": "^4.0.8",
"react": "^15.3.1",
"react-dom": "^15.6.1",
diff --git a/package.json b/package.json
index 59ae778be..9805b4a49 100644
--- a/package.json
+++ b/package.json
@@ -71,7 +71,7 @@
"d3-hexbin": "^0.2.2",
"d3-request": "^1.0.6",
"d3-scale": "^1.0.6",
- "deck.gl": "4.1.6",
+ "deck.gl": "5.3.4",
"fuzzy": "^0.1.3",
"global": "^4.3.0",
"keymirror": "^0.1.1",
@@ -82,7 +82,6 @@
"lodash.pick": "^4.4.0",
"lodash.throttle": "^4.1.1",
"lodash.uniq": "^4.0.1",
- "luma.gl": "4.0.6",
"moment": "^2.10.6",
"prop-types": "^15.6.0",
"react-ace": "^6.1.1",
diff --git a/src/components/map-container.js b/src/components/map-container.js
index 48ae0ed07..fb3363ba5 100644
--- a/src/components/map-container.js
+++ b/src/components/map-container.js
@@ -24,6 +24,9 @@ import PropTypes from 'prop-types';
import MapboxGLMap from 'react-map-gl';
import DeckGL from 'deck.gl';
import {GL} from 'luma.gl';
+import {registerShaderModules, setParameters} from 'luma.gl';
+import pickingModule from 'shaderlib/picking-module';
+import brushingModule from 'shaderlib/brushing-module';
// components
import MapPopoverFactory from 'components/map/map-popover';
@@ -89,8 +92,6 @@ export default function MapContainerFactory(MapPopover, MapControl) {
constructor(props) {
super(props);
this.state = {
- reRenderKey: 0,
- gl: null,
mousePosition: [0, 0]
};
this.previousLayers = {
@@ -98,20 +99,6 @@ export default function MapContainerFactory(MapPopover, MapControl) {
};
}
- componentWillReceiveProps(nextProps) {
- if (
- this.props.mapState.dragRotate !== nextProps.mapState.dragRotate ||
- this.props.layerBlending !== nextProps.layerBlending
- ) {
- // increment rerender key to force gl reinitialize when
- // perspective or layer blending changed
- // TODO: layer blending can now be implemented per layer base
- this.setState({
- reRenderKey: this.state.reRenderKey + 1
- });
- }
- }
-
componentWillUnmount() {
// unbind mapboxgl event listener
if (this._map) {
@@ -120,7 +107,6 @@ export default function MapContainerFactory(MapPopover, MapControl) {
}
/* component private functions */
-
_onCloseMapPopover = () => {
this.props.visStateActions.onLayerClick(null);
};
@@ -132,20 +118,13 @@ export default function MapContainerFactory(MapPopover, MapControl) {
};
_onWebGLInitialized = gl => {
- // enable depth test for perspective mode
- if (this.props.mapState.dragRotate) {
- gl.enable(gl.DEPTH_TEST);
- gl.depthFunc(gl.LEQUAL);
- } else {
- gl.disable(gl.DEPTH_TEST);
- }
+ registerShaderModules(
+ [pickingModule, brushingModule], {
+ ignoreMultipleRegistrations: true
+ });
// allow Uint32 indices in building layer
- gl.getExtension('OES_element_index_uint');
-
- this._togglelayerBlending(gl);
-
- this.setState({gl});
+ // gl.getExtension('OES_element_index_uint');
};
_onMouseMove = evt => {
@@ -191,35 +170,24 @@ export default function MapContainerFactory(MapPopover, MapControl) {
}
}
- /* deck.gl doesn't support blendFuncSeparate yet
- * so we're applying the blending ourselves
- */
- _togglelayerBlending = gl => {
+ _onBeforeRender = ({gl}) => {
+ this._setlayerBlending(gl);
+ };
+
+ _setlayerBlending = gl => {
const blending = LAYER_BLENDINGS[this.props.layerBlending];
- const {
- enable,
- blendFunc,
- blendEquation,
- blendFuncSeparate,
- blendEquationSeparate
- } = blending;
-
- if (enable) {
- gl.enable(GL.BLEND);
- if (blendFunc) {
- gl.blendFunc(...blendFunc.map(getGlConst));
- gl.blendEquation(GL[blendEquation]);
- } else {
- gl.blendFuncSeparate(...blendFuncSeparate.map(getGlConst));
- gl.blendEquationSeparate(...blendEquationSeparate.map(getGlConst));
- }
- } else {
- gl.disable(GL.BLEND);
- }
+ const {blendFunc, blendEquation} = blending;
+
+ setParameters(gl, {
+ [GL.BLEND]: true,
+ ...(blendFunc ? {
+ blendFunc: blendFunc.map(getGlConst),
+ blendEquation: Array.isArray(blendEquation) ? blendEquation.map(getGlConst) : getGlConst(blendEquation)
+ } : {})
+ });
};
/* component render functions */
-
/* eslint-disable complexity */
_renderObjectLayerPopover() {
// TODO: move this into reducer so it can be tested
@@ -310,7 +278,6 @@ export default function MapContainerFactory(MapPopover, MapControl) {
clicked,
mapLayers,
mapState,
- visStateActions,
interactionConfig
} = this.props;
const {mousePosition} = this.state;
@@ -318,8 +285,6 @@ export default function MapContainerFactory(MapPopover, MapControl) {
const data = layerData[idx];
const layerInteraction = {
- onHover: visStateActions.onLayerHover,
- onClick: visStateActions.onLayerClick,
mousePosition
};
@@ -357,7 +322,8 @@ export default function MapContainerFactory(MapPopover, MapControl) {
const {
mapState,
layerData,
- layerOrder
+ layerOrder,
+ visStateActions
} = this.props;
let deckGlLayers = [];
@@ -373,11 +339,13 @@ export default function MapContainerFactory(MapPopover, MapControl) {
return (
<DeckGL
- {...mapState}
+ viewState={mapState}
id="default-deckgl-overlay"
layers={deckGlLayers}
- key={this.state.reRenderKey}
onWebGLInitialized={this._onWebGLInitialized}
+ onBeforeRender={this._onBeforeRender}
+ onLayerHover={visStateActions.onLayerHover}
+ onLayerClick={visStateActions.onLayerClick}
/>
);
}
@@ -456,6 +424,7 @@ export default function MapContainerFactory(MapPopover, MapControl) {
ref={this._setMapboxMap}
mapStyle={mapStyle.bottomMapStyle}
onClick={onMapClick}
+ getCursor={this.props.hoverInfo ? () => 'pointer' : undefined}
>
{this._renderOverlay()}
{this._renderMapboxOverlays()}
diff --git a/src/components/side-panel/layer-panel/layer-configurator.js b/src/components/side-panel/layer-panel/layer-configurator.js
index 72bbee779..54b3efb26 100644
--- a/src/components/side-panel/layer-panel/layer-configurator.js
+++ b/src/components/side-panel/layer-panel/layer-configurator.js
@@ -495,27 +495,28 @@ export default class LayerConfigurator extends Component {
</LayerConfigGroup>
{/* Stroke Width */}
- {featureTypes.line || (featureTypes.polygon && visConfig.stroked) ? (
+ {featureTypes.line || featureTypes.polygon ? (
<LayerConfigGroup
label="stroke"
{...visConfiguratorProps}
{...(featureTypes.polygon ? LAYER_VIS_CONFIGS.stroked : {})}
>
- <div>
- <VisConfigSlider
- {...LAYER_VIS_CONFIGS.thickness}
- {...visConfiguratorProps}
- />
- <ChannelByValueSelector
- channel={layer.visualChannels.size}
- {...layerChannelConfigProps}
- />
- <VisConfigSlider
- {...LAYER_VIS_CONFIGS.strokeWidthRange}
- {...visConfiguratorProps}
- disabled={!layer.config.sizeField}
- />
- </div>
+ {visConfig.stroked ?
+ <div>
+ <VisConfigSlider
+ {...LAYER_VIS_CONFIGS.thickness}
+ {...visConfiguratorProps}
+ />
+ <ChannelByValueSelector
+ channel={layer.visualChannels.size}
+ {...layerChannelConfigProps}
+ />
+ <VisConfigSlider
+ {...LAYER_VIS_CONFIGS.strokeWidthRange}
+ {...visConfiguratorProps}
+ disabled={!layer.config.sizeField}
+ />
+ </div> : null}
</LayerConfigGroup>
) : null}
diff --git a/src/components/side-panel/panel-header.js b/src/components/side-panel/panel-header.js
index d259ceaa7..e5333bfcd 100644
--- a/src/components/side-panel/panel-header.js
+++ b/src/components/side-panel/panel-header.js
@@ -17,6 +17,7 @@
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
+
import React, {Component} from 'react';
import styled from 'styled-components';
import PropTypes from 'prop-types';
diff --git a/src/constants/default-settings.js b/src/constants/default-settings.js
index 322f216d5..6d4708ade 100644
--- a/src/constants/default-settings.js
+++ b/src/constants/default-settings.js
@@ -476,26 +476,23 @@ export const NO_VALUE_COLOR = [147, 147, 147];
export const LAYER_BLENDINGS = {
additive: {
- enable: true,
blendFunc: ['SRC_ALPHA', 'DST_ALPHA'],
blendEquation: 'FUNC_ADD'
},
normal: {
- enable: true,
// reference to
// https://limnu.com/webgl-blending-youre-probably-wrong/
- blendFuncSeparate: [
+ blendFunc: [
'SRC_ALPHA',
'ONE_MINUS_SRC_ALPHA',
'ONE',
'ONE_MINUS_SRC_ALPHA'
],
- blendEquationSeparate: ['FUNC_ADD', 'FUNC_ADD']
+ blendEquation: ['FUNC_ADD', 'FUNC_ADD']
},
subtractive: {
- enable: true,
- blendFuncSeparate: ['ONE', 'ONE_MINUS_DST_COLOR', 'SRC_ALPHA', 'DST_ALPHA'],
- blendEquationSeparate: ['FUNC_SUBTRACT', 'FUNC_ADD']
+ blendFunc: ['ONE', 'ONE_MINUS_DST_COLOR', 'SRC_ALPHA', 'DST_ALPHA'],
+ blendEquation: ['FUNC_SUBTRACT', 'FUNC_ADD']
}
};
diff --git a/src/deckgl-layers/arc-brushing-layer/arc-brushing-layer-vertex-64.glsl.js b/src/deckgl-layers/arc-brushing-layer/arc-brushing-layer-vertex-64.glsl.js
deleted file mode 100644
index cafddb243..000000000
--- a/src/deckgl-layers/arc-brushing-layer/arc-brushing-layer-vertex-64.glsl.js
+++ /dev/null
@@ -1,160 +0,0 @@
-// Copyright (c) 2018 Uber Technologies, Inc.
-//
-// Permission is hereby granted, free of charge, to any person obtaining a copy
-// of this software and associated documentation files (the "Software"), to deal
-// in the Software without restriction, including without limitation the rights
-// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-// copies of the Software, and to permit persons to whom the Software is
-// furnished to do so, subject to the following conditions:
-//
-// The above copyright notice and this permission notice shall be included in
-// all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-// THE SOFTWARE.
-
-// Copyright (c) 2015 - 2017 Uber Technologies, Inc.
-//
-// Permission is hereby granted, free of charge, to any person obtaining a copy
-// of this software and associated documentation files (the "Software"), to deal
-// in the Software without restriction, including without limitation the rights
-// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-// copies of the Software, and to permit persons to whom the Software is
-// furnished to do so, subject to the following conditions:
-//
-// The above copyright notice and this permission notice shall be included in
-// all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-// THE SOFTWARE.
-
-export default `\
-#define SHADER_NAME arc-layer-vertex-shader-64
-
-attribute vec3 positions;
-attribute vec4 instanceSourceColors;
-attribute vec4 instanceTargetColors;
-
-attribute vec4 instancePositions;
-attribute vec4 instancePositions64Low;
-
-attribute vec3 instancePickingColors;
-
-attribute float instanceStrokeWidth;
-
-uniform float numSegments;
-uniform float strokeScale;
-uniform float opacity;
-uniform float renderPickingBuffer;
-uniform vec4 pickedColor;
-
-uniform float enableBrushing;
-uniform float brushSource;
-uniform float brushTarget;
-
-varying vec4 vColor;
-
-vec2 paraboloid_fp64(vec2 source[2], vec2 target[2], float ratio) {
-
- vec2 x[2];
- vec2_mix_fp64(source, target, ratio, x);
- vec2 center[2];
- vec2_mix_fp64(source, target, 0.5, center);
-
- vec2 dSourceCenter = vec2_distance_fp64(source, center);
- vec2 dXCenter = vec2_distance_fp64(x, center);
- return mul_fp64(sum_fp64(dSourceCenter, dXCenter), sub_fp64(dSourceCenter, dXCenter));
-}
-
-float getSegmentRatio(float index) {
- return smoothstep(0.0, 1.0, index / (numSegments - 1.0));
-}
-
-void get_pos_fp64(vec2 source[2], vec2 target[2], float segmentRatio, out vec2 position[4]) {
-
- vec2 vertex_height = paraboloid_fp64(source, target, segmentRatio);
-
- vec2 position_temp[2];
-
- vec2_mix_fp64(source, target, segmentRatio, position_temp);
-
- position[0] = position_temp[0];
- position[1] = position_temp[1];
-
- if (vertex_height.x < 0.0 || (vertex_height.x == 0.0 && vertex_height.y <= 0.0)) {
- vertex_height = vec2(0.0, 0.0);
- }
-
- position[2] = sqrt_fp64(vertex_height);
- position[3] = vec2(1.0, 0.0);
-}
-
-void main(void) {
- vec4 instanceSourcePositions64 = vec4(instancePositions.x,
- instancePositions64Low.x, instancePositions.y, instancePositions64Low.y);
- vec4 instanceTargetPositions64 = vec4(instancePositions.z,
- instancePositions64Low.z, instancePositions.w, instancePositions64Low.w);
-
- vec2 projected_source_coord[2];
- vec2 projected_target_coord[2];
-
- project_position_fp64(instanceSourcePositions64, projected_source_coord);
- project_position_fp64(instanceTargetPositions64, projected_target_coord);
-
- // if not enabled isPointInRange will always return true
- float isSourceInBrush = isPointInRange(instancePositions.xy, brushSource);
- float isTargetInBrush = isPointInRange(instancePositions.zw, brushTarget);
-
- float isInBrush = float(enableBrushing <= 0. ||
- (brushSource * isSourceInBrush > 0. || brushTarget * isTargetInBrush > 0.));
-
- float segmentIndex = positions.x;
- float segmentRatio = getSegmentRatio(segmentIndex);
-
- // if it's the first point, use next - current as direction
- // otherwise use current - prev
- float indexDir = mix(-1.0, 1.0, step(segmentIndex, 0.0));
- float nextSegmentRatio = getSegmentRatio(segmentIndex + indexDir);
-
- vec2 curr_pos_modelspace[4];
-
- get_pos_fp64(projected_source_coord, projected_target_coord, segmentRatio,
- curr_pos_modelspace);
-
- vec2 next_pos_modelspace[4];
-
- get_pos_fp64(projected_source_coord, projected_target_coord, nextSegmentRatio,
- next_pos_modelspace);
-
- vec4 curr_pos_clipspace = project_to_clipspace_fp64(curr_pos_modelspace);
- vec4 next_pos_clipspace = project_to_clipspace_fp64(next_pos_modelspace);
- // mix strokeWidth with brush, if not in brush, return 0
- float strokeWidth = strokeScale * instanceStrokeWidth;
- float finalWidth = mix(0.0, strokeWidth, isInBrush);
-
- vec2 offset = getExtrusionOffset(next_pos_clipspace.xy - curr_pos_clipspace.xy, positions.y, finalWidth);
-
- gl_Position = curr_pos_clipspace + vec4(offset, 0.0, 0.0);
-
- float picked = isPicked(instancePickingColors);
-
- vec4 color = mix(instanceSourceColors, instanceTargetColors, segmentRatio) / 255.;
- vec4 finalColor = mix(color, pickedColor / 255., picked);
-
- vColor = mix(
- vec4(color.rgb, color.a * opacity),
- vec4(instancePickingColors / 255., 1.),
- renderPickingBuffer
- );
-}
-`;
diff --git a/src/deckgl-layers/arc-brushing-layer/arc-brushing-layer-vertex.glsl.js b/src/deckgl-layers/arc-brushing-layer/arc-brushing-layer-vertex.glsl.js
deleted file mode 100644
index fc8aac389..000000000
--- a/src/deckgl-layers/arc-brushing-layer/arc-brushing-layer-vertex.glsl.js
+++ /dev/null
@@ -1,131 +0,0 @@
-// Copyright (c) 2018 Uber Technologies, Inc.
-//
-// Permission is hereby granted, free of charge, to any person obtaining a copy
-// of this software and associated documentation files (the "Software"), to deal
-// in the Software without restriction, including without limitation the rights
-// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-// copies of the Software, and to permit persons to whom the Software is
-// furnished to do so, subject to the following conditions:
-//
-// The above copyright notice and this permission notice shall be included in
-// all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-// THE SOFTWARE.
-
-// Copyright (c) 2015-2017 Uber Technologies, Inc.
-//
-// Permission is hereby granted, free of charge, to any person obtaining a copy
-// of this software and associated documentation files (the "Software"), to deal
-// in the Software without restriction, including without limitation the rights
-// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-// copies of the Software, and to permit persons to whom the Software is
-// furnished to do so, subject to the following conditions:
-//
-// The above copyright notice and this permission notice shall be included in
-// all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-// THE SOFTWARE.
-
-export default `\
-#define SHADER_NAME arc-brushing-layer-vertex-shader
-
-const float N = 49.0;
-
-attribute vec3 positions;
-attribute vec4 instanceSourceColors;
-attribute vec4 instanceTargetColors;
-attribute vec4 instancePositions;
-attribute vec3 instancePickingColors;
-attribute float instanceStrokeWidth;
-
-uniform float numSegments;
-uniform float strokeScale;
-uniform float opacity;
-uniform float renderPickingBuffer;
-uniform vec4 pickedColor;
-
-uniform float enableBrushing;
-uniform float brushSource;
-uniform float brushTarget;
-
-varying vec4 vColor;
-
-float paraboloid(vec2 source, vec2 target, float ratio) {
-
- vec2 x = mix(source, target, ratio);
- vec2 center = mix(source, target, 0.5);
-
- float dSourceCenter = distance(source, center);
- float dXCenter = distance(x, center);
- return (dSourceCenter + dXCenter) * (dSourceCenter - dXCenter);
-}
-
-float getSegmentRatio(float index) {
- return smoothstep(0.0, 1.0, index / (numSegments - 1.0));
-}
-
-vec3 getPos(vec2 source, vec2 target, float segmentRatio) {
- float vertex_height = paraboloid(source, target, segmentRatio);
-
- return vec3(
- mix(source, target, segmentRatio),
- sqrt(max(0.0, vertex_height))
- );
-}
-
-void main(void) {
- vec2 source = project_position(instancePositions.xy);
- vec2 target = project_position(instancePositions.zw);
-
- // if not enabled isPointInRange will always return true
- float isSourceInBrush = isPointInRange(instancePositions.xy, brushSource);
- float isTargetInBrush = isPointInRange(instancePositions.zw, brushTarget);
-
- float isInBrush = float(enableBrushing <= 0. ||
- (brushSource * isSourceInBrush > 0. || brushTarget * isTargetInBrush > 0.));
-
- float segmentIndex = positions.x;
- float segmentRatio = getSegmentRatio(segmentIndex);
-
- // if it's the first point, use next - current as direction
- // otherwise use current - prev
- float indexDir = mix(-1.0, 1.0, step(segmentIndex, 0.0));
- float nextSegmentRatio = getSegmentRatio(segmentIndex + indexDir);
-
- vec3 currPos = getPos(source, target, segmentRatio);
- vec3 nextPos = getPos(source, target, nextSegmentRatio);
- vec4 curr = project_to_clipspace(vec4(currPos, 1.0));
- vec4 next = project_to_clipspace(vec4(nextPos, 1.0));
-
- // mix strokeWidth with brush, if not in brush, return 0
- float strokeWidth = strokeScale * instanceStrokeWidth;
- float finalWidth = mix(0.0, strokeWidth, isInBrush);
-
- // extrude
- vec2 offset = getExtrusionOffset((next.xy - curr.xy) * indexDir, positions.y, finalWidth);
- gl_Position = curr + vec4(offset, 0.0, 0.0);
-
- float picked = isPicked(instancePickingColors);
-
- vec4 color = mix(instanceSourceColors, instanceTargetColors, segmentRatio) / 255.;
- vec4 finalColor = mix(color, pickedColor / 255., picked);
-
- vColor = mix(
- vec4(finalColor.rgb, finalColor.a * opacity),
- vec4(instancePickingColors / 255., 1.),
- renderPickingBuffer
- );
-}
-`;
diff --git a/src/deckgl-layers/arc-brushing-layer/arc-brushing-layer.js b/src/deckgl-layers/arc-brushing-layer/arc-brushing-layer.js
index 3c129b2bb..849b541f1 100644
--- a/src/deckgl-layers/arc-brushing-layer/arc-brushing-layer.js
+++ b/src/deckgl-layers/arc-brushing-layer/arc-brushing-layer.js
@@ -19,13 +19,7 @@
// THE SOFTWARE.
import {ArcLayer} from 'deck.gl';
-
-import isPicked from '../../shaderlib/is-picked';
-import isPtInRange from '../../shaderlib/is-point-in-range';
-import getExtrusion from '../../shaderlib/get-extrusion-offset.glsl';
-
-import vs from './arc-brushing-layer-vertex.glsl';
-import vs64 from './arc-brushing-layer-vertex-64.glsl';
+import {editShader} from 'deckgl-layers/layer-utils/shader-utils';
const defaultProps = {
...ArcLayer.defaultProps,
@@ -38,75 +32,66 @@ const defaultProps = {
strokeScale: 1,
// brush radius in meters
brushRadius: 100000,
- pickedColor: [254, 210, 26, 255],
mousePosition: [0, 0]
};
+function addBrushingVsShader(vs) {
+ return editShader(
+ vs,
+ 'arc brushing vs',
+ 'vec2 offset = getExtrusionOffset((next.xy - curr.xy) * indexDir, positions.y);',
+ 'vec2 offset = brushing_getExtrusionOffset((next.xy - curr.xy) * indexDir, positions.y, project_uViewportSize, instancePositions, instanceWidths);'
+ );
+}
+
+function addBrushingVs64Shader(vs) {
+ return editShader(
+ vs,
+ 'arc brushing vs64',
+ 'vec2 offset = getExtrusionOffset(next_pos_clipspace.xy - curr_pos_clipspace.xy, positions.y);',
+ 'vec2 offset = brushing_getExtrusionOffset(next_pos_clipspace.xy - curr_pos_clipspace.xy, positions.y, project_uViewportSize, instancePositions, instanceWidths);'
+ );
+}
+
export default class ArcBrushingLayer extends ArcLayer {
getShaders() {
const shaders = super.getShaders();
- const addons = getExtrusion + isPicked + isPtInRange;
-
return {
- ...shaders,
- vs: addons + (this.props.fp64 ? vs64 : vs)
+ vs: this.is64bitEnabled()
+ ? addBrushingVs64Shader(shaders.vs)
+ : addBrushingVsShader(shaders.vs),
+ fs: shaders.fs,
+ modules: shaders.modules.concat(['brushing'])
};
}
- initializeState() {
- super.initializeState();
- const {attributeManager} = this.state;
- attributeManager.addInstanced({
- instanceStrokeWidth: {
- size: 1,
- accessor: ['getStrokeWidth'],
- update: this.calculateInstanceStrokeWidth
- }
- });
- }
+ draw(opts) {
+ const {uniforms} = opts;
- draw({uniforms}) {
const {
brushSource,
brushTarget,
brushRadius,
enableBrushing,
- pickedColor,
mousePosition,
strokeScale
} = this.props;
- const picked = !Array.isArray(pickedColor)
- ? defaultProps.pickedColor
- : pickedColor;
super.draw({
+ ...opts,
uniforms: {
...uniforms,
- brushSource,
- brushTarget,
- brushRadius,
- enableBrushing,
- strokeScale,
- pickedColor: new Uint8ClampedArray(
- !Number.isFinite(pickedColor[3]) ? [...picked, 255] : picked
- ),
- mousePos: mousePosition
+ brushing_uBrushSource: brushSource ? 1 : 0,
+ brushing_uBrushTarget: brushTarget ? 1 : 0,
+ brushing_uBrushRadius: brushRadius,
+ brushing_uEnableBrushing: enableBrushing ? 1 : 0,
+ brushing_uStrokeScale: strokeScale,
+ brushing_uMousePosition: mousePosition
? new Float32Array(this.unproject(mousePosition))
: defaultProps.mousePosition
}
});
}
-
- calculateInstanceStrokeWidth(attribute) {
- const {data, getStrokeWidth} = this.props;
- const {value, size} = attribute;
- let i = 0;
- for (const object of data) {
- const width = getStrokeWidth(object);
- value[i] = Number.isFinite(width) ? width : 1;
- i += size;
- }
- }
}
ArcBrushingLayer.layerName = 'ArcBrushingLayer';
diff --git a/src/deckgl-layers/cluster-layer/cluster-layer.js b/src/deckgl-layers/cluster-layer/cluster-layer.js
index 1ac2eb01f..45b6d9f65 100644
--- a/src/deckgl-layers/cluster-layer/cluster-layer.js
+++ b/src/deckgl-layers/cluster-layer/cluster-layer.js
@@ -79,7 +79,7 @@ export default class ClusterLayer extends CompositeLayer {
return changeFlags.somethingChanged;
}
- updateState({oldContext, context, oldProps, props, changeFlags}) {
+ updateState({context, oldProps, props, changeFlags}) {
if (changeFlags.dataChanged || this.needsReProjectPoints(oldProps, props)) {
// project data into clusters, and get clustered data
this.processGeoJSON();
@@ -87,7 +87,7 @@ export default class ClusterLayer extends CompositeLayer {
// this needs clustered data to be set
this.getColorValueDomain();
- } else if (this.needsReclusterPoints(oldContext, context)) {
+ } else if (this.needsReclusterPoints(oldProps, props)) {
this.getClusters();
this.getColorValueDomain();
} else if (this.needsRecalculateScaleFunction(oldProps, props)) {
@@ -102,9 +102,9 @@ export default class ClusterLayer extends CompositeLayer {
);
}
- needsReclusterPoints(oldContext, context) {
+ needsReclusterPoints(oldProps, props) {
return (
- Math.round(oldContext.viewport.zoom) !== Math.round(context.viewport.zoom)
+ Math.round(oldProps.zoom) !== Math.round(props.zoom)
);
}
@@ -253,7 +253,7 @@ export default class ClusterLayer extends CompositeLayer {
const {id, radiusScale, fp64} = this.props;
// base layer props
- const {opacity, pickable} = this.props;
+ const {opacity, pickable, autoHighlight, highlightColor} = this.props;
// return props to the sublayer constructor
return new ScatterplotLayer({
@@ -261,10 +261,12 @@ export default class ClusterLayer extends CompositeLayer {
data: this.state.clusters,
radiusScale,
fp64,
- getPosition: d => d.geometry.coordinates,
- getRadius: this._onGetSublayerRadius.bind(this),
opacity,
pickable,
+ autoHighlight,
+ highlightColor,
+ getPosition: d => d.geometry.coordinates,
+ getRadius: this._onGetSublayerRadius.bind(this),
getColor: this._onGetSublayerColor.bind(this),
updateTriggers: this.getUpdateTriggers()
});
diff --git a/src/shaderlib/is-picked.js b/src/deckgl-layers/geojson-layer/solid-polygon-layer.js
similarity index 70%
rename from src/shaderlib/is-picked.js
rename to src/deckgl-layers/geojson-layer/solid-polygon-layer.js
index 12da1bf77..704fbd6c9 100644
--- a/src/shaderlib/is-picked.js
+++ b/src/deckgl-layers/geojson-layer/solid-polygon-layer.js
@@ -18,14 +18,21 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
-export default `\
+// TODO: a hack becaue solid-polygon-layer is not exported from @deck.gl/layers
+import {_SolidPolygonLayer} from '@deck.gl/layers';
-uniform vec3 selectedPickingColor;
+export default class HighlightSolidPolygonLayer extends _SolidPolygonLayer {
+ draw(opts) {
+ const {uniforms} = opts;
-float isPicked(vec3 pickingColors) {
- return float(pickingColors.x == selectedPickingColor.x
- && pickingColors.y == selectedPickingColor.y
- && pickingColors.z == selectedPickingColor.z);
+ super.draw({
+ ...opts,
+ uniforms: {
+ ...uniforms,
+ picking_uHighlightScale: this.props.extruded ? 1.4 : 0.0
+ }
+ })
+ }
}
-`;
+HighlightSolidPolygonLayer.layerName = 'HighlightSolidPolygonLayer';
diff --git a/src/deckgl-layers/grid-layer/enhanced-grid-cell-layer.js b/src/deckgl-layers/grid-layer/enhanced-grid-cell-layer.js
index 92c94aff4..f9abff404 100644
--- a/src/deckgl-layers/grid-layer/enhanced-grid-cell-layer.js
+++ b/src/deckgl-layers/grid-layer/enhanced-grid-cell-layer.js
@@ -19,13 +19,18 @@
// THE SOFTWARE.
import {GridCellLayer} from 'deck.gl';
-import {getCellLayerVertex} from '../layer-utils/get-cell-layer-vertext';
export default class EnhancedGridCellLayer extends GridCellLayer {
- getShaders() {
- const shaders = super.getShaders();
- const vs = getCellLayerVertex(shaders.vs, {highlightPicked: true});
- return {...shaders, vs};
+ draw(opts) {
+ const {uniforms} = opts;
+
+ super.draw({
+ ...opts,
+ uniforms: {
+ ...uniforms,
+ picking_uHighlightScale: this.props.extruded ? 1.4 : 0.0
+ }
+ })
}
}
diff --git a/src/deckgl-layers/hexagon-layer/enhanced-hexagon-cell-layer.js b/src/deckgl-layers/hexagon-layer/enhanced-hexagon-cell-layer.js
index 003ca8f6b..3939e4100 100644
--- a/src/deckgl-layers/hexagon-layer/enhanced-hexagon-cell-layer.js
+++ b/src/deckgl-layers/hexagon-layer/enhanced-hexagon-cell-layer.js
@@ -19,13 +19,18 @@
// THE SOFTWARE.
import {HexagonCellLayer} from 'deck.gl';
-import {getCellLayerVertex} from '../layer-utils/get-cell-layer-vertext';
export default class EnhancedHexagonCellLayer extends HexagonCellLayer {
- getShaders() {
- const shaders = super.getShaders();
- const vs = getCellLayerVertex(shaders.vs, {highlightPicked: true});
- return {...shaders, vs};
+ draw(opts) {
+ const {uniforms} = opts;
+
+ super.draw({
+ ...opts,
+ uniforms: {
+ ...uniforms,
+ picking_uHighlightScale: this.props.extruded ? 1.4 : 0.0
+ }
+ })
}
}
diff --git a/src/deckgl-layers/layer-utils/get-cell-layer-vertext.js b/src/deckgl-layers/layer-utils/shader-utils.js
similarity index 74%
rename from src/deckgl-layers/layer-utils/get-cell-layer-vertext.js
rename to src/deckgl-layers/layer-utils/shader-utils.js
index 43c52505f..8e8212cdb 100644
--- a/src/deckgl-layers/layer-utils/get-cell-layer-vertext.js
+++ b/src/deckgl-layers/layer-utils/shader-utils.js
@@ -18,22 +18,23 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
+import {console as Console} from 'global/window';
+
/*
* Amendment to default layer vertex shader
* @param {string} vs
- * @param {bool} opt.highlightPicked - whether to highlight picked element
+ * @param {string} type
+ * @param {string} originalText
+ * @param {string} testToReplace
+ * @return {string} output shader
*
*/
-export function getCellLayerVertex(vs, {highlightPicked}) {
- let output = vs;
-
- if (highlightPicked) {
- output = output.replace(
- 'vec3 lightWeightedColor = lightWeight * instanceColors.rgb;',
+export function editShader(vs, type, originalText, testToReplace) {
- `vec3 lightWeightedColor = lightWeight * mix(1.0, mix(1.0, 1.2, selected), extruded) * instanceColors.rgb;`
- );
+ if (!vs.includes(originalText)) {
+ Console.warn(`Cannot edit ${type} layer shader`);
+ return vs;
}
- return output;
+ return vs.replace(originalText, testToReplace);
}
diff --git a/src/deckgl-layers/line-layer/line-brushing-layer-vertex-64.glsl.js b/src/deckgl-layers/line-layer/line-brushing-layer-vertex-64.glsl.js
deleted file mode 100644
index 4abf0130f..000000000
--- a/src/deckgl-layers/line-layer/line-brushing-layer-vertex-64.glsl.js
+++ /dev/null
@@ -1,127 +0,0 @@
-// Copyright (c) 2018 Uber Technologies, Inc.
-//
-// Permission is hereby granted, free of charge, to any person obtaining a copy
-// of this software and associated documentation files (the "Software"), to deal
-// in the Software without restriction, including without limitation the rights
-// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-// copies of the Software, and to permit persons to whom the Software is
-// furnished to do so, subject to the following conditions:
-//
-// The above copyright notice and this permission notice shall be included in
-// all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-// THE SOFTWARE.
-
-// Copyright (c) 2015 - 2017 Uber Technologies, Inc.
-//
-// Permission is hereby granted, free of charge, to any person obtaining a copy
-// of this software and associated documentation files (the "Software"), to deal
-// in the Software without restriction, including without limitation the rights
-// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-// copies of the Software, and to permit persons to whom the Software is
-// furnished to do so, subject to the following conditions:
-//
-// The above copyright notice and this permission notice shall be included in
-// all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-// THE SOFTWARE.
-
-export default `\
-#define SHADER_NAME line-layer-vertex-shader-64
-
-attribute vec3 positions;
-attribute vec3 instanceSourcePositions;
-attribute vec3 instanceTargetPositions;
-attribute vec4 instanceSourceTargetPositions64xyLow;
-attribute vec4 instanceColors;
-attribute vec4 instanceTargetColors;
-attribute vec3 instancePickingColors;
-attribute float instanceStrokeWidth;
-
-uniform float strokeScale;
-uniform float opacity;
-uniform float renderPickingBuffer;
-uniform vec4 pickedColor;
-
-uniform float enableBrushing;
-uniform float brushSource;
-uniform float brushTarget;
-
-varying vec4 vColor;
-
-void main(void) {
- // Position
- vec4 instanceSourcePositions64 = vec4(
- instanceSourcePositions.x, instanceSourceTargetPositions64xyLow.x,
- instanceSourcePositions.y, instanceSourceTargetPositions64xyLow.y);
-
- vec4 instanceTargetPositions64 = vec4(
- instanceTargetPositions.x, instanceSourceTargetPositions64xyLow.z,
- instanceTargetPositions.y, instanceSourceTargetPositions64xyLow.w);
-
- vec2 projected_source_coord[2];
- vec2 projected_target_coord[2];
-
- project_position_fp64(instanceSourcePositions64, projected_source_coord);
- project_position_fp64(instanceTargetPositions64, projected_target_coord);
-
- vec2 source_pos_modelspace[4];
- source_pos_modelspace[0] = projected_source_coord[0];
- source_pos_modelspace[1] = projected_source_coord[1];
- source_pos_modelspace[2] = vec2(project_scale(instanceSourcePositions.z), 0.0);
- source_pos_modelspace[3] = vec2(1.0, 0.0);
-
- vec4 source_pos_clipspace = project_to_clipspace_fp64(source_pos_modelspace);
-
- vec2 target_pos_modelspace[4];
- target_pos_modelspace[0] = projected_target_coord[0];
- target_pos_modelspace[1] = projected_target_coord[1];
- target_pos_modelspace[2] = vec2(project_scale(instanceTargetPositions.z), 0.0);
- target_pos_modelspace[3] = vec2(1.0, 0.0);
-
- vec4 target_pos_clipspace = project_to_clipspace_fp64(target_pos_modelspace);
-
- // if not enabled isPointInRange will always return true
- float isSourceInBrush = isPointInRange(instanceSourcePositions.xy, brushSource);
- float isTargetInBrush = isPointInRange(instanceTargetPositions.xy, brushTarget);
-
- float isInBrush = float(enableBrushing <= 0. ||
- (brushSource * isSourceInBrush > 0. || brushTarget * isTargetInBrush > 0.));
-
- float segmentIndex = positions.x;
- vec4 p = mix(source_pos_clipspace, target_pos_clipspace, segmentIndex);
-
- // mix strokeWidth with brush, if not in brush, return 0
- float width = strokeScale * instanceStrokeWidth;
- float finalWidth = mix(0.0, width, isInBrush);
-
- vec2 offset = getExtrusionOffset(target_pos_clipspace.xy - source_pos_clipspace.xy, positions.y, finalWidth);
-
- gl_Position = p + vec4(offset, 0.0, 0.0);
-
- float picked = isPicked(instancePickingColors);
-
- // Color
- vec4 color = mix(instanceColors, instanceTargetColors, positions.x) / 255.;
- vec4 finalColor = mix(color, pickedColor / 255., picked);
- vec4 pickingColor = vec4(instancePickingColors / 255., 1.);
-
- vColor = mix(
- vec4(finalColor.rgb, finalColor.a * opacity),
- pickingColor,
- renderPickingBuffer
- );
-}
-`;
diff --git a/src/deckgl-layers/line-layer/line-brushing-layer-vertex.glsl.js b/src/deckgl-layers/line-layer/line-brushing-layer-vertex.glsl.js
deleted file mode 100644
index b6d9880fd..000000000
--- a/src/deckgl-layers/line-layer/line-brushing-layer-vertex.glsl.js
+++ /dev/null
@@ -1,83 +0,0 @@
-// Copyright (c) 2018 Uber Technologies, Inc.
-//
-// Permission is hereby granted, free of charge, to any person obtaining a copy
-// of this software and associated documentation files (the "Software"), to deal
-// in the Software without restriction, including without limitation the rights
-// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-// copies of the Software, and to permit persons to whom the Software is
-// furnished to do so, subject to the following conditions:
-//
-// The above copyright notice and this permission notice shall be included in
-// all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-// THE SOFTWARE.
-
-export default `\
-#define SHADER_NAME extruded-line-layer-vertex-shader
-
-
-attribute vec3 positions;
-attribute vec3 instanceSourcePositions;
-attribute vec3 instanceTargetPositions;
-attribute vec4 instanceColors;
-attribute vec4 instanceTargetColors;
-
-attribute vec3 instancePickingColors;
-attribute float instanceStrokeWidth;
-
-uniform float strokeScale;
-uniform float opacity;
-uniform float renderPickingBuffer;
-uniform vec4 pickedColor;
-
-uniform float enableBrushing;
-uniform float brushSource;
-uniform float brushTarget;
-
-varying vec4 vColor;
-
-void main(void) {
- // Position
- vec3 sourcePos = project_position(instanceSourcePositions);
- vec3 targetPos = project_position(instanceTargetPositions);
- vec4 source = project_to_clipspace(vec4(sourcePos, 1.0));
- vec4 target = project_to_clipspace(vec4(targetPos, 1.0));
- // if not enabled isPointInRange will always return true
- float isSourceInBrush = isPointInRange(instanceSourcePositions.xy, brushSource);
- float isTargetInBrush = isPointInRange(instanceTargetPositions.xy, brushTarget);
-
- float isInBrush = float(enableBrushing <= 0. ||
- (brushSource * isSourceInBrush > 0. || brushTarget * isTargetInBrush > 0.));
-
- // mix strokeScale with brush, if not in brush, return 0
- float width = strokeScale * instanceStrokeWidth;
- float finalWidth = mix(0.0, width, isInBrush);
-
- // linear interpolation of source & target to pick right coord
- float segmentIndex = positions.x;
- vec4 p = mix(source, target, segmentIndex);
-
- // extrude
- vec2 offset = getExtrusionOffset(target.xy - source.xy, positions.y, finalWidth);
- gl_Position = p + vec4(offset, 0.0, 0.0);
-
- float picked = isPicked(instancePickingColors);
-
- // Color
- vec4 color = mix(instanceColors, instanceTargetColors, positions.x) / 255.;
- vec4 finalColor = mix(color, pickedColor / 255., picked);
- vec4 pickingColor = vec4(instancePickingColors / 255., 1.);
-
- vColor = mix(
- vec4(finalColor.rgb, finalColor.a * opacity),
- pickingColor,
- renderPickingBuffer
- );
-}
-`;
diff --git a/src/deckgl-layers/line-layer/line-layer.js b/src/deckgl-layers/line-layer/line-layer.js
index 2e3dc21e3..eedc18367 100644
--- a/src/deckgl-layers/line-layer/line-layer.js
+++ b/src/deckgl-layers/line-layer/line-layer.js
@@ -20,12 +20,7 @@
import {LineLayer} from 'deck.gl';
import {GL} from 'luma.gl';
-
-import isPicked from '../../shaderlib/is-picked';
-import isPtInRange from '../../shaderlib/is-point-in-range';
-import getExtrusion from '../../shaderlib/get-extrusion-offset.glsl';
-import vs from './line-brushing-layer-vertex.glsl';
-import vs64 from './line-brushing-layer-vertex-64.glsl';
+import {editShader} from 'deckgl-layers/layer-utils/shader-utils';
const defaultProps = {
...LineLayer.defaultProps,
@@ -36,21 +31,48 @@ const defaultProps = {
enableBrushing: true,
getStrokeWidth: d => d.strokeWidth,
getTargetColor: x => x.color || [0, 0, 0, 255],
+ strokeScale: 1,
// brush radius in meters
brushRadius: 100000,
- pickedColor: [254, 210, 26, 255],
mousePosition: [0, 0]
};
+function addBrushingVsShader(vs) {
+ const targetColorVs = editShader(
+ vs,
+ 'line target color vs',
+ 'attribute vec4 instanceColors;',
+ 'attribute vec4 instanceColors; attribute vec4 instanceTargetColors;'
+ );
+
+ const brushingVs = editShader(
+ targetColorVs,
+ 'line brushing vs',
+ 'vec2 offset = getExtrusionOffset(target.xy - source.xy, positions.y);',
+ 'vec2 offset = brushing_getExtrusionOffset(target.xy - source.xy, positions.y, project_uViewportSize, vec4(instanceSourcePositions.xy, instanceTargetPositions.xy), instanceWidths);'
+ );
+
+ return editShader(
+ brushingVs,
+ 'line color vs',
+ 'vColor = vec4(instanceColors.rgb, instanceColors.a * opacity) / 255.;',
+ `vec4 color = mix(instanceColors, instanceTargetColors, positions.x) / 255.;` +
+ `vColor = vec4(color.rgb, color.a * opacity);`
+ )
+}
+
export default class LineBrushingLayer extends LineLayer {
getShaders() {
const shaders = super.getShaders();
- const addons = getExtrusion + isPicked + isPtInRange;
+ // const addons = getExtrusion + isPicked + isPtInRange;
return {
- ...shaders,
- vs: this.props.fp64 ? addons + vs64 : addons + vs
+ // ...shaders,
+ vs: addBrushingVsShader(shaders.vs),
+ fs: shaders.fs,
+ // vs: this.props.fp64 ? addons + vs64 : addons + vs,
+ modules: shaders.modules.concat(['brushing'])
};
}
@@ -58,11 +80,6 @@ export default class LineBrushingLayer extends LineLayer {
super.initializeState();
const {attributeManager} = this.state;
attributeManager.addInstanced({
- instanceStrokeWidth: {
- size: 1,
- accessor: ['getStrokeWidth'],
- update: this.calculateInstanceStrokeWidth
- },
instanceTargetColors: {
size: 4,
type: GL.UNSIGNED_BYTE,
@@ -78,44 +95,25 @@ export default class LineBrushingLayer extends LineLayer {
brushTarget,
brushRadius,
enableBrushing,
- pickedColor,
mousePosition,
strokeScale
} = this.props;
- const picked = !Array.isArray(pickedColor)
- ? defaultProps.pickedColor
- : pickedColor;
-
super.draw({
uniforms: {
...uniforms,
- brushSource,
- brushTarget,
- brushRadius,
- enableBrushing,
- strokeScale,
- pickedColor: new Uint8ClampedArray(
- !Number.isFinite(pickedColor[3]) ? [...picked, 255] : picked
- ),
- mousePos: mousePosition
+ brushing_uBrushSource: brushSource ? 1 : 0,
+ brushing_uBrushTarget: brushTarget ? 1 : 0,
+ brushing_uBrushRadius: brushRadius,
+ brushing_uEnableBrushing: enableBrushing ? 1 : 0,
+ brushing_uStrokeScale: strokeScale,
+ brushing_uMousePosition: mousePosition
? new Float32Array(this.unproject(mousePosition))
: defaultProps.mousePosition
}
});
}
- calculateInstanceStrokeWidth(attribute) {
- const {data, getStrokeWidth} = this.props;
- const {value, size} = attribute;
- let i = 0;
- for (const object of data) {
- const width = getStrokeWidth(object);
- value[i] = Number.isFinite(width) ? width : 1;
- i += size;
- }
- }
-
calculateInstanceTargetColors(attribute) {
const {data, getTargetColor} = this.props;
const {value, size} = attribute;
diff --git a/src/deckgl-layers/scatterplot-brushing-layer/scatterplot-brushing-layer-fragment.glsl.js b/src/deckgl-layers/scatterplot-brushing-layer/scatterplot-brushing-layer-fragment.glsl.js
deleted file mode 100644
index 66abf8946..000000000
--- a/src/deckgl-layers/scatterplot-brushing-layer/scatterplot-brushing-layer-fragment.glsl.js
+++ /dev/null
@@ -1,62 +0,0 @@
-// Copyright (c) 2018 Uber Technologies, Inc.
-//
-// Permission is hereby granted, free of charge, to any person obtaining a copy
-// of this software and associated documentation files (the "Software"), to deal
-// in the Software without restriction, including without limitation the rights
-// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-// copies of the Software, and to permit persons to whom the Software is
-// furnished to do so, subject to the following conditions:
-//
-// The above copyright notice and this permission notice shall be included in
-// all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-// THE SOFTWARE.
-
-// Copyright (c) 2015 - 2017 Uber Technologies, Inc.
-//
-// Permission is hereby granted, free of charge, to any person obtaining a copy
-// of this software and associated documentation files (the "Software"), to deal
-// in the Software without restriction, including without limitation the rights
-// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-// copies of the Software, and to permit persons to whom the Software is
-// furnished to do so, subject to the following conditions:
-//
-// The above copyright notice and this permission notice shall be included in
-// all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-// THE SOFTWARE.
-
-export default `\
-#define SHADER_NAME scatterplot-layer-fragment-shader
-
-#ifdef GL_ES
-precision highp float;
-#endif
-
-varying vec4 vColor;
-varying vec2 unitPosition;
-varying float innerUnitRadius;
-
-void main(void) {
-
- float distToCenter = length(unitPosition);
-
- if (distToCenter <= 1.0 && distToCenter >= innerUnitRadius) {
- gl_FragColor = vColor;
- } else {
- discard;
- }
-}
-`;
diff --git a/src/deckgl-layers/scatterplot-brushing-layer/scatterplot-brushing-layer-vertex.glsl.js b/src/deckgl-layers/scatterplot-brushing-layer/scatterplot-brushing-layer-vertex.glsl.js
deleted file mode 100644
index b33a13abb..000000000
--- a/src/deckgl-layers/scatterplot-brushing-layer/scatterplot-brushing-layer-vertex.glsl.js
+++ /dev/null
@@ -1,99 +0,0 @@
-// Copyright (c) 2018 Uber Technologies, Inc.
-//
-// Permission is hereby granted, free of charge, to any person obtaining a copy
-// of this software and associated documentation files (the "Software"), to deal
-// in the Software without restriction, including without limitation the rights
-// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-// copies of the Software, and to permit persons to whom the Software is
-// furnished to do so, subject to the following conditions:
-//
-// The above copyright notice and this permission notice shall be included in
-// all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-// THE SOFTWARE.
-
-// Copyright (c) 2015 - 2017 Uber Technologies, Inc.
-//
-// Permission is hereby granted, free of charge, to any person obtaining a copy
-// of this software and associated documentation files (the "Software"), to deal
-// in the Software without restriction, including without limitation the rights
-// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-// copies of the Software, and to permit persons to whom the Software is
-// furnished to do so, subject to the following conditions:
-//
-// The above copyright notice and this permission notice shall be included in
-// all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-// THE SOFTWARE.
-
-export default `\
-#define SHADER_NAME scatterplot-brushing-layer-vertex-shader
-
-attribute vec3 positions;
-
-attribute vec3 instancePositions;
-attribute float instanceRadius;
-attribute vec4 instanceColors;
-attribute vec3 instancePickingColors;
-
-uniform float opacity;
-uniform float radiusScale;
-uniform float radiusMinPixels;
-uniform float radiusMaxPixels;
-uniform float renderPickingBuffer;
-uniform float outline;
-uniform float strokeWidth;
-
-// uniform for brushing
-uniform float enableBrushing;
-uniform float outsideBrushRadius;
-
-varying vec4 vColor;
-varying vec2 unitPosition;
-varying float innerUnitRadius;
-
-void main(void) {
-
- // if enableBrushing is truthy calculate whether instancePosition is in range
- float isPtInBrush = isPointInRange(instancePositions.xy, enableBrushing);
-
- float finalRadius = mix(outsideBrushRadius, instanceRadius, isPtInBrush);
-
- // Multiply out radius and clamp to limits
- float outerRadiusPixels = clamp(
- project_scale(radiusScale * finalRadius),
- mix(0.0, radiusMinPixels, isPtInBrush),
- radiusMaxPixels
- );
- // outline is centered at the radius
- // outer radius needs to offset by half stroke width
- outerRadiusPixels += outline * mix(0., strokeWidth, isPtInBrush) / 2.;
-
- // position on the containing square in [-1, 1] space
- unitPosition = positions.xy;
- // 0 - solid circle, 1 - stroke with lineWidth=0
- innerUnitRadius = outline * (1. - strokeWidth / outerRadiusPixels);
-
- // Find the center of the point and add the current vertex
- vec3 center = project_position(instancePositions);
- vec3 vertex = positions * outerRadiusPixels;
- gl_Position = project_to_clipspace(vec4(center + vertex, 1.));
-
- // Apply opacity to instance color, or return instance picking color
- vec4 color = vec4(instanceColors.rgb, instanceColors.a * opacity) / 255.;
- vec4 pickingColor = vec4(instancePickingColors / 255., 1.);
- vColor = mix(color, pickingColor, renderPickingBuffer);
-}
-`;
diff --git a/src/deckgl-layers/scatterplot-brushing-layer/scatterplot-brushing-layer.js b/src/deckgl-layers/scatterplot-brushing-layer/scatterplot-brushing-layer.js
index 0dbd522c2..ff0dde373 100644
--- a/src/deckgl-layers/scatterplot-brushing-layer/scatterplot-brushing-layer.js
+++ b/src/deckgl-layers/scatterplot-brushing-layer/scatterplot-brushing-layer.js
@@ -19,10 +19,16 @@
// THE SOFTWARE.
import {ScatterplotLayer} from 'deck.gl';
+import {editShader} from 'deckgl-layers/layer-utils/shader-utils';
-import scatterplotVertex from './scatterplot-brushing-layer-vertex.glsl';
-import isPtInRange from '../../shaderlib/is-point-in-range';
-import scatterplotFragment from './scatterplot-brushing-layer-fragment.glsl';
+function addBrushingVsShader(vs) {
+ return editShader(
+ vs,
+ 'scatterplot brushing vs',
+ 'outerRadiusPixels += outline * strokeWidth / 2.0;',
+ 'outerRadiusPixels = brushing_getRadius(instancePositions, outerRadiusPixels + outline * strokeWidth / 2.0);'
+ );
+}
const defaultProps = {
...ScatterplotLayer.defaultProps,
@@ -34,26 +40,35 @@ const defaultProps = {
};
export default class ScatterplotBrushingLayer extends ScatterplotLayer {
+
getShaders() {
- // get customized shaders
+ const shaders = super.getShaders();
return {
- vs: isPtInRange + scatterplotVertex,
- fs: scatterplotFragment,
- shaderCache: this.context.shaderCache
+ vs: addBrushingVsShader(shaders.vs),
+ fs: shaders.fs,
+ modules: shaders.modules.concat(['brushing'])
};
}
+ draw(opts) {
+ const {uniforms} = opts;
+ const {
+ brushRadius,
+ enableBrushing,
+ mousePosition,
+ outsideBrushRadius
+ } = this.props;
- draw({uniforms}) {
// add uniforms
super.draw({
+ ...opts,
uniforms: {
...uniforms,
- brushRadius: this.props.brushRadius,
- outsideBrushRadius: this.props.outsideBrushRadius,
- mousePos: this.props.mousePosition
- ? new Float32Array(this.unproject(this.props.mousePosition))
+ brushing_uBrushRadius: brushRadius,
+ brushing_uOutsideBrushRadius: outsideBrushRadius,
+ brushing_uMousePosition: mousePosition
+ ? new Float32Array(this.unproject(mousePosition))
: defaultProps.mousePosition,
- enableBrushing: this.props.enableBrushing
+ brushing_uEnableBrushing: enableBrushing ? 1 : 0
}
});
}
diff --git a/src/deckgl-layers/svg-icon-layer/scatterplot-icon-layer.js b/src/deckgl-layers/svg-icon-layer/scatterplot-icon-layer.js
index fd17328f9..beaa9fb54 100644
--- a/src/deckgl-layers/svg-icon-layer/scatterplot-icon-layer.js
+++ b/src/deckgl-layers/svg-icon-layer/scatterplot-icon-layer.js
@@ -19,7 +19,8 @@
// THE SOFTWARE.
import {ScatterplotLayer} from 'deck.gl';
-import {GL, Geometry, Model} from 'luma.gl';
+import {Geometry, Model} from 'luma.gl';
+import {GL} from 'luma.gl';
export default class ScatterplotIconLayer extends ScatterplotLayer {
_getModel(gl) {
@@ -31,11 +32,15 @@ export default class ScatterplotIconLayer extends ScatterplotLayer {
const geometry = iconGeometry
? new Geometry({
drawMode: GL.TRIANGLES,
- positions: new Float32Array(iconGeometry)
+ attributes: {
+ positions: new Float32Array(iconGeometry)
+ }
})
: new Geometry({
drawMode: GL.TRIANGLE_FAN,
- positions: new Float32Array(defaultPos)
+ attributes: {
+ positions: new Float32Array(defaultPos)
+ }
});
return new Model(gl, {
diff --git a/src/layers/arc-layer/arc-layer.js b/src/layers/arc-layer/arc-layer.js
index 0720a9a6d..8c9efdc41 100644
--- a/src/layers/arc-layer/arc-layer.js
+++ b/src/layers/arc-layer/arc-layer.js
@@ -169,15 +169,14 @@ export default class ArcLayer extends Layer {
}, []);
}
- const getStrokeWidth = d =>
- sScale ? this.getEncodedChannelValue(sScale, d.data, sizeField) : 1;
+ const getStrokeWidth = sScale ? d =>
+ this.getEncodedChannelValue(sScale, d.data, sizeField, 0) : 1;
- const getColor = d =>
- cScale ? this.getEncodedChannelValue(cScale, d.data, colorField) : color;
+ const getColor = cScale ? d =>
+ this.getEncodedChannelValue(cScale, d.data, colorField) : color;
- const getTargetColor = d =>
- cScale
- ? this.getEncodedChannelValue(cScale, d.data, colorField)
+ const getTargetColor = cScale ? d =>
+ this.getEncodedChannelValue(cScale, d.data, colorField)
: targetColor || color;
return {
@@ -214,8 +213,8 @@ export default class ArcLayer extends Layer {
renderLayer({
data,
idx,
- layerInteraction,
objectHovered,
+ layerInteraction,
mapState,
interactionConfig
}) {
@@ -225,31 +224,43 @@ export default class ArcLayer extends Layer {
color: this.config.color,
colorField: this.config.colorField,
colorRange: this.config.visConfig.colorRange,
- colorScale: this.config.colorScale
+ colorScale: this.config.colorScale,
+ targetColor: this.config.visConfig.targetColor
+ };
+
+ const interaction = {
+ // auto highlighting
+ pickable: true,
+ autoHighlight: !brush.enabled,
+ highlightColor: this.config.highlightColor,
+
+ // brushing
+ brushRadius: brush.config.size * 1000,
+ brushSource: true,
+ brushTarget: true,
+ enableBrushing: brush.enabled
};
return [
- // base layer
new ArcBrushingLayer({
- ...layerInteraction,
...data,
+ ...interaction,
+ ...layerInteraction,
id: this.id,
idx,
- brushRadius: brush.config.size * 1000,
- brushSource: true,
- brushTarget: true,
- enableBrushing: brush.enabled,
fp64: this.config.visConfig['hi-precision'],
opacity: this.config.visConfig.opacity,
- pickable: true,
pickedColor: this.config.highlightColor,
strokeScale: this.config.visConfig.thickness,
+
+ // parameters
+ parameters: {depthTest: mapState.dragRotate},
+
updateTriggers: {
getStrokeWidth: {
sizeField: this.config.sizeField,
sizeRange: this.config.visConfig.sizeRange
},
- getColor: colorUpdateTriggers,
getSourceColor: colorUpdateTriggers,
getTargetColor: colorUpdateTriggers
}
diff --git a/src/layers/base-layer.js b/src/layers/base-layer.js
index 50e8a3f55..d8b9bfbb6 100644
--- a/src/layers/base-layer.js
+++ b/src/layers/base-layer.js
@@ -284,7 +284,7 @@ export default class Layer {
columns: props.columns || null,
isVisible: props.isVisible || false,
isConfigActive: props.isConfigActive || false,
- highlightColor: props.highlightColor || [252, 242, 26],
+ highlightColor: props.highlightColor || [252, 242, 26, 255],
// TODO: refactor this into separate visual Channel config
// color by field, domain is set by filters, field, scale type
diff --git a/src/layers/cluster-layer/cluster-layer.js b/src/layers/cluster-layer/cluster-layer.js
index 5028aa1d1..6f6155795 100644
--- a/src/layers/cluster-layer/cluster-layer.js
+++ b/src/layers/cluster-layer/cluster-layer.js
@@ -18,7 +18,6 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
-import {ScatterplotLayer} from 'deck.gl';
import AggregationLayer from '../aggregation-layer';
import DeckGLClusterLayer from 'deckgl-layers/cluster-layer/cluster-layer';
import {CHANNEL_SCALES} from 'constants/default-settings';
@@ -46,6 +45,7 @@ export default class ClusterLayer extends AggregationLayer {
get layerIcon() {
return ClusterLayerIcon;
}
+
get visualChannels() {
return {
color: {
@@ -65,7 +65,6 @@ export default class ClusterLayer extends AggregationLayer {
renderLayer({
data,
idx,
- layerInteraction,
objectHovered,
mapState,
interaction,
@@ -76,7 +75,6 @@ export default class ClusterLayer extends AggregationLayer {
return [
new DeckGLClusterLayer({
...data,
- ...layerInteraction,
id: this.id,
idx,
radiusScale: 1,
@@ -85,23 +83,19 @@ export default class ClusterLayer extends AggregationLayer {
colorRange: this.getColorRange(visConfig.colorRange),
colorScale: this.config.colorScale,
pickable: true,
+ autoHighlight: true,
+ highlightColor: this.config.highlightColor,
opacity: visConfig.opacity,
fp64: visConfig['hi-precision'],
lightSettings: this.meta.lightSettings,
+ zoom: mapState.zoom,
+
+ // parameters
+ parameters: {depthTest: mapState.dragRotate},
// call back from layer after calculate clusters
onSetColorDomain: layerCallbacks.onSetLayerDomain
- }),
-
- ...(this.isLayerHovered(objectHovered)
- ? [
- new ScatterplotLayer({
- id: `${this.id}-hovered`,
- data: [objectHovered.object],
- getColor: d => this.config.highlightColor
- })
- ]
- : [])
+ })
];
}
}
diff --git a/src/layers/geojson-layer/geojson-layer.js b/src/layers/geojson-layer/geojson-layer.js
index 6d43ccb38..48d58ac6b 100644
--- a/src/layers/geojson-layer/geojson-layer.js
+++ b/src/layers/geojson-layer/geojson-layer.js
@@ -22,7 +22,9 @@ import memoize from 'lodash.memoize';
import uniq from 'lodash.uniq';
import Layer from '../base-layer';
+import HighlightPolygonLayer from 'deckgl-layers/geojson-layer/solid-polygon-layer';
import {GeoJsonLayer as DeckGLGeoJsonLayer} from 'deck.gl';
+
import {hexToRgb} from 'utils/color-utils';
import {
getGeojsonDataMaps,
@@ -32,9 +34,18 @@ import {
import GeojsonLayerIcon from './geojson-layer-icon';
import {GEOJSON_FIELDS} from 'constants/default-settings';
-export const pointVisConfigs = {
+export const geojsonVisConfigs = {
opacity: 'opacity',
- thickness: 'thickness',
+ thickness: {
+ type: 'number',
+ defaultValue: 0.5,
+ label: 'Stroke Width',
+ isRanged: false,
+ range: [0, 100],
+ step: 0.1,
+ group: 'stroke',
+ property: 'thickness'
+ },
colorRange: 'colorRange',
radius: 'radius',
@@ -59,7 +70,7 @@ export default class GeoJsonLayer extends Layer {
super(props);
this.dataToFeature = {};
- this.registerVisConfig(pointVisConfigs);
+ this.registerVisConfig(geojsonVisConfigs);
this.getFeature = memoize(featureAccessor, featureResolver);
}
@@ -317,7 +328,6 @@ export default class GeoJsonLayer extends Layer {
renderLayer({
data,
idx,
- layerInteraction,
objectHovered,
mapState,
interactionConfig
@@ -325,50 +335,49 @@ export default class GeoJsonLayer extends Layer {
const {fp64, lightSettings, fixedRadius} = this.meta;
const radiusScale = this.getRadiusScaleByZoom(mapState, fixedRadius);
const zoomFactor = this.getZoomFactor(mapState);
+ const {visConfig} = this.config;
const layerProps = {
// multiplier applied just so it being consistent with previously saved maps
- lineWidthScale: this.config.visConfig.thickness * zoomFactor * 8,
+ lineWidthScale: visConfig.thickness * zoomFactor * 8,
lineWidthMinPixels: 1,
- elevationScale: this.config.visConfig.elevationScale,
+ elevationScale: visConfig.elevationScale,
pointRadiusScale: radiusScale,
- fp64: fp64 || this.config.visConfig['hi-precision'],
- lineMiterLimit: 10 * zoomFactor,
- rounded: true
+ fp64: fp64 || visConfig['hi-precision'],
+ lineMiterLimit: 4
};
const updateTriggers = {
getElevation: {
heightField: this.config.heightField,
heightScale: this.config.heightScale,
- heightRange: this.config.visConfig.heightRange
+ heightRange: visConfig.heightRange
},
getFillColor: {
color: this.config.color,
colorField: this.config.colorField,
- colorRange: this.config.visConfig.colorRange,
+ colorRange: visConfig.colorRange,
colorScale: this.config.colorScale
},
getLineColor: {
color: this.config.color,
colorField: this.config.colorField,
- colorRange: this.config.visConfig.colorRange,
+ colorRange: visConfig.colorRange,
colorScale: this.config.colorScale
},
getLineWidth: {
sizeField: this.config.sizeField,
- sizeRange: this.config.visConfig.sizeRange
+ sizeRange: visConfig.sizeRange
},
getRadius: {
radiusField: this.config.radiusField,
- radiusRange: this.config.visConfig.radiusRange
+ radiusRange: visConfig.radiusRange
}
};
return [
new DeckGLGeoJsonLayer({
...layerProps,
- ...layerInteraction,
id: this.id,
idx,
data: data.data,
@@ -377,16 +386,26 @@ export default class GeoJsonLayer extends Layer {
getLineWidth: data.getLineWidth,
getRadius: data.getRadius,
getElevation: data.getElevation,
+ // highlight
pickable: true,
- opacity: this.config.visConfig.opacity,
- stroked: this.config.visConfig.stroked,
- filled: this.config.visConfig.filled,
- extruded: this.config.visConfig.enable3d,
- wireframe: this.config.visConfig.wireframe,
+ // highlightColor: this.config.highlightColor,
+ autoHighlight: visConfig.enable3d,
+ // parameters
+ parameters: {depthTest: Boolean(visConfig.enable3d || mapState.dragRotate)},
+ opacity: visConfig.opacity,
+ stroked: visConfig.stroked,
+ filled: visConfig.filled,
+ extruded: visConfig.enable3d,
+ wireframe: visConfig.wireframe,
lightSettings,
- updateTriggers
+ updateTriggers,
+
+ subLayers: {
+ ...DeckGLGeoJsonLayer.defaultProps.subLayers,
+ PolygonLayer: HighlightPolygonLayer
+ }
}),
- ...(this.isLayerHovered(objectHovered)
+ ...(this.isLayerHovered(objectHovered) && !visConfig.enable3d
? [
new DeckGLGeoJsonLayer({
...layerProps,
diff --git a/src/layers/grid-layer/grid-layer.js b/src/layers/grid-layer/grid-layer.js
index 057aef519..df4d0bbd6 100644
--- a/src/layers/grid-layer/grid-layer.js
+++ b/src/layers/grid-layer/grid-layer.js
@@ -54,6 +54,7 @@ export default class GridLayer extends AggregationLayer {
get layerIcon() {
return GridLayerIcon;
}
+
formatLayerData(_, allData, filteredIndex, oldLayerData, opt = {}) {
const formattedData = super.formatLayerData(
_,
@@ -81,7 +82,6 @@ export default class GridLayer extends AggregationLayer {
renderLayer({
data,
idx,
- layerInteraction,
objectHovered,
mapState,
interaction,
@@ -95,11 +95,12 @@ export default class GridLayer extends AggregationLayer {
return [
new EnhancedGridLayer({
...data,
- ...layerInteraction,
id: this.id,
idx,
cellSize,
coverage: visConfig.coverage,
+ // highlight
+ autoHighlight: visConfig.enable3d,
// color
colorRange: this.getColorRange(visConfig.colorRange),
@@ -113,6 +114,8 @@ export default class GridLayer extends AggregationLayer {
elevationScale: visConfig.elevationScale * eleZoomFactor,
elevationLowerPercentile: visConfig.elevationPercentile[0],
elevationUpperPercentile: visConfig.elevationPercentile[1],
+ // parameters
+ parameters: {depthTest: Boolean(visConfig.enable3d || mapState.dragRotate)},
// render
fp64: visConfig['hi-precision'],
@@ -123,6 +126,7 @@ export default class GridLayer extends AggregationLayer {
onSetColorDomain: layerCallbacks.onSetLayerDomain
}),
+ // render an outline of each cell if not extruded
...(this.isLayerHovered(objectHovered) && !visConfig.enable3d
? [
new GeoJsonLayer({
diff --git a/src/layers/hexagon-layer/hexagon-layer.js b/src/layers/hexagon-layer/hexagon-layer.js
index 3db7671c8..5b7198749 100644
--- a/src/layers/hexagon-layer/hexagon-layer.js
+++ b/src/layers/hexagon-layer/hexagon-layer.js
@@ -63,7 +63,6 @@ export default class HexagonLayer extends AggregationLayer {
renderLayer({
data,
idx,
- layerInteraction,
objectHovered,
mapState,
interaction,
@@ -77,9 +76,12 @@ export default class HexagonLayer extends AggregationLayer {
return [
new EnhancedHexagonLayer({
...data,
- ...layerInteraction,
id: this.id,
idx,
+
+ // highlight
+ autoHighlight: visConfig.enable3d,
+
radius,
coverage: visConfig.coverage,
@@ -90,6 +92,9 @@ export default class HexagonLayer extends AggregationLayer {
upperPercentile: visConfig.percentile[1],
lowerPercentile: visConfig.percentile[0],
+ // parameters
+ parameters: {depthTest: Boolean(visConfig.enable3d || mapState.dragRotate)},
+
// elevation
extruded: visConfig.enable3d,
elevationScale: visConfig.elevationScale * eleZoomFactor,
@@ -100,11 +105,11 @@ export default class HexagonLayer extends AggregationLayer {
fp64: visConfig['hi-precision'],
pickable: true,
lightSettings: this.meta.lightSettings,
-
// callbacks
onSetColorDomain: layerCallbacks.onSetLayerDomain
}),
+ // render an outline of each hexagon if not extruded
...(this.isLayerHovered(objectHovered) && !visConfig.enable3d
? [
new GeoJsonLayer({
@@ -112,11 +117,12 @@ export default class HexagonLayer extends AggregationLayer {
data: [
hexagonToPolygonGeo(
objectHovered,
- {lineColor: this.config.highlightColor},
+ {},
radius * visConfig.coverage,
mapState
)
],
+ getLineColor: this.config.highlightColor,
lineWidthScale: 8 * zoomFactor
})
]
diff --git a/src/layers/icon-layer/icon-layer.js b/src/layers/icon-layer/icon-layer.js
index 2778b9e5e..665444d5c 100644
--- a/src/layers/icon-layer/icon-layer.js
+++ b/src/layers/icon-layer/icon-layer.js
@@ -23,7 +23,6 @@ import memoize from 'lodash.memoize';
import {hexToRgb} from 'utils/color-utils';
import {svgIcons as SvgIcons} from './svg-icons.json';
import SvgIconLayer from 'deckgl-layers/svg-icon-layer/svg-icon-layer';
-import ScatterplotIconLayer from 'deckgl-layers/svg-icon-layer/scatterplot-icon-layer';
import IconLayerIcon from './icon-layer-icon';
import {ICON_FIELDS} from 'constants/default-settings';
import IconInfoModalFactory from './icon-info-modal';
@@ -211,11 +210,11 @@ export default class IconLayer extends Layer {
}, []);
}
- const getRadius = d =>
- rScale ? this.getEncodedChannelValue(rScale, d.data, sizeField) : 1;
+ const getRadius = rScale ? d =>
+ this.getEncodedChannelValue(rScale, d.data, sizeField) : 1;
- const getColor = d =>
- cScale ? this.getEncodedChannelValue(cScale, d.data, colorField) : color;
+ const getColor = cScale ? d =>
+ this.getEncodedChannelValue(cScale, d.data, colorField) : color;
return {
data,
@@ -234,7 +233,6 @@ export default class IconLayer extends Layer {
renderLayer({
data,
idx,
- layerInteraction,
objectHovered,
mapState,
interactionConfig
@@ -249,13 +247,21 @@ export default class IconLayer extends Layer {
return [
new SvgIconLayer({
...layerProps,
- ...layerInteraction,
...data,
id: this.id,
idx,
opacity: this.config.visConfig.opacity,
getIconGeometry: id => SvgIconGeometry[id],
+
+ // picking
+ autoHighlight: true,
+ highlightColor: this.config.highlightColor,
pickable: true,
+
+ // parameters
+ parameters: {depthTest: mapState.dragRotate},
+
+ // update triggers
updateTriggers: {
getRadius: {
sizeField: this.config.colorField,
@@ -269,25 +275,7 @@ export default class IconLayer extends Layer {
colorScale: this.config.colorScale
}
}
- }),
- ...(this.isLayerHovered(objectHovered)
- ? [
- new ScatterplotIconLayer({
- ...layerProps,
- id: `${this.id}-hovered`,
- data: [
- {
- ...objectHovered.object,
- position: data.getPosition(objectHovered.object),
- radius: data.getRadius(objectHovered.object),
- color: this.config.highlightColor
- }
- ],
- iconGeometry: SvgIconGeometry[objectHovered.object.icon],
- pickable: false
- })
- ]
- : [])
+ })
];
}
}
diff --git a/src/layers/line-layer/line-layer.js b/src/layers/line-layer/line-layer.js
index f594de6f3..3bd48201d 100644
--- a/src/layers/line-layer/line-layer.js
+++ b/src/layers/line-layer/line-layer.js
@@ -65,7 +65,21 @@ export default class LineLayer extends ArcLayer {
color: this.config.color,
colorField: this.config.colorField,
colorRange: this.config.visConfig.colorRange,
- colorScale: this.config.colorScale
+ colorScale: this.config.colorScale,
+ targetColor: this.config.visConfig.targetColor
+ };
+
+ const interaction = {
+ // auto highlighting
+ pickable: true,
+ autoHighlight: !brush.enabled,
+ highlightColor: this.config.highlightColor,
+
+ // brushing
+ brushRadius: brush.config.size * 1000,
+ brushSource: true,
+ brushTarget: true,
+ enableBrushing: brush.enabled
};
return [
@@ -73,24 +87,22 @@ export default class LineLayer extends ArcLayer {
new DeckGLLineLayer({
...layerInteraction,
...data,
+ ...interaction,
getColor: data.getSourceColor,
id: this.id,
idx,
- brushRadius: brush.config.size * 1000,
- brushSource: true,
- brushTarget: true,
- enableBrushing: brush.enabled,
fp64: this.config.visConfig['hi-precision'],
opacity: this.config.visConfig.opacity,
- pickable: true,
- pickedColor: this.config.highlightColor,
strokeScale: this.config.visConfig.thickness,
+ // parameters
+ parameters: {depthTest: mapState.dragRotate},
updateTriggers: {
getStrokeWidth: {
sizeField: this.config.sizeField,
sizeRange: this.config.visConfig.sizeRange
},
- getColor: colorUpdateTriggers
+ getColor: colorUpdateTriggers,
+ getTargetColor: colorUpdateTriggers
}
})
];
diff --git a/src/layers/point-layer/point-layer.js b/src/layers/point-layer/point-layer.js
index 0b5d7f6f4..f6a5a7637 100644
--- a/src/layers/point-layer/point-layer.js
+++ b/src/layers/point-layer/point-layer.js
@@ -20,7 +20,6 @@
import Layer from '../base-layer';
import memoize from 'lodash.memoize';
-import {ScatterplotLayer} from 'deck.gl';
import ScatterplotBrushingLayer from 'deckgl-layers/scatterplot-brushing-layer/scatterplot-brushing-layer';
import {hexToRgb} from 'utils/color-utils';
import PointLayerIcon from './point-layer-icon';
@@ -191,11 +190,11 @@ export default class PointLayer extends Layer {
}, []);
}
- const getRadius = d =>
- rScale ? this.getEncodedChannelValue(rScale, d.data, sizeField) : 1;
+ const getRadius = rScale ? d =>
+ this.getEncodedChannelValue(rScale, d.data, sizeField) : 1;
- const getColor = d =>
- cScale ? this.getEncodedChannelValue(cScale, d.data, colorField) : color;
+ const getColor = cScale ? d =>
+ this.getEncodedChannelValue(cScale, d.data, colorField) : color;
return {
data,
@@ -218,6 +217,8 @@ export default class PointLayer extends Layer {
mapState,
interactionConfig
}) {
+ const enableBrushing = interactionConfig.brush.enabled;
+
const layerProps = {
outline: this.config.visConfig.outline,
radiusMinPixels: 1,
@@ -227,60 +228,43 @@ export default class PointLayer extends Layer {
...(this.config.visConfig.fixedRadius ? {} : {radiusMaxPixels: 500})
};
- const baseLayerProp = {
- ...layerProps,
- ...layerInteraction,
- ...data,
- idx,
- opacity: this.config.visConfig.opacity,
- pickable: true,
- updateTriggers: {
- getRadius: {
- sizeField: this.config.sizeField,
- radiusRange: this.config.visConfig.radiusRange,
- fixedRadius: this.config.visConfig.fixedRadius,
- sizeScale: this.config.sizeScale
- },
- getColor: {
- color: this.config.color,
- colorField: this.config.colorField,
- colorRange: this.config.visConfig.colorRange,
- colorScale: this.config.colorScale
- }
- }
+ const interaction = {
+ autoHighlight: !enableBrushing,
+ enableBrushing,
+ brushRadius: interactionConfig.brush.config.size * 1000,
+ highlightColor: this.config.highlightColor
};
return [
- // base layer
- interactionConfig.brush.enabled
- ? new ScatterplotBrushingLayer({
- ...baseLayerProp,
- id: `${this.id}-brush`,
- enableBrushing: true,
- brushRadius: interactionConfig.brush.config.size * 1000
- })
- : new ScatterplotLayer({
- id: this.id,
- ...baseLayerProp
- }),
-
- // hover layer
- ...(this.isLayerHovered(objectHovered)
- ? [
- new ScatterplotLayer({
- ...layerProps,
- id: `${this.id}-hovered`,
- data: [
- {
- color: this.config.highlightColor,
- position: data.getPosition(objectHovered.object),
- radius: data.getRadius(objectHovered.object)
- }
- ],
- pickable: false
- })
- ]
- : [])
+ new ScatterplotBrushingLayer({
+ ...layerProps,
+ ...layerInteraction,
+ ...data,
+ ...interaction,
+ idx,
+ id: this.id,
+ opacity: this.config.visConfig.opacity,
+ pickable: true,
+ // parameters
+ parameters: {
+ depthTest: mapState.dragRotate
+ },
+
+ updateTriggers: {
+ getRadius: {
+ sizeField: this.config.sizeField,
+ radiusRange: this.config.visConfig.radiusRange,
+ fixedRadius: this.config.visConfig.fixedRadius,
+ sizeScale: this.config.sizeScale
+ },
+ getColor: {
+ color: this.config.color,
+ colorField: this.config.colorField,
+ colorRange: this.config.visConfig.colorRange,
+ colorScale: this.config.colorScale
+ }
+ }
+ })
];
}
}
diff --git a/src/reducers/vis-state-updaters.js b/src/reducers/vis-state-updaters.js
index 19eeff5e2..b2c8b266a 100644
--- a/src/reducers/vis-state-updaters.js
+++ b/src/reducers/vis-state-updaters.js
@@ -926,6 +926,7 @@ function closeSpecificMapAtIndex(state, action) {
// TODO: redo write handler to not use tasks
export const loadFilesUpdater = (state, action) => {
const {files} = action;
+
const filesToLoad = files.map(fileBlob => ({
fileBlob,
info: {
diff --git a/src/shaderlib/brushing-module.js b/src/shaderlib/brushing-module.js
new file mode 100644
index 000000000..9807a2c5d
--- /dev/null
+++ b/src/shaderlib/brushing-module.js
@@ -0,0 +1,103 @@
+// Copyright (c) 2018 Uber Technologies, Inc.
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+// THE SOFTWARE.
+
+function getUniforms() {
+ return {};
+}
+
+const vs = `\
+uniform vec2 brushing_uMousePosition;
+uniform float brushing_uBrushRadius;
+uniform float brushing_uBrushSource;
+uniform float brushing_uBrushTarget;
+uniform float brushing_uEnableBrushing;
+uniform float brushing_uStrokeScale;
+uniform float brushing_uOutsideBrushRadius;
+
+const float R_EARTH = 6371000.; // earth radius in meter
+// const float PI = 3.1415926538;
+
+// approximate distance between lng lat in meters
+float distanceBetweenLatLng(vec2 source, vec2 target) {
+ float PI = 3.1415926538;
+ vec2 delta = (source - target) * PI / 180.;
+
+ float a =
+ sin(delta.y / 2.) * sin(delta.y / 2.) +
+ cos(source.y * PI / 180.) * cos(target.y * PI / 180.) *
+ sin(delta.x / 2.) * sin(delta.x / 2.);
+
+ float c = 2. * atan(sqrt(a), sqrt(1. - a));
+
+ return R_EARTH * c;
+}
+
+// range is km
+float isPointInRange(vec2 ptLatLng, float enabled) {
+ return float(enabled <= 0. || distanceBetweenLatLng(ptLatLng, brushing_uMousePosition) <= brushing_uBrushRadius);
+}
+
+vec2 getExtrusionOffset(vec2 line_clipspace, vec2 viewportSize, float offset_direction, float lineWidth) {
+ // normalized direction of the line
+ vec2 dir_screenspace = normalize(line_clipspace * viewportSize);
+ // rotate by 90 degrees
+ dir_screenspace = vec2(-dir_screenspace.y, dir_screenspace.x);
+
+ vec2 offset_screenspace = dir_screenspace * offset_direction * lineWidth / 2.0;
+ vec2 offset_clipspace = offset_screenspace / viewportSize * 2.0;
+
+ return offset_clipspace;
+}
+
+vec2 brushing_getExtrusionOffset(
+ vec2 line_clipspace,
+ float offset_direction,
+ vec2 viewportSize,
+ vec4 instancePositions,
+ float instanceStrokeWidth
+) {
+ float isSourceInBrush = isPointInRange(instancePositions.xy, brushing_uBrushSource);
+ float isTargetInBrush = isPointInRange(instancePositions.zw, brushing_uBrushTarget);
+
+ float isInBrush = float(brushing_uEnableBrushing <= 0. ||
+ (brushing_uBrushSource * isSourceInBrush > 0. || brushing_uBrushTarget * isTargetInBrush > 0.));
+
+ float strokeWidth = brushing_uStrokeScale * instanceStrokeWidth;
+
+ float finalWidth = mix(0.0, strokeWidth, isInBrush);
+
+ // extrude
+ return getExtrusionOffset(line_clipspace, viewportSize, offset_direction, finalWidth);
+}
+
+float brushing_getRadius(
+ vec3 instancePositions,
+ float instanceRadius
+) {
+ float isPtInBrush = isPointInRange(instancePositions.xy, brushing_uEnableBrushing);
+ return mix(brushing_uOutsideBrushRadius, instanceRadius, isPtInBrush);
+}
+`;
+
+export default {
+ name: 'brushing',
+ vs,
+ getUniforms
+};
diff --git a/src/shaderlib/get-extrusion-offset.glsl.js b/src/shaderlib/get-extrusion-offset.glsl.js
deleted file mode 100644
index f454342b5..000000000
--- a/src/shaderlib/get-extrusion-offset.glsl.js
+++ /dev/null
@@ -1,37 +0,0 @@
-// Copyright (c) 2018 Uber Technologies, Inc.
-//
-// Permission is hereby granted, free of charge, to any person obtaining a copy
-// of this software and associated documentation files (the "Software"), to deal
-// in the Software without restriction, including without limitation the rights
-// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-// copies of the Software, and to permit persons to whom the Software is
-// furnished to do so, subject to the following conditions:
-//
-// The above copyright notice and this permission notice shall be included in
-// all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-// THE SOFTWARE.
-
-export default `\
-uniform vec2 viewportSize;
-
-// offset vector by strokeWidth pixels
-// offset_direction is -1 (left) or 1 (right)
-vec2 getExtrusionOffset(vec2 line_clipspace, float offset_direction, float lineWidth) {
- // normalized direction of the line
- vec2 dir_screenspace = normalize(line_clipspace * viewportSize);
- // rotate by 90 degrees
- dir_screenspace = vec2(-dir_screenspace.y, dir_screenspace.x);
-
- vec2 offset_screenspace = dir_screenspace * offset_direction * lineWidth / 2.0;
- vec2 offset_clipspace = offset_screenspace / viewportSize * 2.0;
-
- return offset_clipspace;
-}
-`;
diff --git a/src/shaderlib/is-point-in-range.js b/src/shaderlib/is-point-in-range.js
deleted file mode 100644
index 1a396d810..000000000
--- a/src/shaderlib/is-point-in-range.js
+++ /dev/null
@@ -1,49 +0,0 @@
-// Copyright (c) 2018 Uber Technologies, Inc.
-//
-// Permission is hereby granted, free of charge, to any person obtaining a copy
-// of this software and associated documentation files (the "Software"), to deal
-// in the Software without restriction, including without limitation the rights
-// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-// copies of the Software, and to permit persons to whom the Software is
-// furnished to do so, subject to the following conditions:
-//
-// The above copyright notice and this permission notice shall be included in
-// all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-// THE SOFTWARE.
-
-export default `\
-
-const float R_EARTH = 6371000.; // earth radius in meter
-
-// uniform for brushing
-uniform vec2 mousePos;
-uniform float brushRadius;
-
-// approximate distance between lng lat in meters
-float distanceBetweenLatLng(vec2 source, vec2 target) {
-
- vec2 delta = (source - target) * PI / 180.;
-
- float a =
- sin(delta.y / 2.) * sin(delta.y / 2.) +
- cos(source.y * PI / 180.) * cos(target.y * PI / 180.) *
- sin(delta.x / 2.) * sin(delta.x / 2.);
-
- float c = 2. * atan(sqrt(a), sqrt(1. - a));
-
- return R_EARTH * c;
-}
-
-// range is km
-float isPointInRange(vec2 ptLatLng, float enabled) {
-
- return float(enabled <= 0. || distanceBetweenLatLng(ptLatLng, mousePos) <= brushRadius);
-}
-`;
diff --git a/src/shaderlib/picking-module.js b/src/shaderlib/picking-module.js
new file mode 100644
index 000000000..ca3223a1f
--- /dev/null
+++ b/src/shaderlib/picking-module.js
@@ -0,0 +1,69 @@
+// Copyright (c) 2018 Uber Technologies, Inc.
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+// THE SOFTWARE.
+
+import {picking} from 'luma.gl';
+
+// add picking_uHighlightScale to fs uniform
+const fs = `\
+uniform bool picking_uActive; // true during rendering to offscreen picking buffer
+uniform vec3 picking_uSelectedColor;
+uniform vec4 picking_uHighlightColor;
+uniform float picking_uHighlightScale;
+
+varying vec4 picking_vRGBcolor_Aselected;
+
+const float COLOR_SCALE = 1. / 255.;
+
+/*
+ * Returns highlight color if this item is selected.
+ */
+vec4 picking_filterHighlightColor(vec4 color) {
+ bool selected = bool(picking_vRGBcolor_Aselected.a);
+ // return selected ? (picking_uHighlightColor * COLOR_SCALE) : color;
+ return selected ? (
+ (bool(picking_uHighlightScale > 0.0) ? color * picking_uHighlightScale : picking_uHighlightColor * COLOR_SCALE)
+ ) : color;
+}
+
+/*
+ * Returns picking color if picking enabled else unmodified argument.
+ */
+vec4 picking_filterPickingColor(vec4 color) {
+ vec3 pickingColor = picking_vRGBcolor_Aselected.rgb;
+ if (picking_uActive && length(pickingColor) < 0.001) {
+ discard;
+ }
+ return picking_uActive ? vec4(pickingColor, 1.0) : color;
+}
+
+/*
+ * Returns picking color if picking is enabled if not
+ * highlight color if this item is selected, otherwise unmodified argument.
+ */
+vec4 picking_filterColor(vec4 color) {
+ vec4 highightColor = picking_filterHighlightColor(color);
+ return picking_filterPickingColor(highightColor);
+}
+`;
+
+export default {
+ ...picking,
+ fs
+};
diff --git a/test/fixtures/state-saved-v0.js b/test/fixtures/state-saved-v0.js
index 99d10fcc8..154651640 100644
--- a/test/fixtures/state-saved-v0.js
+++ b/test/fixtures/state-saved-v0.js
@@ -1141,7 +1141,7 @@ mergedLayer2.config = {
optional: true
}
},
- highlightColor: [252, 242, 26],
+ highlightColor: [252, 242, 26, 255],
isConfigActive: false,
isVisible: true,
colorField: {
@@ -1225,7 +1225,7 @@ mergedLayer3.config = {
format: '',
tableFieldIndex: 10
},
- highlightColor: [252, 242, 26],
+ highlightColor: [252, 242, 26, 255],
isConfigActive: false,
colorScale: 'quantile',
colorDomain: [0, 1],
@@ -1285,7 +1285,7 @@ mergedLayer4.config = {
fieldIdx: 0
}
},
- highlightColor: [252, 242, 26],
+ highlightColor: [252, 242, 26, 255],
isConfigActive: false,
isVisible: true,
colorField: {
diff --git a/test/fixtures/state-saved-v1-1.js b/test/fixtures/state-saved-v1-1.js
index bc7ec3994..5f6651fcc 100644
--- a/test/fixtures/state-saved-v1-1.js
+++ b/test/fixtures/state-saved-v1-1.js
@@ -875,7 +875,7 @@ mergedLayer0.config = {
},
isVisible: true,
isConfigActive: false,
- highlightColor: [252, 242, 26],
+ highlightColor: [252, 242, 26, 255],
colorField: {
name: 'c_m_r',
type: 'integer',
@@ -2667,7 +2667,7 @@ mergedLayer1.config = {
},
isVisible: true,
isConfigActive: false,
- highlightColor: [252, 242, 26],
+ highlightColor: [252, 242, 26, 255],
colorField: null,
colorScale: 'quantile',
colorDomain: [0, 1],
diff --git a/test/fixtures/state-saved-v1-3.js b/test/fixtures/state-saved-v1-3.js
index b77fb2bce..205910dce 100644
--- a/test/fixtures/state-saved-v1-3.js
+++ b/test/fixtures/state-saved-v1-3.js
@@ -383,7 +383,7 @@ mergedLayer0.config = {
tableFieldIndex: 1
},
colorDomain: [1000, 1000, 2000, 2000, 2000, 3000, 3000, 3000, 3000],
- highlightColor: [252, 242, 26],
+ highlightColor: [252, 242, 26, 255],
isConfigActive: false,
colorScale: 'quantile',
sizeField: {
@@ -441,7 +441,7 @@ mergedLayer1.config = {
isVisible: true,
colorField: null,
colorDomain: [0, 1],
- highlightColor: [252, 242, 26],
+ highlightColor: [252, 242, 26, 255],
isConfigActive: false,
colorScale: 'quantize',
sizeField: null,
diff --git a/test/helpers/mock-state.js b/test/helpers/mock-state.js
index b5bbf756f..79fcfd668 100644
--- a/test/helpers/mock-state.js
+++ b/test/helpers/mock-state.js
@@ -97,7 +97,7 @@ function mockStateWithFileUpload() {
// replace layer id and color with controlled value for easy testing
updatedState.visState.layers.forEach((l, i) => {
l.id = `${l.type}-${i}`;
- l.config.color = [i, i, i]
+ l.config.color = [i, i, i];
});
return Immutable.fromJS(updatedState);
@@ -172,7 +172,10 @@ function mockStateWithLayerDimensions(state) {
{action: VisStateActions.layerVisConfigChange, payload: colorRangePayload},
// add layer
- {action: VisStateActions.addLayer, payload: [{id: 'hexagon-2', color: [2, 2, 2]}]}
+ {
+ action: VisStateActions.addLayer,
+ payload: [{id: 'hexagon-2', color: [2, 2, 2]}]
+ }
]);
const newLayer = prepareState.visState.layers[2];
@@ -216,9 +219,12 @@ function mockStateWithCustomMapStyle(state) {
isValid: true,
label: 'Smoothie the Cat',
icon: 'data:image/png;base64,xyz',
- style: {version: 'v8', id: 'smoothie_the_cat', layers: [
- {id: 'background'}, {id: 'road'}, {id: 'label'}
- ], name: 'Smoothie the Cat'},
+ style: {
+ version: 'v8',
+ id: 'smoothie_the_cat',
+ layers: [{id: 'background'}, {id: 'road'}, {id: 'label'}],
+ name: 'Smoothie the Cat'
+ },
url: 'mapbox://styles/shanhe/smoothie.the.cat'
};
@@ -230,14 +236,16 @@ function mockStateWithCustomMapStyle(state) {
},
{
action: MapStyleActions.loadCustomMapStyle,
- payload: [{
- style: testCustomMapStyle.style
- }]
+ payload: [
+ {
+ style: testCustomMapStyle.style
+ }
+ ]
},
{
action: MapStyleActions.addCustomMapStyle,
payload: [{}]
- },
+ }
]);
return Immutable.fromJS(updatedState);
@@ -369,17 +377,9 @@ export const expectedSavedLayer1 = {
name: 'Uber Viz Sequential 2',
type: 'sequential',
category: 'Uber',
- colors: [
- '#E6FAFA',
- '#AAD7DA',
- '#68B4BB',
- '#00939C'
- ]
+ colors: ['#E6FAFA', '#AAD7DA', '#68B4BB', '#00939C']
},
- radiusRange: [
- 0,
- 50
- ],
+ radiusRange: [0, 50],
'hi-precision': false
}
},
@@ -417,12 +417,7 @@ export const expectedLoadedLayer1 = {
name: 'Uber Viz Sequential 2',
type: 'sequential',
category: 'Uber',
- colors: [
- '#E6FAFA',
- '#AAD7DA',
- '#68B4BB',
- '#00939C'
- ]
+ colors: ['#E6FAFA', '#AAD7DA', '#68B4BB', '#00939C']
},
radiusRange: [0, 50],
'hi-precision': false
@@ -438,24 +433,24 @@ export const expectedLoadedLayer1 = {
};
export const expectedSavedLayer2 = {
- id :'geojson-1',
- type :'geojson',
- config :{
- dataId :'ieukmgne',
- label :'zip',
- color :[1, 1, 1],
- columns :{
- geojson :'_geojson'
+ id: 'geojson-1',
+ type: 'geojson',
+ config: {
+ dataId: 'ieukmgne',
+ label: 'zip',
+ color: [1, 1, 1],
+ columns: {
+ geojson: '_geojson'
},
- isVisible :true,
- visConfig :{
- opacity :0.8,
- thickness :2,
- colorRange :{
- name :'Global Warming',
- type :'sequential',
- category :'Uber',
- colors :[
+ isVisible: true,
+ visConfig: {
+ opacity: 0.8,
+ thickness: 0.5,
+ colorRange: {
+ name: 'Global Warming',
+ type: 'sequential',
+ category: 'Uber',
+ colors: [
'#5A1846',
'#900C3F',
'#C70039',
@@ -464,27 +459,27 @@ export const expectedSavedLayer2 = {
'#FFC300'
]
},
- radius :10,
- sizeRange :[0, 10],
- radiusRange :[0, 50],
- heightRange :[0, 500],
- elevationScale :5,
- 'hi-precision' :false,
- stroked :true,
- filled :false,
- enable3d :false,
- wireframe :false
+ radius: 10,
+ sizeRange: [0, 10],
+ radiusRange: [0, 50],
+ heightRange: [0, 500],
+ elevationScale: 5,
+ 'hi-precision': false,
+ stroked: true,
+ filled: false,
+ enable3d: false,
+ wireframe: false
}
},
- visualChannels :{
- colorField :null,
- colorScale :'quantile',
- sizeField :null,
- sizeScale :'linear',
- heightField :null,
- heightScale :'linear',
- radiusField :null,
- radiusScale :'linear'
+ visualChannels: {
+ colorField: null,
+ colorScale: 'quantile',
+ sizeField: null,
+ sizeScale: 'linear',
+ heightField: null,
+ heightScale: 'linear',
+ radiusField: null,
+ radiusScale: 'linear'
}
};
@@ -501,7 +496,7 @@ export const expectedLoadedLayer2 = {
isVisible: true,
visConfig: {
opacity: 0.8,
- thickness: 2,
+ thickness: 0.5,
colorRange: {
name: 'Global Warming',
type: 'sequential',
diff --git a/test/node/layer-tests/point-layer-specs.js b/test/node/layer-tests/point-layer-specs.js
index 279eaf80d..adea43835 100644
--- a/test/node/layer-tests/point-layer-specs.js
+++ b/test/node/layer-tests/point-layer-specs.js
@@ -120,10 +120,18 @@ test('#PointLayer -> formatLayerData', t => {
'should format correct grid layerData'
);
t.ok(
- ['getPosition', 'getColor', 'getRadius'].every(
- k => typeof layerData[k] === 'function'
- ),
- 'should have getPosition, getColor, getRadius accessor as function'
+ typeof layerData.getPosition === 'function',
+ 'should have getPosition accessor as function'
+ );
+ t.deepEqual(
+ layerData.getColor,
+ layer.config.color,
+ 'getColor should be a constant'
+ );
+ t.deepEqual(
+ layerData.getRadius,
+ 1,
+ 'getRadius should be a constant'
);
t.deepEqual(
layerData.getPosition(layerData.data[0]),
diff --git a/webpack.config.js b/webpack.config.js
index 745bf79f8..85d59c9e1 100644
--- a/webpack.config.js
+++ b/webpack.config.js
@@ -21,7 +21,7 @@
const resolve = require('path').resolve;
const webpack = require('webpack');
-const SRC_DIR = resolve('./src');
+const SRC_DIR = resolve('./src');
const LIBRARY_BUNDLE_CONFIG = env => ({
// Bundle the source code
entry: {
diff --git a/yarn.lock b/yarn.lock
index b70859070..9d4c9efe3 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -2,6 +2,32 @@
# yarn lockfile v1
+"@deck.gl/core@^5.3.3":
+ version "5.3.3"
+ resolved "https://registry.yarnpkg.com/@deck.gl/core/-/core-5.3.3.tgz#a13c07e5fa3e22297fd450d6da8ab9aac334b1f0"
+ dependencies:
+ luma.gl "^5.3.0"
+ math.gl "^1.2.1"
+ mjolnir.js "^1.0.0"
+ probe.gl "^1.0.0"
+ seer "^0.2.4"
+ viewport-mercator-project "^5.1.0"
+
+"@deck.gl/layers@^5.3.4":
+ version "5.3.4"
+ resolved "https://registry.yarnpkg.com/@deck.gl/layers/-/layers-5.3.4.tgz#ab3de1bf8bb68d67772642acbb4e0f87f4f11300"
+ dependencies:
+ "@deck.gl/core" "^5.3.3"
+ d3-hexbin "^0.2.1"
+ earcut "^2.0.6"
+
+"@deck.gl/react@^5.3.3":
+ version "5.3.3"
+ resolved "https://registry.yarnpkg.com/@deck.gl/react/-/react-5.3.3.tgz#e7352934f6742d3ce672a394cbff312aab5ccaa0"
+ dependencies:
+ "@deck.gl/core" "^5.3.3"
+ prop-types "^15.6.0"
+
"@mapbox/[email protected]":
version "0.4.0"
resolved "https://registry.yarnpkg.com/@mapbox/extent/-/extent-0.4.0.tgz#3e591f32e1f0c3981c864239f7b0ac06e610f8a9"
@@ -1144,7 +1170,7 @@ babel-register@^6.24.1, babel-register@^6.26.0, babel-register@^6.3.13:
mkdirp "^0.5.1"
source-map-support "^0.4.15"
-babel-runtime@^6.18.0, babel-runtime@^6.2.0, babel-runtime@^6.22.0, babel-runtime@^6.23.0, babel-runtime@^6.26.0:
+babel-runtime@^6.11.6, babel-runtime@^6.18.0, babel-runtime@^6.2.0, babel-runtime@^6.22.0, babel-runtime@^6.23.0, babel-runtime@^6.26.0:
version "6.26.0"
resolved "https://registry.yarnpkg.com/babel-runtime/-/babel-runtime-6.26.0.tgz#965c7058668e82b55d7bfe04ff2337bc8b5647fe"
dependencies:
@@ -2253,20 +2279,13 @@ decamelize@^1.0.0, decamelize@^1.1.1, decamelize@^1.1.2:
version "1.2.0"
resolved "https://registry.yarnpkg.com/decamelize/-/decamelize-1.2.0.tgz#f6534d15148269b20352e7bee26f501f9a191290"
- version "4.1.6"
- resolved "https://registry.yarnpkg.com/deck.gl/-/deck.gl-4.1.6.tgz#9d5ca87c41c4dde86f9351b981b0bcf3132184e7"
+ version "5.3.4"
+ resolved "https://registry.yarnpkg.com/deck.gl/-/deck.gl-5.3.4.tgz#35e5a7087ef0d8ca7811d06a721ea289edbe7c24"
dependencies:
- d3-hexbin "^0.2.1"
- earcut "^2.0.6"
- gl-mat4 "^1.1.4"
- gl-vec2 "^1.0.0"
- gl-vec3 "^1.0.3"
- gl-vec4 "^1.0.1"
- hammerjs "^2.0.8"
- lodash.flattendeep "^4.4.0"
- prop-types "^15.5.8"
- seer "^0.2.3"
+ "@deck.gl/core" "^5.3.3"
+ "@deck.gl/layers" "^5.3.4"
+ "@deck.gl/react" "^5.3.3"
decode-uri-component@^0.2.0:
version "0.2.0"
@@ -3354,10 +3373,6 @@ getpass@^0.1.1:
dependencies:
assert-plus "^1.0.0"
-gl-constants@^1.0.0:
- version "1.0.0"
- resolved "https://registry.yarnpkg.com/gl-constants/-/gl-constants-1.0.0.tgz#597a504e364750ff50253aa35f8dea7af4a5d233"
-
gl-mat3@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/gl-mat3/-/gl-mat3-1.0.0.tgz#89633219ca429379a16b9185d95d41713453b912"
@@ -4577,18 +4592,14 @@ lru-cache@^4.0.1:
pseudomap "^1.0.2"
yallist "^2.1.2"
- version "4.0.6"
- resolved "https://registry.yarnpkg.com/luma.gl/-/luma.gl-4.0.6.tgz#815de594f121d4dca1d68abd941fd6db60440c67"
+luma.gl@^5.3.0:
+ version "5.3.0"
+ resolved "https://registry.yarnpkg.com/luma.gl/-/luma.gl-5.3.0.tgz#a93b2f34489d8230eb6d8c871335800d9b83ee67"
dependencies:
- gl-constants "^1.0.0"
- gl-mat4 "^1.1.4"
- gl-quat "^1.0.0"
- gl-vec2 "^1.0.0"
- gl-vec3 "^1.0.3"
- gl-vec4 "^1.0.1"
- seer "^0.2.2"
- webgl-debug "^1.0.2"
+ math.gl "^1.1.0"
+ probe.gl "^1.0.0"
+ seer "^0.2.4"
+ webgl-debug "^2.0.0"
magic-string@^0.14.0:
version "0.14.0"
@@ -4667,6 +4678,17 @@ math.gl@^1.1.0, math.gl@^1.1.3:
gl-vec3 "^1.0.3"
gl-vec4 "^1.0.1"
+math.gl@^1.2.1:
+ version "1.2.1"
+ resolved "https://registry.yarnpkg.com/math.gl/-/math.gl-1.2.1.tgz#3c7da0ae4f3383116c24bc183533cc4d7b8065a9"
+ dependencies:
+ gl-mat3 "^1.0.0"
+ gl-mat4 "^1.1.4"
+ gl-quat "^1.0.0"
+ gl-vec2 "^1.0.0"
+ gl-vec3 "^1.0.3"
+ gl-vec4 "^1.0.1"
+
md5-hex@^1.2.0:
version "1.3.0"
resolved "https://registry.yarnpkg.com/md5-hex/-/md5-hex-1.3.0.tgz#d2c4afe983c4370662179b8cad145219135046c4"
@@ -4863,7 +4885,7 @@ mixin-deep@^1.2.0:
for-in "^1.0.2"
is-extendable "^1.0.1"
-mjolnir.js@^1.1.0:
+mjolnir.js@^1.0.0, mjolnir.js@^1.1.0:
version "1.1.0"
resolved "https://registry.yarnpkg.com/mjolnir.js/-/mjolnir.js-1.1.0.tgz#16361c5fc5a5eea47f5f9083e0cc0d540c37932f"
dependencies:
@@ -5617,6 +5639,12 @@ private@^0.1.6, private@^0.1.8:
version "0.1.8"
resolved "https://registry.yarnpkg.com/private/-/private-0.1.8.tgz#2381edb3689f7a53d653190060fcf822d2f368ff"
+probe.gl@^1.0.0:
+ version "1.0.2"
+ resolved "https://registry.yarnpkg.com/probe.gl/-/probe.gl-1.0.2.tgz#3b0bdf015ff07dba6582badc6993890cfa5219e6"
+ dependencies:
+ babel-runtime "^6.11.6"
+
process-nextick-args@~1.0.6:
version "1.0.7"
resolved "https://registry.yarnpkg.com/process-nextick-args/-/process-nextick-args-1.0.7.tgz#150e20b756590ad3f91093f25a4f2ad8bff30ba3"
@@ -6372,7 +6400,7 @@ seedrandom@^2.4.2:
version "2.4.3"
resolved "https://registry.yarnpkg.com/seedrandom/-/seedrandom-2.4.3.tgz#2438504dad33917314bff18ac4d794f16d6aaecc"
-seer@^0.2.2, seer@^0.2.3:
+seer@^0.2.4:
version "0.2.4"
resolved "https://registry.yarnpkg.com/seer/-/seer-0.2.4.tgz#6b8a81d09bfe6b3b3ad0268971a65e7f7405135c"
@@ -7530,9 +7558,9 @@ wbuf@^1.1.0, wbuf@^1.7.2:
dependencies:
minimalistic-assert "^1.0.0"
-webgl-debug@^1.0.2:
- version "1.0.2"
- resolved "https://registry.yarnpkg.com/webgl-debug/-/webgl-debug-1.0.2.tgz#93bac5aed181343a136ad34f249920d3b9ccc69a"
+webgl-debug@^2.0.0:
+ version "2.0.1"
+ resolved "https://registry.yarnpkg.com/webgl-debug/-/webgl-debug-2.0.1.tgz#dc11bea3d947764bce061fdb5a23109c13787c95"
webidl-conversions@^4.0.2:
version "4.0.2"