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') 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..a083870e 100644 --- a/osmtm/static/js/project.js +++ b/osmtm/static/js/project.js @@ -450,6 +450,20 @@ osmtm.project = (function() { } }); } + if (typeof overpass_url != "undefined" && overpass_url !== '') { + 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"); + }); + } } } }); @@ -507,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 9ebe9cce..3c7742da 100644 --- a/osmtm/templates/project.edit.mako +++ b/osmtm/templates/project.edit.mako @@ -135,6 +135,7 @@ geometry = loads(str(project.area.geometry.data))
+ ${_('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} +
+