From b10aa1ba3057df5de245e60c970d0f513bf18eda Mon Sep 17 00:00:00 2001 From: Sander Roosendaal Date: Thu, 14 Sep 2017 17:56:58 +0200 Subject: [PATCH] added a large map view --- rowers/interactiveplots.py | 11 ++++ rowers/templates/biginteractive1.html | 88 +++++++++++++-------------- rowers/templates/map_view.html | 64 +++++++++++++++++++ rowers/templates/workout_form.html | 7 ++- rowers/urls.py | 1 + rowers/views.py | 50 +++++++++++++++ 6 files changed, 175 insertions(+), 46 deletions(-) create mode 100644 rowers/templates/map_view.html diff --git a/rowers/interactiveplots.py b/rowers/interactiveplots.py index 71674fbb..bcf1aac4 100644 --- a/rowers/interactiveplots.py +++ b/rowers/interactiveplots.py @@ -686,6 +686,7 @@ def interactive_histoall(theworkouts): script, div = components(plot) return [script,div] + def leaflet_chart(lat,lon,name=""): if lat.empty or lon.empty: return [0,"invalid coordinate data"] @@ -737,6 +738,14 @@ def leaflet_chart(lat,lon,name=""): layers: [streets, satellite] }}).setView([{latmean},{lonmean}], 13); + var navionics = new JNC.Leaflet.NavionicsOverlay({{ + navKey: 'Navionics_webapi_03205', + chartType: JNC.NAVIONICS_CHARTS.NAUTICAL, + isTransparent: true, + zIndex: 1 + }}); + + var osmUrl2='http://tiles.openseamap.org/seamark/{{z}}/{{x}}/{{y}}.png'; var osmUrl='http://{{s}}.tile.openstreetmap.org/{{z}}/{{x}}/{{y}}.png'; @@ -751,6 +760,8 @@ def leaflet_chart(lat,lon,name=""): "Satellite": satellite, "Outdoors": outdoors, "Nautical": nautical, + }},{{ + "Navionics":navionics, }}).addTo(mymap); var marker = L.marker([{latbegin}, {longbegin}]).addTo(mymap); diff --git a/rowers/templates/biginteractive1.html b/rowers/templates/biginteractive1.html index 97061e31..1e3af861 100644 --- a/rowers/templates/biginteractive1.html +++ b/rowers/templates/biginteractive1.html @@ -6,57 +6,55 @@ {% block content %} - - + + -{{ interactiveplot |safe }} + {{ interactiveplot |safe }} - - + +
- - -

Interactive Plot

- - {% if user.is_authenticated and mayedit %} -
-

- Edit Workout -

-
-
-

- Advanced Edit -

- -
- {% endif %} - -
+ + +

Interactive Plot

+ + {% if user.is_authenticated and mayedit %} +
+

+ Edit Workout +

+
+
+

+ Advanced Edit +

+ +
+ {% endif %} + {{ the_div|safe }} -
- +
{% endblock %} diff --git a/rowers/templates/map_view.html b/rowers/templates/map_view.html new file mode 100644 index 00000000..1ac95005 --- /dev/null +++ b/rowers/templates/map_view.html @@ -0,0 +1,64 @@ +{% extends "base.html" %} +{% load staticfiles %} +{% load rowerfilters %} + +{% block title %}View Workout {% endblock %} + +{% block content %} + + + + + + + + + +
+ + +

Map View

+ + {% if user.is_authenticated and mayedit %} +
+

+ Edit Workout +

+
+
+

+ Advanced Edit +

+ +
+ {% endif %} +
+
+ {{ mapdiv|safe }} + + + {{ mapscript|safe }} +
+ + + +{% endblock %} diff --git a/rowers/templates/workout_form.html b/rowers/templates/workout_form.html index bf47f4c3..5fd5d695 100644 --- a/rowers/templates/workout_form.html +++ b/rowers/templates/workout_form.html @@ -37,7 +37,12 @@
-
+
+

+ Map View +

+
+

Statistics

diff --git a/rowers/urls.py b/rowers/urls.py index 0bc81cb6..e249ef0a 100644 --- a/rowers/urls.py +++ b/rowers/urls.py @@ -188,6 +188,7 @@ urlpatterns = [ url(r'^workout/compare/(?P\d+)/(?P\d+-\d+-\d+)/(?P\w+.*)$',views.workout_comparison_list), url(r'^workout/(?P\d+)/edit$',views.workout_edit_view), url(r'^workout/(?P\d+)/navionics$',views.workout_edit_view_navionics), + url(r'^workout/(?P\d+)/map$',views.workout_map_view), url(r'^workout/(?P\d+)/setprivate$',views.workout_setprivate_view), url(r'^workout/(?P\d+)/updatecp$',views.workout_update_cp_view), url(r'^workout/(?P\d+)/makepublic$',views.workout_makepublic_view), diff --git a/rowers/views.py b/rowers/views.py index fe3635c0..3a659a1a 100644 --- a/rowers/views.py +++ b/rowers/views.py @@ -6405,6 +6405,56 @@ def workout_edit_view(request,id=0,message="",successmessage=""): return HttpResponseRedirect(url) +@login_required() +def workout_map_view(request,id=0): + request.session[translation.LANGUAGE_SESSION_KEY] = USER_LANGUAGE + request.session['referer'] = absolute(request)['PATH'] + + + try: + # check if valid ID exists (workout exists) + row = Workout.objects.get(id=id) + except Workout.DoesNotExist: + raise Http404("Workout doesn't exist") + + # create interactive plot + f1 = row.csvfilename + u = row.user.user + r = getrower(u) + rowdata = rdata(f1) + hascoordinates = 1 + if rowdata != 0: + try: + latitude = rowdata.df[' latitude'] + if not latitude.std(): + hascoordinates = 0 + except KeyError,AttributeError: + hascoordinates = 0 + + else: + hascoordinates = 0 + + + if hascoordinates: + mapscript,mapdiv = leaflet_chart2(rowdata.df[' latitude'], + rowdata.df[' longitude'], + row.name) + mayedit=0 + if not request.user.is_anonymous(): + r = getrower(request.user) + result = request.user.is_authenticated() and ispromember(request.user) + if result: + promember=1 + if request.user == row.user.user: + mayedit=1 + + return render(request, 'map_view.html', + {'mapscript':mapscript, + 'workout':row, + 'mapdiv':mapdiv, + 'mayedit':mayedit, + }) + # The basic edit page @login_required() def workout_edit_view_navionics(request,id=0,message="",successmessage=""):