feat : Cluster Map

This commit is contained in:
2025-07-29 10:50:18 +03:30
parent 8acd951c05
commit 716dd6e70a
7 changed files with 225 additions and 75 deletions

View File

@@ -1,4 +1,5 @@
import 'dart:async';
import 'dart:math';
import 'package:flutter/material.dart';
import 'package:rasadyar_core/core.dart';
@@ -11,12 +12,12 @@ import '../filter/view.dart';
class InspectionMapLogic extends GetxController with GetTickerProviderStateMixin {
final BaseLogic baseLogic = Get.find<BaseLogic>();
final distance = Distance();
Rx<LatLng> currentLocation = LatLng(34.798315281272544, 48.51479142983491).obs;
Rx<Resource<List<PoultryLocationModel>>> allPoultryLocation =
Resource<List<PoultryLocationModel>>.loading().obs;
RxList<PoultryLocationModel> markers = <PoultryLocationModel>[].obs;
RxList<Marker> markers = <Marker>[].obs;
Timer? _debounceTimer;
RxBool isLoading = false.obs;
@@ -25,6 +26,7 @@ class InspectionMapLogic extends GetxController with GetTickerProviderStateMixin
RxInt filterIndex = 0.obs;
RxInt showIndex = 0.obs;
bool showSlideHint = true;
RxInt currentZoom = 15.obs;
late Rx<SlidableController> slidController;
@@ -114,17 +116,28 @@ class InspectionMapLogic extends GetxController with GetTickerProviderStateMixin
isLoading.value = false;
}
void debouncedUpdateVisibleMarkers({required LatLng center}) {
void debouncedUpdateVisibleMarkers({required LatLng center, required double zoom}) {
_debounceTimer?.cancel();
_debounceTimer = Timer(const Duration(milliseconds: 300), () {
var raduis = getVisibleRadiusKm(
zoom: zoom,
screenWidthPx: Get.width.toDouble(),
latitude: center.latitude,
);
final filtered = filterNearbyMarkers(
allPoultryLocation.value.data ?? [],
center.latitude,
center.longitude,
10000, // Radius in meters
raduis * 1000, // Radius in meters
);
markers.assignAll(
filtered.map(
(e) => Marker(
point: LatLng(e.lat ?? 0, e.long ?? 0),
child: Icon(Icons.location_on, color: Colors.red),
),
),
);
markers.addAll(filtered);
});
}
@@ -135,11 +148,10 @@ class InspectionMapLogic extends GetxController with GetTickerProviderStateMixin
double radiusInMeters,
) {
final center = LatLng(centerLat, centerLng);
final distance = Distance();
return allMarkers.where((marker) {
var tmp =LatLng(marker.lat ?? 0, marker.long ?? 0);
return distance(center,tmp ) <= radiusInMeters;
var tmp = LatLng(marker.lat ?? 0, marker.long ?? 0);
return distance(center, tmp) <= radiusInMeters;
}).toList();
}
@@ -155,7 +167,11 @@ class InspectionMapLogic extends GetxController with GetTickerProviderStateMixin
isLoading.value = true;
allPoultryLocation.value = Resource<List<PoultryLocationModel>>.loading();
await safeCall(
call: () => inspectionRepository.getNearbyLocation(),
call: () => inspectionRepository.getNearbyLocation(
centerLat: currentLocation.value.latitude,
centerLng: currentLocation.value.longitude,
radius: 15, // Radius in K meters
),
onSuccess: (result) {
if (result != null) {
allPoultryLocation.value = Resource<List<PoultryLocationModel>>.success(result);
@@ -170,4 +186,14 @@ class InspectionMapLogic extends GetxController with GetTickerProviderStateMixin
},
);
}
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) / 1000; // radius in KM
}
}