Commit 5c78a2713049e5ce4c91c691972f635d2ae5d78b
- Diff rendering mode:
- inline
- side by side
fetch.py
(19 / 0)
  | |||
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) |
myVector.js
(50 / 12)
  | |||
12 | 12 | ]; | |
13 | 13 | var myJSON = []; | |
14 | 14 | var ans = { | |
15 | ans: [] | ||
15 | ans: [], | ||
16 | count: 0 | ||
17 | |||
16 | 18 | }; | |
17 | 19 | // avoid pink tiles | |
18 | 20 | OpenLayers.IMAGE_RELOAD_ATTEMPTS = 3; | |
… | … | ||
59 | 59 | }; | |
60 | 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 | 102 | z = new OpenLayers.Popup.FramedCloud( | |
63 | 103 | "test", | |
64 | 104 | feature.geometry.getBounds().getCenterLonLat(), | |
… | … | ||
114 | 114 | "test", | |
115 | 115 | new OpenLayers.LonLat(x, y), // Always should be at the center of the map, not the center of viewport. | |
116 | 116 | new OpenLayers.Size(640,480), | |
117 | "<pre>"+JSON.stringify(json,null,'\t')+"</pre>" | ||
117 | "<pre>"+JSON.stringify(json,null,' ')+"</pre>" | ||
118 | 118 | ,null,true); | |
119 | 119 | feature.popup = z; | |
120 | 120 | z.panMapIfOutOfView = true; | |
… | … | ||
134 | 134 | ans.ans = JSON.parse(data); | |
135 | 135 | for(var i in ans.ans) | |
136 | 136 | { | |
137 | ans.count+=1; | ||
137 | 138 | makeBoxes(ans.ans[i]); | |
138 | 139 | } | |
139 | 140 | ||
… | … | ||
242 | 242 | function makeBoxes(x) | |
243 | 243 | { | |
244 | 244 | ||
245 | box4 = new OpenLayers.Layer.Vector( "Tags"); | ||
246 | 245 | bounds = new OpenLayers.Bounds(x['left'], x['bottom'], x['right'], x['top']); | |
247 | 246 | box = new OpenLayers.Feature.Vector(bounds.toGeometry()); | |
248 | box4.addFeatures(box); | ||
249 | map.addLayer(box4); | ||
247 | box3.addFeatures(box); | ||
250 | 248 | addLabel(x['left'],x['top'],x['name']); | |
251 | 249 | } | |
252 | function onmouse(data){ | ||
253 | console.log(data); | ||
254 | } | ||
250 | // function onmouse(data){ | ||
251 | // console.log(data); | ||
252 | // } | ||
255 | 253 | function myfeatureadded(myObj) | |
256 | 254 | { | |
257 | 255 | var renderer = OpenLayers.Util.getParameters(window.location.href).renderer; | |
… | … | ||
288 | 288 | favColor: 'blue', | |
289 | 289 | }; | |
290 | 290 | labelFeature.attributes['name'] = prompt("Enter a name"); | |
291 | console.log(labelFeature.attributes['name']); | ||
292 | 291 | if(labelFeature.attributes['name']) | |
293 | 292 | { | |
294 | console.log(myObj.feature.geometry.bounds.top); //Use this to get the bounds. | ||
295 | 293 | topValue = myObj.feature.geometry.bounds.top; | |
296 | 294 | bottom = myObj.feature.geometry.bounds.bottom; | |
297 | 295 | left = myObj.feature.geometry.bounds.left; | |
… | … | ||
369 | 369 | onresize=function(){ resize();}; | |
370 | 370 | function publish() | |
371 | 371 | { | |
372 | console.log(myJSON); | ||
373 | 372 | $.post("http://192.168.100.56:82/submit", JSON.stringify(myJSON), function(data) | |
374 | 373 | { | |
375 | alert(data); | ||
374 | alert("Posted"); | ||
376 | 375 | } | |
377 | 376 | ); | |
378 | 377 | } |
openlayers.html
(1 / 1)
  | |||
42 | 42 | attribs["character"] = $("#character-value").text(); | |
43 | 43 | attribs["material"] = $("#material-value").text(); | |
44 | 44 | myJSON.push(attribs); | |
45 | $("#publish").attr("disbaled", false); | ||
45 | $("#publish").attr("disabled", false); | ||
46 | 46 | } | |
47 | 47 | </script> | |
48 | 48 | </head> |
submit.wsgi
(14 / 0)
  | |||
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' |