feat: make zoom level dependent on search radius
This commit is contained in:
parent
8b4488484d
commit
3bdce18e9e
@ -24,7 +24,7 @@
|
|||||||
container: 'map',
|
container: 'map',
|
||||||
style: '{% static "fellchensammlung/map/styles/colorful.json" %}',
|
style: '{% static "fellchensammlung/map/styles/colorful.json" %}',
|
||||||
center: center,
|
center: center,
|
||||||
zoom: 5
|
zoom: {{ zoom_level }}
|
||||||
}).addControl(new maplibregl.NavigationControl());
|
}).addControl(new maplibregl.NavigationControl());
|
||||||
|
|
||||||
{% for adoption_notice in adoption_notices_map %}
|
{% for adoption_notice in adoption_notices_map %}
|
||||||
|
@ -11,6 +11,18 @@ from notfellchen import settings
|
|||||||
Position = namedtuple('Position', ['latitude', 'longitude'])
|
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):
|
def calculate_distance_between_coordinates(position1, position2):
|
||||||
"""
|
"""
|
||||||
Calculate the distance between two points identified by coordinates
|
Calculate the distance between two points identified by coordinates
|
||||||
|
@ -21,7 +21,7 @@ from .forms import AdoptionNoticeForm, AdoptionNoticeFormWithDateWidget, ImageFo
|
|||||||
CommentForm, ReportCommentForm, AnimalForm, \
|
CommentForm, ReportCommentForm, AnimalForm, \
|
||||||
AdoptionNoticeSearchForm, AnimalFormWithDateWidget, AdoptionNoticeFormWithDateWidgetAutoAnimal
|
AdoptionNoticeSearchForm, AnimalFormWithDateWidget, AdoptionNoticeFormWithDateWidgetAutoAnimal
|
||||||
from .models import Language, Announcement
|
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.metrics import gather_metrics_data
|
||||||
from .tools.admin import clean_locations, get_unchecked_adoption_notices, deactivate_unchecked_adoption_notices, \
|
from .tools.admin import clean_locations, get_unchecked_adoption_notices, deactivate_unchecked_adoption_notices, \
|
||||||
deactivate_404_adoption_notices
|
deactivate_404_adoption_notices
|
||||||
@ -203,7 +203,8 @@ def search(request):
|
|||||||
"searched": searched,
|
"searched": searched,
|
||||||
"adoption_notices_map": AdoptionNotice.get_active_ANs(),
|
"adoption_notices_map": AdoptionNotice.get_active_ANs(),
|
||||||
"map_center": search.position,
|
"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)
|
return render(request, 'fellchensammlung/search.html', context=context)
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user