From ae3edb59f437b6f4c3b10d655c288bc3108a6b2b Mon Sep 17 00:00:00 2001 From: Brian DeRocher Date: Fri, 4 Aug 2017 07:33:26 -0400 Subject: [PATCH 1/5] Initial push to get overpass in josm working. Still need to expand {{bbox}}, probably. --- osmtm/models.py | 1 + osmtm/static/js/project.js | 8 ++++++++ osmtm/templates/project.edit.mako | 21 +++++++++++++++++++++ osmtm/templates/task.mako | 12 ++++++++++++ osmtm/views/project.py | 2 +- 5 files changed, 43 insertions(+), 1 deletion(-) diff --git a/osmtm/models.py b/osmtm/models.py index 5cc7dc0a..775e65dc 100644 --- a/osmtm/models.py +++ b/osmtm/models.py @@ -529,6 +529,7 @@ class Project(Base, Translatable): zoom = Column(Integer) # is not None when project is auto-filled (grid) imagery = Column(Unicode) + overpass = Column(Unicode) # priorities are: # 0 - Urgent diff --git a/osmtm/static/js/project.js b/osmtm/static/js/project.js index 2468cd65..132ffda8 100644 --- a/osmtm/static/js/project.js +++ b/osmtm/static/js/project.js @@ -450,6 +450,14 @@ osmtm.project = (function() { } }); } + if (typeof overpass_url != "undefined" && overpass_url !== '') { + $.ajax({ + url: 'http://127.0.0.1:8111/import', + data: { + url: overpass_url + } + }); + } } } }); diff --git a/osmtm/templates/project.edit.mako b/osmtm/templates/project.edit.mako index 9ebe9cce..b8f48070 100644 --- a/osmtm/templates/project.edit.mako +++ b/osmtm/templates/project.edit.mako @@ -135,6 +135,7 @@ geometry = loads(str(project.area.geometry.data))
  • ${_('Instructions')}
  • ${_('Area')}
  • ${_('Imagery')}
  • +
  • ${_('Features')}
  • ${_('Priority Areas')}
  • ${_('Permissions')}
  • ${_('Labels')}
  • @@ -153,6 +154,9 @@ geometry = loads(str(project.area.geometry.data))
    ${imagery()}
    +
    + ${features()} +
    ${priority_areas_()}
    @@ -400,6 +404,23 @@ geometry = loads(str(project.area.geometry.data)) +<%block name="features"> +
    +
    +
    + + +

    + ${_('Note:')} ${_('Generate the query on overpass-turbo.eu and export as JOSM. Allow it to auto repair. Then copy the query here.')|n} +

    +
    +
    +
    + + <%block name="permissions">
    diff --git a/osmtm/templates/task.mako b/osmtm/templates/task.mako index 0534af36..2a177647 100644 --- a/osmtm/templates/task.mako +++ b/osmtm/templates/task.mako @@ -86,6 +86,18 @@ var gpx_url = window.location.origin + (project.license in user.accepted_licenses or not project.license): var imagery_url = "${project.imagery|n}"; % endif +<% +import urllib +overpass_url = '' +if project.overpass is not None: + overpass_data = urllib.quote(project.overpass.encode('utf8').replace('\n',''), '*()') + overpass_url = "http://overpass-api.de/api/interpreter?data=" + overpass_data +%> +% if overpass is not None: +var overpass_data = '${overpass_data|n}'; +var overpass_dataz = '${overpass_data}'; +var overpass_url = '${overpass_url|n}'; +% endif var changeset_comment = "${quote(project.changeset_comment.encode('utf8'), '')}"; osmtm.project.initAtWho(); diff --git a/osmtm/views/project.py b/osmtm/views/project.py index e328974f..12fa42e3 100644 --- a/osmtm/views/project.py +++ b/osmtm/views/project.py @@ -253,7 +253,7 @@ def project_edit(request): setattr(project, field, request.params[translated]) DBSession.add(project) - for p in ['changeset_comment', 'entities_to_map', 'imagery']: + for p in ['changeset_comment', 'entities_to_map', 'imagery', 'overpass']: if p in request.params: setattr(project, p, request.params[p]) From 975e64a238e3b9c5a36dffd42a99e42f3f5a96e6 Mon Sep 17 00:00:00 2001 From: Brian DeRocher Date: Fri, 4 Aug 2017 09:45:19 -0400 Subject: [PATCH 2/5] Add migration to add overpass column to project table. --- .../40d0f2b07d22_add_overpass_to_project.py | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 alembic/versions/40d0f2b07d22_add_overpass_to_project.py diff --git a/alembic/versions/40d0f2b07d22_add_overpass_to_project.py b/alembic/versions/40d0f2b07d22_add_overpass_to_project.py new file mode 100644 index 00000000..34b693ca --- /dev/null +++ b/alembic/versions/40d0f2b07d22_add_overpass_to_project.py @@ -0,0 +1,22 @@ +"""add overpass to project + +Revision ID: 40d0f2b07d22 +Revises: 1bdc819ae210 +Create Date: 2017-08-03 23:55:01.541405 + +""" + +# revision identifiers, used by Alembic. +revision = '40d0f2b07d22' +down_revision = '1bdc819ae210' + +from alembic import op +import sqlalchemy as sa + + +def upgrade(): + op.add_column('project', sa.Column('overpass', sa.Unicode(), nullable=True)) + + +def downgrade(): + op.drop_column('project', 'overpass') From 93f301b1acf525ea61c2be88c2734e7bf6bc4c9b Mon Sep 17 00:00:00 2001 From: Brian DeRocher Date: Fri, 4 Aug 2017 13:22:42 -0400 Subject: [PATCH 3/5] Call Remote Control the same way as Turbo does, with $.get() instead of $.ajax(). It gets the encoding right. Replace {{bbox}} with the bounding box of the current task. --- osmtm/static/js/project.js | 25 ++++++++++++++++++++----- osmtm/templates/project.edit.mako | 2 +- osmtm/templates/task.mako | 2 +- 3 files changed, 22 insertions(+), 7 deletions(-) diff --git a/osmtm/static/js/project.js b/osmtm/static/js/project.js index 132ffda8..a083870e 100644 --- a/osmtm/static/js/project.js +++ b/osmtm/static/js/project.js @@ -451,12 +451,18 @@ osmtm.project = (function() { }); } if (typeof overpass_url != "undefined" && overpass_url !== '') { - $.ajax({ - url: 'http://127.0.0.1:8111/import', - data: { + var re = new RegExp(encodeURIComponent('{{bbox}}'), 'g'); + var bbox = map2bbox(selectedTaskLayer); + overpass_url = overpass_url.replace(re, encodeURIComponent(bbox)); + $.get('http://127.0.0.1:8111/import', { url: overpass_url - } - }); + }) + .error(function(xhr, s, e) { + alert("Error: Unexpected JOSM remote control error."); + }) + .success(function(d, s, xhr) { + console.log("successfully invoked JOSM remote constrol"); + }); } } } @@ -515,6 +521,15 @@ osmtm.project = (function() { } } + function map2bbox(map) { + var bbox = map.getBounds(); + var lat1 = Math.min(Math.max(bbox.getSouthWest().lat, -90), 90); + var lat2 = Math.min(Math.max(bbox.getNorthEast().lat, -90), 90); + var lng1 = Math.min(Math.max(bbox.getSouthWest().lng, -180), 180); + var lng2 = Math.min(Math.max(bbox.getNorthEast().lng, -180), 180); + return lat1 + "," + lng1 + "," + lat2 + "," + lng2; + }; + /** * Loads random task * diff --git a/osmtm/templates/project.edit.mako b/osmtm/templates/project.edit.mako index b8f48070..3c7742da 100644 --- a/osmtm/templates/project.edit.mako +++ b/osmtm/templates/project.edit.mako @@ -414,7 +414,7 @@ geometry = loads(str(project.area.geometry.data)) class="form-control" rows="13">${project.overpass if project.overpass is not None else ''}

    - ${_('Note:')} ${_('Generate the query on overpass-turbo.eu and export as JOSM. Allow it to auto repair. Then copy the query here.')|n} + ${_('Note:')} ${_('Generate the query on overpass-turbo.eu and export as JOSM. Allow it to auto repair. Then copy the query here. The {{bbox}} shortcut is supported.')|n}

    diff --git a/osmtm/templates/task.mako b/osmtm/templates/task.mako index 2a177647..928b3e2a 100644 --- a/osmtm/templates/task.mako +++ b/osmtm/templates/task.mako @@ -90,7 +90,7 @@ var imagery_url = "${project.imagery|n}"; import urllib overpass_url = '' if project.overpass is not None: - overpass_data = urllib.quote(project.overpass.encode('utf8').replace('\n',''), '*()') + overpass_data = urllib.quote(project.overpass.encode('utf8').replace('\r',''), '*()~') overpass_url = "http://overpass-api.de/api/interpreter?data=" + overpass_data %> % if overpass is not None: From 58c9b4a547754052d7e4769b30c9de37ae733806 Mon Sep 17 00:00:00 2001 From: Brian DeRocher Date: Fri, 4 Aug 2017 14:47:43 -0400 Subject: [PATCH 4/5] Clean up unused variables and set JS overpass_url only if python overpass_url is not None. --- osmtm/templates/task.mako | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/osmtm/templates/task.mako b/osmtm/templates/task.mako index 928b3e2a..68bcf109 100644 --- a/osmtm/templates/task.mako +++ b/osmtm/templates/task.mako @@ -93,9 +93,7 @@ if project.overpass is not None: overpass_data = urllib.quote(project.overpass.encode('utf8').replace('\r',''), '*()~') overpass_url = "http://overpass-api.de/api/interpreter?data=" + overpass_data %> -% if overpass is not None: -var overpass_data = '${overpass_data|n}'; -var overpass_dataz = '${overpass_data}'; +% if overpass_url is not None: var overpass_url = '${overpass_url|n}'; % endif var changeset_comment = "${quote(project.changeset_comment.encode('utf8'), '')}"; From 6f244824c3b6a4fff9c450c87cdd35e3a7a87c0d Mon Sep 17 00:00:00 2001 From: Brian DeRocher Date: Fri, 11 Aug 2017 22:47:59 -0400 Subject: [PATCH 5/5] Fix flake8 long lines. --- osmtm/views/project.py | 3 ++- osmtm/views/views.py | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/osmtm/views/project.py b/osmtm/views/project.py index 12fa42e3..a486db50 100644 --- a/osmtm/views/project.py +++ b/osmtm/views/project.py @@ -253,7 +253,8 @@ def project_edit(request): setattr(project, field, request.params[translated]) DBSession.add(project) - for p in ['changeset_comment', 'entities_to_map', 'imagery', 'overpass']: + for p in ['changeset_comment', 'entities_to_map', 'imagery', + 'overpass']: if p in request.params: setattr(project, p, request.params[p]) diff --git a/osmtm/views/views.py b/osmtm/views/views.py index 4205f7aa..e3d226c4 100644 --- a/osmtm/views/views.py +++ b/osmtm/views/views.py @@ -152,7 +152,8 @@ def get_projects(request, items_per_page): filter = and_(Project.status != Project.status_archived, filter) sort_by = 'project.%s' % request.params.get('sort_by', 'priority') - if sort_by not in ['project.priority', 'project.created', 'project.last_update']: + if sort_by not in ['project.priority', 'project.created', + 'project.last_update']: sort_by = 'project.priority' direction = request.params.get('direction', 'asc') if direction not in ['asc', 'desc']: