Добавил геофильтры. Теперь нужен рефакторинг.

This commit is contained in:
2025-11-17 17:44:24 +03:00
parent b889fb29a3
commit c0f2f16303
7 changed files with 385 additions and 2 deletions

View File

@@ -472,6 +472,52 @@ class TransponderDataAPIView(LoginRequiredMixin, View):
return JsonResponse({'error': str(e)}, status=500)
class GeoPointsAPIView(LoginRequiredMixin, View):
"""API endpoint for getting all geo points for polygon filter visualization."""
def get(self, request):
from ..models import Geo
try:
# Limit to reasonable number of points to avoid performance issues
limit = int(request.GET.get('limit', 10000))
limit = min(limit, 50000) # Max 50k points
# Get all Geo objects with coordinates
geo_objs = Geo.objects.filter(
coords__isnull=False
).select_related(
'objitem',
'objitem__source'
)[:limit]
points = []
for geo_obj in geo_objs:
if not geo_obj.coords:
continue
# Get source_id if available
source_id = None
if hasattr(geo_obj, 'objitem') and geo_obj.objitem:
if hasattr(geo_obj.objitem, 'source') and geo_obj.objitem.source:
source_id = geo_obj.objitem.source.id
points.append({
'id': geo_obj.id,
'lat': geo_obj.coords.y,
'lng': geo_obj.coords.x,
'source_id': source_id or '-'
})
return JsonResponse({
'points': points,
'total': len(points),
'limited': len(points) >= limit
})
except Exception as e:
return JsonResponse({'error': str(e)}, status=500)
class SatelliteDataAPIView(LoginRequiredMixin, View):
"""API endpoint for getting Satellite data."""