Skip to content

Commit

Permalink
remote msgpack
Browse files Browse the repository at this point in the history
  • Loading branch information
nofurtherinformation committed Apr 4, 2024
1 parent bc9d3fc commit 07452ec
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 12 deletions.
12 changes: 7 additions & 5 deletions app/api/stores/[geoid]/route.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
"use server"
import path from "path";
import fs from "fs";
import { unpack } from 'msgpackr';
import { unpack, UnpackrStream } from 'msgpackr';
import nodeFetch from "node-fetch";

export type ReqParams = {
params: {
Expand All @@ -14,15 +15,16 @@ const isochorones: Record<string, Record<string, {geometry:any}>> = {}
const getIsochrone = async (geoid: string) => {
const state = geoid.slice(0, 2)
if (isochorones[state] === undefined) {
const isochroneFile = path.join(process.cwd(), "public", "data", "isochrones", `isochrones${state}.msgpack`)
const buffer = fs.readFileSync(isochroneFile)
let data = unpack(buffer);
const r = await nodeFetch(`${process.env.DATA_ENDPOINT}isochrones/isochrones${state}.msgpack`)
const buffer = await r.arrayBuffer()
const dataBuffer = Buffer.from(buffer)
let data = unpack(dataBuffer);
isochorones[state] = data
}
return isochorones[state]![geoid]
}

export async function GET(request: Request, reqParams: ReqParams) {
export async function GET(_req: Request, reqParams: ReqParams) {
const geoid = reqParams.params.geoid
if (!geoid || geoid == 'null') {
return new Response("Not found", { status: 404 });
Expand Down
2 changes: 2 additions & 0 deletions components/Map/Map.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { GeoJsonLayer, ScatterplotLayer} from "@deck.gl/layers/typed"
import DropdownMenuDemo from "components/Dropdown/Dropdown"
import * as DropdownMenu from "@radix-ui/react-dropdown-menu"
import { useDataService } from "utils/hooks/useDataService"
import { ScaleControl } from "react-map-gl"
import "./styles.css"
import config from "utils/data/config"
import { SelectMenu } from "components/Select/Select"
Expand Down Expand Up @@ -314,6 +315,7 @@ export const Map = () => {
ref={mapRef}
reuseMaps={true}
>
<ScaleControl unit="imperial" />
<NavigationControl />
<DeckGLOverlay layers={layers} interleaved={true} />
</GlMap>
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@
"next": "^14.0.3",
"next-compose-plugins": "^2.2.1",
"next-mdx-remote": "^4.4.1",
"node-fetch": "^3.3.2",
"node-polyfill-webpack-plugin": "^3.0.0",
"papaparse": "^5.4.1",
"pmtiles": "^3.0.3",
Expand Down
21 changes: 14 additions & 7 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 07452ec

Please sign in to comment.