mirror of
https://github.com/azaion/satellite-provider.git
synced 2026-04-22 09:16:39 +00:00
fix warnings
This commit is contained in:
@@ -192,24 +192,28 @@ public class RouteService : IRouteService
|
||||
throw new ArgumentException("Geofence northWest latitude must be greater than southEast latitude");
|
||||
}
|
||||
|
||||
var center = GeoUtils.CalculateCenter(polygon.NorthWest, polygon.SouthEast);
|
||||
var diagonalDistance = GeoUtils.CalculatePolygonDiagonalDistance(polygon.NorthWest, polygon.SouthEast);
|
||||
var geofenceRegionSize = Math.Max(diagonalDistance * 0.6, request.RegionSizeMeters);
|
||||
|
||||
var geofenceRegionId = Guid.NewGuid();
|
||||
var geofenceRegions = CreateGeofenceRegionGrid(polygon.NorthWest, polygon.SouthEast, request.RegionSizeMeters);
|
||||
|
||||
_logger.LogInformation("Route {RouteId}: Requesting geofence region {RegionId} at center ({Lat}, {Lon}) with size {Size}m",
|
||||
request.Id, geofenceRegionId, center.Lat, center.Lon, geofenceRegionSize);
|
||||
_logger.LogInformation("Route {RouteId}: Created grid of {Count} regions to cover geofence area",
|
||||
request.Id, geofenceRegions.Count);
|
||||
|
||||
await _regionService.RequestRegionAsync(
|
||||
geofenceRegionId,
|
||||
center.Lat,
|
||||
center.Lon,
|
||||
geofenceRegionSize,
|
||||
request.ZoomLevel,
|
||||
stitchTiles: false);
|
||||
|
||||
await _routeRepository.LinkRouteToRegionAsync(request.Id, geofenceRegionId, isGeofence: true);
|
||||
foreach (var geofencePoint in geofenceRegions)
|
||||
{
|
||||
var geofenceRegionId = Guid.NewGuid();
|
||||
|
||||
_logger.LogInformation("Route {RouteId}: Requesting geofence region {RegionId} at ({Lat}, {Lon}) with size {Size}m",
|
||||
request.Id, geofenceRegionId, geofencePoint.Lat, geofencePoint.Lon, request.RegionSizeMeters);
|
||||
|
||||
await _regionService.RequestRegionAsync(
|
||||
geofenceRegionId,
|
||||
geofencePoint.Lat,
|
||||
geofencePoint.Lon,
|
||||
request.RegionSizeMeters,
|
||||
request.ZoomLevel,
|
||||
stitchTiles: false);
|
||||
|
||||
await _routeRepository.LinkRouteToRegionAsync(request.Id, geofenceRegionId, isGeofence: true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -278,5 +282,36 @@ public class RouteService : IRouteService
|
||||
UpdatedAt = route.UpdatedAt
|
||||
};
|
||||
}
|
||||
|
||||
private List<GeoPoint> CreateGeofenceRegionGrid(GeoPoint northWest, GeoPoint southEast, double regionSizeMeters)
|
||||
{
|
||||
var regions = new List<GeoPoint>();
|
||||
|
||||
var northPoint = new GeoPoint(northWest.Lat, (northWest.Lon + southEast.Lon) / 2);
|
||||
var southPoint = new GeoPoint(southEast.Lat, (northWest.Lon + southEast.Lon) / 2);
|
||||
var heightMeters = GeoUtils.CalculateDistance(northPoint, southPoint);
|
||||
|
||||
var westPoint = new GeoPoint((northWest.Lat + southEast.Lat) / 2, northWest.Lon);
|
||||
var eastPoint = new GeoPoint((northWest.Lat + southEast.Lat) / 2, southEast.Lon);
|
||||
var widthMeters = GeoUtils.CalculateDistance(westPoint, eastPoint);
|
||||
|
||||
var numLatSteps = Math.Max(1, (int)Math.Ceiling(heightMeters / regionSizeMeters));
|
||||
var numLonSteps = Math.Max(1, (int)Math.Ceiling(widthMeters / regionSizeMeters));
|
||||
|
||||
var latStep = (northWest.Lat - southEast.Lat) / numLatSteps;
|
||||
var lonStep = (southEast.Lon - northWest.Lon) / numLonSteps;
|
||||
|
||||
for (int latIdx = 0; latIdx < numLatSteps; latIdx++)
|
||||
{
|
||||
for (int lonIdx = 0; lonIdx < numLonSteps; lonIdx++)
|
||||
{
|
||||
var lat = northWest.Lat - (latIdx + 0.5) * latStep;
|
||||
var lon = northWest.Lon + (lonIdx + 0.5) * lonStep;
|
||||
regions.Add(new GeoPoint(lat, lon));
|
||||
}
|
||||
}
|
||||
|
||||
return regions;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user