Kepler.gl is a powerful open source geospatial analysis tool for large-scale data sets.
[Bug] avoid duplicated h3 layer detection (#93) (#1307)
Shan He307cd3d45b1e
diff --git a/src/components/common/item-selector/item-selector.js b/src/components/common/item-selector/item-selector.jsindex 3c3dc8766..d664cd795 100644--- a/src/components/common/item-selector/item-selector.js+++ b/src/components/common/item-selector/item-selector.js@@ -55,8 +55,9 @@ export const StyledDropdownSelect = styled.div.attrs({const DropdownSelectValue = styled.span`color: ${props =>- props.hasPlaceholder && props.inputTheme === 'light' ?- props.theme.selectColorPlaceHolderLT : props.hasPlaceholder+ props.hasPlaceholder && props.inputTheme === 'light'+ ? props.theme.selectColorPlaceHolderLT+ : props.hasPlaceholder? props.theme.selectColorPlaceHolder: props.inputTheme === 'light'? props.theme.selectColorLTdiff --git a/src/layers/h3-hexagon-layer/h3-hexagon-layer.js b/src/layers/h3-hexagon-layer/h3-hexagon-layer.jsindex a6d9875a2..1b1c1cca4 100644--- a/src/layers/h3-hexagon-layer/h3-hexagon-layer.js+++ b/src/layers/h3-hexagon-layer/h3-hexagon-layer.js@@ -29,10 +29,6 @@ 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']-};-export const hexIdRequiredColumns = ['hex_id'];export const hexIdAccessor = ({hex_id}) => d => d.data[hex_id.fieldIdx];export const defaultElevation = 500;@@ -92,31 +88,22 @@ export default class HexagonIdLayer extends Layer {}static findDefaultLayerProps({fields = [], allData = []}) {- const foundColumns = this.findDefaultColumnField(HEXAGON_ID_FIELDS, fields);const hexFields = getHexFields(fields, allData);- if ((!foundColumns || !foundColumns.length) && !hexFields.length) {+ if (!hexFields.length) {return {props: []};}return {- props: (foundColumns || [])- .map(columns => ({- isVisible: true,- label: 'H3 Hexagon',- columns- }))- .concat(- (hexFields || []).map(f => ({- isVisible: true,- label: f.name,- columns: {- hex_id: {- value: f.name,- fieldIdx: fields.findIndex(fid => fid.name === f.name)- }- }- }))- )+ props: hexFields.map(f => ({+ isVisible: true,+ label: f.displayName || f.name,+ columns: {+ hex_id: {+ value: f.name,+ fieldIdx: fields.findIndex(fid => fid.name === f.name)+ }+ }+ }))};}@@ -180,7 +167,6 @@ export default class HexagonIdLayer extends Layer {colorDomain,colorRange.colors.map(c => hexToRgb(c)));-// heightconst sScale =sizeField && enable3d && this.getVisChannelScale(sizeScale, sizeDomain, sizeRange, 0);diff --git a/src/layers/h3-hexagon-layer/h3-utils.js b/src/layers/h3-hexagon-layer/h3-utils.jsindex faa2c7e75..20759cf1c 100644--- a/src/layers/h3-hexagon-layer/h3-utils.js+++ b/src/layers/h3-hexagon-layer/h3-utils.js@@ -18,7 +18,7 @@// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN// THE SOFTWARE.-import {h3GetResolution, h3IsValid, h3ToGeo, h3ToGeoBoundary, geoToH3} from 'h3-js';+import {h3GetResolution, h3IsValid, h3ToGeo, h3ToGeoBoundary} from 'h3-js';import {ALL_FIELD_TYPES} from 'constants/default-settings';import {notNullorUndefined} from 'utils/data-utils';@@ -52,128 +52,6 @@ export function idToPolygonGeo({object}, properties) {};}-export function getCenterHex({latitude, longitude}, resolution) {- return geoToH3(latitude, longitude, resolution);-}--// H3 hexagon are not perfect hexagon after projection, they are slightly distorted-// Here we calculate the distortion from perfect hexagon to h3 hexagon-// A mathematica proof can be found at-// https://beta.observablehq.com/@heshan0131/h3-hexagon-shape-normalize-export function getH3VerticeTransform(rawVertices, centroid) {- const vertices = revertVertices(rawVertices.map(vt => offset(vt, centroid)));- const radius = getRadius(vertices[0], vertices[3]);-- const angle = getAngle(vertices[0], vertices[3]);-- // rotate hexagon vertices, so that v0 - v3 axis parallel with xAxis- // 2___1- // 3 / \ 0- // \___/- // 4 5- //- const rotatedVertices = vertices.map(vt => rotate([0, 0], vt, angle));-- // vertices of a perfect hexagon- const normalVertices = getHexagonVertices(radius);-- // calculate distortion- return getDistortions(rotatedVertices, normalVertices);-}--// Vertices index based on-// https://github.com/uber/luma.gl/blob/master/modules/core/src/geometry/truncated-cone-geometry.js-export function distortCylinderPositions(positions, distortions) {- const primitives = distortions.map(({dr, da}, i) => getPtOnCircle(dr, da + (Math.PI * i) / 3));- // close it- primitives.push(primitives[0]);-- // starting from the 8th vertice, repeat 4 times, only replace x(0), y(1)- return positions.map((v, i) => {- if (i > 20 && i < 21 * 5 && i % 3 < 2) {- const row = Math.floor(i / 3);- const col = i % 3;- return primitives[row % 7][col];- }- return v;- });-}--function offset([px, py], [x0, y0]) {- return [[px - x0], [py - y0]];-}--function rotate([cx, cy], [x, y], radians) {- const cos = Math.cos(radians);- const sin = Math.sin(radians);- const nx = cos * (x - cx) + sin * (y - cy) + cx;- const ny = cos * (y - cy) - sin * (x - cx) + cy;-- return [nx, ny];-}--function getDistance(pt0, pt1) {- const dx = pt0[0] - pt1[0];- const dy = pt0[1] - pt1[1];- const dxy = Math.sqrt(dx * dx + dy * dy);- return dxy;-}--export function getRadius(pt0, pt3) {- const dxy = getDistance(pt0, pt3);- return dxy / 2;-}--export function getAngle(pt0, pt3) {- const dx = pt0[0] - pt3[0];- const dy = pt0[1] - pt3[1];- const dxy = Math.sqrt(dx * dx + dy * dy);-- // Calculate angle that the perpendicular hexagon vertex axis is tilted- const angle = Math.acos(dx / dxy) * Math.sign(dy);- return angle;-}--function getPtOnCircle(radius, angle) {- return [radius * Math.cos(angle), radius * Math.sin(angle)];-}--function getHexagonVertices(r) {- const ang60 = Math.PI / 3;- const pts = [];- for (let i = 0; i < 6; i++) {- pts.push(getPtOnCircle(r, ang60 * i));- }-- return pts;-}--function revertVertices(verts) {- // reverting verts from clock (h3) to counter clock wise (luma cylinder)- const seq = [0, 5, 4, 3, 2, 1];- return seq.map(s => verts[s]);-}--function getDistortions(vts, origs) {- // 0 and 3 should be the guide- const ct = [0, 0];- const distortions = [];-- for (let i = 0; i < 6; i++) {- const vt = vts[i];- const org = origs[i];-- const r = getRadius(org, ct);- const dr = getRadius(vt, ct) / r;-- const da = Math.atan2(vt[1], vt[0]) - Math.atan2(org[1], org[0]);-- distortions.push({dr, da});- }-- return distortions;-}-export const isHexField = (field, fieldIdx, allData) => {if (!field.type === ALL_FIELD_TYPES.string) {return false;