Skip to content

Commit d9df091

Browse files
committed
[Feat] support create geojson path from point csv in polygon layer
Signed-off-by: Ihor Dykhta <[email protected]>
1 parent 4c48994 commit d9df091

File tree

29 files changed

+941
-242
lines changed

29 files changed

+941
-242
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@
140140
"@testing-library/user-event": "^14.4.3",
141141
"@types/d3-array": "^2.0.0",
142142
"@types/d3-scale": "^3.2.2",
143-
"@types/geojson": "^7946.0.7",
143+
"@types/geojson": "^7946.0.8",
144144
"@types/jsdom": "^21.1.1",
145145
"@types/redux-actions": "^2.6.2",
146146
"@types/supercluster": "^7.1.0",

src/components/src/side-panel/layer-panel/layer-column-config.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ function getValidFieldPairsSuggestionsForColumn(
5353
LayerColumnConfigFactory.deps = [ColumnSelectorFactory];
5454

5555
function LayerColumnConfigFactory(ColumnSelector: ReturnType<typeof ColumnSelectorFactory>) {
56-
const LayerColumnConfig: React.FC<LayerColumnConfigProps<MinimalField>> = ({
56+
const LayerColumnConfig: React.FC<LayerColumnConfigProps<MinimalField & {fieldIdx: number}>> = ({
5757
columnPairs,
5858
fieldPairs,
5959
columns,

src/components/src/side-panel/layer-panel/layer-column-mode-config.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,9 @@ const ConfigPanesContainer = styled.div`
7676
}
7777
`;
7878

79-
interface FieldOption extends MinimalField {}
79+
interface FieldOption extends MinimalField {
80+
fieldIdx: number;
81+
}
8082

8183
export type ColumnModeConfigProps = {
8284
supportedColumnModes: SupportedColumnMode[] | null;
@@ -237,9 +239,7 @@ function LayerColumnModeConfigFactory(
237239
columnPairs={layer.columnPairs}
238240
columns={cols}
239241
assignColumnPairs={layer.assignColumnPairs.bind(layer)}
240-
assignColumn={
241-
layer.assignColumn.bind(layer) as (key: string, field: FieldOption) => LayerColumns
242-
}
242+
assignColumn={layer.assignColumn.bind(layer)}
243243
columnLabels={layer.columnLabels}
244244
fields={fields}
245245
fieldPairs={fieldPairs}

src/deckgl-layers/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
"@mapbox/geo-viewport": "^0.4.1",
4444
"@mapbox/vector-tile": "^1.3.1",
4545
"@types/d3-array": "^2.0.0",
46-
"@types/geojson": "^7946.0.7",
46+
"@types/geojson": "^7946.0.8",
4747
"@types/lodash.memoize": "^4.1.7",
4848
"@types/supercluster": "^7.1.0",
4949
"d3-array": "^2.8.0",

src/layers/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
"@turf/boolean-within": "^6.0.1",
5757
"@turf/center": "^6.0.1",
5858
"@turf/helpers": "^6.1.4",
59-
"@types/geojson": "^7946.0.7",
59+
"@types/geojson": "^7946.0.8",
6060
"@types/keymirror": "^0.1.1",
6161
"@types/lodash.memoize": "^4.1.7",
6262
"@types/lodash.uniq": "^4.5.7",

src/layers/src/base-layer.ts

Lines changed: 28 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ import {
4141
hexToRgb,
4242
getLatLngBounds,
4343
isPlainObject,
44+
toArray,
4445
notNullorUndefined,
4546
DataContainerInterface,
4647
getSampleContainerData
@@ -355,8 +356,9 @@ class Layer {
355356
*/
356357
get defaultPointColumnPairs(): ColumnPairs {
357358
return {
358-
lat: {pair: 'lng', fieldPairKey: 'lat'},
359-
lng: {pair: 'lat', fieldPairKey: 'lng'}
359+
lat: {pair: ['lng', 'altitude'], fieldPairKey: 'lat'},
360+
lng: {pair: ['lat', 'altitude'], fieldPairKey: 'lng'},
361+
altitude: {pair: ['lng', 'lat'], fieldPairKey: 'altitude'}
360362
};
361363
}
362364

@@ -546,11 +548,8 @@ class Layer {
546548

547549
/**
548550
* Assign a field to layer column, return column config
549-
* @param key - Column Key
550-
* @param field - Selected field
551-
* @returns {{}} - Column config
552551
*/
553-
assignColumn(key: string, field: Field): LayerColumns {
552+
assignColumn(key: string, field: {name: string; fieldIdx: number}): LayerColumns {
554553
// field value could be null for optional columns
555554
const update = field
556555
? {
@@ -570,30 +569,41 @@ class Layer {
570569

571570
/**
572571
* Assign a field pair to column config, return column config
573-
* @param key - Column Key
574-
* @param pair - field Pair
575-
* @returns Column config
576572
*/
577-
assignColumnPairs(key: string, pair: FieldPair): LayerColumns {
573+
assignColumnPairs(key: string, fieldPairs: FieldPair): LayerColumns {
578574
if (!this.columnPairs || !this.columnPairs?.[key]) {
579575
// should not end in this state
580576
return this.config.columns;
581577
}
578+
// key = 'lat'
579+
const {pair, fieldPairKey} = this.columnPairs?.[key];
582580

583-
const {pair: partnerKey, fieldPairKey} = this.columnPairs?.[key] || {};
584-
585-
if (!pair[fieldPairKey]) {
581+
if (typeof fieldPairKey === 'string' && !pair[fieldPairKey]) {
586582
// do not allow `key: undefined` to creep into the `updatedColumn` object
587583
return this.config.columns;
588584
}
589585

590-
const {fieldPairKey: partnerFieldPairKey} = this.columnPairs?.[partnerKey] || {};
591-
592-
return {
586+
// pair = ['lng', 'alt] | 'lng'
587+
const updatedColumn = {
593588
...this.config.columns,
594-
[key]: pair[fieldPairKey],
595-
[partnerKey]: pair[partnerFieldPairKey]
589+
// @ts-expect-error fieldPairKey can be string[] here?
590+
[key]: fieldPairs[fieldPairKey]
596591
};
592+
593+
const partnerKeys = toArray(pair);
594+
for (const partnerKey of partnerKeys) {
595+
if (
596+
this.config.columns[partnerKey] &&
597+
this.columnPairs?.[partnerKey] &&
598+
// @ts-ignore
599+
fieldPairs[this.columnPairs?.[partnerKey].fieldPairKey]
600+
) {
601+
// @ts-ignore
602+
updatedColumn[partnerKey] = fieldPairs[this.columnPairs?.[partnerKey].fieldPairKey];
603+
}
604+
}
605+
606+
return updatedColumn;
597607
}
598608

599609
/**
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
// SPDX-License-Identifier: MIT
2+
// Copyright contributors to the kepler.gl project
3+
4+
import React from 'react';
5+
import styled from 'styled-components';
6+
import ReactMarkdown from 'react-markdown';
7+
import {useIntl} from 'react-intl';
8+
9+
import {FormattedMessage} from '@kepler.gl/localization';
10+
11+
import Table from '../table';
12+
13+
const InfoModal = styled.div`
14+
font-size: 13px;
15+
color: ${props => props.theme.titleColorLT};
16+
17+
pre {
18+
padding: 12px;
19+
background-color: #f8f8f9;
20+
}
21+
`;
22+
23+
const StyledTitle = styled.div`
24+
font-size: 20px;
25+
letter-spacing: 1.25px;
26+
margin: 18px 0 14px 0;
27+
color: ${props => props.theme.titleColorLT};
28+
`;
29+
30+
const StyledCode = styled.code`
31+
color: ${props => props.theme.titleColorLT};
32+
`;
33+
34+
const exampleTableHeader = ['id', 'latitude', 'longitude', 'sort by'];
35+
const exampleTabbleRows = [
36+
['A', '40.81773', '-74.20986', '0'],
37+
['A', '40.81765', '-74.20987', '1'],
38+
['A', '40.81746', '-74.20998', '2'],
39+
['B', '40.64375', '-74.33242', '0'],
40+
['B', '40.64353', '-74.20987', '1'],
41+
['B', '40.64222', '-74.33001', '2']
42+
];
43+
44+
const ExampleTable = () => (
45+
<Table className="geojson-example-table">
46+
<thead>
47+
<tr>
48+
{exampleTableHeader.map(v => (
49+
<th key={v}>{v}</th>
50+
))}
51+
</tr>
52+
</thead>
53+
<tbody>
54+
{exampleTabbleRows.map((row, i) => (
55+
<tr key={i}>
56+
{row.map((v, j) => (
57+
<td key={j}>
58+
<StyledCode>{v}</StyledCode>
59+
</td>
60+
))}
61+
</tr>
62+
))}
63+
</tbody>
64+
</Table>
65+
);
66+
67+
const GeojsonInfoModalFactory = columnMode => {
68+
const GeojsonInfoModal = () => {
69+
const intl = useIntl();
70+
return (
71+
<InfoModal className="geojson-info-modal">
72+
<div className="geojson-info-modal__description">
73+
<ReactMarkdown
74+
children={intl.formatMessage({
75+
id:
76+
columnMode === 'geojson'
77+
? 'modal.polygonInfo.description'
78+
: 'modal.polygonInfo.descriptionTable'
79+
})}
80+
/>
81+
</div>
82+
{columnMode === 'table' ? (
83+
<div className="geojson-info-modal__example">
84+
<StyledTitle>
85+
<FormattedMessage id="modal.polygonInfo.exampleTable" />
86+
</StyledTitle>
87+
<ExampleTable />
88+
</div>
89+
) : null}
90+
</InfoModal>
91+
);
92+
};
93+
return GeojsonInfoModal;
94+
};
95+
96+
export default GeojsonInfoModalFactory;

0 commit comments

Comments
 (0)