Skip to content

Commit f45d84c

Browse files
committed
Lint fixes
1 parent 37905e7 commit f45d84c

File tree

8 files changed

+391
-317
lines changed

8 files changed

+391
-317
lines changed

modules/carto/src/layers/edged-layers.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,4 +96,4 @@ export class EdgedTripsLayer extends TripsLayer {
9696
patchShaders(shaders, (this.props as any).outline || 'none');
9797
return shaders;
9898
}
99-
}
99+
}

modules/carto/src/layers/trajectory-speed-utils.ts

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,52 +19,54 @@ function distanceBetweenPoints([lon1, lat1, lon2, lat2]: number[]): number {
1919
return R * 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
2020
}
2121

22-
2322
/**
2423
* Calculate speeds and write to numericProps attribute for trajectory geometry
2524
*/
2625
export function autocomputeSpeed(geometry: ProcessedGeometry): void {
2726
const {positions, attributes} = geometry;
2827
const n = positions.value.length / positions.size;
29-
geometry.numericProps.speed = { value: new Float32Array(n), size: 1 };
30-
28+
geometry.numericProps.speed = {value: new Float32Array(n), size: 1};
29+
3130
// Calculate speed and write to numericProps
3231
let previousSpeed = 0;
33-
32+
3433
for (let i = 0; i < n; i++) {
3534
let speed = 0;
36-
35+
3736
if (i < n - 1) {
3837
const start = i === n - 1 ? i - 1 : i;
39-
const step = positions.value.subarray(positions.size * start, positions.size * start + 2 * positions.size);
38+
const step = positions.value.subarray(
39+
positions.size * start,
40+
positions.size * start + 2 * positions.size
41+
);
4042
let lat1: number = 0;
4143
let lat2: number = 0;
4244
let lon1: number = 0;
4345
let lon2: number = 0;
44-
46+
4547
if (positions.size === 2) {
4648
[lon1, lat1, lon2, lat2] = step;
4749
} else if (positions.size === 3) {
4850
[lon1, lat1, , lon2, lat2] = step; // skip altitude values
4951
}
50-
52+
5153
const deltaP = distanceBetweenPoints([lon1, lat1, lon2, lat2]);
5254
const [t1, t2] = attributes.getTimestamps.value.subarray(start, start + 2);
5355
const deltaT = t2 - t1;
5456
speed = deltaT > 0 ? deltaP / deltaT : previousSpeed;
55-
57+
5658
if (deltaT === 0) {
5759
speed = previousSpeed;
5860
}
59-
61+
6062
previousSpeed = speed;
6163
}
62-
64+
6365
if (speed === 0) {
6466
speed = 100; // fallback speed
6567
}
66-
68+
6769
// Write speed to numericProps
68-
geometry.numericProps.speed!.value[i] = speed;
70+
geometry.numericProps.speed.value[i] = speed;
6971
}
70-
}
72+
}

modules/carto/src/layers/trajectory-tile-layer.ts

Lines changed: 38 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {_Tile2DHeader, TripsLayer, TripsLayerProps} from '@deck.gl/geo-layers';
77
import {GeoJsonLayer} from '@deck.gl/layers';
88

99
import type {TilejsonResult} from '@carto/api-client';
10-
import VectorTileLayer, { VectorTileLayerProps } from './vector-tile-layer';
10+
import VectorTileLayer, {VectorTileLayerProps} from './vector-tile-layer';
1111
import {transformTrajectoryData, type TileBounds, normalizeTimestamp} from './trajectory-utils';
1212
import {autocomputeSpeed} from './trajectory-speed-utils';
1313
import {createBinaryProxy, createEmptyBinary} from '../utils';
@@ -24,7 +24,10 @@ const defaultProps: DefaultProps<TrajectoryTileLayerProps> = {
2424
/** All properties supported by TrajectoryTileLayer. */
2525
export type TrajectoryTileLayerProps<FeaturePropertiesT = unknown> = _TrajectoryTileLayerProps &
2626
Omit<TripsLayerProps<FeaturePropertiesT>, 'data'> &
27-
Pick<VectorTileLayerProps<FeaturePropertiesT>, 'getFillColor' | 'getLineColor' | 'uniqueIdProperty'>;
27+
Pick<
28+
VectorTileLayerProps<FeaturePropertiesT>,
29+
'getFillColor' | 'getLineColor' | 'uniqueIdProperty'
30+
>;
2831

2932
/** Properties added by TrajectoryTileLayer. */
3033
type _TrajectoryTileLayerProps = {
@@ -46,8 +49,8 @@ type _TrajectoryTileLayerProps = {
4649
/**
4750
* Helper function to wrap `getFillColor` accessor into a `getLineColor` accessor
4851
* which will invoke `getFillColor` for each vertex in the line
49-
* @param getFillColor
50-
* @returns
52+
* @param getFillColor
53+
* @returns
5154
*/
5255
function getLineColorFromFillColor(getFillColor: TrajectoryTileLayerProps['getFillColor']) {
5356
return (d: any, info: any) => {
@@ -58,12 +61,14 @@ function getLineColorFromFillColor(getFillColor: TrajectoryTileLayerProps['getFi
5861
const colors = new Array(nVertices).fill(0).map((_, i) => {
5962
const index = startIndex + i;
6063
const properties = createBinaryProxy(data, index);
61-
const d = { properties } as any;
62-
return typeof getFillColor === 'function' ? getFillColor(d, { index, data, target }) : getFillColor;
64+
const d = {properties} as any;
65+
return typeof getFillColor === 'function'
66+
? getFillColor(d, {index, data, target})
67+
: getFillColor;
6368
});
6469

6570
return colors;
66-
}
71+
};
6772
}
6873

6974
// @ts-ignore
@@ -90,18 +95,22 @@ export default class TrajectoryTileLayer<
9095
super.updateState(parameters);
9196
if (parameters.props.data && parameters.props.data.widgetSource) {
9297
const dataSourceProps = parameters.props.data.widgetSource.props;
93-
const { trajectoryIdColumn, timestampColumn } = dataSourceProps;
94-
98+
const {trajectoryIdColumn, timestampColumn} = dataSourceProps;
99+
95100
if (!trajectoryIdColumn) {
96-
throw new Error('TrajectoryTileLayer: trajectoryIdColumn is required in data source configuration');
101+
throw new Error(
102+
'TrajectoryTileLayer: trajectoryIdColumn is required in data source configuration'
103+
);
97104
}
98105
if (!timestampColumn) {
99-
throw new Error('TrajectoryTileLayer: timestampColumn is required in data source configuration');
106+
throw new Error(
107+
'TrajectoryTileLayer: timestampColumn is required in data source configuration'
108+
);
100109
}
101-
110+
102111
this.setState({trajectoryIdColumn, timestampColumn});
103112
}
104-
113+
105114
// Read timestampRange from the data source (tilejson)
106115
if (parameters.props.data && parameters.props.data.timestampRange) {
107116
const {min, max} = parameters.props.data.timestampRange;
@@ -119,7 +128,7 @@ export default class TrajectoryTileLayer<
119128
const tileBounds = tile.bbox as TileBounds;
120129
const {minTime, maxTime} = this.state;
121130

122-
let lines = transformTrajectoryData(
131+
const lines = transformTrajectoryData(
123132
data.points,
124133
this.state.trajectoryIdColumn,
125134
this.state.timestampColumn,
@@ -131,7 +140,7 @@ export default class TrajectoryTileLayer<
131140
if (this.props.autocomputeSpeed) {
132141
autocomputeSpeed(lines);
133142
}
134-
return { ...createEmptyBinary(), lines }
143+
return {...createEmptyBinary(), lines};
135144
}
136145

137146
renderSubLayers(
@@ -140,7 +149,7 @@ export default class TrajectoryTileLayer<
140149
data: any;
141150
_offset: number;
142151
tile: _Tile2DHeader;
143-
_subLayerProps: CompositeLayerProps["_subLayerProps"];
152+
_subLayerProps: CompositeLayerProps['_subLayerProps'];
144153
}
145154
): GeoJsonLayer | GeoJsonLayer[] | null {
146155
if (props.data === null) {
@@ -150,7 +159,7 @@ export default class TrajectoryTileLayer<
150159
// This may not be as efficient as just rendering a PathLayer, but it allows to
151160
// switch between the render modes without reloading data
152161
const showTrips = props.renderMode === 'trips';
153-
162+
154163
// Normalize currentTime to match the normalized timestamps in the data
155164
const normalizedCurrentTime = props.currentTime! - this.state.minTime;
156165
const {minTime, maxTime} = this.state;
@@ -161,27 +170,29 @@ export default class TrajectoryTileLayer<
161170
widthUnits: props.widthUnits || 'pixels',
162171
lineJointRounded: props.jointRounded !== undefined ? props.jointRounded : true,
163172
capRounded: props.capRounded !== undefined ? props.capRounded : true,
164-
_pathType: props._pathType || 'open',
173+
_pathType: props._pathType || 'open'
165174
};
166175

167-
const getLineColor = props.getFillColor ? getLineColorFromFillColor(props.getFillColor) : props.getLineColor;
176+
const getLineColor = props.getFillColor
177+
? getLineColorFromFillColor(props.getFillColor)
178+
: props.getLineColor;
168179

169180
const modifiedProps = {
170181
...props,
171182
getLineColor,
172183
_subLayerProps: {
173184
...props._subLayerProps,
174185
linestrings: {
175-
type: TripsLayer,
176-
currentTime: showTrips ? normalizedCurrentTime : totalTimeSpan,
177-
trailLength: showTrips ? props.trailLength : totalTimeSpan,
178-
parameters: {depthTest: false},
179-
...layerProps,
180-
...props._subLayerProps?.linestrings
181-
}
186+
type: TripsLayer,
187+
currentTime: showTrips ? normalizedCurrentTime : totalTimeSpan,
188+
trailLength: showTrips ? props.trailLength : totalTimeSpan,
189+
parameters: {depthTest: false},
190+
...layerProps,
191+
...props._subLayerProps?.linestrings
192+
}
182193
}
183194
};
184195

185196
return super.renderSubLayers(modifiedProps as any);
186197
}
187-
}
198+
}

0 commit comments

Comments
 (0)