Sistema_Gestion_Transporte/project/api/views/mapa.py

63 lines
1.9 KiB
Python
Raw Normal View History

2023-07-21 19:26:10 -04:00
from django.http import JsonResponse
from rest_framework.decorators import action, api_view, schema
from django.views.decorators.csrf import csrf_exempt
from ..models import Paradero, ParaderoImagen
from ..models import Linea, GtfsShape, GtfsTrips
from .paradero import url_image_paradero
from logging import error
2023-07-21 19:26:10 -04:00
google_api_key = 'AIzaSyDnFO9w_SsodjBuY5tOK8-kQJns_l5klQ4'
center = {'lat': -36.8077884, 'lng': -73.0775401}
2023-07-21 19:26:10 -04:00
@csrf_exempt
@action(detail=False, methods=['get'])
@api_view(['GET'])
def paraderos(request):
zoom = 17
2023-07-21 19:26:10 -04:00
marks = []
paraderos = Paradero.objects.all()
for p in paraderos:
url_image = url_image_paradero(request, p.id_paradero)
marks.append({
'position': { 'lat': p.stop_lat, 'lng': p.stop_lon },
'id_paradero': p.id_paradero,
'title': 'Paradero #' + str(p.id_paradero),
'location': p.stop_name,
'id_comuna': p.id_comuna,
'id_tipo_paradero': p.id_tipo_paradero,
'url_image': url_image
})
2023-07-21 19:26:10 -04:00
return JsonResponse({
'google_api_key': google_api_key,
2023-07-21 19:26:10 -04:00
'zoom': zoom,
'center': center,
'marks': marks
})
@csrf_exempt
@action(detail=False, methods=['get'])
@api_view(['GET'])
def rutas(request):
id_linea = request.GET.get('id_linea')
sectores = GtfsTrips.objects.filter(id_linea = id_linea).all()
data = []
for s in sectores:
rutas = GtfsShape.objects.filter(id_shape = s.id_shape).order_by('shape_pt_sequence')
for r in rutas:
data.append({
'shape_pt_lat': r.shape_pt_lat,
'shape_pt_lon': r.shape_pt_lon,
'shape_pt_sequence': r.shape_pt_sequence
})
data_ordenada = sorted(data, key=lambda k: k['shape_pt_sequence'])
2023-08-16 18:28:32 -04:00
return JsonResponse({
'google_api_key': google_api_key,
'positions': data_ordenada
2023-08-16 18:28:32 -04:00
})