Skip to content

Commit be50bed

Browse files
committed
Correct palette updateTriggers
1 parent 6c21193 commit be50bed

File tree

1 file changed

+17
-31
lines changed
  • test/apps/carto-trajectories

1 file changed

+17
-31
lines changed

test/apps/carto-trajectories/app.tsx

Lines changed: 17 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,7 @@ const DATASETS = {
3737
layerType: 'Trips 2D',
3838
lineWidth: 2,
3939
mapStyle: 'dark-v11',
40-
palette: 'Sunset',
41-
outline: 'none'
40+
palette: 'Sunset'
4241
},
4342
'NYC Taxi Trips (Table)': {
4443
name: 'NYC Taxi Trips (Table)',
@@ -61,8 +60,7 @@ const DATASETS = {
6160
layerType: 'Trips 2D',
6261
lineWidth: 2,
6362
mapStyle: 'outdoors-v12',
64-
palette: 'ArmyRose',
65-
outline: 'black'
63+
palette: 'ArmyRose'
6664
},
6765
'Atlanta Vehicle Trajectories': {
6866
name: 'Atlanta Vehicle Trajectories',
@@ -85,8 +83,7 @@ const DATASETS = {
8583
layerType: 'Trips 2D',
8684
lineWidth: 1.5,
8785
mapStyle: 'dark-v11',
88-
palette: 'Vivid',
89-
outline: 'none'
86+
palette: 'Vivid'
9087
},
9188
'Memphis Vehicle Trajectories (Query)': {
9289
name: 'Memphis Vehicle Trajectories (Query)',
@@ -108,19 +105,13 @@ const DATASETS = {
108105
layerType: 'Trips 2D',
109106
lineWidth: 1.5,
110107
mapStyle: 'satellite-streets-v12',
111-
palette: 'Temps',
112-
outline: 'white'
108+
palette: 'Temps'
113109
}
114110
}
115111
const DATASET_NAMES = Object.keys(DATASETS);
116112

117113
const LAYER = { Path: 'Path 2D', Trips: 'Trips 2D', Points: 'Point 2D' };
118114

119-
const OUTLINES = {
120-
black: 'black',
121-
white: 'white',
122-
none: 'none'
123-
};
124115

125116
const PALETTES = {
126117
ArmyRose: 'ArmyRose',
@@ -162,7 +153,6 @@ export default function App() {
162153
const [layerType, setLayerType] = useState(initialDataset.layerType);
163154
const [mapStyle, setMapStyle] = useState(initialDataset.mapStyle);
164155
const [palette, setPalette] = useState(initialDataset.palette);
165-
const [outline, setOutline] = useState(initialDataset.outline);
166156
const [currentTime, setCurrentTime] = useState(0);
167157
const [animationSpeed, setAnimationSpeed] = useState(100);
168158
const [trailLength, setTrailLength] = useState(1000);
@@ -176,7 +166,6 @@ export default function App() {
176166
setLayerType(dataset.layerType);
177167
setLineWidth(dataset.lineWidth);
178168
setMapStyle(dataset.mapStyle);
179-
setOutline(dataset.outline);
180169
setPalette(dataset.palette);
181170
// Reset time controls to defaults - they'll be updated when data loads
182171
setCurrentTime(0);
@@ -191,7 +180,7 @@ export default function App() {
191180
const [clickedTrajectoryId, setClickedTrajectoryId] = useState(null);
192181

193182
// Handle trajectory click to jump to start time
194-
async function handleTrajectoryClick(info) {
183+
function handleTrajectoryClick(info) {
195184
console.log('handleTrajectoryClick', info);
196185
if (!info.object || !dataSource?.widgetSource) return;
197186

@@ -204,13 +193,11 @@ export default function App() {
204193

205194
console.log('Clicked trajectory with ID:', trajectoryId);
206195

207-
try {
208-
// Use getRange to efficiently get min/max timestamps for this trajectory
209-
const timeRange = await dataSource.widgetSource.getRange({
210-
column: timestampColumn,
211-
filters: { [trajectoryIdColumn]: { in: { values: [trajectoryId] } } }
212-
});
213-
196+
// Use getRange to efficiently get min/max timestamps for this trajectory
197+
dataSource.widgetSource.getRange({
198+
column: timestampColumn,
199+
filters: { [trajectoryIdColumn]: { in: { values: [trajectoryId] } } }
200+
}).then(timeRange => {
214201
if (timeRange && timeRange.min) {
215202
const startTime = normalizeTimestamp(timeRange.min);
216203

@@ -224,9 +211,9 @@ export default function App() {
224211
setCurrentTime(startTime);
225212
setClickedTrajectoryId(trajectoryId);
226213
}
227-
} catch (error) {
214+
}).catch(error => {
228215
console.error('Error fetching trajectory time range:', error);
229-
}
216+
});
230217
}
231218

232219
useEffect(() => {
@@ -293,19 +280,20 @@ export default function App() {
293280

294281
const layers = showPoints ? [
295282
new VectorTileLayer({
296-
id: `points-${palette}`,
283+
id: 'points',
297284
data: dataSource,
298285
pointRadiusMinPixels: lineWidth,
299286
pointRadiusMaxPixels: lineWidth,
300287
getFillColor: colorContinuous({
301288
attr: 'trajectoryId',
302289
domain: [0, 100, 200, 300, 400, 500, 600, 700, 800, 900, 1000],
303290
colors: palette
304-
})
291+
}),
292+
updateTriggers: {getFillColor: [palette]},
305293
})
306294
] : [
307295
new TrajectoryTileLayer({
308-
id: `${palette}-${outline}`,
296+
id: 'trajectories',
309297
data: dataSource,
310298
renderMode: showTrips ? 'trips' : 'paths',
311299
uniqueIdProperty: 'trajectoryId', // TODO internalize this
@@ -324,7 +312,7 @@ export default function App() {
324312
domain: [0, 5, 10, 15, 20, 25],
325313
colors: palette
326314
}),
327-
315+
updateTriggers: {getLineColor: [palette], getFillColor: [palette]},
328316
currentTime,
329317
trailLength,
330318
getWidth: lineWidth,
@@ -335,7 +323,6 @@ export default function App() {
335323
jointRounded: true,
336324
capRounded: true,
337325
_pathType: 'open',
338-
outline,
339326
zRange: [0, 4000],
340327
onClick: handleTrajectoryClick,
341328
onHover: info => {
@@ -379,7 +366,6 @@ export default function App() {
379366
<ObjectSelect title="Layer" obj={LAYER} value={layerType} onSelect={setLayerType} top={30} />
380367
<ObjectSelect title="Map Style" obj={MAP_STYLES} value={mapStyle} onSelect={setMapStyle} top={60} />
381368
<ObjectSelect title="Palette" obj={PALETTES} value={palette} onSelect={setPalette} top={90}/>
382-
<ObjectSelect title="Outline" obj={OUTLINES} value={outline} onSelect={setOutline} top={120} />
383369
{showTrips && <RangeInput
384370
name={'Time'}
385371
animationSpeed={animationSpeed}

0 commit comments

Comments
 (0)