Kepler.gl is a powerful open source geospatial analysis tool for large-scale data sets.
Add cluster and range brush layers
Adam Krebse4dd94eeb7b7
diff --git a/src/components/common/range-brush.js b/src/components/common/range-brush.jsnew file mode 100644index 000000000..0dfea5a6a--- /dev/null+++ b/src/components/common/range-brush.js@@ -0,0 +1,130 @@+// 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 React from 'react';+import PropTypes from 'prop-types';+import styled from 'styled-components';+import {event, select} from 'd3-selection';+import {brushX} from 'd3-brush';++const propTypes = {+ domain: PropTypes.arrayOf(PropTypes.number).isRequired,+ onBrush: PropTypes.func.isRequired,+ range: PropTypes.arrayOf(PropTypes.number).isRequired,+ value: PropTypes.arrayOf(PropTypes.number).isRequired,+ width: PropTypes.number.isRequired+};++const StyledG = styled.g`+ .selection {+ stroke: none;+ fill: ${props => props.theme.rangeBrushBgd};+ opacity: 1;+ }+`;+export default class RangeBrush extends React.Component {+ componentDidMount() {+ const {range: [min, max], value: [val0, val1]} = this.props;+ // We want the React app to respond to brush state and vice-versa+ // but d3-brush fires the same events for both user-initiated brushing+ // and programmatic brushing (brush.move). We need these flags to+ // distinguish between the uses.+ //+ // We don't use state because that would trigger another `componentDidUpate`+ this.brushing = false;+ this.moving = false;++ this.root = select(this.rootContainer);+ this.brush = brushX()+ .on('start', () => {+ this.brushing = true;+ })+ .on('brush', () => {+ if (this.moving) {+ return;+ }++ event.selection === null ? this._reset() : this._brush(event.selection);+ })+ .on('end', () => {+ if (!this.moving && event.selection === null) {+ this._reset();+ }++ this.brushing = false;+ this.moving = false;+ });++ this.root.call(this.brush);++ if (val0 === min && val1 === max) {+ this._reset();+ }+ }++ componentDidUpdate(prevProps) {+ const {range: [min, max], value: [val0, val1], width} = this.props;+ const [prevVal0, prevVal1] = prevProps.value;++ if (prevProps.width !== width) {+ this.root.call(this.brush);+ this._move(val0, val1);+ }++ if (!this.brushing && !this.moving) {+ if (val0 === min && val1 === max) {+ this.moving = true;+ this.brush.move(this.root, null);+ }++ if (prevVal0 !== val0 || prevVal1 !== val1) {+ this.moving = true;+ this._move(val0, val1);+ }+ }+ }++ _reset() {+ const [minValue, maxValue] = this.props.range;+ this.props.onBrush(minValue, maxValue);+ }++ _move(val0, val1) {+ const {domain: [min, max], width} = this.props;+ const scale = x => (x - min) * width / (max - min);+ this.brush.move(this.root, [scale(val0), scale(val1)]);+ }++ _brush([sel0, sel1]) {+ const {domain: [min, max], onBrush, width} = this.props;+ const invert = x => x * (max - min) / width + min;+ onBrush(invert(sel0), invert(sel1));+ }++ render() {+ return <StyledG className="kg-range-slider__brush"+ innerRef={comp => {+ this.rootContainer = comp;+ }}/>;+ }+}++RangeBrush.displayName = 'RangeBrush';+RangeBrush.propTypes = propTypes;diff --git a/src/components/common/range-plot.js b/src/components/common/range-plot.jsnew file mode 100644index 000000000..755c63f87--- /dev/null+++ b/src/components/common/range-plot.js@@ -0,0 +1,237 @@+// 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 React, {Component} from 'react';+import PropTypes from 'prop-types';+import {scaleLinear} from 'd3-scale';+import moment from 'moment';+import {max} from 'd3-array';+import {createSelector} from 'reselect';+import {LineSeries, XYPlot, CustomSVGSeries, Hint, MarkSeries} from 'react-vis';+import styled from 'styled-components';+import RangeBrush from './range-brush';+import {getTimeWidgetHintFormatter} from 'utils/filter-utils';+import {theme} from 'styles/base';++const propTypes = {+ value: PropTypes.array.isRequired,+ histogram: PropTypes.array,+ lineChart: PropTypes.object,+ plotType: PropTypes.string,+ isEnlarged: PropTypes.bool,+ onBlur: PropTypes.func,+ width: PropTypes.number.isRequired+};++const chartMargin = {top: 18, bottom: 0, left: 0, right: 0};+const chartH = 52;+const containerH = 78;+const histogramStyle = {+ highlightW: 0.7,+ unHighlightedW: 0.4,+ highlightedColor: theme.activeColor,+ unHighlightedColor: theme.sliderBarColor+};++export default class RangePlot extends Component {+ state = {+ hoveredDP: null+ };++ domainSelector = props => props.lineChart && props.lineChart.xDomain;+ hintFormatter = createSelector(this.domainSelector, domain =>+ getTimeWidgetHintFormatter(domain)+ );++ onMouseMove = hoveredDP => {+ this.setState({hoveredDP});+ };++ render() {+ const {+ onBrush,+ range,+ value,+ width,+ plotType,+ lineChart,+ histogram+ } = this.props;+ const domain = [histogram[0].x0, histogram[histogram.length - 1].x1];++ const brushComponent = (+ <RangeBrush+ domain={domain}+ onBrush={onBrush}+ range={range}+ value={value}+ width={width}+ />+ );++ return (+ <div+ style={{+ height: `${containerH}px`,+ position: 'relative'+ }}+ >+ {plotType === 'lineChart' ? (+ <LineChart+ hoveredDP={this.state.hoveredDP}+ width={width}+ height={containerH}+ margin={chartMargin}+ children={brushComponent}+ onMouseMove={this.onMouseMove}+ yDomain={lineChart.yDomain}+ hintFormat={this.hintFormatter(this.props)}+ data={lineChart.series}+ />+ ) : (+ <Histogram+ width={width}+ height={chartH}+ value={value}+ margin={chartMargin}+ histogram={histogram}+ brushComponent={brushComponent}+ />+ )}+ </div>+ );+ }+}++RangePlot.propTypes = propTypes;++const Histogram = ({+ width,+ height,+ margin,+ histogram,+ value,+ brushComponent+}) => {+ const domain = [histogram[0].x0, histogram[histogram.length - 1].x1];+ const barWidth = width / histogram.length;++ const x = scaleLinear()+ .domain(domain)+ .range([0, width]);++ const y = scaleLinear()+ .domain([0, max(histogram, d => d.count)])+ .range([0, height]);++ return (+ <svg width={width} height={height} style={{marginTop: `${margin.top}px`}}>+ <g className="histogram-bars">+ {histogram.map(bar => {+ const inRange = bar.x0 >= value[0] && bar.x1 <= value[1];+ const fill = inRange ? histogramStyle.highlightedColor : histogramStyle.unHighlightedColor;+ const wRatio = inRange ? histogramStyle.highlightW : histogramStyle.unHighlightedW;++ return (+ <rect+ key={bar.x0}+ fill={fill}+ height={y(bar.count)}+ width={barWidth * wRatio}+ x={x(bar.x0) + barWidth * (1 - wRatio) / 2}+ rx={1}+ ry={1}+ y={height - y(bar.count)}+ />+ );+ })}+ </g>+ {brushComponent}+ </svg>+ );+};++const LineChartWrapper = styled.div`+ .rv-xy-plot__inner path {+ fill: none;+ stroke-width: 1.5;+ }+`;++const LineChart = ({+ width,+ height,+ yDomain,+ hintFormat,+ hoveredDP,+ margin,+ color,+ data,+ onMouseMove,+ children+}) => {+ const brushData = [+ {x: data[0].x, y: yDomain[1], customComponent: () => children}+ ];++ return (+ <LineChartWrapper>+ <XYPlot width={width} height={height} margin={{...margin, bottom: 12}}>+ <LineSeries+ strokeWidth={2}+ color={color}+ data={data}+ onNearestX={onMouseMove}+ />+ <MarkSeries+ data={hoveredDP ? [hoveredDP] : []}+ color={color}+ size={3}+ />+ <CustomSVGSeries data={brushData} />+ {hoveredDP ? (+ <Hint value={hoveredDP}>+ <HintContent+ {...hoveredDP}+ format={val => moment.utc(val).format(hintFormat)}+ />+ </Hint>+ ) : null}+ </XYPlot>+ </LineChartWrapper>+ );+};++const StyledHint = styled.div`+ background-color: #d3d8e0;+ border-radius: 2px;+ color: ${props => props.theme.textColorLT};+ font-size: 9px;+ margin: 4px;+ padding: 3px 6px;+ pointer-events: none;+ user-select: none;+`;+const HintContent = ({x, y, format}) => (+ <StyledHint>+ <div className="hint--x">{format(x)}</div>+ <div className="row">{y}</div>+ </StyledHint>+);diff --git a/src/deckgl-layers/cluster-layer/cluster-layer.js b/src/deckgl-layers/cluster-layer/cluster-layer.jsnew file mode 100644index 000000000..42d41b981--- /dev/null+++ b/src/deckgl-layers/cluster-layer/cluster-layer.js@@ -0,0 +1,270 @@+// 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 {CompositeLayer, ScatterplotLayer} from 'deck.gl';+import geoViewport from '@mapbox/geo-viewport';+import {ascending, extent, max} from 'd3-array';++import {+ getColorScaleFunction,+ getRadiusScaleFunction,+ needsRecalculateRadiusRange,+ needsRecalculateColorDomain,+ needReCalculateScaleFunction+} from '../layer-utils/utils';+import {DefaultColorRange} from 'constants/color-ranges';+import {LAYER_VIS_CONFIGS} from 'layers/layer-factory';+import {SCALE_TYPES} from 'constants/default-settings';++import {+ clearClustererCache,+ clustersAtZoom,+ getGeoJSON+} from '../layer-utils/cluster-utils';++const defaultRadius = LAYER_VIS_CONFIGS.clusterRadius.defaultValue;+const defaultRadiusRange = LAYER_VIS_CONFIGS.clusterRadiusRange.defaultValue;++const defaultProps = {+ clusterRadius: defaultRadius,+ colorDomain: null,+ colorRange: DefaultColorRange,+ colorScale: SCALE_TYPES.quantize,+ radiusRange: defaultRadiusRange,++ // maybe later...+ lowerPercentile: 0,+ upperPercentile: 100,++ getPosition: x => x.position,++ // if want to have color based on customized aggregator, instead of count+ getColorValue: points => points.length,++ // if want to have radius based on customized aggregator, instead of count+ getRadiusValue: cell => cell.properties.point_count,+ fp64: false+};++export default class ClusterLayer extends CompositeLayer {+ initializeState() {+ this.state = {+ clusters: null,+ geoJSON: null+ };+ }++ shouldUpdateState({changeFlags}) {+ return changeFlags.somethingChanged;+ }++ updateState({oldContext, context, oldProps, props, changeFlags}) {+ if (changeFlags.dataChanged || this.needsReProjectPoints(oldProps, props)) {+ // project data into clusters, and get clustered data+ this.processGeoJSON();+ this.getClusters();++ // this needs clustered data to be set+ this.getColorValueDomain();+ } else if (this.needsReclusterPoints(oldContext, context)) {+ this.getClusters();+ this.getColorValueDomain();+ } else if (this.needsRecalculateScaleFunction(oldProps, props)) {+ this.getColorValueDomain();+ }+ }++ needsReProjectPoints(oldProps, props) {+ return (+ oldProps.clusterRadius !== props.clusterRadius ||+ oldProps.getPosition !== props.getPosition+ );+ }++ needsReclusterPoints(oldContext, context) {+ return (+ Math.round(oldContext.viewport.zoom) !== Math.round(context.viewport.zoom)+ );+ }++ needsRecalculateScaleFunction(oldProps, props) {+ return (+ needsRecalculateColorDomain(oldProps, props) ||+ needReCalculateScaleFunction(oldProps, props) ||+ needsRecalculateRadiusRange(oldProps, props) ||+ oldProps.getColorValue !== props.getColorValue+ );+ }++ processGeoJSON() {+ const {data, getPosition} = this.props;+ this.setState({geoJSON: getGeoJSON(data, getPosition)});+ clearClustererCache();+ }++ getClusters() {+ const {geoJSON} = this.state;+ const {clusterRadius} = this.props;+ const {+ viewport,+ viewport: {longitude, latitude, height, width}+ } = this.context;++ // zoom needs to be an integer for the different map utils. Also helps with cache key.+ const zoom = Math.round(viewport.zoom);+ const bbox = geoViewport.bounds([longitude, latitude], zoom, [+ width,+ height+ ]);++ const clusters = clustersAtZoom({bbox, clusterRadius, geoJSON, zoom});++ this.setState({clusters});+ }++ getColorValueDomain() {+ const {+ colorScale,+ getColorValue,+ getRadiusValue,+ onSetColorDomain+ } = this.props;+ const {clusters} = this.state;++ const radiusDomain = [0, max(clusters, getRadiusValue)];++ const colorValues = clusters+ .map(d => getColorValue(d.properties.points))+ .filter(n => Number.isFinite(n));+ const colorDomain =+ colorScale === SCALE_TYPES.quantize+ ? extent(colorValues)+ : colorValues.sort(ascending);++ this.setState({+ colorDomain,+ radiusDomain+ });++ getColorScaleFunction(this);+ getRadiusScaleFunction(this);++ onSetColorDomain(colorDomain);+ }++ getUpdateTriggers() {+ return {+ getColor: {+ colorRange: this.props.colorRange,+ colorDomain: this.props.colorDomain,+ getColorValue: this.props.getColorValue,+ colorScale: this.props.colorScale,+ lowerPercentile: this.props.lowerPercentile,+ upperPercentile: this.props.upperPercentile+ },+ getRadius: {+ radiusRange: this.props.radiusRange,+ radiusDomain: this.props.radiusDomain,+ getRadiusValue: this.props.getRadiusValue+ }+ };+ }++ /*+ * override default layer method to calculate cell color based on color scale function+ */+ _onGetSublayerColor(cell) {+ const {getColorValue} = this.props;+ const {colorScaleFunc, colorDomain} = this.state;++ const cv = getColorValue(cell.properties.points);++ // if cell value is outside domain, set alpha to 0+ const color =+ Number.isFinite(cv) &&+ cv >= colorDomain[0] &&+ cv <= colorDomain[colorDomain.length - 1]+ ? colorScaleFunc(cv)+ : [0, 0, 0, 0];++ // add final alpha to color+ color[3] = Number.isFinite(color[3]) ? color[3] : 255;++ return color;+ }++ _onGetSublayerRadius(cell) {+ const {getRadiusValue} = this.props;+ const {radiusScaleFunc} = this.state;+ return radiusScaleFunc(getRadiusValue(cell));+ }++ getPickingInfo({info}) {+ const {clusters} = this.state;+ const isPicked = info.picked && info.index > -1;++ let object = null;+ if (isPicked) {+ // add cluster colorValue to object+ const cluster = clusters[info.index];+ const colorValue = this.props.getColorValue(cluster.properties.points);++ object = {+ ...cluster.properties,+ colorValue,+ radius: this._onGetSublayerRadius(cluster),+ position: cluster.geometry.coordinates+ };+ }++ return {+ ...info,+ picked: Boolean(object),+ // override object with picked cluster property+ object+ };+ }++ renderLayers() {+ // for subclassing, override this method to return+ // customized sub layer props+ const {id, radiusScale, fp64} = this.props;++ // base layer props+ const {opacity, pickable} = this.props;++ // return props to the sublayer constructor+ return new ScatterplotLayer({+ id: `${id}-cluster`,+ data: this.state.clusters,+ radiusScale,+ fp64,+ getPosition: d => d.geometry.coordinates,+ getRadius: this._onGetSublayerRadius.bind(this),+ opacity,+ pickable,+ getColor: this._onGetSublayerColor.bind(this),+ updateTriggers: this.getUpdateTriggers()+ });+ }+}++ClusterLayer.layerName = 'ClusterLayer';+ClusterLayer.defaultProps = defaultProps;diff --git a/src/layers/cluster-layer/cluster-layer-icon.js b/src/layers/cluster-layer/cluster-layer-icon.jsnew file mode 100644index 000000000..81ce221c3--- /dev/null+++ b/src/layers/cluster-layer/cluster-layer-icon.js@@ -0,0 +1,70 @@+// 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 React from 'react';+import PropTypes from 'prop-types';+import Base from 'components/common/icons/base';++const ClusterLayerIcon = React.createClass({+ displayName: 'ClusterLayerIcon',+ propTypes: {+ /** Set the height of the icon, ex. '16px' */+ height: PropTypes.string,+ colors: PropTypes.arrayOf(PropTypes.string)+ },+ defaultProps: {+ height: '16px',+ predefinedClassName: 'cluster-layer-icon',+ totalColor: 5+ },+ render() {+ return (+ <Base {...this.props}>+ <path+ d="M13.6,22.7c2.9-3.6,4.4-6.3,4.4-8c0-2.7-2.2-4.9-4.9-4.9S8.2,12,8.2,14.7c0,1.7,1.5,4.4,4.4,8l0,0+ C12.8,23,13.2,23,13.6,22.7C13.5,22.8,13.6,22.7,13.6,22.7z"+ className="cr1"+ />+ <path+ d="M22.9,57.4c2.5-3.1,3.8-5.5,3.8-7c0-2.4-2-4.4-4.4-4.4S18,48,18,50.4c0,1.5,1.3,3.8,3.8,7l0,0+ c0.3,0.3,0.7,0.4,1,0.1C22.9,57.4,22.9,57.4,22.9,57.4z"+ className="cr2"+ />+ <path+ d="M51.4,22.5c2.8-3.4,4.2-6,4.2-7.6c0-2.6-2.1-4.8-4.8-4.8c-2.6,0-4.8,2.1-4.8,4.8c0,1.6,1.4,4.2,4.2,7.6+ l0,0c0.3,0.3,0.8,0.4,1.1,0.1C51.3,22.5,51.4,22.5,51.4,22.5z"+ className="cr3"+ />+ <path+ d="M49.2,53.8c3.7-4.5,5.5-7.8,5.5-9.9c0-3.3-2.7-6.1-6.1-6.1c-3.3,0-6.1,2.7-6.1,6.1+ c0,2.1,1.8,5.4,5.5,9.9l0,0c0.3,0.3,0.7,0.4,1.1,0.1C49.1,53.8,49.1,53.8,49.2,53.8z"+ className="cr4"+ />+ <path+ d="M31.4,39.6C36.5,33.5,39,29,39,26.1c0-4.4-3.6-8-8-8s-8,3.6-8,8c0,2.9,2.5,7.4,7.6,13.5l0,0+ C30.8,39.8,31.1,39.9,31.4,39.6C31.3,39.7,31.4,39.6,31.4,39.6z"+ className="cr5"+ />+ </Base>+ );+ }+});++export default ClusterLayerIcon;diff --git a/src/layers/cluster-layer/cluster-layer.js b/src/layers/cluster-layer/cluster-layer.jsnew file mode 100644index 000000000..228914d70--- /dev/null+++ b/src/layers/cluster-layer/cluster-layer.js@@ -0,0 +1,108 @@+// 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 {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';+import ClusterLayerIcon from './cluster-layer-icon';++export const clusterVisConfigs = {+ opacity: 'opacity',+ clusterRadius: 'clusterRadius',+ colorRange: 'colorRange',+ radiusRange: 'clusterRadiusRange',+ 'hi-precision': 'hi-precision',+ colorAggregation: 'aggregation',+ sizeAggregation: 'aggregation'+};++export default class ClusterLayer extends AggregationLayer {+ constructor(props) {+ super(props);++ this.registerVisConfig(clusterVisConfigs);+ }++ get type() {+ return 'cluster';+ }++ get layerIcon() {+ return ClusterLayerIcon;+ }+ get visualChannels() {+ return {+ color: {+ property: 'color',+ field: 'colorField',+ scale: 'colorScale',+ domain: 'colorDomain',+ range: 'colorRange',+ key: 'color',+ defaultMeasure: 'Point Count',+ channelScaleType: CHANNEL_SCALES.colorAggr+ }+ };+ }++ renderLayer({+ data,+ idx,+ layerInteraction,+ objectHovered,+ mapState,+ interaction,+ layerCallbacks+ }) {+ const {visConfig} = this.config;++ return [+ new DeckGLClusterLayer({+ ...data,+ ...layerInteraction,+ id: this.id,+ idx,+ radiusScale: 1,+ radiusRange: visConfig.radiusRange,+ clusterRadius: visConfig.clusterRadius,+ colorRange: this.getColorRange(visConfig.colorRange),+ colorScale: this.config.colorScale,+ pickable: true,+ opacity: visConfig.opacity,+ fp64: visConfig['hi-precision'],+ lightSettings: this.meta.lightSettings,++ // 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+ })+ ]+ : [])+ ];+ }+}