maps with container overlays

pull/3/head
Marek Baczynski 6 years ago
parent c4ca575ca1
commit 0fdcd100ff

@ -164,20 +164,28 @@ def query(filter_dummy, query):
r.close()
return json.dumps(l)
@app.route('/parts/map/<mapurl>')
def getMap(mapurl):
@app.route('/parts/map/<containerID>')
def getMap(containerID):
s = 'select map, overlay from containers where id = :id;'
r = db_engine.execute(text(s), id=containerID)
l = []
for row in r:
l.append(dict(row))
mapFile = l[0]['map']
overlayFile = l[0]['overlay']
try:
mapimage = Image.open('maps/' + mapurl).convert("RGBA")
mapImage = Image.open('maps/' + mapFile).convert("RGBA")
overlayImage = Image.open('maps/overlays/' + overlayFile).convert("RGBA")
except FileNotFoundError:
return serveImage(Image.open("maps/404.png"))
if request.args.get('x') is not None and request.args.get('y') is not None:
x = int(request.args.get('x'))
y = int(request.args.get('y'))
pointer = Image.open('maps/here.png')
pointerLayer = Image.new("RGBA", mapimage.size)
width, height = pointer.size
pointerLayer.paste(pointer, (x - int(width/2), y-int(height/2)))
mapimage = Image.alpha_composite(mapimage, pointerLayer)
# if request.args.get('x') is not None and request.args.get('y') is not None:
# x = int(request.args.get('x'))
# y = int(request.args.get('y'))
# pointer = Image.open('maps/here.png')
# pointerLayer = Image.new("RGBA", mapimage.size)
# width, height = pointer.size
# pointerLayer.paste(pointer, (x - int(width/2), y-int(height/2)))
mapimage = Image.alpha_composite(mapImage, overlayImage)
return serveImage(mapimage)

Loading…
Cancel
Save