未確認だが問題回避のためプッシュ

This commit is contained in:
2024-04-09 01:58:25 +09:00
parent dd9dd0d087
commit 1b4073f690
59 changed files with 2384 additions and 410 deletions

View File

@ -18,6 +18,21 @@ import 'package:rogapp/widgets/bottom_sheet_new.dart';
import 'package:rogapp/widgets/current_position_widget.dart';
import 'package:rogapp/widgets/game_state_view.dart';
// map_widget.dartファイルは、アプリ内の地図表示を担当するウィジェットを定義しています。以下に、主要な部分を解説します。
// 地図表示に関連する主要な機能を提供しています。以下のような機能が含まれています。
//
// 地図の表示と操作
// マーカーの表示とカスタマイズ
// ルートの表示
// 現在位置の表示
// アイドル状態の処理
// ローディングインジケーターの表示
// ゲーム状態の表示
// 現在位置ボタンの表示
// StatefulWidgetを継承したクラスで、地図表示のメインウィジェットです。
//
class MapWidget extends StatefulWidget {
MapWidget({Key? key}) : super(key: key);
@ -25,16 +40,23 @@ class MapWidget extends StatefulWidget {
State<MapWidget> createState() => _MapWidgetState();
}
// MapWidgetの状態を管理するクラスです。
//
class _MapWidgetState extends State<MapWidget> {
final IndexController indexController = Get.find<IndexController>();
// IndexControllerのインスタンスを保持します。
final DestinationController destinationController =
Get.find<DestinationController>();
// DestinationControllerのインスタンスを保持します。
final LocationController locationController = Get.find<LocationController>();
// LocationControllerのインスタンスを保持します。
StreamSubscription? subscription;
Timer? _timer;
StreamSubscription? subscription; // 地図イベントの購読を保持します。
Timer? _timer; // アイドル状態のタイマーを保持します。
// 地図上のマーカーのUIを生成するメソッドです。
// GeoJSONFeatureを受け取り、マーカーのUIを返します。
//
Widget getMarkerShape(GeoJSONFeature i, BuildContext context) {
GeoJSONMultiPoint p = i.geometry as GeoJSONMultiPoint;
//print("lat is ${p.geoSerie!.geoPoints[0].latitude} and lon is ${p.geoSerie!.geoPoints[0].longitude}");
@ -155,6 +177,9 @@ class _MapWidgetState extends State<MapWidget> {
);
}
// ルートポイントをLatLngのリストに変換するメソッドです。
// IndexControllerのroutePointsからLatLngのリストを生成しています。
//
List<LatLng>? getPoints() {
//print("##### --- route point ${indexController.routePoints.length}");
List<LatLng> pts = [];
@ -165,21 +190,31 @@ class _MapWidgetState extends State<MapWidget> {
return pts;
}
// ウィジェットの初期化時に呼び出されるメソッドです。
// _startIdleTimerメソッドを呼び出して、アイドル状態のタイマーを開始します。
//
@override
void initState() {
super.initState();
_startIdleTimer();
_startIdleTimer(); // _startIdleTimerメソッドを呼び出してアイドル状態のタイマーを開始しています。
}
// アイドル状態のタイマーを開始するメソッドです。
// 一定時間後に_centerMapOnUserメソッドを呼び出すようにタイマーを設定しています。
//
void _startIdleTimer() {
_timer = Timer(const Duration(milliseconds: (1000 * 10)), _centerMapOnUser);
}
// アイドル状態のタイマーをリセットするメソッドです。
//
void _resetTimer() {
_timer?.cancel();
_startIdleTimer();
}
// 地図をユーザーの現在位置に中央揃えするメソッドです。
//
void _centerMapOnUser() {
assert(() {
print("showBottomSheet ${destinationController.shouldShowBottomSheet}");
@ -192,6 +227,13 @@ class _MapWidgetState extends State<MapWidget> {
//}
}
// ウィジェットのUIを構築するメソッドです。
// FlutterMapウィジェットを使用して地図を表示します。
// layersプロパティに、ベースレイヤー、ルートレイヤー、現在位置レイヤー、マーカーレイヤーを設定します。
// PopupControllerを使用して、ポップアップの制御を行います。
// IndexControllerのisLoading変数に基づいて、ローディングインジケーターを表示します。
// GameStateWidgetとCurrentPositionウィジェットを重ねて表示します。
//
@override
Widget build(BuildContext context) {
// print(
@ -200,18 +242,22 @@ class _MapWidgetState extends State<MapWidget> {
final PopupController popupController = PopupController();
return Stack(
children: [
// IndexControllerのisLoading変数に基づいて、ローディングインジケーターを表示します。
// isLoadingがtrueの場合はCircularProgressIndicatorを表示し、falseの場合は地図を表示します。
Obx(() => indexController.isLoading.value == true
? const Padding(
padding: EdgeInsets.only(top: 60.0),
child: CircularProgressIndicator(),
)
: FlutterMap(
// 地図の表示を担当
mapController: indexController.mapController,
options: MapOptions(
// 地図の初期設定(最大ズームレベル、初期位置、ズームレベルなど)を行っています。
maxZoom: 18.4,
onMapReady: () {
// print("Map controller ready!!"); ... working corretly
indexController.isMapControllerReady.value = true; // Added Akira,2024-4-6 for #2800
// print("Map controller ready!!"); ... working corretly
indexController.isMapControllerReady.value = true; // Added Akira,2024-4-6 for #2800
subscription = indexController.mapController.mapEventStream
.listen((MapEvent mapEvent) {
@ -235,6 +281,7 @@ class _MapWidgetState extends State<MapWidget> {
InteractiveFlag.pinchZoom | InteractiveFlag.drag,
onPositionChanged: (MapPosition pos, hasGesture) {
// 地図の位置が変更された際の処理を行います。
//print("map position changed ${pos.center!.latitude}");
if (hasGesture) {
_resetTimer();
@ -249,9 +296,10 @@ class _MapWidgetState extends State<MapWidget> {
Obx(
() => indexController.routePointLenght > 0
? PolylineLayer(
// ルートの表示を担当
polylines: [
Polyline(
points: getPoints()!,
points: getPoints()!, // ルートのポイントを設定しています。
strokeWidth: 6.0,
color: Colors.indigo),
],
@ -259,11 +307,14 @@ class _MapWidgetState extends State<MapWidget> {
: Container(),
),
CurrentLocationLayer(
// 現在位置の表示を担当
positionStream: locationController
.locationMarkerPositionStreamController.stream,
// locationMarkerPositionStreamController.streamを設定して、現在位置の更新を監視しています。
alignDirectionOnUpdate: AlignOnUpdate.never,
turnOnHeadingUpdate: TurnOnHeadingUpdate.never,
style: const LocationMarkerStyle(
// styleプロパティで、現在位置のマーカーのスタイルを設定しています。
marker: DefaultLocationMarker(
child: Icon(
Icons.navigation,
@ -277,6 +328,7 @@ class _MapWidgetState extends State<MapWidget> {
indexController.locations.isNotEmpty &&
indexController.locations[0].features.isNotEmpty
? MarkerLayer(
// マーカーの表示を担当
markers:
indexController.locations[0].features.map((i) {
//print("i si ${i.properties!['location_id']}");
@ -293,13 +345,29 @@ class _MapWidgetState extends State<MapWidget> {
point: LatLng(
p.coordinates[0][1], p.coordinates[0][0]),
child: getMarkerShape(i, context));
// マーカーのUIを生成しています。
// マーカーのアイコン、ラベル、色などをカスタマイズしています。
}).toList(),
)
: const Center(child: CircularProgressIndicator()),
],
)),
const Positioned(top: 0, left: 0, child: GameStateWidget()),
const Positioned(bottom: 10, right: 10, child: CurrentPosition())
// ゲーム状態の表示を担当。ゲームの状態(開始、終了など)を表示するカスタムウィジェットです。
const Positioned(bottom: 10, right: 10, child: CurrentPosition()),
// 現在位置ボタンの表示を担当。現在位置に移動するためのボタンを表示するカスタムウィジェットです。
StreamBuilder<LocationMarkerPosition?>(
stream: locationController.locationMarkerPositionStream,
builder: (context, snapshot) {
if (snapshot.hasData) {
print("Display current marker");
} else {
print("Not display current marker");
}
return Container();
},
)
// const Positioned(
// bottom: 10,
// left: 0,