Skip to content

Commit 24bff78

Browse files
committed
Drop timestamp filter
1 parent f45baa9 commit 24bff78

File tree

2 files changed

+37
-28
lines changed

2 files changed

+37
-28
lines changed

packages/web/src/app/reducer/index.ts

Lines changed: 25 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,14 @@ import { calculateStats } from "../map/utils.ts";
44
import tArea from "@turf/area";
55
import tBboxPolygon from "@turf/bbox-polygon";
66
import { getFgbData } from "../utils/get-fgb-data.ts";
7+
import { Map } from "maplibre-gl";
8+
9+
const availableTimestamps = [
10+
`2024-05-19T05:00:00Z`,
11+
`2024-05-19T06:00:00Z`,
12+
`2024-05-19T07:00:00Z`,
13+
`2024-05-19T08:00:00Z`,
14+
];
715

816
// TODO move to types.ts
917
/* eslint-disable no-unused-vars */
@@ -29,20 +37,21 @@ export interface AppState {
2937
map: any;
3038
mapStatus: MapStatus;
3139
geojson?: any;
40+
currentTimestamp?: Date;
3241
currentTimestampGeojson?: any;
3342
}
3443

3544
export type AppAction =
3645
| {
3746
type: AppActionTypes.SET_MAP_REF;
3847
data: {
39-
map: any;
48+
map: Map;
4049
};
4150
}
4251
| {
4352
type: AppActionTypes.SET_CURRENT_TIMESTAMP;
4453
data: {
45-
currentTimestamp: string;
54+
currentTimestamp: Date;
4655
};
4756
}
4857
| {
@@ -66,17 +75,10 @@ export const appInitialState = {
6675
type: "FeatureCollection",
6776
features: [],
6877
},
78+
currentTimestamp: new Date(availableTimestamps[2]),
79+
timestamps: [...availableTimestamps],
6980
};
7081

71-
function applyTimestampFilter(geojson: any, timestamp: string) {
72-
return {
73-
type: "FeatureCollection",
74-
features: geojson.features.filter(
75-
(f: any) => f.properties.timestamp === timestamp,
76-
),
77-
};
78-
}
79-
8082
function appReducer(state: AppState, action: AppAction) {
8183
switch (action.type) {
8284
case AppActionTypes.SET_MAP_REF:
@@ -91,13 +93,10 @@ function appReducer(state: AppState, action: AppAction) {
9193
mapStatus: MapStatus.LOADING,
9294
};
9395
case AppActionTypes.UPDATE_VIEW_SUCCESS: {
94-
const { geojson, timestamps } = action.data;
95-
const currentTimestamp = timestamps[timestamps.length - 1];
96-
const currentTimestampGeojson = applyTimestampFilter(
97-
geojson,
98-
currentTimestamp,
99-
);
100-
const stats = calculateStats(currentTimestampGeojson);
96+
const { geojson } = action.data;
97+
const { currentTimestamp } = state;
98+
99+
const stats = calculateStats(geojson);
101100

102101
const bounds = state.map.getBounds().toArray();
103102
const [[minX, minY], [maxX, maxY]] = bounds;
@@ -110,18 +109,15 @@ function appReducer(state: AppState, action: AppAction) {
110109
formattedArea,
111110
stats,
112111
geojson,
113-
timestamps,
114112
currentTimestamp,
115-
currentTimestampGeojson,
113+
currentTimestampGeojson: currentTimestamp,
116114
mapStatus: MapStatus.READY,
117115
};
118116
}
119117
case AppActionTypes.SET_CURRENT_TIMESTAMP: {
120118
const { currentTimestamp } = action.data;
121-
const currentTimestampGeojson = applyTimestampFilter(
122-
state.geojson,
123-
currentTimestamp,
124-
);
119+
120+
const currentTimestampGeojson = state.geojson;
125121
const stats = calculateStats(currentTimestampGeojson);
126122
return {
127123
...state,
@@ -141,7 +137,7 @@ const asyncActionHandlers: any = {
141137
({ dispatch, getState }: any) =>
142138
async () => {
143139
try {
144-
const { map, mapStatus } = getState();
140+
const { map, mapStatus, currentTimestamp } = getState();
145141

146142
// Only update the view if the map is ready
147143
if (mapStatus !== MapStatus.READY) {
@@ -152,7 +148,10 @@ const asyncActionHandlers: any = {
152148
type: AppActionTypes.UPDATE_VIEW_START,
153149
});
154150

155-
const { geojson, timestamps } = await getFgbData({ map });
151+
const { geojson, timestamps } = await getFgbData({
152+
map,
153+
timestamp: currentTimestamp,
154+
});
156155

157156
map.getSource("data").setData(geojson);
158157

packages/web/src/app/utils/get-fgb-data.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,22 @@ import { geojson as flatgeobuf } from "flatgeobuf";
22
import { getFlatGeobufRectangle } from "./get-fgb-rect";
33
import { Map } from "maplibre-gl";
44

5-
export async function getFgbData({ map }: { map: Map }) {
5+
export async function getFgbData({
6+
map,
7+
timestamp,
8+
}: {
9+
map: Map;
10+
timestamp: Date;
11+
}) {
612
let i = 0;
713
const geojson = { type: "FeatureCollection", features: [] as any[] };
814

15+
const filename = `https://storage.googleapis.com/osm-tardis/${timestamp
16+
.toISOString()
17+
.slice(0, 13)}%3A00.fgb`;
18+
919
const iter = flatgeobuf.deserialize(
10-
"https://storage.googleapis.com/osm-tardis/2013-02-03T15%3A00.fgb",
20+
filename,
1121
getFlatGeobufRectangle(map),
1222
) as AsyncGenerator<any>;
1323

0 commit comments

Comments
 (0)