diff --git a/src/fellchensammlung/templates/fellchensammlung/partials/partial-map.html b/src/fellchensammlung/templates/fellchensammlung/partials/partial-map.html index 5c5ae0d..1b3eb3a 100644 --- a/src/fellchensammlung/templates/fellchensammlung/partials/partial-map.html +++ b/src/fellchensammlung/templates/fellchensammlung/partials/partial-map.html @@ -6,35 +6,81 @@ + + +
diff --git a/src/fellchensammlung/tools/geo.py b/src/fellchensammlung/tools/geo.py index 210745a..8fcb198 100644 --- a/src/fellchensammlung/tools/geo.py +++ b/src/fellchensammlung/tools/geo.py @@ -1,4 +1,6 @@ import logging +from collections import namedtuple + import requests import json from math import radians, sqrt, sin, cos, atan2 @@ -6,6 +8,8 @@ from math import radians, sqrt, sin, cos, atan2 from notfellchen import __version__ as nf_version from notfellchen import settings +Position = namedtuple('Position', ['latitude', 'longitude']) + def calculate_distance_between_coordinates(position1, position2): """ diff --git a/src/fellchensammlung/tools/search.py b/src/fellchensammlung/tools/search.py index 70b0006..a74a40a 100644 --- a/src/fellchensammlung/tools/search.py +++ b/src/fellchensammlung/tools/search.py @@ -1,7 +1,7 @@ import logging from django.utils.translation import gettext_lazy as _ -from .geo import GeoAPI, LocationProxy +from .geo import LocationProxy, Position from ..forms import AdoptionNoticeSearchForm from ..models import SearchSubscription, AdoptionNotice, AdoptionNoticeNotification, SexChoicesWithAll, Location @@ -69,6 +69,13 @@ class Search: except ValueError: self.place_not_found = True + @property + def position(self): + if self.area_search and not self.place_not_found: + return Position(latitude=self.location.latitude, longitude=self.location.longitude) + else: + return None + def adoption_notice_fits_search(self, adoption_notice: AdoptionNotice): # Make sure sex is set and sex is not set to all (then it can be disregarded) if self.sex is not None and self.sex != SexChoicesWithAll.ALL: diff --git a/src/fellchensammlung/views.py b/src/fellchensammlung/views.py index 6ec0f65..4af0769 100644 --- a/src/fellchensammlung/views.py +++ b/src/fellchensammlung/views.py @@ -195,12 +195,15 @@ def search(request): subscribed_search = search.get_subscription_or_none(request.user) else: subscribed_search = None + context = {"adoption_notices": search.get_adoption_notices(), "search_form": search.search_form, "place_not_found": search.place_not_found, "subscribed_search": subscribed_search, "searched": searched, - "adoption_notices_map": AdoptionNotice.get_active_ANs()} + "adoption_notices_map": AdoptionNotice.get_active_ANs(), + "map_center": search.position, + "search_radius": search.max_distance,} return render(request, 'fellchensammlung/search.html', context=context)