Skip to content

Commit f45baa9

Browse files
committed
Reorganize helper functions
1 parent 20c159a commit f45baa9

File tree

4 files changed

+39
-38
lines changed

4 files changed

+39
-38
lines changed

packages/web/src/app/map/utils.ts

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,3 @@
1-
import { geojson as flatgeobuf } from "flatgeobuf";
2-
import { getFlatGeobufRectangle } from "../utils/get-flatgeobuf-rect";
3-
4-
export async function getFgbData(map: any) {
5-
let i = 0;
6-
const geojson = { type: "FeatureCollection", features: [] as any[] };
7-
8-
const iter = flatgeobuf.deserialize(
9-
"https://storage.googleapis.com/osm-tardis/2013-02-03T15%3A00.fgb",
10-
getFlatGeobufRectangle(map),
11-
) as AsyncGenerator<any>;
12-
13-
const timestamps = new Set();
14-
15-
for await (const feature of iter) {
16-
const { properties } = feature;
17-
18-
if (!properties || properties === null || properties === undefined) {
19-
continue;
20-
}
21-
22-
if (
23-
properties.type !== "relation" &&
24-
(properties.changeType === "added" ||
25-
properties.changeType === "modifiedNew" ||
26-
properties.changeType === "deletedNew")
27-
) {
28-
geojson.features.push({ ...feature, id: i });
29-
i += 1;
30-
timestamps.add(properties.timestamp);
31-
}
32-
}
33-
34-
return { geojson, timestamps: Array.from(timestamps).sort() };
35-
}
36-
371
export function calculateStats(geojson: any) {
382
const stats = {
393
tags: {},

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import { useReducerAsync } from "use-reducer-async";
22
import logReducer from "./log.ts";
3-
import { calculateStats, getFgbData } from "../map/utils.ts";
3+
import { calculateStats } from "../map/utils.ts";
44
import tArea from "@turf/area";
55
import tBboxPolygon from "@turf/bbox-polygon";
6+
import { getFgbData } from "../utils/get-fgb-data.ts";
67

78
// TODO move to types.ts
89
/* eslint-disable no-unused-vars */
@@ -151,7 +152,7 @@ const asyncActionHandlers: any = {
151152
type: AppActionTypes.UPDATE_VIEW_START,
152153
});
153154

154-
const { geojson, timestamps } = await getFgbData(map);
155+
const { geojson, timestamps } = await getFgbData({ map });
155156

156157
map.getSource("data").setData(geojson);
157158

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import { geojson as flatgeobuf } from "flatgeobuf";
2+
import { getFlatGeobufRectangle } from "./get-fgb-rect";
3+
import { Map } from "maplibre-gl";
4+
5+
export async function getFgbData({ map }: { map: Map }) {
6+
let i = 0;
7+
const geojson = { type: "FeatureCollection", features: [] as any[] };
8+
9+
const iter = flatgeobuf.deserialize(
10+
"https://storage.googleapis.com/osm-tardis/2013-02-03T15%3A00.fgb",
11+
getFlatGeobufRectangle(map),
12+
) as AsyncGenerator<any>;
13+
14+
const timestamps = new Set();
15+
16+
for await (const feature of iter) {
17+
const { properties } = feature;
18+
19+
if (!properties || properties === null || properties === undefined) {
20+
continue;
21+
}
22+
23+
if (
24+
properties.type !== "relation" &&
25+
(properties.changeType === "added" ||
26+
properties.changeType === "modifiedNew" ||
27+
properties.changeType === "deletedNew")
28+
) {
29+
geojson.features.push({ ...feature, id: i });
30+
i += 1;
31+
timestamps.add(properties.timestamp);
32+
}
33+
}
34+
35+
return { geojson, timestamps: Array.from(timestamps).sort() };
36+
}

0 commit comments

Comments
 (0)