Advertisement
Guest User

Untitled

a guest
Nov 20th, 2017
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.08 KB | None | 0 0
  1. from run import app
  2.  
  3. if __name__ == "__main__":
  4. app.run(threaded=True, debug=True)
  5.  
  6. Error on request:
  7. Traceback (most recent call last):
  8. File "/Library/Python/2.7/site-packages/werkzeug/serving.py", line 209, in run_wsgi
  9. execute(self.server.app)
  10. File "/Library/Python/2.7/site-packages/werkzeug/serving.py", line 200, in execute
  11. write(data)
  12. File "/Library/Python/2.7/site-packages/werkzeug/serving.py", line 175, in write
  13. self.send_header('Server', self.version_string())
  14. File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/BaseHTTPServer.py", line 401, in send_header
  15. self.wfile.write("%s: %srn" % (keyword, value))
  16. IOError: [Errno 32] Broken pipe
  17.  
  18. from flask import Flask, render_template
  19. from flask_cors import CORS
  20.  
  21. app = Flask(__name__)
  22. CORS(app)
  23. @app.route('/demo')
  24. def webMap():
  25. return render_template('demo3.html')
  26.  
  27. if __name__ == '__main__':
  28. app.config['DEBUG'] = True
  29. app.run(host='localhost', port=8090)
  30.  
  31. var map = L.map('map1').setView([51.506725, -0.076486], 12);
  32.  
  33. L.tileLayer('https://api.tiles.mapbox.com/v4/{id}/{z}/{x}/{y}.png?access_token={accessToken}', {
  34. attribution: 'Map data &copy; <a href="http://openstreetmap.org">OpenStreetMap</a> contributors, <a href="http://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>, Imagery © <a href="http://mapbox.com">Mapbox</a>',
  35. maxZoom: 18,
  36. id: 'mapbox.streets',
  37. accessToken: '*************************'
  38. }).addTo(map);
  39.  
  40.  
  41. //add start marker to map and delete old marker
  42. var startmarker = null;
  43.  
  44. map.on('click', function (e) {
  45. if (startmarker !== null) {
  46. map.removeLayer(startmarker);
  47. }
  48. startmarker = L.marker(e.latlng, {
  49. title: "Start Point",
  50. }).addTo(map);
  51. startcoords = e.latlng.lng.toString() + "&" + e.latlng.lat.toString();
  52. startmarker.bindPopup("Start " + startcoords);
  53. });
  54.  
  55.  
  56. //add end marker to map and delete old marker
  57.  
  58. var endmarker = null;
  59. map.on('contextmenu', function (e) {
  60. if (endmarker !== null) {
  61. map.removeLayer(endmarker);
  62. }
  63. endmarker = L.marker(e.latlng, {
  64. title: "End Point",
  65. }).addTo(map);
  66. endcoords = e.latlng.lng.toString() + "&" + e.latlng.lat.toString();
  67. endmarker.bindPopup("End " + endcoords);
  68. coords = startcoords+"&"+endcoords;
  69. });
  70.  
  71. // choose query type, click button & Ajax call to API server
  72.  
  73. $("#button").click(function() {
  74. var val = $('input[name=query]:checked').val()
  75. if (val == 'route') {
  76. stuff = $.ajax({
  77. url: "http://127.0.0.1:5000/route&"+coords,
  78. type: "GET",
  79. dataType: "json" ,
  80. })
  81. .done(function( json ) {
  82. alert(JSON.stringify(stuff)); // trying to JSON back will work out how to display it after I get some data returned
  83. })
  84. .fail(function( xhr, status, errorThrown ) {
  85. alert( "Sorry, there was a problem!");
  86. console.log( "Error: " + errorThrown );
  87. console.log( "Status: " + status );
  88. console.dir( xhr );
  89. })
  90. .always(function( xhr, status ) {
  91. alert( "The request is complete!" );
  92. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement