Commit 5c78a2713049e5ce4c91c691972f635d2ae5d78b
Adding python files and now tags are displayed with the content
| | | | | | 1 | import json |
---|
| | 2 | import pymongo |
---|
| | 3 | #from bson.code import * |
---|
| | 4 | #from urllib import unquote_plus |
---|
| | 5 | def application(environ, start_response): |
---|
| | 6 | status = '200 OK' |
---|
| | 7 | response_headers = [('Content-type', 'application/json'),('Access-Control-Allow-Origin', '*')] |
---|
| | 8 | start_response(status, response_headers) |
---|
| | 9 | c = pymongo.Connection() |
---|
| | 10 | db = c['mural'] |
---|
| | 11 | coll = db['data'] |
---|
| | 12 | ret = {} |
---|
| | 13 | x = 0 |
---|
| | 14 | for i in coll.find(): |
---|
| | 15 | del(i['_id']) |
---|
| | 16 | ret[x] = i |
---|
| | 17 | x = x + 1 |
---|
| | 18 | #return repr(recieved) |
---|
| | 19 | return json.dumps(ret) |
---|
| | | | 12 | ]; | 12 | ]; |
---|
13 | var myJSON = []; | 13 | var myJSON = []; |
---|
14 | var ans = { | 14 | var ans = { |
---|
15 | ans: [] | | ans: [] |
---|
| | 15 | ans: [], | | | 16 | count: 0 |
---|
| | 17 | |
---|
16 | }; | 18 | }; |
---|
17 | // avoid pink tiles | 19 | // avoid pink tiles |
---|
18 | OpenLayers.IMAGE_RELOAD_ATTEMPTS = 3; | 20 | OpenLayers.IMAGE_RELOAD_ATTEMPTS = 3; |
---|
… | | … | |
---|
59 | }; | 59 | }; |
---|
60 | function onFeatureSelect(feature) | 60 | function onFeatureSelect(feature) |
---|
61 | { | 61 | { |
---|
| | 62 | for(var i in ans.ans) |
---|
| | 63 | { |
---|
| | 64 | 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']) |
---|
| | 65 | { |
---|
| | 66 | str = {}; |
---|
| | 67 | if(ans.ans[i]['character']) |
---|
| | 68 | str['character'] = ans.ans[i]['character']; |
---|
| | 69 | else |
---|
| | 70 | { |
---|
| | 71 | str['material'] = ans.ans[i]['material']; |
---|
| | 72 | // str['jewellery'] = ans.ans[i]['jewellery'] |
---|
| | 73 | } |
---|
| | 74 | z = new OpenLayers.Popup.FramedCloud( |
---|
| | 75 | "test", |
---|
| | 76 | feature.geometry.getBounds().getCenterLonLat(), |
---|
| | 77 | new OpenLayers.Size(640,480), |
---|
| | 78 | JSON.stringify(str,null,' '),null,true); |
---|
| | 79 | feature.popup = z; |
---|
| | 80 | z.panMapIfOutOfView = true; |
---|
| | 81 | map.addPopup(z); |
---|
| | 82 | break; |
---|
| | 83 | } |
---|
| | 84 | else{ |
---|
| | 85 | if(i == ans.count-1) |
---|
| | 86 | { |
---|
| | 87 | z = new OpenLayers.Popup.FramedCloud( |
---|
| | 88 | "test", |
---|
| | 89 | feature.geometry.getBounds().getCenterLonLat(), |
---|
| | 90 | new OpenLayers.Size(640,480), |
---|
| | 91 | '<iframe width="480" height="360" src="http://www.youtube.com/embed/WwNUnmZ_aww" frameborder="0" allowfullscreen></iframe>',null,true); |
---|
| | 92 | feature.popup = z; |
---|
| | 93 | z.panMapIfOutOfView = true; |
---|
| | 94 | map.addPopup(z); |
---|
| | 95 | } |
---|
| | 96 | } |
---|
| | 97 | } |
---|
| | 98 | |
---|
| | 99 | } |
---|
| | 100 | function onFeatureSelect1(feature) |
---|
| | 101 | { |
---|
62 | z = new OpenLayers.Popup.FramedCloud( | 102 | z = new OpenLayers.Popup.FramedCloud( |
---|
63 | "test", | 103 | "test", |
---|
64 | feature.geometry.getBounds().getCenterLonLat(), | 104 | feature.geometry.getBounds().getCenterLonLat(), |
---|
… | | … | |
---|
114 | "test", | 114 | "test", |
---|
115 | new OpenLayers.LonLat(x, y), // Always should be at the center of the map, not the center of viewport. | 115 | new OpenLayers.LonLat(x, y), // Always should be at the center of the map, not the center of viewport. |
---|
116 | new OpenLayers.Size(640,480), | 116 | new OpenLayers.Size(640,480), |
---|
117 | "<pre>"+JSON.stringify(json,null,'\t')+"</pre>" | | "<pre>"+JSON.stringify(json,null,'\t')+"</pre>" |
---|
| | 117 | "<pre>"+JSON.stringify(json,null,' ')+"</pre>" | 118 | ,null,true); | 118 | ,null,true); |
---|
119 | feature.popup = z; | 119 | feature.popup = z; |
---|
120 | z.panMapIfOutOfView = true; | 120 | z.panMapIfOutOfView = true; |
---|
… | | … | |
---|
134 | ans.ans = JSON.parse(data); | 134 | ans.ans = JSON.parse(data); |
---|
135 | for(var i in ans.ans) | 135 | for(var i in ans.ans) |
---|
136 | { | 136 | { |
---|
| | 137 | ans.count+=1; |
---|
137 | makeBoxes(ans.ans[i]); | 138 | makeBoxes(ans.ans[i]); |
---|
138 | } | 139 | } |
---|
139 | | 140 | |
---|
… | | … | |
---|
242 | function makeBoxes(x) | 242 | function makeBoxes(x) |
---|
243 | { | 243 | { |
---|
244 | | 244 | |
---|
245 | box4 = new OpenLayers.Layer.Vector( "Tags"); | | box4 = new OpenLayers.Layer.Vector( "Tags"); |
---|
246 | bounds = new OpenLayers.Bounds(x['left'], x['bottom'], x['right'], x['top']); | 245 | bounds = new OpenLayers.Bounds(x['left'], x['bottom'], x['right'], x['top']); |
---|
247 | box = new OpenLayers.Feature.Vector(bounds.toGeometry()); | 246 | box = new OpenLayers.Feature.Vector(bounds.toGeometry()); |
---|
248 | box4.addFeatures(box); | | box4.addFeatures(box); |
---|
249 | map.addLayer(box4); | | map.addLayer(box4); |
---|
| | 247 | box3.addFeatures(box); | 250 | addLabel(x['left'],x['top'],x['name']); | 248 | addLabel(x['left'],x['top'],x['name']); |
---|
251 | } | 249 | } |
---|
252 | function onmouse(data){ | | function onmouse(data){ |
---|
253 | console.log(data); | | console.log(data); |
---|
254 | } | | } |
---|
| | 250 | // function onmouse(data){ | | | 251 | // console.log(data); |
---|
| | 252 | // } |
---|
255 | function myfeatureadded(myObj) | 253 | function myfeatureadded(myObj) |
---|
256 | { | 254 | { |
---|
257 | var renderer = OpenLayers.Util.getParameters(window.location.href).renderer; | 255 | var renderer = OpenLayers.Util.getParameters(window.location.href).renderer; |
---|
… | | … | |
---|
288 | favColor: 'blue', | 288 | favColor: 'blue', |
---|
289 | }; | 289 | }; |
---|
290 | labelFeature.attributes['name'] = prompt("Enter a name"); | 290 | labelFeature.attributes['name'] = prompt("Enter a name"); |
---|
291 | console.log(labelFeature.attributes['name']); | | console.log(labelFeature.attributes['name']); |
---|
292 | if(labelFeature.attributes['name']) | 291 | if(labelFeature.attributes['name']) |
---|
293 | { | 292 | { |
---|
294 | console.log(myObj.feature.geometry.bounds.top); //Use this to get the bounds. | | console.log(myObj.feature.geometry.bounds.top); //Use this to get the bounds. |
---|
295 | topValue = myObj.feature.geometry.bounds.top; | 293 | topValue = myObj.feature.geometry.bounds.top; |
---|
296 | bottom = myObj.feature.geometry.bounds.bottom; | 294 | bottom = myObj.feature.geometry.bounds.bottom; |
---|
297 | left = myObj.feature.geometry.bounds.left; | 295 | left = myObj.feature.geometry.bounds.left; |
---|
… | | … | |
---|
369 | onresize=function(){ resize();}; | 369 | onresize=function(){ resize();}; |
---|
370 | function publish() | 370 | function publish() |
---|
371 | { | 371 | { |
---|
372 | console.log(myJSON); | | console.log(myJSON); |
---|
373 | $.post("http://192.168.100.56:82/submit", JSON.stringify(myJSON), function(data) | 372 | $.post("http://192.168.100.56:82/submit", JSON.stringify(myJSON), function(data) |
---|
374 | { | 373 | { |
---|
375 | alert(data); | | alert(data); |
---|
| | 374 | alert("Posted"); | 376 | } | 375 | } |
---|
377 | ); | 376 | ); |
---|
378 | } | 377 | } |
---|
| | | | 42 | attribs["character"] = $("#character-value").text(); | 42 | attribs["character"] = $("#character-value").text(); |
---|
43 | attribs["material"] = $("#material-value").text(); | 43 | attribs["material"] = $("#material-value").text(); |
---|
44 | myJSON.push(attribs); | 44 | myJSON.push(attribs); |
---|
45 | $("#publish").attr("disbaled", false); | | $("#publish").attr("disbaled", false); |
---|
| | 45 | $("#publish").attr("disabled", false); | 46 | } | 46 | } |
---|
47 | </script> | 47 | </script> |
---|
48 | </head> | 48 | </head> |
---|
| | | | | | 1 | import json |
---|
| | 2 | import pymongo |
---|
| | 3 | def application(environ, start_response): |
---|
| | 4 | status = '200 OK' |
---|
| | 5 | response_headers = [('Content-type', 'text/html'),('Access-Control-Allow-Origin', '*')] |
---|
| | 6 | start_response(status, response_headers) |
---|
| | 7 | recieved = environ['wsgi.input'].read(int(environ['CONTENT_LENGTH'])) |
---|
| | 8 | c = pymongo.Connection() |
---|
| | 9 | db = c['mural'] |
---|
| | 10 | coll = db['data'] |
---|
| | 11 | d = json.loads(recieved) |
---|
| | 12 | for i in d: |
---|
| | 13 | coll.insert(d) |
---|
| | 14 | return 'ok' |
---|