Browse Source

Show ISPs on the map

Gu1 11 years ago
parent
commit
b7708e1448

BIN
ffdnispdb/static/img/marker.png


BIN
ffdnispdb/static/img/marker_ffdn.png


+ 25 - 0
ffdnispdb/static/js/site.js

@@ -58,6 +58,31 @@ function init_map() {
             map.removeLayer(hyb);
         }
     });
+
+
+    var icon = L.icon({
+        iconUrl: 'static/img/marker.png',
+
+        iconSize:     [14, 20], // size of the icon
+        shadowSize:   [14, 20], // size of the shadow
+        iconAnchor:   [7, 20], // point of the icon which will correspond to marker's location
+        popupAnchor:  [0, -20] // point from which the popup should open relative to the iconAnchor
+    });
+    var icon_ffdn = $.extend(true, {}, icon);
+    icon_ffdn['options']['iconUrl'] = 'static/img/marker_ffdn.png';
+
+    $.getJSON('/isp/map_data.json', function(data) {
+        $.each(data, function(k, isp) {
+            var marker = L.marker([isp['coordinates']['latitude'], isp['coordinates']['longitude']],
+                                  {'icon': isp.ffdn_member ? icon_ffdn : icon});
+
+            marker./*on('click', function() {
+                $.getJSON('/isp/'+isp.id+'/covered_areas.json', function(data) {
+                    alert(data);
+                });
+            }).*/bindPopup(isp.popup).addTo(map);
+        });
+    });
 }
 
 function change_input_num(li, new_num, reset=false) {

+ 6 - 0
ffdnispdb/templates/map_popup.html

@@ -0,0 +1,6 @@
+{% if isp.shortname -%}
+<strong>{{ isp.shortname }}</strong><br />
+{{ isp.name }}
+{% else -%}
+<strong>{{ isp.name }}</strong>
+{% endif %}

+ 27 - 1
ffdnispdb/views.py

@@ -28,6 +28,32 @@ def home():
 def project_list():
     return render_template('project_list.html', projects=ISP.query.filter_by(is_disabled=False))
 
+# this needs to be cached
+@app.route('/isp/map_data.json', methods=['GET'])
+def isp_map_data():
+    isps=ISP.query.filter_by(is_disabled=False)
+    data=[]
+    for isp in isps:
+        d=dict(isp.json)
+        for k in d.keys():
+            if k not in ('name', 'shortname', 'coordinates'):
+                del d[k]
+
+        d['id']=isp.id
+        d['ffdn_member']=isp.is_ffdn_member
+        d['popup']=render_template('map_popup.html', isp=isp)
+        data.append(d)
+
+    return json.dumps(data)
+
+
+@app.route('/isp/<projectid>/covered_areas.json', methods=['GET'])
+def isp_covered_areas(projectid):
+    p=ISP.query.filter_by(id=projectid, is_disabled=False).first()
+    if not p:
+        abort(404)
+    return json.dumps(p.json['coveredAreas'])
+
 
 @app.route('/isp/<projectid>/')
 def project(projectid):
@@ -271,7 +297,7 @@ def create_project_json_confirm():
         jdict=session['form_json']['jdict']
         isp=ISP()
         isp.name=jdict['name']
-        isp.shotname=jdict['shortname']
+        isp.shortname=jdict['shortname']
         isp.url=session['form_json']['url']
         isp.json=jdict
         del session['form_json']