diff --git a/parts/server.py b/parts/server.py index f62fcc0..033b114 100644 --- a/parts/server.py +++ b/parts/server.py @@ -164,20 +164,28 @@ def query(filter_dummy, query): r.close() return json.dumps(l) -@app.route('/parts/map/') -def getMap(mapurl): +@app.route('/parts/map/') +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)