--- a/server.py +++ b/server.py @@ -90,8 +90,7 @@ del(i['_id']) ret[y] = i y = y + 1 - - return render_template('blank.html', content = ret) + return render_template('blank.html', content = ret, flag = request.args['flag']) @app.route('/submit', methods=['POST']) --- /dev/null +++ b/static/config.js.sample @@ -1 +1,4 @@ +var config = { + 'indexer':'http://127.0.0.1:5000' +} --- a/static/myVector.js +++ b/static/myVector.js @@ -62,8 +62,8 @@ { for(var i in ans.ans) { - if(feature.geometry.bounds['left'] == ans.ans[i]['left'] && feature.geometry.bounds['right'] == ans.ans[i]['right'] && feature.geometry.bounds['top'] == ans.ans[i]['top'] && feature.geometry.bounds['bottom'] == ans.ans[i]['bottom']) - { + // if(feature.geometry.bounds['left'] == ans.ans[i]['left'] && feature.geometry.bounds['right'] == ans.ans[i]['right'] && feature.geometry.bounds['top'] == ans.ans[i]['top'] && feature.geometry.bounds['bottom'] == ans.ans[i]['bottom']) + // { str = {}; if(ans.ans[i]['character']) str['character'] = ans.ans[i]['character']; @@ -72,30 +72,42 @@ str['material'] = ans.ans[i]['material']; // str['jewellery'] = ans.ans[i]['jewellery'] } - + if(ans.ans[i]["how"]) + { z = new OpenLayers.Popup.FramedCloud( "test", feature.geometry.getBounds().getCenterLonLat(), new OpenLayers.Size(640,480), - '",null,true); + '",null,true); + } + else + { + z = new OpenLayers.Popup.FramedCloud( + "test", + feature.geometry.getBounds().getCenterLonLat(), + new OpenLayers.Size(640,480), + '",null,true); + + } + feature.popup = z; z.panMapIfOutOfView = true; map.addPopup(z); break; - } - else{ - if(i == ans.count-1) - { - z = new OpenLayers.Popup.FramedCloud( - "test", - feature.geometry.getBounds().getCenterLonLat(), - new OpenLayers.Size(640,480), - '',null,true); - feature.popup = z; - z.panMapIfOutOfView = true; - map.addPopup(z); - } - } + //} + //else{ + // if(i == ans.count-1) + // { + // z = new OpenLayers.Popup.FramedCloud( + // "test", + // feature.geometry.getBounds().getCenterLonLat(), + // new OpenLayers.Size(640,480), + // '',null,true); + // feature.popup = z; + // z.panMapIfOutOfView = true; + // map.addPopup(z); + // } + //} } } @@ -184,6 +196,7 @@ $.get(config.indexer+"/fetch",{uri:"default"} , function(data){ if (data != undefined) { + console.log(data); ans.ans = data; for(var i in ans.ans) { @@ -316,11 +329,23 @@ } function makeBoxes(x) { - + if(x.left) + { bounds = new OpenLayers.Bounds(x['left'], x['bottom'], x['right'], x['top']); box = new OpenLayers.Feature.Vector(bounds.toGeometry()); box3.addFeatures(box); addLabel(x['left'],x['top'],x['name']); + } + else if(x.where) + { + position = JSON.parse(x.where.split("#")[1]); + console.log(position); + bounds = new OpenLayers.Bounds(position[2], position[1], position[3], position[0]); + box = new OpenLayers.Feature.Vector(bounds.toGeometry()); + box3.addFeatures(box); + addLabel(position[2],position[0],x['name']); + + } } // function onmouse(data){ // console.log(data); @@ -471,9 +496,5 @@ myJSON = []; }); }); -} -var config = { - 'postTweetUrl':'http://demo.swtr.us/add', - 'indexer':'http://folkhampi.openrun.net/mural-annotation' } --- a/static/text-annotation.css +++ b/static/text-annotation.css @@ -18,4 +18,8 @@ width: 500px; margin: -250px 0 0 28%; } +.highlight{ +background-color: rgba(255, 212, 0, 0.6); + +} --- a/static/text-annotation.js +++ b/static/text-annotation.js @@ -14,7 +14,12 @@ modal.id = 'modal-wrap'; document.body.appendChild(modal); modal.innerHTML = modal_template(); - $('#publish').click(function() { + $("#list-anno").on("hidden", function(){ + $(".well a").off("click"); + $(".highlight").removeClass("highlight"); + + }) + $('#publish').click(function() { sweet.publish(); }); }; @@ -37,7 +42,8 @@ }; window.listAnno = function() { // list annotations of current page console.log('listing annotations'); - $.get(config.indexer + '/search?data=' + + + $.get(config.indexer + '/search?flag=1&data=' + JSON.stringify({'where': window.location.search.split('url=')[1]}), function(data) { //console.log(data); @@ -45,6 +51,15 @@ $('#list-anno').modal({ backdrop: false, }); + $('.well a').click(function(event){ + xpath = $(event.currentTarget).text().split('#')[1]; + var nodes = document.evaluate(xpath, document, null, XPathResult.ANY_TYPE,null); + result = nodes.iterateNext(); + while(result){ + $(result).addClass("highlight"); + result = nodes.iterateNext(); + } + }); }); }; --- a/templates/blank.html +++ b/templates/blank.html @@ -1,8 +1,26 @@ + + +{% if flag == '1' %} {% for obj in content %}
-{% for key in content[obj].keys() %} -

{{ key }}: {{ content[obj][key] }}

+ {% for key in content[obj].keys() %} + {% if key == "where" or key == "xpath" %} +

{{ key }}: {{ content[obj][key] }}

+ {% else %} +

{{ key }}: {{ content[obj][key] }}

+ {% endif %} + {% endfor %} +
{% endfor %} +{% else %} +{% for obj in content %} +
+ {% for key in content[obj].keys() %} +

{{ key }}: {{ content[obj][key] }}

+ {% endfor %}
{% endfor %} +{% endif %} + + --- a/templates/index.html +++ b/templates/index.html @@ -14,6 +14,7 @@ + {% if url %}