Browse Source

Introduce LOCATE_POINT_MAX_DISTANCE setting

Baptiste Jonglez 6 years ago
parent
commit
f11f7817b4
3 changed files with 11 additions and 3 deletions
  1. 2 1
      INSTALL.md
  2. 8 1
      celutz/settings.py
  3. 1 1
      panorama/views.py

+ 2 - 1
INSTALL.md

@@ -48,7 +48,8 @@ There are also celutz-specific settings:
 
 - `LOGIN_REQUIRED`: is celutz public or are users required to login first?
 - `PANORAMA_TILES_DIR`: where the tiles are, relatively to `MEDIA_ROOT` and `MEDIA_URL`
-- `PANORAMA_MAX_DISTANCE`: maximum distance (in meters) after which reference points are considered to be too far away
+- `PANORAMA_MAX_DISTANCE`: maximum distance (in meters) for reference points to be displayed when viewing a panorama
+- `LOCATE_POINT_MAX_DISTANCE`:  when locating a reference point, only consider panoramas that are closer than this maximum distance, in meters.
 - `MAP_BOUNDS`: if defined, limit the view of the main map to the given rectangle.  By default, the view is fitted to display all points.  See `celutz/settings.py` for an example.
 
 Then run the migrations:

+ 8 - 1
celutz/settings.py

@@ -133,10 +133,15 @@ MEDIA_URL = '/media/'
 # Relative to MEDIA_ROOT and MEDIA_URL
 PANORAMA_TILES_DIR = "tiles"
 
-# Max distance around a point at which to consider reference points
+# Maximum distance for reference points to be displayed when viewing a panorama
 # (in meters)
 PANORAMA_MAX_DISTANCE = 50000
 
+# When locating a reference point, only consider panoramas that are closer than
+# this maximum distance, in meters.
+# Cannot be greater than PANORAMA_MAX_DISTANCE.
+LOCATE_POINT_MAX_DISTANCE = 50000
+
 # Map bounds (in degrees) for the main view.
 # If not defined, all points are used to fit the view.
 #MAP_BOUNDS = {
@@ -157,3 +162,5 @@ try:
 except ImportError:
     pass
 
+# Ensure that LOCATE_POINT_MAX_DISTANCE <= PANORAMA_MAX_DISTANCE
+LOCATE_POINT_MAX_DISTANCE = min(LOCATE_POINT_MAX_DISTANCE, PANORAMA_MAX_DISTANCE)

+ 1 - 1
panorama/views.py

@@ -87,7 +87,7 @@ class MainView(CelutzLoginMixin, TemplateView):
         else:
             queryset = Panorama.objects
         l = [(pano, pano.line_distance(point), pano.bearing(point), pano.elevation(point))
-             for pano in queryset.all() if pano.is_visible(point)]
+             for pano in queryset.all() if pano.is_visible(point) and pano.great_circle_distance(point) <= settings.LOCATE_POINT_MAX_DISTANCE]
         # Sort by increasing distance
         return sorted(l, key=lambda x: x[1])