Kepler.gl is a powerful open source geospatial analysis tool for large-scale data sets.
rollback change, and truncate tooltip (#3300)
bdjulbice5b7df170d14
diff --git a/src/common-utils/src/data-type.ts b/src/common-utils/src/data-type.tsindex 0dc827917..4f94f36ff 100644--- a/src/common-utils/src/data-type.ts+++ b/src/common-utils/src/data-type.ts@@ -11,27 +11,6 @@ import {h3IsValid} from './h3-utils';const H3_ANALYZER_TYPE = 'H3';-// Returns true if the value is likely a WKT geometry string (heuristic check).-const WKT_PREFIX_RE =- /^(?:SRID=\d+\s*;\s*)?(?:POINT|LINESTRING|POLYGON|MULTIPOINT|MULTILINESTRING|MULTIPOLYGON|GEOMETRYCOLLECTION)(?:\s+(?:Z|M|ZM))?\s*\(/i;--export function isWkt(value: unknown): boolean {- if (typeof value !== 'string') {- return false;- }-- const s = value.trim();- if (s.length < 10) {- return false;- }-- if (!s.includes('(') || !s.includes(')')) {- return false;- }-- return WKT_PREFIX_RE.test(s);-}-export const ACCEPTED_ANALYZER_TYPES = [AnalyzerDATA_TYPES.DATE,AnalyzerDATA_TYPES.TIME,@@ -288,11 +267,6 @@ export function getFieldsFromData(data: RowData, fieldOrder: string[]): Field[]type = data.some(d => isHexWkb(d[name])) ? AnalyzerDATA_TYPES.GEOMETRY : type;}- // quick check if string is wkt- if (type === AnalyzerDATA_TYPES.STRING) {- type = data.some(d => isWkt(d[name])) ? AnalyzerDATA_TYPES.GEOMETRY_FROM_STRING : type;- }-return {name,id: name,diff --git a/src/components/src/map/layer-hover-info.tsx b/src/components/src/map/layer-hover-info.tsxindex 2562ac877..16332f8b6 100644--- a/src/components/src/map/layer-hover-info.tsx+++ b/src/components/src/map/layer-hover-info.tsx@@ -3,6 +3,7 @@import React, {useMemo} from 'react';import styled from 'styled-components';+import truncate from 'lodash/truncate';import {CompareType, Field, Merge, TooltipField} from '@kepler.gl/types';import {CenterFlexbox} from '../common/styled-components';import {Layers} from '../common/icons';@@ -66,12 +67,19 @@ interface RowProps {url?: string;}+const TOOLTIP_VALUE_MAX_LENGTH = 256;+const Row: React.FC<RowProps> = ({name, value, deltaValue, url}) => {// Set 'url' to 'value' if it looks like a urlif (!url && value && typeof value === 'string' && value.match(/^http/)) {url = value;}+ const displayValue =+ typeof value === 'string' && value.length > TOOLTIP_VALUE_MAX_LENGTH+ ? truncate(value, {length: TOOLTIP_VALUE_MAX_LENGTH})+ : value;+const asImg = /<img>/.test(name);return (<tr className="layer-hover-info__row" key={name}>@@ -81,11 +89,11 @@ const Row: React.FC<RowProps> = ({name, value, deltaValue, url}) => {<img src={value} />) : url ? (<a target="_blank" rel="noopener noreferrer" href={url}>- {value}+ {displayValue}</a>) : (<>- <span>{value}</span>+ <span>{displayValue}</span>{notNullorUndefined(deltaValue) ? (<spanclassName={`row__delta-value ${diff --git a/test/node/utils/dataset-utils-test.js b/test/node/utils/dataset-utils-test.jsindex 5cd62426f..fe44bb82a 100644--- a/test/node/utils/dataset-utils-test.js+++ b/test/node/utils/dataset-utils-test.js@@ -3,8 +3,7 @@import test from 'tape';import {findDefaultColorField, createNewDataEntry} from '@kepler.gl/utils';-import {isHexWkb, isWkt} from '@kepler.gl/common-utils';-+import {isHexWkb} from '@kepler.gl/common-utils';import {processCsvData} from '@kepler.gl/processors';import csvData from 'test/fixtures/test-layer-data';@@ -89,42 +88,4 @@ test('datasetUtils.isHexWkb', t => {const validEWktNDR = '0020000001000013ff0000000000400000000000000040';t.ok(isHexWkb(validEWktNDR), 'A valid hex ewkb in NDR should be valid');- t.end();-});--test('datasetUtils.isWkt', t => {- // non-strings- t.notOk(isWkt(null), 'null is not a valid WKT');- t.notOk(isWkt(undefined), 'undefined is not a valid WKT');- t.notOk(isWkt(123), 'number is not a valid WKT');- t.notOk(isWkt({}), 'object is not a valid WKT');-- // regular strings / known non-WKT identifiers- t.notOk(isWkt(''), 'empty string is not a valid WKT');- t.notOk(isWkt('hello world'), 'regular string is not a valid WKT');- t.notOk(isWkt('06075'), 'FIPS code should not be a valid WKT');- t.notOk(isWkt('8a2a1072b59ffff'), 'H3 code should not be a valid WKT');-- // edge cases (missing coordinates / parentheses)- t.notOk(isWkt('POINT'), 'POINT without coordinates should not be a valid WKT');- t.notOk(isWkt('POINT 1 2'), 'POINT without parentheses should not be a valid WKT');- t.notOk(isWkt('SRID=4326;POINT'), 'SRID prefix without geometry should not be a valid WKT');- t.notOk(isWkt('POINT (1 2'), 'missing closing parenthesis should not be a valid WKT');- t.notOk(isWkt('POINT ( )'), 'empty coordinates should not be a valid WKT');-- // valid WKT examples (heuristic)- t.ok(isWkt('POINT (1 2)'), 'POINT should be recognized as WKT');- t.ok(isWkt('POINT(1 2)'), 'POINT without space before parentheses should be recognized as WKT');- t.ok(isWkt('LINESTRING (0 0, 1 1)'), 'LINESTRING should be recognized as WKT');- t.ok(isWkt('POLYGON ((0 0, 1 0, 1 1, 0 0))'), 'POLYGON should be recognized as WKT');- t.ok(- isWkt('SRID=4326;POINT(1 2)'),- 'WKT with SRID prefix should be recognized as WKT'- );- t.ok(isWkt('POINT Z (1 2 3)'), 'WKT with Z dimension should be recognized as WKT');-- // not WKT but contains parentheses- t.notOk(isWkt('HELLO (1 2)'), 'non-WKT string with parentheses should not be valid WKT');-- t.end();});