--- /dev/null +++ b/fetch.py @@ -1 +1,20 @@ +import json +import pymongo +#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) --- a/myVector.js +++ b/myVector.js @@ -12,7 +12,9 @@ ]; var myJSON = []; var ans = { - ans: [] + ans: [], + count: 0 + }; // avoid pink tiles OpenLayers.IMAGE_RELOAD_ATTEMPTS = 3; @@ -57,6 +59,46 @@ }; function onFeatureSelect(feature) { + 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']) + { + str = {}; + if(ans.ans[i]['character']) + str['character'] = ans.ans[i]['character']; + else + { + str['material'] = ans.ans[i]['material']; + // str['jewellery'] = ans.ans[i]['jewellery'] + } + z = new OpenLayers.Popup.FramedCloud( + "test", + feature.geometry.getBounds().getCenterLonLat(), + new OpenLayers.Size(640,480), + JSON.stringify(str,null,' '),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); + } + } + } + +} +function onFeatureSelect1(feature) +{ z = new OpenLayers.Popup.FramedCloud( "test", feature.geometry.getBounds().getCenterLonLat(), @@ -72,7 +114,7 @@ "test", new OpenLayers.LonLat(x, y), // Always should be at the center of the map, not the center of viewport. new OpenLayers.Size(640,480), - "
"+JSON.stringify(json,null,'\t')+"" + "
"+JSON.stringify(json,null,' ')+"" ,null,true); feature.popup = z; z.panMapIfOutOfView = true; @@ -92,6 +134,7 @@ ans.ans = JSON.parse(data); for(var i in ans.ans) { + ans.count+=1; makeBoxes(ans.ans[i]); } @@ -199,16 +242,14 @@ function makeBoxes(x) { - box4 = new OpenLayers.Layer.Vector( "Tags"); bounds = new OpenLayers.Bounds(x['left'], x['bottom'], x['right'], x['top']); box = new OpenLayers.Feature.Vector(bounds.toGeometry()); - box4.addFeatures(box); - map.addLayer(box4); + box3.addFeatures(box); addLabel(x['left'],x['top'],x['name']); } -function onmouse(data){ - console.log(data); -} +// function onmouse(data){ +// console.log(data); +// } function myfeatureadded(myObj) { var renderer = OpenLayers.Util.getParameters(window.location.href).renderer; @@ -247,10 +288,8 @@ favColor: 'blue', }; labelFeature.attributes['name'] = prompt("Enter a name"); - console.log(labelFeature.attributes['name']); if(labelFeature.attributes['name']) { - console.log(myObj.feature.geometry.bounds.top); //Use this to get the bounds. topValue = myObj.feature.geometry.bounds.top; bottom = myObj.feature.geometry.bounds.bottom; left = myObj.feature.geometry.bounds.left; @@ -330,10 +369,9 @@ onresize=function(){ resize();}; function publish() { - console.log(myJSON); $.post("http://192.168.100.56:82/submit", JSON.stringify(myJSON), function(data) { - alert(data); + alert("Posted"); } ); } --- a/openlayers.html +++ b/openlayers.html @@ -42,7 +42,7 @@ attribs["character"] = $("#character-value").text(); attribs["material"] = $("#material-value").text(); myJSON.push(attribs); - $("#publish").attr("disbaled", false); + $("#publish").attr("disabled", false); } --- /dev/null +++ b/submit.wsgi @@ -1 +1,15 @@ +import json +import pymongo +def application(environ, start_response): + status = '200 OK' + response_headers = [('Content-type', 'text/html'),('Access-Control-Allow-Origin', '*')] + start_response(status, response_headers) + recieved = environ['wsgi.input'].read(int(environ['CONTENT_LENGTH'])) + c = pymongo.Connection() + db = c['mural'] + coll = db['data'] + d = json.loads(recieved) + for i in d: + coll.insert(d) + return 'ok'