Kepler.gl is a powerful open source geospatial analysis tool for large-scale data sets.
[Feat] S2 layer (#800)
Giuseppe Macrì2cbe68c84815
diff --git a/docs/user-guides/a-introduction.md b/docs/user-guides/a-introduction.mdindex a0f921299..cfc7fd472 100644--- a/docs/user-guides/a-introduction.md+++ b/docs/user-guides/a-introduction.md@@ -35,7 +35,8 @@ This guide will teach you how to perform data analysis in Kepler.gl by adding da* [Hexbin](./c-types-of-layers/h-hexbin.md)* [Heatmap](./c-types-of-layers/i-heatmap.md)* [H3](./c-types-of-layers/j-h3.md)-* [Trip](./c-types-of-layers/k.trip.md)+* [Trip](./c-types-of-layers/k-trip.md)+* [S2](./c-types-of-layers/l-s2.md)#### [Layer attributes](./d-layer-attributes.md)diff --git a/docs/user-guides/c-types-of-layers/j-h3.md b/docs/user-guides/c-types-of-layers/j-h3.mdindex 3679cb199..172948e16 100644--- a/docs/user-guides/c-types-of-layers/j-h3.md+++ b/docs/user-guides/c-types-of-layers/j-h3.md@@ -4,7 +4,7 @@H3 layers visualize spatial data using [H3 Hexagonal Hierarchical Spatial Index](https://eng.uber.com/h3/).-To use H3 layer, you need a `hex_id` in your dataset, which can be generated using [h3-js](https://github.com/uber/h3-js) from latitude, longitude and resolution.+To use H3 layer, you need a `hex_id` or `hexagon_id` in your dataset, which can be generated using [h3-js](https://github.com/uber/h3-js) from latitude, longitude and resolution.### Naming Conventionkepler.gl __auto generates__ H3 layer from column: `hex_id`, `hexagon_id`diff --git a/docs/user-guides/c-types-of-layers/k.trip.md b/docs/user-guides/c-types-of-layers/k-trip.mdsimilarity index 100%rename from docs/user-guides/c-types-of-layers/k.trip.mdrename to docs/user-guides/c-types-of-layers/k-trip.mddiff --git a/docs/user-guides/c-types-of-layers/l-s2.md b/docs/user-guides/c-types-of-layers/l-s2.mdnew file mode 100644index 000000000..c2b98c88c--- /dev/null+++ b/docs/user-guides/c-types-of-layers/l-s2.md@@ -0,0 +1,23 @@+# S2 Layer++++To use S2 layer, you need to assign a column containing S2 tokens.++### Naming Convention+Kepler.gl __auto generates__ S2 layer from column named `s2` or `s2_token`+++### Simple Dataset+token | value |+|----------|:------:|+80858004 | 0.5979242952642347 |+8085800c | 0.5446256069712141 |+80858014 | 0.1187171597109975 |+8085801c | 0.2859146314037557 |+80858024 | 0.19549012367504126 |+80858034 | 0.3373452974230604 |+8085803c | 0.9218176408795662 |+80858044 | 0.23470692356446143 |+8085804c | 0.1580509670379684 |+80858054 | 0.15992745628743954 |diff --git a/docs/user-guides/d-layer-attributes.md b/docs/user-guides/d-layer-attributes.mdindex 01a551d81..dba38b93b 100644--- a/docs/user-guides/d-layer-attributes.md+++ b/docs/user-guides/d-layer-attributes.md@@ -11,12 +11,12 @@| Stroke width/stroke width based on | Change the thickness of lines and arcs, or assign a width based on a field from your dataset(s). | Arc, line, Geojson || Stroke width range | Set a lower and upper threshold for projected stroke width. | Arc, Line, Geojson || Grid size | Change the number of square kilometers covered by each grid square. | Grid |-| Color Palette | Choose from multiple, predefined or customized color palettes to apply to your layer. Predefined palettes are either Uber or ColorBrewer colors. | All layers |+| Color Palette | Choose from multiple, predefined or customized color palettes to apply to your layer. Predefined palettes are either Uber or ColorBrewer colors. | All layers || Color Scale | Choose either a quantile or quantized color scale. A quantile color scale is determined by rank, while a quantized color scale is determined by value. | All layers |-| Height based on | Assign grid square height based on a field from your dataset. | Grid, Hexagon |+| Height based on | Assign grid square height based on a field from your dataset. | Grid, Hexagon, S2 || Filter by count percentile | Increase or decrease the number of grid squares by choosing a range of percentiles to display. | Grid, Hexagon || Coverage | Change what portion of each grid cell is covered by a color square. | Grid, Hexagon |-| Height Scale | Change the height of the grid squares or hexagons when in 3D mode. | Grid, Hexagon |+| Height Scale | Change the height of the grid squares, hexagons or S2 when in 3D mode. | Grid, Hexagon, S2 || Stroked | When activated, draws outlines around geoshapes. | GeoJSON, Point || Filled | When activated, geo shapes are filled in with colors. | GeoJSON || Extruded | In 3D mode, assign polygon height values based on some value from your dataset. | GeoJSON |diff --git a/examples/demo-app/src/app.js b/examples/demo-app/src/app.jsindex b4bcf23eb..fd682cc34 100644--- a/examples/demo-app/src/app.js+++ b/examples/demo-app/src/app.js@@ -54,6 +54,7 @@ import sampleGeojson from './data/sample-small-geojson';import sampleGeojsonPoints from './data/sample-geojson-points';import sampleGeojsonConfig from './data/sample-geojson-config';import sampleH3Data, {config as h3MapConfig} from './data/sample-hex-id-csv';+import sampleS2Data, {config as s2MapConfig, dataId as s2DataId} from './data/sample-s2-data';import sampleAnimateTrip from './data/sample-animate-trip-data';import sampleIconCsv, {config as savedMapConfig} from './data/sample-icon-csv';import {addDataToMap, addNotification} from 'kepler.gl/actions';@@ -175,11 +176,12 @@ class App extends Component {}_loadSampleData() {- this._loadPointData();+ // this._loadPointData();// this._loadGeojsonData();// this._loadTripGeoJson();// this._loadIconData();// this._loadH3HexagonData();+ this._loadS2Data();// this._loadScenegraphLayer();}@@ -309,6 +311,27 @@ class App extends Component {);}+ _loadS2Data() {+ // load s2+ this.props.dispatch(+ addDataToMap({+ datasets: [+ {+ info: {+ label: 'S2 Data',+ id: s2DataId+ },+ data: processCsvData(sampleS2Data)+ }+ ],+ config: s2MapConfig,+ options: {+ keepExistingConfig: true+ }+ })+ );+ }+_toggleCloudModal = () => {// TODO: this lives only in the demo hence we use the state for now// REFCOTOR using reduxdiff --git a/examples/demo-app/src/data/sample-s2-data.js b/examples/demo-app/src/data/sample-s2-data.jsnew file mode 100644index 000000000..093e1d20b--- /dev/null+++ b/examples/demo-app/src/data/sample-s2-data.js@@ -0,0 +1,73 @@+// Copyright (c) 2020 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 `s2, value+80858004,0.5979242952642347+8085800c,0.5446256069712141+80858014,0.1187171597109975+8085801c,0.2859146314037557+80858024,0.19549012367504126+80858034,0.3373452974230604+8085803c,0.9218176408795662+80858044,0.23470692356446143+8085804c,0.1580509670379684+80858054,0.15992745628743954+`;++export const dataId = 's2-data';+export const config = {+ version: 'v1',+ config: {+ visState: {+ filters: [],+ layers: [+ {+ type: 's2',+ config: {+ dataId,+ label: 'S2 Layer',+ color: [241, 92, 23],+ columns: {+ token: 's2'+ },+ isVisible: true,+ visConfig: {+ opacity: 0.8,+ strokeColor: [253, 230, 230],+ colorRange: {+ name: 'Global Warming',+ type: 'sequential',+ category: 'Uber',+ colors: ['#5A1846', '#900C3F', '#C70039', '#E3611C', '#F1920E', '#FFC300']+ }+ }+ },+ visualChannels: {+ colorField: {+ name: ' value',+ type: 'real'+ },+ colorScale: 'quantile'+ }+ }+ ]+ }+ }+};diff --git a/package.json b/package.jsonindex 01b59a2ac..bec73e605 100644--- a/package.json+++ b/package.json@@ -74,16 +74,16 @@"umd"],"dependencies": {- "@deck.gl/extensions": "^8.0.15",+ "@deck.gl/aggregation-layers": "^8.0.15","@deck.gl/core": "^8.0.15",+ "@deck.gl/extensions": "^8.0.15",+ "@deck.gl/geo-layers": "^8.0.15","@deck.gl/layers": "^8.0.15",- "@deck.gl/aggregation-layers": "^8.0.15","@deck.gl/mesh-layers": "^8.0.15","@deck.gl/react": "^8.0.15",- "@deck.gl/geo-layers": "^8.0.15",+ "@loaders.gl/gltf": "^2.0.0","@luma.gl/constants": "^8.0.5","@luma.gl/core": "^8.0.5",- "@loaders.gl/gltf": "^2.0.0","@mapbox/geo-viewport": "^0.2.2","@mapbox/geojson-normalize": "0.0.1","@mapbox/vector-tile": "^1.3.1",@@ -117,6 +117,7 @@"lodash.uniq": "^4.0.1","lodash.uniqby": "^4.7.0","lodash.xor": "^4.5.0",+ "long": "^4.0.0","mini-svg-data-uri": "^1.0.3","moment": "^2.10.6","pbf": "^3.1.0",@@ -139,6 +140,7 @@"redux": "^3.0.4","redux-actions": "^2.2.1","reselect": "^3.0.1",+ "s2-geometry": "^1.2.10","supercluster": "^6.0.1","type-analyzer": "0.2.5","uber-licence": "^3.1.1",diff --git a/src/components/side-panel/layer-panel/layer-configurator.js b/src/components/side-panel/layer-panel/layer-configurator.jsindex 7cfbd8916..c25acf1e0 100644--- a/src/components/side-panel/layer-panel/layer-configurator.js+++ b/src/components/side-panel/layer-panel/layer-configurator.js@@ -37,8 +37,6 @@ import VisConfigSlider from './vis-config-slider';import LayerConfigGroup, {ConfigGroupCollapsibleContent} from './layer-config-group';import TextLabelPanel from './text-label-panel';-import {LAYER_VIS_CONFIGS} from 'layers/layer-factory';-import {capitalizeFirstLetter} from 'utils/utils';import {LAYER_TYPES, CHANNEL_SCALE_SUPPORTED_FIELDS} from 'constants/default-settings';@@ -80,6 +78,7 @@ export const getLayerChannelConfigProps = props => ({});LayerConfiguratorFactory.deps = [SourceDataSelectorFactory];+export default function LayerConfiguratorFactory(SourceDataSelector) {class LayerConfigurator extends Component {static propTypes = {@@ -126,7 +125,7 @@ export default function LayerConfiguratorFactory(SourceDataSelector) {channel={layer.visualChannels.color}{...layerChannelConfigProps}/>- <VisConfigSlider {...LAYER_VIS_CONFIGS.opacity} {...visConfiguratorProps} />+ <VisConfigSlider {...layer.visConfigSettings.opacity} {...visConfiguratorProps} /></ConfigGroupCollapsibleContent></LayerConfigGroup>@@ -165,14 +164,14 @@ export default function LayerConfiguratorFactory(SourceDataSelector) {<LayerConfigGroup label={'radius'} collapsible>{!layer.config.sizeField ? (<VisConfigSlider- {...LAYER_VIS_CONFIGS.radius}+ {...layer.visConfigSettings.radius}{...visConfiguratorProps}label={false}disabled={Boolean(layer.config.sizeField)}/>) : (<VisConfigSlider- {...LAYER_VIS_CONFIGS.radiusRange}+ {...layer.visConfigSettings.radiusRange}{...visConfiguratorProps}label={false}disabled={!layer.config.sizeField || layer.config.visConfig.fixedRadius}@@ -184,7 +183,10 @@ export default function LayerConfiguratorFactory(SourceDataSelector) {{...layerChannelConfigProps}/>{layer.config.sizeField ? (- <VisConfigSwitch {...LAYER_VIS_CONFIGS.fixedRadius} {...visConfiguratorProps} />+ <VisConfigSwitch+ {...layer.visConfigSettings.fixedRadius}+ {...visConfiguratorProps}+ />) : null}</ConfigGroupCollapsibleContent></LayerConfigGroup>@@ -397,7 +399,7 @@ export default function LayerConfiguratorFactory(SourceDataSelector) {channel={layer.visualChannels.color}{...layerChannelConfigProps}/>- <VisConfigSlider {...LAYER_VIS_CONFIGS.opacity} {...visConfiguratorProps} />+ <VisConfigSlider {...layer.visConfigSettings.opacity} {...visConfiguratorProps} /></ConfigGroupCollapsibleContent></LayerConfigGroup>@@ -425,19 +427,22 @@ export default function LayerConfiguratorFactory(SourceDataSelector) {</LayerConfigGroup>{/* height */}- <LayerConfigGroup {...LAYER_VIS_CONFIGS.enable3d} {...visConfiguratorProps} collapsible>+ <LayerConfigGroup+ {...layer.visConfigSettings.enable3d}+ {...visConfiguratorProps}+ collapsible+ ><ChannelByValueSelectorchannel={layer.visualChannels.size}{...layerChannelConfigProps}/><ConfigGroupCollapsibleContent><VisConfigSlider- {...LAYER_VIS_CONFIGS.elevationScale}+ {...layer.visConfigSettings.elevationScale}{...visConfiguratorProps}- labl="Zoom scale"/><VisConfigSlider- {...LAYER_VIS_CONFIGS.elevationRange}+ {...layer.visConfigSettings.sizeRange}{...visConfiguratorProps}label="Height Range"/>@@ -476,7 +481,7 @@ export default function LayerConfiguratorFactory(SourceDataSelector) {channel={layer.visualChannels.color}{...layerChannelConfigProps}/>- <VisConfigSlider {...LAYER_VIS_CONFIGS.opacity} {...visConfiguratorProps} />+ <VisConfigSlider {...layer.visConfigSettings.opacity} {...visConfiguratorProps} /></ConfigGroupCollapsibleContent></LayerConfigGroup>@@ -484,14 +489,14 @@ export default function LayerConfiguratorFactory(SourceDataSelector) {<LayerConfigGroup label={'stroke'} collapsible>{layer.config.sizeField ? (<VisConfigSlider- {...LAYER_VIS_CONFIGS.strokeWidthRange}+ {...layer.visConfigSettings.sizeRange}{...visConfiguratorProps}disabled={!layer.config.sizeField}label={false}/>) : (<VisConfigSlider- {...LAYER_VIS_CONFIGS.thickness}+ {...layer.visConfigSettings.thickness}{...visConfiguratorProps}label={false}/>@@ -531,7 +536,7 @@ export default function LayerConfiguratorFactory(SourceDataSelector) {channel={layer.visualChannels.color}{...layerChannelConfigProps}/>- <VisConfigSlider {...LAYER_VIS_CONFIGS.opacity} {...visConfiguratorProps} />+ <VisConfigSlider {...layer.visConfigSettings.opacity} {...visConfiguratorProps} /></ConfigGroupCollapsibleContent></LayerConfigGroup>@@ -539,13 +544,13 @@ export default function LayerConfiguratorFactory(SourceDataSelector) {<LayerConfigGroup {...visConfiguratorProps} label="Stroke Width" collapsible>{layer.config.sizeField ? (<VisConfigSlider- {...LAYER_VIS_CONFIGS.strokeWidthRange}+ {...layer.visConfigSettings.sizeRange}{...visConfiguratorProps}label={false}/>) : (<VisConfigSlider- {...LAYER_VIS_CONFIGS.thickness}+ {...layer.visConfigSettings.thickness}{...visConfiguratorProps}label={false}/>@@ -562,12 +567,12 @@ export default function LayerConfiguratorFactory(SourceDataSelector) {{/* Trail Length*/}<LayerConfigGroup{...visConfiguratorProps}- {...(featureTypes.polygon ? LAYER_VIS_CONFIGS.stroked : {})}+ {...(featureTypes.polygon ? layer.visConfigSettings.stroked : {})}label="Trail Length"description="Number of seconds for a path to completely fade out"><VisConfigSlider- {...LAYER_VIS_CONFIGS.trailLength}+ {...layer.visConfigSettings.trailLength}{...visConfiguratorProps}label={false}/>@@ -643,19 +648,19 @@ export default function LayerConfiguratorFactory(SourceDataSelector) {{/* Stroke Width */}<LayerConfigGroup{...visConfiguratorProps}- {...(featureTypes.polygon ? LAYER_VIS_CONFIGS.stroked : {})}+ {...(featureTypes.polygon ? layer.visConfigSettings.stroked : {})}label="Stroke Width"collapsible>{layer.config.sizeField ? (<VisConfigSlider- {...LAYER_VIS_CONFIGS.strokeWidthRange}+ {...layer.visConfigSettings.sizeRange}{...visConfiguratorProps}label={false}/>) : (<VisConfigSlider- {...LAYER_VIS_CONFIGS.thickness}+ {...layer.visConfigSettings.thickness}{...visConfiguratorProps}label={false}/>@@ -672,12 +677,12 @@ export default function LayerConfiguratorFactory(SourceDataSelector) {{featureTypes.polygon ? (<LayerConfigGroup{...visConfiguratorProps}- {...LAYER_VIS_CONFIGS.enable3d}+ {...layer.visConfigSettings.enable3d}disabled={!visConfig.filled}collapsible><VisConfigSlider- {...LAYER_VIS_CONFIGS.elevationScale}+ {...layer.visConfigSettings.elevationScale}{...visConfiguratorProps}label={false}/>@@ -686,7 +691,7 @@ export default function LayerConfiguratorFactory(SourceDataSelector) {channel={layer.visualChannels.height}{...layerChannelConfigProps}/>- <VisConfigSwitch {...visConfiguratorProps} {...LAYER_VIS_CONFIGS.wireframe} />+ <VisConfigSwitch {...visConfiguratorProps} {...layer.visConfigSettings.wireframe} /></ConfigGroupCollapsibleContent></LayerConfigGroup>) : null}@@ -696,14 +701,14 @@ export default function LayerConfiguratorFactory(SourceDataSelector) {<LayerConfigGroup label={'radius'} collapsible>{!layer.config.radiusField ? (<VisConfigSlider- {...LAYER_VIS_CONFIGS.radius}+ {...layer.visConfigSettings.radius}{...visConfiguratorProps}label={false}disabled={Boolean(layer.config.radiusField)}/>) : (<VisConfigSlider- {...LAYER_VIS_CONFIGS.radiusRange}+ {...layer.visConfigSettings.radiusRange}{...visConfiguratorProps}label={false}disabled={!layer.config.radiusField}@@ -721,12 +726,7 @@ export default function LayerConfiguratorFactory(SourceDataSelector) {);}- _render3DLayerConfig({- layer,- visConfiguratorProps,- layerConfiguratorProps,- layerChannelConfigProps- }) {+ _render3DLayerConfig({layer, visConfiguratorProps}) {return (<Fragment><LayerConfigGroup label={'3D Model'} collapsible>@@ -743,29 +743,23 @@ export default function LayerConfiguratorFactory(SourceDataSelector) {</LayerConfigGroup><LayerConfigGroup label={'3D Model Options'} collapsible><VisConfigSlider- {...LAYER_VIS_CONFIGS.sizeScale}+ {...layer.visConfigSettings.sizeScale}{...visConfiguratorProps}disabled={false}/><VisConfigSlider- {...LAYER_VIS_CONFIGS.angle}+ {...layer.visConfigSettings.angleX}{...visConfiguratorProps}- label="Angle X"- property="angleX"disabled={false}/><VisConfigSlider- {...LAYER_VIS_CONFIGS.angle}+ {...layer.visConfigSettings.angleY}{...visConfiguratorProps}- label="Angle Y"- property="angleY"disabled={false}/><VisConfigSlider- {...LAYER_VIS_CONFIGS.angle}+ {...layer.visConfigSettings.angleZ}{...visConfiguratorProps}- label="Angle Z"- property="angleZ"disabled={false}/></LayerConfigGroup>@@ -773,6 +767,115 @@ export default function LayerConfiguratorFactory(SourceDataSelector) {);}+ _renderS2LayerConfig({+ layer,+ visConfiguratorProps,+ layerConfiguratorProps,+ layerChannelConfigProps+ }) {+ const {+ config: {visConfig}+ } = layer;++ return (+ <StyledLayerVisualConfigurator>+ {/* Color */}+ <LayerConfigGroup+ {...layer.visConfigSettings.filled}+ {...visConfiguratorProps}+ label="Fill Color"+ collapsible+ >+ {layer.config.colorField ? (+ <LayerColorRangeSelector {...visConfiguratorProps} />+ ) : (+ <LayerColorSelector {...layerConfiguratorProps} />+ )}+ <ConfigGroupCollapsibleContent>+ <ChannelByValueSelector+ channel={layer.visualChannels.color}+ {...layerChannelConfigProps}+ />+ <VisConfigSlider {...layer.visConfigSettings.opacity} {...visConfiguratorProps} />+ </ConfigGroupCollapsibleContent>+ </LayerConfigGroup>++ {/* Stroke */}+ <LayerConfigGroup+ {...layer.visConfigSettings.stroked}+ {...visConfiguratorProps}+ label="Stroke Color"+ collapsible+ >+ {layer.config.strokeColorField ? (+ <LayerColorRangeSelector {...visConfiguratorProps} property="strokeColorRange" />+ ) : (+ <LayerColorSelector+ {...visConfiguratorProps}+ selectedColor={layer.config.visConfig.strokeColor}+ property="strokeColor"+ />+ )}+ <ConfigGroupCollapsibleContent>+ <ChannelByValueSelector+ channel={layer.visualChannels.strokeColor}+ {...layerChannelConfigProps}+ />+ </ConfigGroupCollapsibleContent>+ </LayerConfigGroup>++ {/* Stroke Width */}+ <LayerConfigGroup {...visConfiguratorProps} label="Stroke Width" collapsible>+ {layer.config.sizeField ? (+ <VisConfigSlider+ {...layer.visConfigSettings.sizeRange}+ {...visConfiguratorProps}+ label={false}+ />+ ) : (+ <VisConfigSlider+ {...layer.visConfigSettings.thickness}+ {...visConfiguratorProps}+ label={false}+ />+ )}+ <ConfigGroupCollapsibleContent>+ <ChannelByValueSelector+ channel={layer.visualChannels.size}+ {...layerChannelConfigProps}+ />+ </ConfigGroupCollapsibleContent>+ </LayerConfigGroup>++ {/* Elevation */}+ <LayerConfigGroup+ {...visConfiguratorProps}+ {...layer.visConfigSettings.enable3d}+ disabled={!visConfig.filled}+ collapsible+ >+ <ChannelByValueSelector+ channel={layer.visualChannels.height}+ {...layerChannelConfigProps}+ />+ <VisConfigSlider+ {...layer.visConfigSettings.elevationScale}+ {...visConfiguratorProps}+ label="Elevation Scale"+ />+ <ConfigGroupCollapsibleContent>+ <VisConfigSlider+ {...layer.visConfigSettings.heightRange}+ {...visConfiguratorProps}+ label="Height Range"+ />+ <VisConfigSwitch {...visConfiguratorProps} {...layer.visConfigSettings.wireframe} />+ </ConfigGroupCollapsibleContent>+ </LayerConfigGroup>+ </StyledLayerVisualConfigurator>+ );+ }+render() {const {layer, datasets, updateLayerConfig, layerTypeOptions, updateLayerType} = this.props;const {fields = [], fieldPairs} = layer.config.dataId ? datasets[layer.config.dataId] : {};diff --git a/src/layers/base-layer.js b/src/layers/base-layer.jsindex a5777fa1a..233e25c0c 100644--- a/src/layers/base-layer.js+++ b/src/layers/base-layer.js@@ -215,7 +215,7 @@ export default class Layer {* Given a array of preset required column names* found field that has the same name to set as layer column*- * @param {object[]} defaultFields+ * @param {object} defaultFields* @param {object[]} allFields* @returns {object[] | null} all possible required layer column pairs*/diff --git a/src/layers/geojson-layer/geojson-layer.js b/src/layers/geojson-layer/geojson-layer.jsindex 035d1cc94..1123ce4b6 100644--- a/src/layers/geojson-layer/geojson-layer.js+++ b/src/layers/geojson-layer/geojson-layer.js@@ -116,7 +116,7 @@ export default class GeoJsonLayer extends Layer {domain: 'heightDomain',range: 'heightRange',key: 'height',- channelScaleType: 'size',+ channelScaleType: CHANNEL_SCALES.size,condition: config => config.visConfig.enable3d},radius: {@@ -126,7 +126,7 @@ export default class GeoJsonLayer extends Layer {domain: 'radiusDomain',range: 'radiusRange',key: 'radius',- channelScaleType: 'radius'+ channelScaleType: CHANNEL_SCALES.radius}};}diff --git a/src/layers/h3-hexagon-layer/h3-hexagon-layer.js b/src/layers/h3-hexagon-layer/h3-hexagon-layer.jsindex 628994c9e..b59c11aa3 100644--- a/src/layers/h3-hexagon-layer/h3-hexagon-layer.js+++ b/src/layers/h3-hexagon-layer/h3-hexagon-layer.js@@ -25,6 +25,9 @@ import EnhancedColumnLayer from 'deckgl-layers/column-layer/enhanced-column-layeimport {getCentroid, idToPolygonGeo, h3IsValid} from './h3-utils';import H3HexagonLayerIcon from './h3-hexagon-layer-icon';import {CHANNEL_SCALES, HIGHLIGH_COLOR_3D} from 'constants/default-settings';+import {hexToRgb} from 'utils/color-utils';++const DEFAULT_LINE_SCALE_VALUE = 8;export const HEXAGON_ID_FIELDS = {hex_id: ['hex_id', 'hexagon_id', 'h3_id']@@ -39,21 +42,12 @@ export const HexagonIdVisConfigs = {opacity: 'opacity',colorRange: 'colorRange',coverage: 'coverage',+ enable3d: 'enable3d',sizeRange: 'elevationRange',coverageRange: 'coverageRange',elevationScale: 'elevationScale'};-function hexToRgb(hex) {- const result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);-- const r = parseInt(result[1], 16);- const g = parseInt(result[2], 16);- const b = parseInt(result[3], 16);-- return [r, g, b];-}-export default class HexagonIdLayer extends Layer {constructor(props) {super(props);@@ -158,7 +152,7 @@ export default class HexagonIdLayer extends Layer {coverageField,coverageScale,coverageDomain,- visConfig: {sizeRange, colorRange, coverageRange}+ visConfig: {sizeRange, colorRange, coverageRange, enable3d}} = this.config;const {gpuFilter} = datasets[this.config.dataId];@@ -174,7 +168,8 @@ export default class HexagonIdLayer extends Layer {);// height- const sScale = sizeField && this.getVisChannelScale(sizeScale, sizeDomain, sizeRange, 0);+ const sScale =+ sizeField && enable3d && this.getVisChannelScale(sizeScale, sizeDomain, sizeRange, 0);// coverageconst coScale =@@ -237,7 +232,8 @@ export default class HexagonIdLayer extends Layer {getElevation: {sizeField: config.sizeField,sizeRange: visConfig.sizeRange,- sizeScale: config.sizeScale+ sizeScale: config.sizeScale,+ enable3d: visConfig.enable3d},getFilterValue: gpuFilter.filterValueUpdateTriggers};@@ -263,11 +259,11 @@ export default class HexagonIdLayer extends Layer {coverage: config.coverageField ? 1 : visConfig.coverage,// highlight- autoHighlight: Boolean(config.sizeField),+ autoHighlight: visConfig.enable3d,highlightColor: HIGHLIGH_COLOR_3D,// elevation- extruded: Boolean(config.sizeField),+ extruded: visConfig.enable3d,elevationScale: visConfig.elevationScale * eleZoomFactor,// render@@ -286,7 +282,7 @@ export default class HexagonIdLayer extends Layer {...this.getDefaultHoverLayerProps(),data: [idToPolygonGeo(objectHovered)],getLineColor: config.highlightColor,- lineWidthScale: 8 * zoomFactor,+ lineWidthScale: DEFAULT_LINE_SCALE_VALUE * zoomFactor,wrapLongitude: false})]diff --git a/src/layers/index.js b/src/layers/index.jsindex 961076bc5..ae6e40a2d 100644--- a/src/layers/index.js+++ b/src/layers/index.js@@ -30,6 +30,7 @@ import {default as HeatmapLayer} from './heatmap-layer/heatmap-layer';import {default as H3Layer} from './h3-hexagon-layer/h3-hexagon-layer';import {default as ScenegraphLayer} from './scenegraph-layer/scenegraph-layer';import {default as TripLayer} from './trip-layer/trip-layer';+import {default as S2GeometryLayer} from './s2-geometry-layer/s2-geometry-layer';// base layerexport {default as Layer} from './base-layer';@@ -47,7 +48,8 @@ export const KeplerGlLayers = {HeatmapLayer,H3Layer,ScenegraphLayer,- TripLayer+ TripLayer,+ S2GeometryLayer};export const LayerClasses = {@@ -62,5 +64,6 @@ export const LayerClasses = {heatmap: HeatmapLayer,hexagonId: H3Layer,'3D': ScenegraphLayer,- trip: TripLayer+ trip: TripLayer,+ s2: S2GeometryLayer};diff --git a/src/layers/layer-factory.js b/src/layers/layer-factory.jsindex 3c430b137..272010a4b 100644--- a/src/layers/layer-factory.js+++ b/src/layers/layer-factory.js@@ -285,13 +285,6 @@ export const LAYER_VIS_CONFIGS = {range: [0, 360],step: 1},- angleZ: {- type: 'number',- defaultValue: 90,- isRanged: false,- range: [0, 360],- step: 1- },worldUnitSize: {type: 'number',defaultValue: 1,@@ -322,6 +315,16 @@ export const LAYER_VIS_CONFIGS = {group: PROPERTY_GROUPS.height,property: 'sizeRange'},+ heightRange: {+ type: 'number',+ defaultValue: [0, 500],+ label: 'Height Scale',+ isRanged: true,+ range: [0, 1000],+ step: 0.01,+ group: PROPERTY_GROUPS.height,+ property: 'heightRange'+ },coverageRange: {type: 'number',defaultValue: [0, 1],diff --git a/src/layers/s2-geometry-layer/s2-geometry-layer.js b/src/layers/s2-geometry-layer/s2-geometry-layer.jsnew file mode 100644index 000000000..0fd8767b5--- /dev/null+++ b/src/layers/s2-geometry-layer/s2-geometry-layer.js@@ -0,0 +1,331 @@+// Copyright (c) 2020 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 {S2Layer} from '@deck.gl/geo-layers';+import {hexToRgb} from 'utils/color-utils';+import {HIGHLIGH_COLOR_3D, CHANNEL_SCALES} from 'constants/default-settings';+import {LAYER_VIS_CONFIGS} from 'layers/layer-factory';+import Layer from '../base-layer';+import S2LayerIcon from './s2-layer-icon';+import {getS2Center} from './s2-utils';++const zoomFactorValue = 8;++export const S2_TOKEN_FIELDS = {+ token: ['s2', 's2_token']+};++export const s2RequiredColumns = ['token'];+export const S2TokenAccessor = ({token}) => d => d[token.fieldIdx];+export const defaultElevation = 500;+export const defaultLineWidth = 1;++export const S2VisConfigs = {+ // Filled color+ opacity: 'opacity',+ colorRange: 'colorRange',+ filled: {+ type: 'boolean',+ label: 'Fill Color',+ defaultValue: true,+ property: 'filled'+ },++ // stroke+ thickness: {+ ...LAYER_VIS_CONFIGS.thickness,+ defaultValue: 0.5+ },+ strokeColor: 'strokeColor',+ strokeColorRange: 'strokeColorRange',+ sizeRange: 'strokeWidthRange',+ stroked: 'stroked',++ // height+ enable3d: 'enable3d',+ elevationScale: 'elevationScale',+ heightRange: 'elevationRange',++ // wireframe+ wireframe: 'wireframe'+};++export default class S2GeometryLayer extends Layer {+ constructor(props) {+ super(props);+ this.registerVisConfig(S2VisConfigs);+ this.getPositionAccessor = () => S2TokenAccessor(this.config.columns);+ }++ get type() {+ return 's2';+ }++ get name() {+ return 'S2';+ }++ get requiredLayerColumns() {+ return s2RequiredColumns;+ }++ get layerIcon() {+ return S2LayerIcon;+ }++ get visualChannels() {+ return {+ ...super.visualChannels,+ color: {+ property: 'color',+ field: 'colorField',+ scale: 'colorScale',+ domain: 'colorDomain',+ range: 'colorRange',+ key: 'color',+ channelScaleType: CHANNEL_SCALES.color+ },+ size: {+ ...super.visualChannels.size,+ property: 'stroke',+ condition: config => config.visConfig.stroked+ },+ strokeColor: {+ property: 'strokeColor',+ field: 'strokeColorField',+ scale: 'strokeColorScale',+ domain: 'strokeColorDomain',+ range: 'strokeColorRange',+ key: 'strokeColor',+ channelScaleType: CHANNEL_SCALES.color,+ condition: config => config.visConfig.stroked+ },+ height: {+ property: 'height',+ field: 'heightField',+ scale: 'heightScale',+ domain: 'heightDomain',+ range: 'heightRange',+ key: 'height',+ channelScaleType: CHANNEL_SCALES.size,+ condition: config => config.visConfig.enable3d+ }+ };+ }++ getDefaultLayerConfig(props = {}) {+ return {+ ...super.getDefaultLayerConfig(props),++ // add height visual channel+ heightField: null,+ heightDomain: [0, 1],+ heightScale: 'linear',++ // add stroke color visual channel+ strokeColorField: null,+ strokeColorDomain: [0, 1],+ strokeColorScale: 'quantile'+ };+ }++ static findDefaultLayerProps({fields = []}) {+ const foundColumns = this.findDefaultColumnField(S2_TOKEN_FIELDS, fields);+ if (!foundColumns || !foundColumns.length) {+ return {props: []};+ }++ return {+ props: foundColumns.map(columns => ({+ isVisible: true,+ label: 'S2',+ columns+ }))+ };+ }++ calculateDataAttribute({allData, filteredIndex}, getS2Token) {+ const data = [];+ for (let i = 0; i < filteredIndex.length; i++) {+ const index = filteredIndex[i];+ const token = getS2Token(allData[index]);++ if (token) {+ data.push({+ // keep a reference to the original data index+ index,+ data: allData[index],+ token+ });+ }+ }+ return data;+ }++ updateLayerMeta(allData, getS2Token) {+ const centroids = allData.reduce((acc, entry) => {+ const s2Token = getS2Token(entry);+ return s2Token ? [...acc, getS2Center(s2Token)] : acc;+ }, []);++ const bounds = this.getPointsBounds(centroids);+ this.dataToFeature = {centroids};+ this.updateMeta({bounds});+ }++ /* eslint-disable complexity */+ formatLayerData(datasets, oldLayerData, opt = {}) {+ const {+ colorScale,+ colorDomain,+ colorField,+ color,+ heightField,+ heightDomain,+ heightScale,+ strokeColorField,+ strokeColorScale,+ strokeColorDomain,+ sizeScale,+ sizeDomain,+ sizeField,+ visConfig+ } = this.config;++ const {+ enable3d,+ stroked,+ colorRange,+ heightRange,+ sizeRange,+ strokeColorRange,+ strokeColor+ } = visConfig;++ const {gpuFilter} = datasets[this.config.dataId];+ const getS2Token = this.getPositionAccessor();+ const {data} = this.updateData(datasets, oldLayerData);++ const cScale =+ colorField &&+ this.getVisChannelScale(colorScale, colorDomain, colorRange.colors.map(hexToRgb));++ // calculate elevation scale - if extruded = true+ const eScale =+ heightField && enable3d && this.getVisChannelScale(heightScale, heightDomain, heightRange);++ // stroke color+ const scScale =+ strokeColorField &&+ this.getVisChannelScale(+ strokeColorScale,+ strokeColorDomain,+ strokeColorRange.colors.map(hexToRgb)+ );++ // calculate stroke scale - if stroked = true+ const sScale =+ sizeField && stroked && this.getVisChannelScale(sizeScale, sizeDomain, sizeRange);++ return {+ data,+ getS2Token,+ getLineColor: d =>+ scScale+ ? this.getEncodedChannelValue(scScale, d.data, strokeColorField)+ : strokeColor || color,+ getLineWidth: d =>+ sScale ? this.getEncodedChannelValue(sScale, d.data, sizeField, 0) : defaultLineWidth,+ getFillColor: d => (cScale ? this.getEncodedChannelValue(cScale, d.data, colorField) : color),+ getElevation: d =>+ eScale ? this.getEncodedChannelValue(eScale, d.data, heightField, 0) : defaultElevation,+ getFilterValue: gpuFilter.filterValueAccessor()+ };+ }+ /* eslint-enable complexity */++ renderLayer(opts) {+ const {data, gpuFilter, interactionConfig, mapState} = opts;++ const defaultLayerProps = this.getDefaultDeckLayerProps(opts);++ const eleZoomFactor = this.getElevationZoomFactor(mapState);+ const zoomFactor = this.getZoomFactor(mapState);+ const {config} = this;+ const {visConfig} = config;++ const updateTriggers = {+ getLineColor: {+ color: visConfig.strokeColor,+ colorField: config.strokeColorField,+ colorRange: visConfig.strokeColorRange,+ colorScale: config.strokeColorScale+ },+ getLineWidth: {+ sizeField: config.sizeField,+ sizeRange: visConfig.sizeRange+ },+ getFillColor: {+ color: config.color,+ colorField: config.colorField,+ colorRange: visConfig.colorRange,+ colorScale: config.colorScale+ },+ getElevation: {+ heightField: config.heightField,+ heightScaleType: config.heightScale,+ heightRange: visConfig.heightRange+ },+ getFilterValue: gpuFilter.filterValueUpdateTriggers+ };++ return [+ new S2Layer({+ ...defaultLayerProps,+ ...interactionConfig,+ ...data,+ getS2Token: d => d.token,++ autoHighlight: visConfig.enable3d,+ highlightColor: HIGHLIGH_COLOR_3D,++ // stroke+ lineWidthScale: visConfig.thickness * zoomFactor * zoomFactorValue,+ stroked: visConfig.stroked,+ lineMiterLimit: 2,++ // Filled color+ filled: visConfig.filled,+ opacity: visConfig.opacity,+ wrapLongitude: false,++ // Elevation+ elevationScale: visConfig.elevationScale * eleZoomFactor,+ extruded: visConfig.enable3d,++ wireframe: visConfig.wireframe,++ pickable: true,++ updateTriggers+ })+ ];+ }+}diff --git a/src/layers/s2-geometry-layer/s2-layer-icon.js b/src/layers/s2-geometry-layer/s2-layer-icon.jsnew file mode 100644index 000000000..6b14bc5ed--- /dev/null+++ b/src/layers/s2-geometry-layer/s2-layer-icon.js@@ -0,0 +1,47 @@+// Copyright (c) 2020 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 Base from 'components/common/icons/base';++class S2LayerIcon extends Component {+ static propTypes = {+ /** Set the height of the icon, ex. '16px' */+ height: PropTypes.string,+ colors: PropTypes.arrayOf(PropTypes.string)+ };+ static defaultProps = {+ height: '18px',+ predefinedClassName: 's2-layer-icon'+ };++ render() {+ return (+ <Base {...this.props}>+ <path d="M14.76,58,15,20.54,50.06,6.75V44Zm4-34.86L18.6,52.38l27.66-11V12.33Z" />+ <path d="M27.21,38.58a7.38,7.38,0,0,1-3.62-.9l.3-2a6.49,6.49,0,0,0,3.3.9c1.49,0,2.18-.59,2.18-1.63,0-2.26-5.71-1.28-5.71-5.3,0-2,1.26-3.54,4.16-3.54a8.38,8.38,0,0,1,3.28.64l-.29,1.9a8.41,8.41,0,0,0-2.88-.54c-1.63,0-2.14.66-2.14,1.42,0,2.19,5.71,1.18,5.71,5.27C31.5,37.16,29.93,38.58,27.21,38.58Z" />+ <path d="M36.17,36.36v0h5.06l0,2H33.32V36.9c3-2.88,5.67-5.09,5.67-7,0-1-.64-1.67-2.19-1.67a5,5,0,0,0-3,1.1l-.53-1.79a6.31,6.31,0,0,1,3.91-1.28c2.66,0,4,1.34,4,3.41C41.21,31.94,39.13,33.89,36.17,36.36Z" />+ </Base>+ );+ }+}++export default S2LayerIcon;diff --git a/src/layers/s2-geometry-layer/s2-utils.js b/src/layers/s2-geometry-layer/s2-utils.jsnew file mode 100644index 000000000..587c888f7--- /dev/null+++ b/src/layers/s2-geometry-layer/s2-utils.js@@ -0,0 +1,36 @@+// Copyright (c) 2020 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 Long from 'long';+import {S2} from 's2-geometry';++const MAXIMUM_TOKEN_LENGTH = 16;++/**+ * Retrieve S2 geometry center+ * @param s2Token string | number+ * @return {*[]}+ */+export function getS2Center(s2Token) {+ const paddedToken = s2Token.toString().padEnd(MAXIMUM_TOKEN_LENGTH, '0');+ const s2Id = Long.fromString(paddedToken, MAXIMUM_TOKEN_LENGTH);+ const {lat, lng} = S2.idToLatLng(s2Id.toString());+ return [lng, lat];+}diff --git a/src/layers/scenegraph-layer/scenegraph-layer.js b/src/layers/scenegraph-layer/scenegraph-layer.jsindex 1bfdd0092..574a9b1d3 100644--- a/src/layers/scenegraph-layer/scenegraph-layer.js+++ b/src/layers/scenegraph-layer/scenegraph-layer.js@@ -25,6 +25,7 @@ import {GLTFLoader} from '@loaders.gl/gltf';import Layer from '../base-layer';import ScenegraphLayerIcon from './scenegraph-layer-icon';import ScenegraphInfoModalFactory from './scenegraph-info-modal';+import {LAYER_VIS_CONFIGS} from 'layers/layer-factory';export const scenegraphRequiredColumns = ['lat', 'lng'];export const scenegraphOptionalColumns = ['altitude'];@@ -51,9 +52,22 @@ export const scenegraphVisConfigs = {colorRange: 'colorRange',//sizeScale: 'sizeScale',- angleX: 'angle',- angleY: 'angle',- angleZ: 'angleZ'+ angleX: {+ ...LAYER_VIS_CONFIGS.angle,+ property: 'angleX',+ label: 'angle X'+ },+ angleY: {+ ...LAYER_VIS_CONFIGS.angle,+ property: 'angleY',+ label: 'angle Y'+ },+ angleZ: {+ ...LAYER_VIS_CONFIGS.angle,+ property: 'angleZ',+ defaultValue: 90,+ label: 'angle Z'+ }};const DEFAULT_MODEL =diff --git a/src/layers/trip-layer/trip-layer.js b/src/layers/trip-layer/trip-layer.jsindex ad260d31d..9e4d09ed7 100644--- a/src/layers/trip-layer/trip-layer.js+++ b/src/layers/trip-layer/trip-layer.js@@ -37,6 +37,8 @@ import {isTripGeoJsonField, parseTripGeoJsonTimestamp} from './trip-utils';import {hexToRgb} from 'utils/color-utils';import TripInfoModalFactory from './trip-info-modal';+const zoomFactorValue = 8;+export const defaultThickness = 0.5;export const defaultWidth = 1;@@ -283,7 +285,7 @@ export default class TripLayer extends Layer {...defaultLayerProps,...data,getTimestamps: d => data.getTimestamps(d).map(ts => ts - animationConfig.domain[0]),- widthScale: this.config.visConfig.thickness * zoomFactor * 8,+ widthScale: this.config.visConfig.thickness * zoomFactor * zoomFactorValue,rounded: true,wrapLongitude: false,parameters: {diff --git a/test/browser/components/modals/data-table-modal-test.js b/test/browser/components/modals/data-table-modal-test.jsindex f3213e6a2..c538a50e1 100644--- a/test/browser/components/modals/data-table-modal-test.js+++ b/test/browser/components/modals/data-table-modal-test.js@@ -36,6 +36,7 @@ const DataGrid = DataGridFactory(FieldHeader, Cell);const DataTableModal = DataTableModalFactory(DataGrid);// This makes sure react-virtualized renders the full grid+// width needs to be large enough to fit allconst WIDTH = 2100;const HEIGHT = 800;diff --git a/test/browser/layer-tests/h3-hexagon-layer-specs.js b/test/browser/layer-tests/h3-hexagon-layer-specs.jsindex c1bab1946..eaa630d42 100644--- a/test/browser/layer-tests/h3-hexagon-layer-specs.js+++ b/test/browser/layer-tests/h3-hexagon-layer-specs.js@@ -165,7 +165,8 @@ test('#H3Layer -> formatLayerData', t => {colorRange: {colors: ['#010101', '#020202', '#030303']},- elevationRange: [10, 20]+ elevationRange: [10, 20],+ enable3d: true}},type: 'hexagonId',@@ -198,7 +199,7 @@ test('#H3Layer -> formatLayerData', t => {t.deepEqual(layerData.data.map(layerData.getElevation),[0, 41.445270988310305],- 'getElevation should be a constant'+ 'getElevation should correct');// getFilterValuet.deepEqual(diff --git a/test/browser/layer-tests/index.js b/test/browser/layer-tests/index.jsindex 93777067f..adc0a1abf 100644--- a/test/browser/layer-tests/index.js+++ b/test/browser/layer-tests/index.js@@ -31,3 +31,4 @@ import './line-layer-specs';import './point-layer-specs';import './scenegraph-layer-specs';import './trip-layer-specs';+import './s2-geometry-layer-specs';diff --git a/test/browser/layer-tests/s2-geometry-layer-specs.js b/test/browser/layer-tests/s2-geometry-layer-specs.jsnew file mode 100644index 000000000..db8a24f29--- /dev/null+++ b/test/browser/layer-tests/s2-geometry-layer-specs.js@@ -0,0 +1,339 @@+// Copyright (c) 2020 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 test from 'tape';+import {+ testCreateCases,+ testFormatLayerDataCases,+ testRenderLayerCases+} from 'test/helpers/layer-utils';+import {getGpuFilterProps} from 'utils/gpu-filter-utils';+import {data} from 'test/fixtures/s2-geometry';+import S2GeometryLayer, {defaultElevation} from 'layers/s2-geometry-layer/s2-geometry-layer';+import {processCsvData} from 'processors/data-processor';++test('#S2Geometry -> constructor', t => {+ const TEST_CASES = [+ {+ props: {+ dataId: 'smoothie',+ isVisible: true,+ label: 'text s2geometry layer'+ },+ test: layer => {+ t.ok(layer.config.dataId === 'smoothie', 'S2GeometryLayer dataId should be correct');+ t.ok(layer.type === 's2', 'type should be s2');+ t.deepEqual(+ Object.keys(layer.visConfigSettings),+ [+ 'opacity',+ 'colorRange',+ 'filled',+ 'thickness',+ 'strokeColor',+ 'strokeColorRange',+ 'sizeRange',+ 'stroked',+ 'enable3d',+ 'elevationScale',+ 'heightRange',+ 'wireframe'+ ],+ 'should provide the correct visConfigSettings properties'+ );+ }+ }+ ];++ testCreateCases(t, S2GeometryLayer, TEST_CASES);+ t.end();+});++test('#S2Geometry -> formatLayerData', t => {+ const {rows, fields} = processCsvData(data);++ t.deepEqual(+ fields,+ [+ {+ name: 's2',+ format: '',+ tableFieldIndex: 1,+ type: 'string',+ analyzerType: 'STRING'+ },+ {+ name: 'value',+ format: '',+ tableFieldIndex: 2,+ type: 'real',+ analyzerType: 'FLOAT'+ }+ ],+ 'Should compute fields correctly'+ );++ const filteredIndex = [0, 2, 4];++ const dataId = 'puppy';++ const nullRows = [+ [null, 12345],+ [null, 3456]+ ];++ const invalidRows = [+ [0, 12345],+ [1234, 3456],+ ['abcd', 123]+ ];++ const allRows = nullRows.concat(rows).concat(invalidRows);+ const dataset = {+ fields,+ rows,+ id: dataId,+ data: allRows,+ allData: allRows,+ filteredIndexForDomain: filteredIndex,+ filteredIndex,+ gpuFilter: getGpuFilterProps([], dataId, fields)+ };++ const props = {+ name: 's2 layer',+ layer: {+ type: 's2',+ id: 'test_layer_1',+ config: {+ dataId,+ label: 'S2',+ color: [255, 203, 153],+ columns: {+ token: 's2'+ },+ isVisible: true+ }+ },+ datasets: {+ [dataId]: dataset+ }+ };++ const TEST_CASES = [+ {+ ...props,+ data: [data, rows, filteredIndex, undefined],+ assert: result => {+ const {layerData, layer} = result;+ const expectedLayerData = {+ data: [+ {index: 2, token: rows[0][0], data: rows[0]},+ {index: 4, token: rows[2][0], data: rows[2]}+ ],+ getElevation: () => {},+ getFillColor: () => {},+ getFilterValue: () => {},+ getS2Token: () => {},+ getLineColor: () => {},+ getLineWidth: () => {}+ };++ t.equal(+ layerData.getElevation(),+ defaultElevation,+ `Elevation should be set to ${defaultElevation}`+ );++ // test layer.meta+ t.deepEqual(+ layer.meta,+ {+ bounds: [-122.39575481805574, -50.18582525999928, 143.41537625914856, 37.81968456730113]+ },+ 'should format correct S2 layer meta'+ );++ t.deepEqual(+ layerData.data,+ expectedLayerData.data,+ 'should format correct s2-geometry layerData'+ );++ t.deepEqual(+ Object.keys(layerData).sort(),+ Object.keys(expectedLayerData).sort(),+ `layerData should have ${expectedLayerData.length} keys`+ );+ }+ },+ {+ ...props,+ updates: [+ {method: 'updateLayerConfig', args: [{colorField: fields[1]}]},+ {method: 'updateLayerConfig', args: [{sizeField: fields[1]}]},+ {+ method: 'updateLayerVisualChannel',+ args: [dataset, 'color']+ }+ ],+ data: [allRows, allRows, filteredIndex, undefined],+ assert: result => {+ const {layerData} = result;+ const expectedLayerData = {+ data: [+ {index: 2, token: rows[0][0], data: rows[0]},+ {index: 4, token: rows[2][0], data: rows[2]}+ ],+ getElevation: () => {},+ getFillColor: () => {},+ getFilterValue: () => {},+ getS2Token: () => {},+ getLineColor: () => {},+ getLineWidth: () => {}+ };++ t.ok(typeof layerData.getFillColor === 'function', 'should have getFillColor');++ t.ok(typeof layerData.getElevation === 'function', 'should have getElevation');++ t.ok(typeof layerData.getFilterValue === 'function', 'should have getFilterValue');++ t.ok(typeof layerData.getS2Token === 'function', 'should have getS2Token');++ t.deepEqual(+ layerData.data,+ expectedLayerData.data,+ 'should format correct s2-geometry layerData and remove null values'+ );++ t.deepEqual(+ Object.keys(layerData).sort(),+ Object.keys(expectedLayerData).sort(),+ `layerData should have ${Object.keys(expectedLayerData).length} keys`+ );+ }+ }+ ];++ testFormatLayerDataCases(t, S2GeometryLayer, TEST_CASES);++ t.end();+});++test('#S2Geometry -> renderLayer', t => {+ const {rows, fields} = processCsvData(data);+ const filteredIndex = [0, 2, 4];++ const dataId = 'puppy';++ const nullRows = [+ [null, 12345],+ [null, 3456]+ ];+ const invalidRows = [+ [0, 12345],+ [1234, 3456],+ ['abcd', 123]+ ];++ const allRows = nullRows.concat(rows).concat(invalidRows);++ const dataset = {+ fields,+ rows,+ id: dataId,+ data: allRows,+ allData: allRows,+ filteredIndexForDomain: filteredIndex,+ filteredIndex,+ gpuFilter: getGpuFilterProps([], dataId, fields)+ };++ const props = {+ name: 's2 layer',+ layer: {+ type: 's2',+ id: 'test_layer_1',+ config: {+ dataId,+ label: 'S2',+ color: [255, 203, 153],+ columns: {+ token: 's2'+ },+ isVisible: true+ }+ },+ datasets: {+ [dataId]: dataset+ }+ };++ const TEST_CASES = [+ {+ ...props,+ data: [data, rows, filteredIndex, undefined],+ assert: (deckLayers, layer) => {+ t.equal(layer.type, 's2', 'should create 1 s2 layer');+ t.equal(deckLayers.length, 4, 'Should create 4 deck.gl layers');++ const expectedLayerIds = [+ 'test_layer_1',+ 'test_layer_1-cell',+ 'test_layer_1-cell-fill',+ 'test_layer_1-cell-stroke'+ ];++ t.deepEqual(+ deckLayers.map(l => l.id),+ expectedLayerIds,+ 'should create 1 composite, 1 hexagon-cell layer'+ );++ const {props: layerProps} = deckLayers[0];++ const expectedProps = {+ opacity: layer.config.visConfig.opacity,+ filterRange: [+ [0, 0],+ [0, 0],+ [0, 0],+ [0, 0]+ ],+ filled: true,+ wrapLongitude: false,+ autoHighlight: false,+ highlightColor: [255, 255, 255, 60],+ extruded: false,+ elevationScale: 5+ };++ Object.keys(expectedProps).forEach(key => {+ t.deepEqual(layerProps[key], expectedProps[key], `should have correct props.${key}`);+ });+ }+ }+ ];++ testRenderLayerCases(t, S2GeometryLayer, TEST_CASES);++ t.end();+});diff --git a/test/fixtures/s2-geometry.js b/test/fixtures/s2-geometry.jsnew file mode 100644index 000000000..fe2d6aac6--- /dev/null+++ b/test/fixtures/s2-geometry.js@@ -0,0 +1,32 @@+// Copyright (c) 2020 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 const data =+ 's2,value\n' ++ '80858004,0.5979242952642347\n' ++ '8085800c,0.5446256069712141\n' ++ '80858014,0.1187171597109975\n' ++ '8085801c,0.2859146314037557\n' ++ '80858024,0.19549012367504126\n' ++ '80858034,0.3373452974230604\n' ++ '8085803c,0.9218176408795662\n' ++ '80858044,0.23470692356446143\n' ++ '8085804c,0.1580509670379684\n' ++ '80858054,0.15992745628743954';diff --git a/test/fixtures/test-hex-id-data.js b/test/fixtures/test-hex-id-data.jsindex 230336f32..780bd9d15 100644--- a/test/fixtures/test-hex-id-data.js+++ b/test/fixtures/test-hex-id-data.js@@ -366,7 +366,8 @@ mergedH3Layer.config = {coverage: 1,sizeRange: [0, 500],coverageRange: [0, 1],- elevationScale: 5+ elevationScale: 5,+ enable3d: false},textLabel: [{diff --git a/test/node/utils/index.js b/test/node/utils/index.jsindex 97e6dbc1f..758721257 100644--- a/test/node/utils/index.js+++ b/test/node/utils/index.js@@ -31,3 +31,4 @@ import './aggregate-utils-test';import './color-util-test';import './util-test';import './export-utils-test';+import './s2-utils-test';diff --git a/test/node/utils/s2-utils-test.js b/test/node/utils/s2-utils-test.jsnew file mode 100644index 000000000..680f70731--- /dev/null+++ b/test/node/utils/s2-utils-test.js@@ -0,0 +1,28 @@+// Copyright (c) 2020 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 test from 'tape';+import {getS2Center} from 'layers/s2-geometry-layer/s2-utils';++test('Utils -> set', t => {+ const s2Toekn = '8085873c';+ t.deepEqual(getS2Center(s2Toekn), [-122.4637079795235, 37.78228912269449]);+ t.end();+});diff --git a/yarn.lock b/yarn.lockindex c92e4d2f8..fff2b7974 100644--- a/yarn.lock+++ b/yarn.lock@@ -8668,6 +8668,11 @@ long@^3.2.0:resolved "https://registry.yarnpkg.com/long/-/long-3.2.0.tgz#d821b7138ca1cb581c172990ef14db200b5c474b"integrity sha1-2CG3E4yhy1gcFymQ7xTbIAtcR0s=+long@^4.0.0:+ version "4.0.0"+ resolved "https://registry.yarnpkg.com/long/-/long-4.0.0.tgz#9a7b71cfb7d361a194ea555241c92f7468d5bf28"+ integrity sha512-XsP+KhQif4bjX1kbuSiySJFNAehNxgLb6hPRGJ9QsUr8ajHkuXGdrHmFUTUUXhDwVX2R5bY4JNZEwbUiMhV+MA==+longest-streak@^2.0.1:version "2.0.4"resolved "https://registry.yarnpkg.com/longest-streak/-/longest-streak-2.0.4.tgz#b8599957da5b5dab64dee3fe316fa774597d90e4"