Files
rog_app/lib/pages/destination_map/destination_map_page.dart

208 lines
8.6 KiB
Dart
Raw Normal View History

2022-06-04 20:16:29 +05:30
import 'dart:async';
2022-05-24 20:43:41 +05:30
import 'package:flutter/material.dart';
2023-12-06 11:16:17 +05:30
import 'package:flutter_map/flutter_map.dart';
2022-06-04 20:16:29 +05:30
import 'package:flutter_map_location_marker/flutter_map_location_marker.dart';
//import 'package:flutter_map_marker_popup/flutter_map_marker_popup.dart';
2022-05-24 20:43:41 +05:30
import 'package:flutter_polyline_points/flutter_polyline_points.dart';
import 'package:get/get.dart';
import 'package:latlong2/latlong.dart';
2022-07-09 22:51:34 +05:30
import 'package:rogapp/model/destination.dart';
2022-05-24 20:43:41 +05:30
import 'package:rogapp/pages/destination/destination_controller.dart';
import 'package:rogapp/pages/index/index_controller.dart';
2022-10-12 21:46:17 +05:30
import 'package:rogapp/utils/text_util.dart';
2023-03-17 11:54:12 +05:30
import 'package:rogapp/widgets/base_layer_widget.dart';
2024-04-20 12:34:49 +09:00
import 'package:rogapp/widgets/bottom_sheet_new.dart';
//import 'package:rogapp/widgets/bottom_sheets/bottom_sheet_start.dart';
//import 'package:rogapp/widgets/bottom_sheets/bottom_sheet_goal.dart';
//import 'package:rogapp/widgets/bottom_sheets/bottom_sheet_normal_point.dart';
2022-05-24 20:43:41 +05:30
// FlutterMapウィジェットを使用して、地図を表示します。
// IndexControllerから目的地のリストを取得し、マーカーとしてマップ上に表示します。
// マーカーがタップされると、BottomSheetウィジェットを表示します。
// 現在地の表示、ルートの表示、ベースレイヤーの表示などの機能を提供します。
// 主なロジック:
// FlutterMapウィジェットを使用して、地図を表示します。
// IndexControllerから目的地のリストを取得し、MarkerLayerを使用してマーカーを表示します。
// getMarkerShapeメソッドを使用して、マーカーの見た目をカスタマイズします。目的地の種類に応じて、異なるマーカーを表示します。
// マーカーがタップされると、festuretoDestinationメソッドを使用してGeoJSONFeatureをDestinationオブジェクトに変換し、showModalBottomSheetを使用してBottomSheetウィジェットを表示します。
// CurrentLocationLayerを使用して、現在地をマップ上に表示します。
// PolylineLayerを使用して、ルートをマップ上に表示します。getPointsメソッドを使用して、ルートの座標を取得します。
// BaseLayerを使用して、マップのベースレイヤーを表示します。
//
2022-09-22 20:36:56 +05:30
class DestinationMapPage extends StatelessWidget {
DestinationMapPage({Key? key}) : super(key: key);
2022-06-14 14:37:59 +05:30
2022-05-24 20:43:41 +05:30
final IndexController indexController = Get.find<IndexController>();
2023-09-06 21:36:11 +05:30
final DestinationController destinationController =
Get.find<DestinationController>();
2022-06-04 20:16:29 +05:30
StreamSubscription? subscription;
//final PopupController _popupLayerController = PopupController();
2022-06-14 14:37:59 +05:30
2023-09-06 21:36:11 +05:30
List<LatLng>? getPoints() {
2023-10-06 16:25:21 +05:30
//print("##### --- route point ${indexController.routePoints.length}");
2023-09-06 21:36:11 +05:30
List<LatLng> pts = [];
for (PointLatLng p in indexController.routePoints) {
LatLng l = LatLng(p.latitude, p.longitude);
pts.add(l);
2022-05-24 20:43:41 +05:30
}
2023-09-06 21:36:11 +05:30
return pts;
}
2022-05-24 20:43:41 +05:30
// 要検討:マーカーのタップイベントを処理する際に、エラーハンドリングが不十分です。例外が発生した場合の処理を追加することをお勧めします。
//
2023-09-06 21:36:11 +05:30
List<Marker>? getMarkers() {
List<Marker> pts = [];
//int index = -1;
2023-09-06 21:36:11 +05:30
for (int i = 0; i < destinationController.destinations.length; i++) {
Destination d = destinationController.destinations[i];
2023-10-06 16:25:21 +05:30
//print("^^^^ $d ^^^^");
2023-09-06 21:36:11 +05:30
Marker m = Marker(
2022-07-27 19:43:12 +05:30
point: LatLng(d.lat!, d.lon!),
2023-12-07 10:20:44 +05:30
alignment: Alignment.center,
2023-12-06 11:16:17 +05:30
child: InkWell(
onTap: () {
//print("-- Destination is --- ${d.name} ------");
if (indexController.currentDestinationFeature.isNotEmpty) {
indexController.currentDestinationFeature.clear();
}
indexController.currentDestinationFeature.add(d);
//indexController.getAction();
2023-09-06 21:36:11 +05:30
2024-04-20 12:34:49 +09:00
Widget bottomSheet = BottomSheetNew(destination: d);
/*
if (d.cp == -1 || d.cp == 0) {
bottomSheet = BottomSheetStart(destination: d);
} else if (d.cp == -2 || d.cp == 0) {
bottomSheet = BottomSheetGoal(destination: d);
} else {
bottomSheet = BottomSheetNormalPoint(destination: d);
}
2024-04-20 12:34:49 +09:00
*/
2023-12-06 11:16:17 +05:30
showModalBottomSheet(
context: Get.context!,
isScrollControlled: true,
constraints:
BoxConstraints.loose(Size(Get.width, Get.height * 0.85)),
builder: ((context) => bottomSheet ),
).whenComplete(() {
2023-12-06 11:16:17 +05:30
//print("---- set skip gps to false -----");
destinationController.skipGps = false;
});
},
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Container(
width: 20,
height: 20,
decoration: BoxDecoration(
color: Colors.red,
shape: BoxShape.circle,
border: Border.all(
color: Colors.white,
width: d.checkin_radious != null ? d.checkin_radious! : 1,
2022-09-01 19:14:18 +05:30
),
2023-12-06 11:16:17 +05:30
),
child: Center(
child: Text(
(i + 1).toString(),
style: const TextStyle(color: Colors.white),
2022-09-01 19:14:18 +05:30
),
2022-07-28 19:01:45 +05:30
),
2023-12-06 11:16:17 +05:30
),
Container(
color: Colors.yellow,
child: Text(
TextUtils.getDisplayText(d),
style: const TextStyle(
fontSize: 15.0,
fontWeight: FontWeight.bold,
overflow: TextOverflow.visible),
)),
],
),
));
2023-09-06 21:36:11 +05:30
pts.add(m);
2022-05-24 20:43:41 +05:30
}
2023-09-06 21:36:11 +05:30
return pts;
}
2022-05-24 20:43:41 +05:30
@override
Widget build(BuildContext context) {
2023-09-06 21:36:11 +05:30
return Obx((() => Stack(
children: [
// indexController.is_rog_mapcontroller_loaded.value == false ?
// Center(child: CircularProgressIndicator())
// :
// Padding(
// padding: const EdgeInsets.only(left:8.0),
// child: BreadCrumbWidget(mapController:indexController.rogMapController),
// ),
Padding(
padding: const EdgeInsets.only(top: 0.0),
//child: TravelMap(),
2023-10-06 16:25:21 +05:30
child: travelMap(),
2023-09-06 21:36:11 +05:30
),
],
)));
2022-07-09 22:51:34 +05:30
}
// 要検討MapOptionsのboundsプロパティにハードコードされた座標が使用されています。これを動的に設定できるようにすることを検討してください。
//
2023-10-06 16:25:21 +05:30
FlutterMap travelMap() {
2022-07-09 22:51:34 +05:30
return FlutterMap(
2023-03-17 11:54:12 +05:30
mapController: indexController.rogMapController,
2023-09-06 21:36:11 +05:30
options: MapOptions(
onMapReady: () {
2023-10-06 16:25:21 +05:30
indexController.isRogMapcontrollerLoaded.value = true;
2023-09-06 21:36:11 +05:30
subscription = indexController.rogMapController.mapEventStream
.listen((MapEvent mapEvent) {
if (mapEvent is MapEventMoveStart) {}
2022-07-09 22:51:34 +05:30
if (mapEvent is MapEventMoveEnd) {
2022-10-30 21:43:29 +05:30
//destinationController.is_gps_selected.value = true;
//indexController.mapController!.move(c.center, c.zoom);
2023-08-16 14:53:32 +05:30
LatLngBounds bounds = indexController.rogMapController.bounds!;
2022-10-30 21:43:29 +05:30
indexController.currentBound.clear();
indexController.currentBound.add(bounds);
2023-09-06 21:36:11 +05:30
if (indexController.currentUser.isEmpty) {
2023-02-16 19:36:39 +05:30
indexController.loadLocationsBound();
}
2022-07-09 22:51:34 +05:30
}
2022-06-04 20:16:29 +05:30
});
2023-09-06 21:36:11 +05:30
},
bounds: indexController.currentBound.isNotEmpty
? indexController.currentBound[0]
: LatLngBounds.fromPoints([
const LatLng(35.03999881162295, 136.40587119778962),
const LatLng(36.642756778706904, 137.95226720406063)
2023-09-06 21:36:11 +05:30
]),
initialZoom: 1,
2023-09-06 21:36:11 +05:30
maxZoom: 42,
interactiveFlags: InteractiveFlag.pinchZoom | InteractiveFlag.drag,
2022-07-15 21:50:14 +05:30
),
2023-09-06 21:36:11 +05:30
children: [
const BaseLayer(),
Obx(
() => indexController.routePointLenght > 0
? PolylineLayer(
polylines: [
Polyline(
points: getPoints()!,
strokeWidth: 6.0,
color: Colors.indigo),
],
)
: Container(),
),
CurrentLocationLayer(),
MarkerLayer(markers: getMarkers()!),
],
);
2022-05-24 20:43:41 +05:30
}
2022-09-22 20:36:56 +05:30
}