Advertisement
Guest User

Untitled

a guest
Jan 11th, 2016
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.60 KB | None | 0 0
  1. {% load leaflet_tags %}
  2. <html>
  3. <head>
  4. {% leaflet_js %}
  5. {% leaflet_css %}
  6. <!-- <script src="OpenLayers.js" type="text/javascript"></script> -->
  7.  
  8. <style>
  9. header {
  10. background-color:black;
  11. color:white;
  12. text-align:center;
  13. padding:5px;
  14. }
  15. nav {
  16. line-height:30px;
  17. background-color:#eeeeee;
  18. height:503px;
  19. width:240px;
  20. float:left;
  21. padding:5px;
  22. }
  23. section {
  24. width:579px;
  25. float:left;
  26. padding:10px;
  27. height:494px;
  28. }
  29. footer {
  30. background-color:black;
  31. color:white;
  32. clear:both;
  33. text-align:center;
  34. padding:5px;
  35. }
  36. </style>
  37. </head>
  38. <body>
  39. {% leaflet_map "main" callback="main_map_init" %}
  40. <header>
  41. <h2>Plant Functional Types</h2>
  42. </header>
  43. <nav>
  44. <a href="{% url 'geojson_provinces'%}"><button type="button" onclick=>Actual plant functional type</button>
  45. <button type="button" >Potential plant functional type</button>
  46. <button type="button" > Plant functional types likely to change</button>
  47. <a href="{% url 'add_multiple_accounts' %}"><button type="button" > Upload species data</button></a>
  48. </nav>
  49.  
  50. <div id="map" class="map" style="width:1080px; height:512px;float:right;" ></div>
  51. <script type="text/javascript">
  52. function main_map_init (map, options) {
  53.  
  54. var dataurl = '{% url "data" %}';
  55. // Download GeoJSON via Ajax
  56. $.getJSON(dataurl, function (data) {
  57. // Add GeoJSON layer
  58. L.geoJson(data).addTo(map);
  59. });
  60.  
  61. }
  62.  
  63. </script>
  64. <footer>
  65. </footer>
  66. </body>
  67. </html>
  68.  
  69. def geojson_provinces(request):
  70. conn = psycopg2.connect(dbname="geodjango",host='localhost',user='postgres', password='postgres', port=5433)
  71. dict_cur = conn.cursor(cursor_factory=psycopg2.extras.DictCursor)
  72. cur=conn.cursor()
  73. res = dict_cur.execute("SELECT ST_AsGeoJson(geom) AS json FROM pft_pft LIMIT 10;")
  74.  
  75. points=dict_cur.fetchall()
  76. print (points)
  77. json_res = []
  78. for row in points:
  79. json_obj = row['json']
  80. print (json_obj)
  81. json_res.append(json_obj)
  82. print(json_res)
  83. #json = simplejson.dumps(data)
  84.  
  85. dict_cur.close()
  86. data = {'geojson': mark_safe(json_res)}
  87. return render(request, 'map.html', data)
  88.  
  89. url(r'^data/$', GeoJSONLayerView.as_view(model=PFT), name='data'),
  90.  
  91. class PFT(models.Model):
  92. species=models.CharField(max_length=50)
  93. # GeoDjango-specific: a geometry field (MultiPolygonField)
  94. geom = models.PointField(srid=4326)
  95. objects=models.GeoManager()
  96. # Returns the string representation of the model.
  97. def __str__(self): # __unicode__ on Python 2
  98. return '%s %s %s' % (self.species, self.geom.x, self.geom.y)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement