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

268 lines
9.5 KiB
Dart
Raw Normal View History

2022-05-24 20:43:41 +05:30
2022-06-04 20:16:29 +05:30
import 'dart:async';
2022-05-24 20:43:41 +05:30
import 'package:flutter/material.dart';
import 'package:flutter_map/plugin_api.dart';
2022-06-04 20:16:29 +05:30
import 'package:flutter_map_location_marker/flutter_map_location_marker.dart';
2022-06-14 14:37:59 +05:30
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';
2022-06-14 14:37:59 +05:30
import 'package:geojson/geojson.dart';
2022-06-04 20:16:29 +05:30
import 'package:geolocator/geolocator.dart';
2022-05-24 20:43:41 +05:30
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:google_maps_flutter/google_maps_flutter.dart';
import 'package:rogapp/pages/index/index_controller.dart';
import 'package:rogapp/services/destination_service.dart';
2022-06-27 12:15:54 +05:30
import 'package:rogapp/widgets/bottom_sheet_new.dart';
2022-06-14 14:37:59 +05:30
import 'package:rogapp/widgets/bottom_sheet_widget.dart';
2022-07-09 22:51:34 +05:30
import 'package:rogapp/widgets/bread_crum_widget.dart';
2022-05-24 20:43:41 +05:30
class DestinationMapPage extends StatefulWidget {
DestinationMapPage({ Key? key }) : super(key: key);
2022-06-14 14:37:59 +05:30
2022-05-24 20:43:41 +05:30
@override
State<DestinationMapPage> createState() => _DestinationMapPageState();
}
class _DestinationMapPageState extends State<DestinationMapPage> {
final IndexController indexController = Get.find<IndexController>();
final DestinationController destinationController = Get.find<DestinationController>();
2022-06-04 20:16:29 +05:30
StreamSubscription? subscription;
2022-06-14 14:37:59 +05:30
final PopupController _popupLayerController = PopupController();
2022-05-24 20:43:41 +05:30
List<LatLng>? getPoints(){
//print("##### --- route point ${indexController.routePoints.length}");
List<LatLng> pts = [];
for(PointLatLng p in indexController.routePoints){
LatLng l = LatLng(p.latitude, p.longitude);
pts.add(l);
}
return pts;
}
2022-09-01 19:14:18 +05:30
String getDisplaytext(Destination dp){
String txt = "";
if(dp.cp! > 0){
txt = "${dp.cp}";
if(dp.checkin_point != null && dp.checkin_point! > 0){
txt = txt + "{${dp.checkin_point}}";
}
if(dp.buy_point != null && dp.buy_point! > 0){
txt = txt + "[${dp.buy_point}]";
}
}
return txt;
}
2022-06-14 14:37:59 +05:30
List<Marker>? getMarkers() {
2022-05-24 20:43:41 +05:30
List<Marker> pts = [];
2022-07-28 19:01:45 +05:30
int index = -1;
for (int i = 0; i < destinationController.destinations.length; i++) {
Destination d = destinationController.destinations[i];
//for(Destination d in destinationController.destinations){
2022-06-14 14:37:59 +05:30
//print("-----lat ${lat}, ----- lon ${lan}");
2022-07-27 19:43:12 +05:30
Marker m = Marker(
point: LatLng(d.lat!, d.lon!),
anchorPos: AnchorPos.align(AnchorAlign.center),
builder:(cts){
2022-07-28 19:01:45 +05:30
return InkWell(
onTap: (){
print("-- Destination is --- ${d.name} ------");
if(d != null){
if(indexController.currentDestinationFeature.length > 0) {
indexController.currentDestinationFeature.clear();
}
indexController.currentDestinationFeature.add(d);
//indexController.getAction();
showModalBottomSheet(context: context, isScrollControlled: true,
//builder:((context) => BottomSheetWidget())
builder:((context) => BottomSheetNew())
);
}
},
2022-09-01 19:14:18 +05:30
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Container(
width:20,
height:20,
decoration: BoxDecoration(
color: Colors.red,
shape: BoxShape.circle,
border: new Border.all(
color: Colors.white,
width: d.checkin_radious != null ? d.checkin_radious! : 1,
),
),
child: new Center(
child: new Text(
(i + 1).toString(),
style: TextStyle(color: Colors.white),
),
),
2022-07-28 19:01:45 +05:30
),
2022-09-01 19:14:18 +05:30
Container( color: Colors.yellow, child: Text(getDisplaytext(d), style: TextStyle(fontSize: 15.0, fontWeight: FontWeight.bold, overflow: TextOverflow.visible),)),
],
2022-07-28 19:01:45 +05:30
),
);
2022-07-27 19:43:12 +05:30
2022-06-14 14:37:59 +05:30
//return Icon(Icons.pin_drop);
2022-07-27 19:43:12 +05:30
// return IconButton(
// onPressed: ()async {
// Destination? fs = await destinationController.getDEstinationForLatLong(d.lat!, d.lon!);
// print("-- Destination is --- ${fs!.name} ------");
// if(fs != null){
// if(indexController.currentDestinationFeature.length > 0) {
// indexController.currentDestinationFeature.clear();
// }
// indexController.currentDestinationFeature.add(fs);
// //indexController.getAction();
2022-06-14 14:37:59 +05:30
2022-07-27 19:43:12 +05:30
// showModalBottomSheet(context: context, isScrollControlled: true,
// //builder:((context) => BottomSheetWidget())
// builder:((context) => BottomSheetNew())
// );
// }
// },
// icon: Container(
// width: 60,
// height: 60,
// decoration: BoxDecoration(
// borderRadius: BorderRadius.circular(d.checkin_radious ?? 0),
// color: Colors.transparent,
// border: BoxBorder()
// ),
// child: Icon(Icons.pin_drop)
// )
// );
2022-06-14 14:37:59 +05:30
2022-05-24 20:43:41 +05:30
});
2022-06-14 14:37:59 +05:30
2022-05-24 20:43:41 +05:30
pts.add(m);
}
return pts;
}
@override
void initState() {
2022-07-09 22:51:34 +05:30
2022-05-24 20:43:41 +05:30
DestinationService.getDestinationLine(destinationController.destinations)?.then((value){
2022-07-09 22:51:34 +05:30
//print("---- loading destination points ------ ${value}");
2022-05-24 20:43:41 +05:30
indexController.routePoints.clear();
2022-07-26 19:18:15 +05:30
setState(() {
indexController.routePoints = value;
});
2022-05-24 20:43:41 +05:30
});
super.initState();
}
@override
Widget build(BuildContext context) {
return Obx((() =>
2022-07-09 22:51:34 +05:30
Stack(
children: [
indexController.is_rog_mapcontroller_loaded.value == false ?
Center(child: CircularProgressIndicator())
:
BreadCrumbWidget(mapController:indexController.rogMapController),
Padding(
padding: const EdgeInsets.only(top:50.0),
//child: TravelMap(),
child:
TravelMap(),
2022-07-20 15:57:40 +05:30
),
2022-07-21 20:42:33 +05:30
// Positioned(
// bottom: 200,
// left: 10,
// child: Container(
// color: Colors.white,
// child: Row(
// children: [
// Text(destinationController.gps[0]),
// Text(destinationController.locationPermission[0])
// ],
// ),
// )
// ),
2022-07-09 22:51:34 +05:30
],
)
));
}
FlutterMap TravelMap() {
return FlutterMap(
options: MapOptions(
onMapCreated: (c){
indexController.rogMapController = c;
indexController.rogMapController!.onReady.then((_) {
indexController.is_rog_mapcontroller_loaded.value = true;
subscription = indexController.rogMapController!.mapEventStream.listen((MapEvent mapEvent) {
if (mapEvent is MapEventMoveStart) {
//print(DateTime.now().toString() + ' [MapEventMoveStart] START');
// do something
}
if (mapEvent is MapEventMoveEnd) {
2022-07-14 23:10:24 +05:30
destinationController.isSelected.clear();
destinationController.isSelected.add(false);
2022-07-09 22:51:34 +05:30
//print(DateTime.now().toString() + ' [MapEventMoveStart] END');
//indexController.loadLocationsBound();
}
2022-06-04 20:16:29 +05:30
});
2022-07-09 22:51:34 +05:30
});
} ,
bounds: indexController.currentBound.length > 0 ? indexController.currentBound[0]: LatLngBounds.fromPoints([LatLng(35.03999881162295, 136.40587119778962), LatLng(36.642756778706904, 137.95226720406063)]),
zoom: 1,
2022-07-25 19:56:32 +05:30
maxZoom: 42,
2022-07-09 22:51:34 +05:30
interactiveFlags: InteractiveFlag.pinchZoom | InteractiveFlag.drag,
2022-07-15 21:50:14 +05:30
//plugins: [LocationMarkerPlugin(),]
2022-07-09 22:51:34 +05:30
),
children: [
TileLayerWidget(
options: TileLayerOptions(
2022-09-01 19:14:18 +05:30
urlTemplate: 'https://cyberjapandata.gsi.go.jp/xyz/std/{z}/{x}/{y}.png',
2022-07-09 22:51:34 +05:30
subdomains: ['a', 'b', 'c'],
2022-05-24 20:43:41 +05:30
),
2022-07-09 22:51:34 +05:30
),
2022-07-26 19:18:15 +05:30
//Obx(() =>
2022-07-25 19:56:32 +05:30
indexController.routePoints.length > 0 ?
PolylineLayerWidget(
options: PolylineLayerOptions(
polylines: [
Polyline(
points: getPoints()!,
2022-09-01 19:14:18 +05:30
strokeWidth: 6.0,
color: Colors.indigo),
2022-07-25 19:56:32 +05:30
],
),
)
:
Container(),
2022-07-26 19:18:15 +05:30
//),
2022-07-09 22:51:34 +05:30
// PopupMarkerLayerWidget(
// options: PopupMarkerLayerOptions(
// popupController: _popupLayerController,
// markers: _markers,
// markerRotateAlignment:
// PopupMarkerLayerOptions.rotationAlignmentFor(AnchorAlign.top),
// popupBuilder: (BuildContext context, Marker marker) =>
// examplePopup(marker),
// ),
// ),
2022-07-21 20:42:33 +05:30
LocationMarkerLayerWidget(),
2022-07-09 22:51:34 +05:30
MarkerLayerWidget(
options: MarkerLayerOptions(
markers: getMarkers()!
2022-06-14 14:37:59 +05:30
),
2022-07-15 21:50:14 +05:30
),
2022-07-09 22:51:34 +05:30
],
);
2022-05-24 20:43:41 +05:30
}
}