Skip to content

Commit d648114

Browse files
committed
fix bug
1 parent 9dc0fa8 commit d648114

File tree

6 files changed

+36
-8
lines changed

6 files changed

+36
-8
lines changed

.env.development

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
VERCEL_ENV=development
2-
USE_OLLAMA=1
3-
OLLAMA_BASE_URL="http://ollama:11434"
4-
USE_POSTGRES=1
2+
#USE_OLLAMA=1
3+
#OLLAMA_BASE_URL="http://ollama:11434"
4+
#USE_POSTGRES=1

src/app/api/ai/surface/route.ts

+1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ export async function POST(request: Request) {
2424
console.error("Error parsing pastMessages:", error);
2525
chatHistoryLines = [];
2626
}
27+
chatHistoryLines.push(query);
2728

2829
console.log("");
2930
console.log("chatHistoryLines:");

src/app/page.tsx

+24-4
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { DialogueElement } from "@/types/DialogueElement";
88
import { nextPostJson, nextPostJsonWithCache } from "@/utils/nextPostJson";
99
import { sleep } from "@/lib/sleep";
1010
import React, { useCallback, useEffect, useRef, useState } from "react";
11-
import { MapProvider, MapRef } from "react-map-gl/maplibre";
11+
import { MapProvider, MapRef, useMap } from "react-map-gl/maplibre";
1212
import { FeatureCollection } from "geojson";
1313
import { getOverpassResponseJsonWithCache } from "@/lib/osm/getOverpass";
1414
import osmtogeojson from "osmtogeojson";
@@ -29,6 +29,7 @@ import { useScrollToBottom } from "@/hooks/scrollToBottom";
2929
import { parseSurfaceResJson } from "@/utils/trident/parseSurfaceResJson";
3030
import { Ability } from "@/types/Ability";
3131
import { AccountButton } from "@/components/AccountButton";
32+
import * as turf from "@turf/turf";
3233

3334
export default function Home() {
3435
// all state
@@ -41,6 +42,7 @@ export default function Home() {
4142

4243
// maps ref and state
4344
const mapRef = useRef<MapRef | null>(null);
45+
const { mainMap } = useMap();
4446
const [geoJsonWithStyleList, setGeoJsonWithStyleList] = useState<
4547
Array<{
4648
id: string;
@@ -258,6 +260,7 @@ export default function Home() {
258260

259261
switch (ability) {
260262
case "overpass-api":
263+
console.debug("ability: overpass-api");
261264
await invokeOverpassInner(surfaceResJson.history);
262265
break;
263266
case "apology":
@@ -288,7 +291,7 @@ export default function Home() {
288291
// fit bounds to all geojson in the geojsonWithStyleList
289292
useEffect(() => {
290293
setTimeout(() => {
291-
if (!mapRef || !mapRef.current) return;
294+
console.log("geoJsonWithStyleList", geoJsonWithStyleList);
292295
if (geoJsonWithStyleList.length === 0) return;
293296

294297
try {
@@ -329,8 +332,20 @@ export default function Home() {
329332
};
330333
}
331334
}
332-
333-
fitBoundsToGeoJson(mapRef, everything, padding);
335+
console.log("map", mainMap);
336+
if (!mainMap || mainMap === undefined) return;
337+
338+
const [minLng, minLat, maxLng, maxLat] = turf.bbox(everything);
339+
mainMap.fitBounds(
340+
[
341+
[minLng, minLat],
342+
[maxLng, maxLat],
343+
],
344+
{
345+
padding: padding,
346+
duration: 1000,
347+
}
348+
);
334349
} catch (error) {
335350
console.error(error);
336351
setResponding(false);
@@ -400,6 +415,9 @@ export default function Home() {
400415
latitude={0}
401416
zoom={1}
402417
style={mapStyleJsonUrl}
418+
onMapLoad={() => {
419+
console.log("Map loaded");
420+
}}
403421
>
404422
{geoJsonWithStyleList &&
405423
geoJsonWithStyleList.map((geojsonWithStyle) => {
@@ -439,6 +457,7 @@ export default function Home() {
439457
</div>
440458
);
441459
})}
460+
{/*
442461
<LocationProvider locationInfo={{ location: location }}>
443462
{dialogueList.length === 1 && inputText.length === 0 && (
444463
<InputSuggest
@@ -461,6 +480,7 @@ export default function Home() {
461480
/>
462481
)}
463482
</LocationProvider>
483+
*/}
464484
<div style={{ height: "1px" }} ref={dialogueEndRef} />
465485
</div>
466486
<TextInput

src/lib/maplibre/fitBoundsToGeoJson.ts

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { MapRef, PaddingOptions } from "react-map-gl/maplibre";
22
import * as turf from "@turf/turf";
33
import { MutableRefObject } from "react";
4+
import { Map } from "react-map-gl/maplibre";
45

56
export const fitBoundsToGeoJson = (
67
mapRef: MutableRefObject<MapRef | null>,

src/utils/trident/getChatModel.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,13 @@ export const getChatModel = () => {
1919
configuration: {
2020
baseURL: process.env.CLOUDFLARE_AI_GATEWAY + "/openai",
2121
},
22+
model: "gpt-4o",
2223
temperature: 0,
2324
});
2425
} else {
25-
return new ChatOpenAI({ temperature: 0 });
26+
return new ChatOpenAI({
27+
model: "gpt-4o",
28+
temperature: 0,
29+
});
2630
}
2731
};

src/utils/trident/parseSurfaceResJson.ts

+2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ export const parseSurfaceResJson = (surfaceResJson: {
1414

1515
if (line.includes("Ability")) {
1616
ability = line.split(": ")[1] as Ability;
17+
// 空白除去
18+
ability = ability.replace(/\s+/g, "");
1719
}
1820
if (line.includes("Reply")) {
1921
reply = line.split(": ")[1];

0 commit comments

Comments
 (0)