@@ -8,7 +8,7 @@ import { DialogueElement } from "@/types/DialogueElement";
8
8
import { nextPostJson , nextPostJsonWithCache } from "@/utils/nextPostJson" ;
9
9
import { sleep } from "@/lib/sleep" ;
10
10
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" ;
12
12
import { FeatureCollection } from "geojson" ;
13
13
import { getOverpassResponseJsonWithCache } from "@/lib/osm/getOverpass" ;
14
14
import osmtogeojson from "osmtogeojson" ;
@@ -29,6 +29,7 @@ import { useScrollToBottom } from "@/hooks/scrollToBottom";
29
29
import { parseSurfaceResJson } from "@/utils/trident/parseSurfaceResJson" ;
30
30
import { Ability } from "@/types/Ability" ;
31
31
import { AccountButton } from "@/components/AccountButton" ;
32
+ import * as turf from "@turf/turf" ;
32
33
33
34
export default function Home ( ) {
34
35
// all state
@@ -41,6 +42,7 @@ export default function Home() {
41
42
42
43
// maps ref and state
43
44
const mapRef = useRef < MapRef | null > ( null ) ;
45
+ const { mainMap } = useMap ( ) ;
44
46
const [ geoJsonWithStyleList , setGeoJsonWithStyleList ] = useState <
45
47
Array < {
46
48
id : string ;
@@ -258,6 +260,7 @@ export default function Home() {
258
260
259
261
switch ( ability ) {
260
262
case "overpass-api" :
263
+ console . debug ( "ability: overpass-api" ) ;
261
264
await invokeOverpassInner ( surfaceResJson . history ) ;
262
265
break ;
263
266
case "apology" :
@@ -288,7 +291,7 @@ export default function Home() {
288
291
// fit bounds to all geojson in the geojsonWithStyleList
289
292
useEffect ( ( ) => {
290
293
setTimeout ( ( ) => {
291
- if ( ! mapRef || ! mapRef . current ) return ;
294
+ console . log ( "geoJsonWithStyleList" , geoJsonWithStyleList ) ;
292
295
if ( geoJsonWithStyleList . length === 0 ) return ;
293
296
294
297
try {
@@ -329,8 +332,20 @@ export default function Home() {
329
332
} ;
330
333
}
331
334
}
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
+ ) ;
334
349
} catch ( error ) {
335
350
console . error ( error ) ;
336
351
setResponding ( false ) ;
@@ -400,6 +415,9 @@ export default function Home() {
400
415
latitude = { 0 }
401
416
zoom = { 1 }
402
417
style = { mapStyleJsonUrl }
418
+ onMapLoad = { ( ) => {
419
+ console . log ( "Map loaded" ) ;
420
+ } }
403
421
>
404
422
{ geoJsonWithStyleList &&
405
423
geoJsonWithStyleList . map ( ( geojsonWithStyle ) => {
@@ -439,6 +457,7 @@ export default function Home() {
439
457
</ div >
440
458
) ;
441
459
} ) }
460
+ { /*
442
461
<LocationProvider locationInfo={{ location: location }}>
443
462
{dialogueList.length === 1 && inputText.length === 0 && (
444
463
<InputSuggest
@@ -461,6 +480,7 @@ export default function Home() {
461
480
/>
462
481
)}
463
482
</LocationProvider>
483
+ */ }
464
484
< div style = { { height : "1px" } } ref = { dialogueEndRef } />
465
485
</ div >
466
486
< TextInput
0 commit comments