From d6119719590359a48c796beb2d3b4dde40538e16 Mon Sep 17 00:00:00 2001 From: Arvind Date: Tue, 26 Mar 2013 21:26:08 +0530 Subject: [PATCH] Major changes - Implementing panorama viewer. - Removing JSON editing and saving on server side. Switching to another graph for annotation. --- fetch.py | 81 +++++-------------------- static/myVector.js | 153 +++++++++++++++++++++++++++++++++--------------- templates/editor.html | 54 ----------------- templates/history.html | 18 ------ templates/index.html | 105 ++++++++------------------------- 5 files changed, 146 insertions(+), 265 deletions(-) delete mode 100644 templates/editor.html delete mode 100644 templates/history.html diff --git a/fetch.py b/fetch.py index 2cd4c48..b22b5f8 100644 --- a/fetch.py +++ b/fetch.py @@ -2,66 +2,34 @@ from flask import Flask from flask import request from flask import render_template from flask import make_response +from flask import jsonify import logging from logging import FileHandler -import json import pymongo -import os -import glob + app = Flask(__name__) @app.route('/', methods=['GET']) def index(): - if request.args.has_key('json'): - return render_template('index.html', json=request.args['json']) + if request.args.has_key('url'): + return render_template('index.html', url=request.args['url']) else: return render_template('index.html') -@app.route('/editor', methods=['GET']) -def editor(): - if request.args.has_key('json'): - filename = request.args['json'] - else: - filename = 'test.json' - filename = os.path.join(os.path.join(os.path.dirname(__file__), 'static'), filename) - try: - f = open(filename, 'r') - except: - f = open(os.path.join(os.path.join(os.path.dirname(__file__), 'static'), 'test.json'), 'r') - buf = f.read() - f.close() - return render_template('editor.html', json = buf) - -@app.route('/saveJSON', methods=['POST']) -def saveJSON(): - if request.method == 'POST': - response = make_response() - JSON = request.form['json'] - filename = os.path.join(os.path.join(os.path.dirname(__file__), 'static'), request.form['filename']) - ls = glob.glob(filename) - if len(ls) > 0: - response.status_code = 409 - response.status ="409 Conflict" - response.data = "The file that you were trying to save already exits, please try a different name." - return response - f = open(filename, 'w') - f.write(JSON) - f.close() - return response - else: - response = make_response() - response.code = 400 - return reponse +@app.route('/fetch',methods=['GET']) +def fetch(): + connection = pymongo.Connection() + db = connection['mural'] + collection = db['data'] + ret = {} + x = 0 + for i in collection.find({'url':request.args['url']}): + del(i['_id']) + ret[x] = i + x = x + 1 + jsonify(ret) -@app.route('/history', methods=['GET']) -def listJSON(): - path = os.path.join(os.path.join(os.path.dirname(__file__), 'static'), '*.json') - ls = glob.glob(path) - def sanitize(i): - return i.split('/')[-1] - ls = map(sanitize, ls) - return render_template('history.html', ls=ls) #Log the errors, don't depend on apache to log it for you. fil = FileHandler(os.path.join(os.path.dirname(__file__), 'logme'),mode='a') @@ -72,20 +40,3 @@ def listJSON(): if __name__ == "__main__": app.run(debug=True, host='0.0.0.0') -# #from bson.code import * - # #from urllib import unquote_plus - # def application(environ, start_response): - # status = '200 OK' - # response_headers = [('Content-type', 'application/json'),('Access-Control-Allow-Origin', '*')] - # start_response(status, response_headers) - # c = pymongo.Connection() - # db = c['mural'] - # coll = db['data'] - # ret = {} - # x = 0 - # for i in coll.find(): - # del(i['_id']) - # ret[x] = i - # x = x + 1 - # #return repr(recieved) - # return json.dumps(ret) diff --git a/static/myVector.js b/static/myVector.js index ecacf10..af4d63e 100644 --- a/static/myVector.js +++ b/static/myVector.js @@ -124,68 +124,123 @@ function onMyFeatureSelect(feature, json, x, y) z.panMapIfOutOfView = true; map.addPopup(z); } -function init(){ - var options = { - controls: [], - maxExtent: new OpenLayers.Bounds( 0.0, -4668.0, 31110.0, 0.0 ), - maxResolution: 128.000000, - numZoomLevels: 8, - restrictedExtent: new OpenLayers.Bounds( 0.0, -4668.0, 31110.0, 0.0 ) - }; - map = new OpenLayers.Map('map', options); - $.get(config.indexer+"/fetch", function(data){ - if (data != undefined) - { - ans.ans = data; - for(var i in ans.ans) - { - ans.count+=1; - makeBoxes(ans.ans[i]); - } +function init(url){ + box2 = new OpenLayers.Layer.Vector( "Boxes"); + box3 = new OpenLayers.Layer.Vector( "Boxes"); + if(url != undefined) + { + var options = { + controls: [], + maxExtent: new OpenLayers.Bounds( 0.0, -928.0, 6744.0, 0.0 ), + maxResolution: 32.000000, + numZoomLevels: 6 + }; + map = new OpenLayers.Map('map', options); - } + $.get(config.indexer+"/fetch",{url:decodeURIComponent(window.location.search.split("=")[1]).replace("\"","","gi")} , function(data){ + if (data != undefined) + { + ans.ans = data; + for(var i in ans.ans) + { + ans.count+=1; + makeBoxes(ans.ans[i]); + } - }); + } + + }); - buffer0 = new OpenLayers.Layer.TMS( "TMS Layer","static/", + + buffer0 = new OpenLayers.Layer.TMS( "TMS Layer","static/withpiv/", { url: '', serviceVersion: '.', layername: 'buffer0', alpha: true, type: 'png', getURL: overlay_getTileURL, buffer:0, singleTile: false }); - buffer1 = new OpenLayers.Layer.TMS( "TMS Layer","static/", + buffer1 = new OpenLayers.Layer.TMS( "TMS Layer","static/withpiv/", { url: '', serviceVersion: '.', layername: 'buffer1', alpha: true, type: 'png', getURL: overlay_getTileURL, buffer:1, singleTile: false }); - buffer2 = new OpenLayers.Layer.TMS( "TMS Layer","static/", + buffer2 = new OpenLayers.Layer.TMS( "TMS Layer","static/withpiv/", { url: '', serviceVersion: '.', layername: 'buffer2', alpha: true, type: 'png', getURL: overlay_getTileURL, buffer:2, singleTile: false }); - var layer = new OpenLayers.Layer.TMS( "TMS Layer","static/", - { url: '', serviceVersion: '.', layername: '.', alpha: true, - type: 'png', getURL: overlay_getTileURL, isBaseLayer:true + var layer = new OpenLayers.Layer.TMS( "TMS Layer","static/withpiv/", + { url: '', serviceVersion: '.', layername: '.', alpha: true, + type: 'png', getURL: overlay_getTileURL, isBaseLayer:true + }); + } + else{ + var options = { + controls: [], + maxExtent: new OpenLayers.Bounds( 0.0, -4668.0, 31110.0, 0.0 ), + maxResolution: 128.000000, + numZoomLevels: 8 + }; + map = new OpenLayers.Map('map', options); + $.get(config.indexer+"/fetch",{url:window.location.href} , function(data){ + if (data != undefined) + { + ans.ans = data; + for(var i in ans.ans) + { + ans.count+=1; + makeBoxes(ans.ans[i]); + } + + } + + }); + + buffer0 = new OpenLayers.Layer.TMS( "TMS Layer","static/", + { url: '', serviceVersion: '.', layername: 'buffer0', alpha: true, + type: 'png', getURL: overlay_getTileURL, buffer:0, singleTile: false + }); + + buffer1 = new OpenLayers.Layer.TMS( "TMS Layer","static/", + { url: '', serviceVersion: '.', layername: 'buffer1', alpha: true, + type: 'png', getURL: overlay_getTileURL, buffer:1, singleTile: false + }); + + buffer2 = new OpenLayers.Layer.TMS( "TMS Layer","static/", + { url: '', serviceVersion: '.', layername: 'buffer2', alpha: true, + type: 'png', getURL: overlay_getTileURL, buffer:2, singleTile: false }); + + var layer = new OpenLayers.Layer.TMS( "TMS Layer","static/", + { url: '', serviceVersion: '.', layername: '.', alpha: true, + type: 'png', getURL: overlay_getTileURL, isBaseLayer:true + }); + + + addLabel('3759.0000','-1274.33337','Face'); + addLabel('3719','-1771','Jewelery'); + addLabel('4263.0000','-1345.33337', 'Video'); + + for (var i = 0; i < box_extents.length; i++) { + ext = box_extents[i]; + bounds = OpenLayers.Bounds.fromArray(ext); + + box = new OpenLayers.Feature.Vector(bounds.toGeometry()); + box2.addFeatures(box); + } + for (var i = 0; i < box_extents1.length; i++) { + ext = box_extents1[i]; + bounds = OpenLayers.Bounds.fromArray(ext); + + box = new OpenLayers.Feature.Vector(bounds.toGeometry()); + box3.addFeatures(box); + } + + } boxes = new OpenLayers.Layer.Vector( "Boxes" ); map.addLayers([layer, buffer0, buffer1, buffer2, boxes]); + layer.wrapDateLine = true; boxes.events.register('featureadded', boxes, myfeatureadded); - box2 = new OpenLayers.Layer.Vector( "Boxes" ); - for (var i = 0; i < box_extents.length; i++) { - ext = box_extents[i]; - bounds = OpenLayers.Bounds.fromArray(ext); - box = new OpenLayers.Feature.Vector(bounds.toGeometry()); - box2.addFeatures(box); - } - box3 = new OpenLayers.Layer.Vector( "Boxes"); - for (var i = 0; i < box_extents1.length; i++) { - ext = box_extents1[i]; - bounds = OpenLayers.Bounds.fromArray(ext); - - box = new OpenLayers.Feature.Vector(bounds.toGeometry()); - box3.addFeatures(box); - } map.addLayers([box2, box3]); selectControl = new OpenLayers.Control.SelectFeature(box3, @@ -203,20 +258,17 @@ function init(){ select: selectControl }; - map.zoomToExtent( mapBounds ); + for(var key in drawControls){ map.addControl(drawControls[key]); } drawControls['select'].activate(); - addLabel('3759.0000','-1274.33337','Face'); - addLabel('3719','-1771','Jewelery'); - addLabel('4263.0000','-1345.33337', 'Video'); map.addControl(new OpenLayers.Control.PanZoomBar()); map.addControl(new OpenLayers.Control.MousePosition()); map.addControl(new OpenLayers.Control.Navigation()); map.addControl(new OpenLayers.Control.KeyboardDefaults()); map.addControl(new OpenLayers.Control.LayerSwitcher()); - map.zoomToExtent( mapBounds ); + map.zoomToExtent( options['maxExtent'] ); //document.getElementById('noneToggle').checked = true; } function addLabel(left, top, name) @@ -403,7 +455,14 @@ function publish() myJSON[i].text = ' annotated '+window.location.href+"#[top="+myJSON[i].top+",bottom="+myJSON[i].bottom+",left="+myJSON[i].left+",right="+myJSON[i].right+"] as "+myJSON[i].name+" "+jString+" #swtr"; //The string which gets posted as a tweet. myJSON[i].text = encodeURIComponent(myJSON[i].text); myJSON[i].user = user; // User need not know the modification to the JSON. - myJSON[i].title = 'Annotation for '+window.location.href; + if(window.location.search == ""){ + myJSON[i].title = 'Annotation for '+window.location.href; + myJSON[i].url = window.location.href; + } + else{ + myJSON[i].title = 'Annotation for '+ decodeURIComponent(window.location.search.split("=")[1]).replace("\"","","gi"); + myJSON[i].url = decodeURIComponent(window.location.search.split("=")[1]).replace("\"","","gi"); + } } $.post(config.indexer+'/submit', JSON.stringify(myJSON),function(){ $.post(config.postTweetUrl, {"data":JSON.stringify(myJSON)}, function(data) { diff --git a/templates/editor.html b/templates/editor.html deleted file mode 100644 index 0e23d6b..0000000 --- a/templates/editor.html +++ /dev/null @@ -1,54 +0,0 @@ - - - - Lepakshi Mural - JSON editor - - - - - -


-
-

JSON Editor

- - - - Enter JSON filename - - -
- - - - - - diff --git a/templates/history.html b/templates/history.html deleted file mode 100644 index 4722183..0000000 --- a/templates/history.html +++ /dev/null @@ -1,18 +0,0 @@ - - - - Lepakshi Mural - JSON history - - - - -
-

JSON history

- -
- - diff --git a/templates/index.html b/templates/index.html index 8e13f33..53ab22c 100644 --- a/templates/index.html +++ b/templates/index.html @@ -1,8 +1,7 @@ - - - + + - + + - Lepakshi Mural + Flask Lepakshi Mural @@ -36,10 +36,8 @@ #map {border: 1px solid #888;} - - - + - +{% if url %} + +{% else %} + +{% endif %}
@@ -86,35 +88,18 @@ Success! Post successfully posted.
-
- -

- - - -

-
Generated by MapTilerGDAL2Tiles, Copyright © 2008 Klokan Petr Pridal, GDAL & OSGeo GSoC
-
- - - -
- @@ -128,9 +113,19 @@ - - - - -- 1.7.10.4