fix: stabilize passenger mapping interactions and finalize localization
This commit is contained in:
@@ -6,14 +6,14 @@ import 'package:Intaleq/controller/functions/crud.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:maplibre_gl/maplibre_gl.dart';
|
||||
import 'package:intaleq_maps/intaleq_maps.dart';
|
||||
|
||||
class TripMonitorController extends GetxController {
|
||||
bool isLoading = false;
|
||||
Map tripData = {};
|
||||
late String rideId;
|
||||
late String driverId;
|
||||
MapLibreMapController? mapController;
|
||||
IntaleqMapController? mapController;
|
||||
List myListString = [];
|
||||
late Timer timer;
|
||||
late LatLng parentLocation;
|
||||
@@ -23,6 +23,8 @@ class TripMonitorController extends GetxController {
|
||||
double rotation = 0;
|
||||
double speed = 0;
|
||||
bool isStyleLoaded = false;
|
||||
|
||||
Set<Marker> markers = {};
|
||||
|
||||
getLocationParent() async {
|
||||
var res = await CRUD().get(
|
||||
@@ -34,76 +36,56 @@ class TripMonitorController extends GetxController {
|
||||
double.parse(tripData['message'][0]['longitude'].toString()));
|
||||
rotation = double.parse(tripData['message'][0]['heading'].toString());
|
||||
speed = double.parse(tripData['message'][0]['speed'].toString());
|
||||
|
||||
_updateMarker();
|
||||
update();
|
||||
}
|
||||
}
|
||||
|
||||
void onMapCreated(MapLibreMapController controller) async {
|
||||
void onMapCreated(IntaleqMapController controller) async {
|
||||
mapController = controller;
|
||||
update();
|
||||
}
|
||||
|
||||
void onStyleLoaded() async {
|
||||
isStyleLoaded = true;
|
||||
await _loadMapIcons();
|
||||
mapController?.animateCamera(
|
||||
CameraUpdate.newLatLng(parentLocation),
|
||||
);
|
||||
refreshMapElements();
|
||||
_updateMarker();
|
||||
|
||||
// Set up a timer or interval to trigger the marker update every 10 seconds.
|
||||
timer = Timer.periodic(const Duration(seconds: 10), (_) async {
|
||||
await getLocationParent();
|
||||
mapController?.animateCamera(CameraUpdate.newLatLng(parentLocation));
|
||||
refreshMapElements();
|
||||
update();
|
||||
});
|
||||
}
|
||||
|
||||
Future<void> _loadMapIcons() async {
|
||||
if (mapController == null) return;
|
||||
final icons = {
|
||||
'car': 'assets/images/car.png',
|
||||
'moto': 'assets/images/moto1.png',
|
||||
'lady': 'assets/images/lady1.png',
|
||||
};
|
||||
for (var entry in icons.entries) {
|
||||
final bytes = await rootBundle.load(entry.value);
|
||||
await mapController!.addImage(entry.key, bytes.buffer.asUint8List());
|
||||
}
|
||||
}
|
||||
|
||||
void refreshMapElements() async {
|
||||
if (!isStyleLoaded || mapController == null) return;
|
||||
await mapController!.clearSymbols();
|
||||
|
||||
String iconToUse = carIcon;
|
||||
void _updateMarker() {
|
||||
String iconPath = 'assets/images/car.png';
|
||||
if (tripData['message'] != null && tripData['message'].isNotEmpty) {
|
||||
final model = tripData['message'][0]['model'].toString();
|
||||
final gender = tripData['message'][0]['gender'].toString();
|
||||
if (model.contains('دراجة')) {
|
||||
iconToUse = motoIcon;
|
||||
iconPath = 'assets/images/moto1.png';
|
||||
} else if (gender == 'Female') {
|
||||
iconToUse = ladyIcon;
|
||||
iconPath = 'assets/images/lady1.png';
|
||||
}
|
||||
}
|
||||
|
||||
await mapController!.addSymbol(SymbolOptions(
|
||||
geometry: parentLocation,
|
||||
iconImage: iconToUse,
|
||||
iconRotate: rotation,
|
||||
textField: 'driver',
|
||||
textOpacity: 0,
|
||||
));
|
||||
markers = {
|
||||
Marker(
|
||||
markerId: const MarkerId('driver'),
|
||||
position: parentLocation,
|
||||
icon: InlqBitmap.fromAsset(iconPath),
|
||||
rotation: rotation,
|
||||
anchor: const Offset(0.5, 0.5),
|
||||
),
|
||||
};
|
||||
update();
|
||||
}
|
||||
|
||||
// init() async {
|
||||
// final arguments = Get.arguments;
|
||||
// driverId = arguments['driverId'];
|
||||
// rideId = arguments['rideId'];
|
||||
// await getLocationParent();
|
||||
// }
|
||||
|
||||
Future<void> init({String? rideId, String? driverId}) async {
|
||||
this.driverId = driverId!;
|
||||
this.rideId = rideId!;
|
||||
@@ -120,7 +102,6 @@ class TripMonitorController extends GetxController {
|
||||
void onClose() {
|
||||
timer.cancel();
|
||||
mapController = null;
|
||||
|
||||
super.onClose();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user