Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Overpass in josm #992

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions alembic/versions/40d0f2b07d22_add_overpass_to_project.py
Original file line number Diff line number Diff line change
@@ -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')
1 change: 1 addition & 0 deletions osmtm/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
23 changes: 23 additions & 0 deletions osmtm/static/js/project.js
Original file line number Diff line number Diff line change
Expand Up @@ -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");
});
}
}
}
});
Expand Down Expand Up @@ -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
*
Expand Down
21 changes: 21 additions & 0 deletions osmtm/templates/project.edit.mako
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ geometry = loads(str(project.area.geometry.data))
<li><a href="#instructions" data-toggle="tab">${_('Instructions')}</a></li>
<li><a href="#area" data-toggle="tab">${_('Area')}</a></li>
<li><a href="#imagery" data-toggle="tab">${_('Imagery')}</a></li>
<li><a href="#features" data-toggle="tab">${_('Features')}</a></li>
<li><a id="priority_areas_tab" href="#priority_areas" data-toggle="tab">${_('Priority Areas')}</a></li>
<li><a href="#permissions" data-toggle="tab">${_('Permissions')}</a></li>
<li><a href="#labels" data-toggle="tab">${_('Labels')}</a></li>
Expand All @@ -153,6 +154,9 @@ geometry = loads(str(project.area.geometry.data))
<div class="tab-pane" id="imagery">
${imagery()}
</div>
<div class="tab-pane" id="features">
${features()}
</div>
<div class="tab-pane" id="priority_areas">
${priority_areas_()}
</div>
Expand Down Expand Up @@ -400,6 +404,23 @@ geometry = loads(str(project.area.geometry.data))
</div>
</%block>

<%block name="features">
<div class="row">
<div class="col-md-6">
<div class="form-group">
<label class="control-label" for="id_overpass">${_('Overpass Query')}</label>
<textarea id="id_overpass"
name="overpass"
class="form-control"
rows="13">${project.overpass if project.overpass is not None else ''}</textarea>
<p class="help-block">
<strong>${_('Note:')}</strong> ${_('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}
</p>
</div>
</div>
</div>
</%block>

<%block name="permissions">
<div class="row">
<div class="input-group">
Expand Down
10 changes: 10 additions & 0 deletions osmtm/templates/task.mako
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,16 @@ 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('\r',''), '*()~')
overpass_url = "http://overpass-api.de/api/interpreter?data=" + overpass_data
%>
% if overpass_url is not None:
var overpass_url = '${overpass_url|n}';
% endif
var changeset_comment = "${quote(project.changeset_comment.encode('utf8'), '')}";
osmtm.project.initAtWho();
</script>
Expand Down
3 changes: 2 additions & 1 deletion osmtm/views/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -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']:
for p in ['changeset_comment', 'entities_to_map', 'imagery',
'overpass']:
if p in request.params:
setattr(project, p, request.params[p])

Expand Down
3 changes: 2 additions & 1 deletion osmtm/views/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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']:
Expand Down