@@ -17,7 +17,7 @@ import { Layer_GeoJson } from "@/lib/map/layers.js"
17
17
import { Toast_Component } from "@/components/utils/toast" ;
18
18
import { Info_Component } from "@/components/Main/traffic/info_drawer.jsx" ;
19
19
import { useGetTraffic } from "@/hooks/useGetTraffic" ;
20
- import { useTime , useDrawer } from "@/context" ;
20
+ import { useENV , useTime , useDrawer } from "@/context" ;
21
21
//import { Client } from "@googlemaps/google-maps-services-js";
22
22
23
23
@@ -26,22 +26,17 @@ Date.prototype.addHours = function (h) {
26
26
return this ;
27
27
}
28
28
29
- // 取得MapBox金鑰
30
- const mapbox_api_key = process . env . NEXT_PUBLIC_MAPBOX_TOKENS ;
31
- const mapbox_style = process . env . NEXT_PUBLIC_MAPBOX_STYLE
32
-
33
- // 取得 Polstar北宸科技地圖服務 API 金鑰
34
- const polstar_api_key = process . env . NEXT_PUBLIC_POLSTAR_API_KEY ;
35
-
36
29
37
30
const LocationAggregatorMap = ( { off, useExistToken } ) => {
31
+ // 取得環境變數
32
+ const { ENVConfig, SetENVConfig } = useENV ( ) ;
38
33
// 取得時間軸指定日期
39
34
const { selectedTime } = useTime ( ) ;
40
35
// 取得開啟壅塞詳細側邊欄狀態
41
36
const { showDrawer, setShowDrawer } = useDrawer ( ) ;
42
37
43
38
// 儲存使用者經緯度
44
- const [ location , setLocation ] = useState ( null ) ;
39
+ const [ location , setLocation ] = useState ( ) ;
45
40
46
41
// 儲存觀看座標、縮放等資訊
47
42
const [ initialViewState , setInitialViewState ] = useState ( INITIAL_VIEW_STATE . SF ) ;
@@ -66,7 +61,19 @@ const LocationAggregatorMap = ({ off, useExistToken }) => {
66
61
const [ searchResult , setSearchResult ] = useState ( [ ] ) ;
67
62
68
63
// 儲存動畫過渡狀態
69
- const [ isTransition , setIsTransition ] = useState ( false ) ;
64
+ //const [isTransition, setIsTransition] = useState(false);
65
+
66
+ const [ messages , setMessages ] = useState ( "" ) ;
67
+
68
+ if ( ENVConfig ) {
69
+ // 取得MapBox金鑰
70
+ var mapbox_api_key = ENVConfig . mapbox . token ;
71
+ var mapbox_style = ENVConfig . mapbox . style ;
72
+
73
+ // 取得 Polstar北宸科技地圖服務 API 金鑰
74
+ var polstar_api_key = ENVConfig . polstar . key ;
75
+ }
76
+
70
77
71
78
// 更新初始座標起始點(如果已儲存使用者位置)
72
79
useEffect ( ( ) => {
@@ -92,8 +99,11 @@ const LocationAggregatorMap = ({ off, useExistToken }) => {
92
99
// 儲存至LocalStorage
93
100
window . localStorage . setItem ( "UserLocation" , JSON . stringify ( INITIAL_VIEW_STATE . NYC ) )
94
101
} )
102
+ } else {
103
+ setLocation ( INITIAL_VIEW_STATE . SF ) ;
95
104
}
96
105
}
106
+
97
107
useEffect ( ( ) => {
98
108
getCurrentPosition ( )
99
109
} , [ ] ) ;
@@ -194,45 +204,6 @@ const LocationAggregatorMap = ({ off, useExistToken }) => {
194
204
"street_number"
195
205
]
196
206
},
197
- {
198
- "long_name": "台元街",
199
- "short_name": "台元街",
200
- "types": [
201
- "route"
202
- ]
203
- },
204
- {
205
- "long_name": "竹北里",
206
- "short_name": "竹北里",
207
- "types": [
208
- "administrative_area_level_4",
209
- "political"
210
- ]
211
- },
212
- {
213
- "long_name": "竹北市",
214
- "short_name": "竹北市",
215
- "types": [
216
- "administrative_area_level_3",
217
- "political"
218
- ]
219
- },
220
- {
221
- "long_name": "新竹縣",
222
- "short_name": "新竹縣",
223
- "types": [
224
- "administrative_area_level_2",
225
- "political"
226
- ]
227
- },
228
- {
229
- "long_name": "台灣",
230
- "short_name": "TW",
231
- "types": [
232
- "country",
233
- "political"
234
- ]
235
- },
236
207
{
237
208
"long_name": "302082",
238
209
"short_name": "302082",
@@ -619,7 +590,7 @@ const LocationAggregatorMap = ({ off, useExistToken }) => {
619
590
setTimeout ( ( ) => {
620
591
getLocation ( )
621
592
} , 1000 ) ;
622
- } , [ search , initialViewState . latitude , initialViewState . longitude ] ) ;
593
+ } , [ search , initialViewState ] ) ;
623
594
624
595
return (
625
596
< div className = "grid h-full w-full" >
@@ -719,14 +690,21 @@ const LocationAggregatorMap = ({ off, useExistToken }) => {
719
690
color = "blue"
720
691
className = { `flex select-none order-first md:order-none font-bold items-center border-[2px] border-gray-800 h-fit w-fit z-[9998]` }
721
692
onClick = { ( ) => {
722
- //getCurrentPosition();
723
- setInitialViewState ( {
724
- longitude : location . longitude ,
725
- latitude : location . latitude ,
726
- zoom : 18 ,
727
- transitionInterpolator : new FlyToInterpolator ( { speed : 2 } ) ,
728
- transitionDuration : 'auto' ,
729
- } ) ;
693
+ if ( location ) {
694
+ //getCurrentPosition();
695
+ setInitialViewState ( {
696
+ longitude : location ?. longitude ,
697
+ latitude : location ?. latitude ,
698
+ zoom : 18 ,
699
+ transitionInterpolator : new FlyToInterpolator ( { speed : 2 } ) ,
700
+ transitionDuration : 'auto' ,
701
+ } ) ;
702
+ } else {
703
+ setMessages ( "尚未啟用位置權限" )
704
+ setTimeout ( ( ) => {
705
+ setMessages ( null )
706
+ } , 1500 )
707
+ }
730
708
} }
731
709
>
732
710
< div className = "flex flex-col justify-center items-center p-0 m-0" >
@@ -748,6 +726,15 @@ const LocationAggregatorMap = ({ off, useExistToken }) => {
748
726
update_time = { update_time }
749
727
/>
750
728
}
729
+ {
730
+ messages &&
731
+ < Toast_Component
732
+ icon_text = { "系統訊息" }
733
+ title = { "系統訊息" }
734
+ contents = { messages }
735
+ showExit = { false }
736
+ />
737
+ }
751
738
{
752
739
warn &&
753
740
< Toast_Component
0 commit comments