1 - search location and conditions
2 - parse list in isolate
This commit is contained in:
2025-08-02 11:10:22 +03:30
parent aaa69a94e9
commit 6040ca9f86
10 changed files with 695 additions and 375 deletions

View File

@@ -57,8 +57,9 @@ class InspectionMapLogic extends GetxController {
allPoultryLocation.value = Resource<List<PoultryLocationModel>>.loading();
await safeCall(
call: () => inspectionRepository.getNearbyLocation(),
onSuccess: (result) {
onSuccess: (result) async{
if (result != null) {
allPoultryLocation.value = Resource<List<PoultryLocationModel>>.success(result);
mapLogic.allLocations.value = Resource<List<PoultryLocationModel>>.success(result);
} else {

View File

@@ -20,7 +20,6 @@ class InspectionMapPage extends GetView<InspectionMapLogic> {
filteringWidget: filterWidget(showIndex: 3.obs, filterIndex: 5.obs),
widgets: [
MapPage(),
ObxValue((p0) => Text(p0.toString()), controller.showIndex),
ObxValue((data) {
if (data.value) {
WidgetsBinding.instance.addPostFrameCallback((_) {
@@ -66,7 +65,7 @@ class InspectionMapPage extends GetView<InspectionMapLogic> {
controller.baseLogic.searchTextController.clear();
controller.baseLogic.searchValue.value = null;
controller.baseLogic.isSearchSelected.value = false;
controller. mapLogic.hasFilterOrSearch.value = false;
controller.mapLogic.hasFilterOrSearch.value = false;
controller.searchedPoultryLocation.value = Resource.initial();
},
enableFeedback: true,
@@ -92,7 +91,6 @@ class InspectionMapPage extends GetView<InspectionMapLogic> {
),
GestureDetector(
onTap: () {
Get.back();
},
child: Assets.vec.mapSvg.svg(

View File

@@ -74,6 +74,8 @@ class MapLogic extends GetxController with GetTickerProviderStateMixin {
super.onClose();
}
double _deg2rad(double deg) => deg * (pi / 180);
Future<void> determineCurrentPosition() async {
isLoading.value = true;
final position = await Geolocator.getCurrentPosition(
@@ -95,7 +97,8 @@ class MapLogic extends GetxController with GetTickerProviderStateMixin {
isLoading.value = false;
}
/* void debouncedUpdateVisibleMarkers({required LatLng center, required double zoom}) {
/*
void debouncedUpdateVisibleMarkers({required LatLng center, required double zoom}) {
_debounceTimer?.cancel();
_debounceTimer = Timer(const Duration(milliseconds: 300), () {
final radius = getVisibleRadiusKm(
@@ -105,7 +108,7 @@ class MapLogic extends GetxController with GetTickerProviderStateMixin {
);
final filtered = filterNearbyMarkers(
allPoultryLocation.value.data ?? [],
all.value.data ?? [],
center.latitude,
center.longitude,
radius,
@@ -114,7 +117,8 @@ class MapLogic extends GetxController with GetTickerProviderStateMixin {
final uniqueFiltered = filtered.where((e) => !existingIds.contains(e.id)).toList();
markers2.addAll(uniqueFiltered);
});
}*/
}
*/
List<LatLng> filterNearbyMarkers(
List<LatLng> allMarkers,
@@ -127,13 +131,27 @@ class MapLogic extends GetxController with GetTickerProviderStateMixin {
return allMarkers.where((marker) => distance(center, marker) <= radiusInMeters).toList();
}
double getVisibleRadiusKm({
required double zoom,
required double screenWidthPx,
required double latitude,
}) {
double metersPerPixel = 156543.03392 * cos(latitude * pi / 180) / pow(2, zoom);
double visibleWidthInMeters = metersPerPixel * screenWidthPx;
return (visibleWidthInMeters / 2); // radius in Meter
double getVisibleRadiusKm({required LatLng center, required LatLng corner}) {
const earthRadius = 6371; // Km
final dLat = _deg2rad(corner.latitude - center.latitude);
final dLng = _deg2rad(corner.longitude - center.longitude);
final a =
sin(dLat / 2) * sin(dLat / 2) +
cos(_deg2rad(center.latitude)) *
cos(_deg2rad(corner.latitude)) *
sin(dLng / 2) *
sin(dLng / 2);
final c = 2 * atan2(sqrt(a), sqrt(1 - a));
return earthRadius * c;
}
bool isInVisibleBounds(LatLng point, LatLngBounds bounds) {
return point.latitude <= bounds.north &&
point.latitude >= bounds.south &&
point.longitude >= bounds.west &&
point.longitude <= bounds.east;
}
}