Kepler.gl is a powerful open source geospatial analysis tool for large-scale data sets.
fix(trip-layer): scenegraph filters, one-point animation domain, and UI docs (#3778)
Igor Dykhtad22dd52832b5
diff --git a/docs/user-guides/c-types-of-layers/k-trip.md b/docs/user-guides/c-types-of-layers/k-trip.mdindex 62de6d4a4..971f644df 100644--- a/docs/user-guides/c-types-of-layers/k-trip.md+++ b/docs/user-guides/c-types-of-layers/k-trip.md@@ -6,10 +6,11 @@ Trip layer can display animated path.### How to use trip layer to animate path-**Data format**-Currently trip layer supports a special `geoJSON` format where the coordinate `linestring` has a 4th element denoting timestamp.+The trip layer supports two column modes: **GeoJSON** and **Table columns** (CSV and other tabular files).-In order to animate the path, the `geoJSON` data needs to contain `LineString` in its features' geometry, and the coordinates in the `LineString` need to have 4 elements in the format of `[longitude, latitude, altitude, timestamp]`, with the last element being a timestamp. Valid timestamp formats include unix in seconds such as `1564184363` or in milliseconds such as `1564184363000`.+#### GeoJSON++The GeoJSON data needs to contain `LineString` in its features' geometry, and the coordinates in the `LineString` need to have 4 elements in the format of `[longitude, latitude, altitude, timestamp]`, with the last element being a timestamp. Valid timestamp formats include unix in seconds such as `1564184363` or in milliseconds such as `1564184363000`.**Sample data**@@ -35,7 +36,29 @@ In order to animate the path, the `geoJSON` data needs to contain `LineString` i}```-**Note** Support for more data formats such as csv will be added in future releases.+#### Table columns++Trips can also be created from a list of points (for example a CSV), grouped by a unique trip id, sorted by timestamp, and joined from latitude and longitude.++| Column | Required | Description |+| --------- | -------- | ------------------------------------ |+| id | Yes | Unique id that groups points into a trip |+| lat | Yes | Latitude of each point |+| lng | Yes | Longitude of each point |+| timestamp | Yes | Timestamp of each point |+| altitude | No | Altitude of each point |++**Sample CSV**++```csv+id,latitude,longitude,timestamp+A,40.81773,-74.20986,1564184363+A,40.81765,-74.20987,1564184396+A,40.81746,-74.20998,1564184409+B,40.64375,-74.33242,1565578213+B,40.64353,-74.20987,1565578217+B,40.64222,-74.33001,1565578243+```**Layer attributes**diff --git a/src/components/src/side-panel/layer-panel/layer-configurator.tsx b/src/components/src/side-panel/layer-panel/layer-configurator.tsxindex 4970da8aa..67b6f234e 100644--- a/src/components/src/side-panel/layer-panel/layer-configurator.tsx+++ b/src/components/src/side-panel/layer-panel/layer-configurator.tsx@@ -7,6 +7,7 @@ import React, {Component, Fragment, useCallback, useRef, useState} from 'react';import styled from 'styled-components';import ItemSelector from '../../common/item-selector/item-selector';+import InfoHelperFactory from '../../common/info-helper';import {Input,InputLight,@@ -423,7 +424,8 @@ LayerConfiguratorFactory.deps = [AggrScaleSelectorFactory,VectorTileLayerConfiguratorFactory,RasterTileLayerConfiguratorFactory,- ScenegraphModelSelectorFactory+ ScenegraphModelSelectorFactory,+ InfoHelperFactory];export default function LayerConfiguratorFactory(@@ -441,7 +443,8 @@ export default function LayerConfiguratorFactory(AggrScaleSelector: ReturnType<typeof AggrScaleSelectorFactory>,VectorTileLayerConfigurator: ReturnType<typeof VectorTileLayerConfiguratorFactory>,RasterTileLayerConfigurator: ReturnType<typeof RasterTileLayerConfiguratorFactory>,- ScenegraphModelSelector: ReturnType<typeof ScenegraphModelSelectorFactory>+ ScenegraphModelSelector: ReturnType<typeof ScenegraphModelSelectorFactory>,+ InfoHelper: ReturnType<typeof InfoHelperFactory>): React.ComponentType<LayerConfiguratorProps> {class LayerConfigurator extends Component<LayerConfiguratorProps> {_renderPointLayerConfig(props) {@@ -1086,6 +1089,11 @@ export default function LayerConfiguratorFactory(<PanelLabel><FormattedMessage id="layer.3DModelURL" /></PanelLabel>+ <InfoHelper+ id={`${layer.id}-scenegraphCustomModelUrl`}+ description="layer.3DModelURLDescription"+ property="scenegraphCustomModelUrl"+ /></PanelLabelWrapper><ScenegraphCustomModelUrlInputcustomModelUrl={layer.config.visConfig.scenegraphCustomModelUrl}diff --git a/src/layers/src/trip-layer/trip-layer.ts b/src/layers/src/trip-layer/trip-layer.tsindex f0d2e5732..629c1cfc7 100644--- a/src/layers/src/trip-layer/trip-layer.ts+++ b/src/layers/src/trip-layer/trip-layer.ts@@ -89,6 +89,9 @@ export type TripLayerVisConfig = {invertRoll: boolean;invertPitch: boolean;invertYaw: boolean;+ fixedRoll: boolean;+ fixedPitch: boolean;+ fixedYaw: boolean;scenegraphEnabled: boolean;scenegraph: string;scenegraphColor: RGBColor;@@ -172,6 +175,7 @@ export const tripVisConfigs: {sizeScale: {...LAYER_VIS_CONFIGS.sizeScale,label: 'layerVisConfigs.adjustSize',+ description: 'layerVisConfigs.adjustSizeDescription',defaultValue: 1,isRanged: false,range: [-10, 10],@@ -824,6 +828,8 @@ export default class TripLayer extends Layer {layers.push(new DeckScenegraphLayer({...baseLayerProps,+ // gpu data filtering is not supported at the moment in scenegraphLayer https://github.com/visgl/deck.gl/issues/8099+ extensions: [],id: `${layerProps.id}-scenegraph`,...data,opacity: 1.0,@@ -1129,11 +1135,15 @@ function toQuaternion(roll: number, pitch: number, yaw: number): Quaternion {function getYawFromSpeedVector(prevPoint: number[], nextPoint: number[]) {if (!prevPoint || !nextPoint) return 0;- const p1 = lngLatToWorld(prevPoint);- const p2 = lngLatToWorld(nextPoint);- const dx = p2[0] - p1[0];- const dy = p2[1] - p1[1];- return radiansToDegrees(Math.atan2(dy, dx));+ try {+ const p1 = lngLatToWorld(prevPoint);+ const p2 = lngLatToWorld(nextPoint);+ const dx = p2[0] - p1[0];+ const dy = p2[1] - p1[1];+ return radiansToDegrees(Math.atan2(dy, dx));+ } catch {+ return 0;+ }}function radiansToDegrees(x: number) {diff --git a/src/layers/src/trip-layer/trip-utils.ts b/src/layers/src/trip-layer/trip-utils.tsindex c2ced2a56..c378c0d62 100644--- a/src/layers/src/trip-layer/trip-utils.ts+++ b/src/layers/src/trip-layer/trip-utils.ts@@ -116,9 +116,13 @@ function findMinFromSorted(list: number[]) {return list?.find(d => notNullorUndefined(d) && Number.isFinite(d)) || null;}-function findMaxFromSorted(list: number[] = []) {+function findMaxFromSorted(list: number[] | null = []) {+ // Default [] only applies for undefined. Invalid trips are passed as null.+ if (!list) {+ return null;+ }let i = list.length - 1;- while (i > 0) {+ while (i >= 0) {if (notNullorUndefined(list[i]) && Number.isFinite(list[i])) {return list[i];}diff --git a/test/browser/layer-tests/trip-layer-specs.js b/test/browser/layer-tests/trip-layer-specs.jsindex e9d1adb7d..3494a1086 100644--- a/test/browser/layer-tests/trip-layer-specs.js+++ b/test/browser/layer-tests/trip-layer-specs.js@@ -8,6 +8,7 @@ import cloneDeep from 'es-toolkit/compat/cloneDeep';import {tripDefaultLineWidth as defaultLineWidth,parseTripGeoJsonTimestamp,+ getAnimationDomainFromTimestamps,KeplerGlLayers} from '@kepler.gl/layers';@@ -484,3 +485,17 @@ test('#TripLayer -> parseTripGeoJsonTimestamp', t => {t.deepEqual(result.animationDomain, [1565577261, 1565578836], 'should filter out illugal value');t.end();});++test('#TripLayer -> getAnimationDomainFromTimestamps includes single-timestamp trips', t => {+ t.deepEqual(+ getAnimationDomainFromTimestamps([[1000], [2000, 3000]]),+ [1000, 3000],+ 'a one-point trip should contribute both min and max to the animation domain'+ );+ t.deepEqual(+ getAnimationDomainFromTimestamps([[1000, 2000], null, [3000]]),+ [1000, 3000],+ 'a trip without geometry should be skipped'+ );+ t.end();+});