Normalize latitude in horde-members-api

master
Nikola Forró 6 years ago
parent b65ea43e34
commit fc0e42dede

@ -117,6 +117,10 @@ def member2feature(member):
} }
def normalize(x, y):
return x % 180 if x > 0 else x % -180, y
class MemberResource(flask_restful.Resource): class MemberResource(flask_restful.Resource):
@flask_restful.marshal_with(member_fields) @flask_restful.marshal_with(member_fields)
def get(self, id): def get(self, id):
@ -136,8 +140,7 @@ class MemberResource(flask_restful.Resource):
if not member: if not member:
member = Member(id=id, created_at=now) member = Member(id=id, created_at=now)
member.nick = args['nick'] member.nick = args['nick']
member.x = args['x'] member.x, member.y = normalize(args['x'], args['y'])
member.y = args['y']
member.updated_at = now member.updated_at = now
db.session.add(member) db.session.add(member)
db.session.commit() db.session.commit()
@ -196,8 +199,7 @@ class MembersResource(flask_restful.Resource):
if not member: if not member:
member = Member(created_at=now) member = Member(created_at=now)
member.user = args['nick'] member.user = args['nick']
member.x = args['x'] member.x, member.y = normalize(args['x'], args['y'])
member.y = args['y']
member.updated_at = now member.updated_at = now
db.session.add(member) db.session.add(member)
db.session.commit() db.session.commit()
@ -238,7 +240,7 @@ class FeaturesResource(flask_restful.Resource):
if not member: if not member:
member = Member(created_at=now) member = Member(created_at=now)
member.nick = properties_args['nick'] member.nick = properties_args['nick']
member.x, member.y = geometry_args['coordinates'] member.x, member.y = normalize(*geometry_args['coordinates'])
member.updated_at = now member.updated_at = now
db.session.add(member) db.session.add(member)
db.session.commit() db.session.commit()

Loading…
Cancel
Save