diff --git a/src/fellchensammlung/templates/fellchensammlung/partials/partial-map.html b/src/fellchensammlung/templates/fellchensammlung/partials/partial-map.html index 1b3eb3a..2f4993d 100644 --- a/src/fellchensammlung/templates/fellchensammlung/partials/partial-map.html +++ b/src/fellchensammlung/templates/fellchensammlung/partials/partial-map.html @@ -24,7 +24,7 @@ container: 'map', style: '{% static "fellchensammlung/map/styles/colorful.json" %}', center: center, - zoom: 5 + zoom: {{ zoom_level }} }).addControl(new maplibregl.NavigationControl()); {% for adoption_notice in adoption_notices_map %} diff --git a/src/fellchensammlung/tools/geo.py b/src/fellchensammlung/tools/geo.py index 8fcb198..1b34b06 100644 --- a/src/fellchensammlung/tools/geo.py +++ b/src/fellchensammlung/tools/geo.py @@ -11,6 +11,18 @@ from notfellchen import settings Position = namedtuple('Position', ['latitude', 'longitude']) +def zoom_level_for_radius(radius) -> int: + if radius <= 20: + return 8 + if radius <= 50: + return 7 + if radius <= 150: + return 6 + if radius <= 300: + return 5 + else: + return 4 + def calculate_distance_between_coordinates(position1, position2): """ Calculate the distance between two points identified by coordinates diff --git a/src/fellchensammlung/views.py b/src/fellchensammlung/views.py index 4af0769..70448ac 100644 --- a/src/fellchensammlung/views.py +++ b/src/fellchensammlung/views.py @@ -21,7 +21,7 @@ from .forms import AdoptionNoticeForm, AdoptionNoticeFormWithDateWidget, ImageFo CommentForm, ReportCommentForm, AnimalForm, \ AdoptionNoticeSearchForm, AnimalFormWithDateWidget, AdoptionNoticeFormWithDateWidgetAutoAnimal from .models import Language, Announcement -from .tools.geo import GeoAPI +from .tools.geo import GeoAPI, zoom_level_for_radius from .tools.metrics import gather_metrics_data from .tools.admin import clean_locations, get_unchecked_adoption_notices, deactivate_unchecked_adoption_notices, \ deactivate_404_adoption_notices @@ -203,7 +203,8 @@ def search(request): "searched": searched, "adoption_notices_map": AdoptionNotice.get_active_ANs(), "map_center": search.position, - "search_radius": search.max_distance,} + "search_radius": search.max_distance, + "zoom_level": zoom_level_for_radius(search.max_distance)} return render(request, 'fellchensammlung/search.html', context=context)