Permalink
Browse files

version demoed

last minute maps hack doesnt really work
this will each your kids
  • Loading branch information...
dgorissen committed Dec 4, 2011
1 parent d89692c commit 1dc93c5cb3fc30efa8c148a7d06c7eea37164007
Showing with 96 additions and 5 deletions.
  1. +3 −3 src/ngoq/rules.py
  2. +2 −2 src/ngoq/templates/base.html
  3. +84 −0 src/ngoq/templates/main.html
  4. +1 −0 src/ngoq/urls.py
  5. +6 −0 src/ngoq/views.py
View
@@ -53,9 +53,9 @@ def get_rules(self):
@lfu_cache()
def load_class_data():
class1 = []
- reader = csv.DictReader(open(os.path.join(settings.DATADIR,"ngoclass1.csv"), "rb"))
- for row in reader:
- class1.append(row)
+ #reader = csv.DictReader(open(os.path.join(settings.DATADIR,"ngoclass1.csv"), "rb"))
+ #for row in reader:
+ # class1.append(row)
class2 = []
reader = csv.DictReader(open(os.path.join(settings.DATADIR,"ngoclass2.csv"), "rb"))
@@ -26,7 +26,7 @@
<script type="text/javascript" src="http://twitter.github.com/bootstrap/1.4.0/bootstrap-dropdown.min.js"></script>
<script type="text/javascript" src="http://twitter.github.com/bootstrap/1.4.0/bootstrap-twipsy.min.js"></script>
<script type="text/javascript" src="http://twitter.github.com/bootstrap/1.4.0/bootstrap-popover.js"></script>
-
+ <script src="http://maps.google.com/maps/api/js?sensor=false" type="text/javascript"></script>
<script type="text/javascript" src="{{ STATIC_URL }}js/ngoq.js"></script>
<script type="text/javascript">
@@ -99,7 +99,7 @@
{% block footer %}
<div class="footer">
<footer>
- <p>
+ <p style="text-align:center">
-- RHOK Oxford 2011 --
</p>
</footer>
@@ -97,4 +97,88 @@ <h3>Records</h3>
</div>
+ <hr>
+
+ <div id="map" style="width: 500px; height: 400px; text-align:center"></div>
+
+ <script type="text/javascript">
+ //This is the entry
+function codeLocations(list, map) {
+ for (var i = 0; i < list.length; i++) {
+
+ var geocoder = new google.maps.Geocoder();
+ var geoOptions = {
+ address: list[i],
+ region: "NO"
+ };
+ geocoder.geocode(geoOptions, createGeocodeCallback(list[i], map));
+ }
+}
+
+function createGeocodeCallback(item, map) {
+ console.log("Generating geocode callback for " + item.location);
+ return function(results, status) {
+ if (status == google.maps.GeocoderStatus.OK) {
+ console.log("Geocoding " + item.location + " OK");
+ addMarker(map, item, results[0].geometry.location);
+ } else {
+ console.log("Geocode failed " + status);
+ }
+ }
+}
+
+function addMarker(map, item, location) {
+ console.log("Setting marker for " + item.location + " (location: " + location + ")");
+ var marker = new google.maps.Marker({ map : map, position : location});
+ marker.setTitle(item.title);
+ var infowindow = new google.maps.InfoWindow( {
+ content : item.body,
+ size : new google.maps.Size(100, 300)
+ });
+ new google.maps.event.addListener(marker, "click", function() {
+ infowindow.open(map, marker);
+ });
+}
+ $.get("locations",function(data){
+
+
+ var locations = [
+ 'Mumbai, India',
+ 'Calcutta,India',
+ 'Munnar,India',
+ 'Bangalore, India',
+ 'Delhi,India'
+ ];
+
+ //locations = data
+
+ var map = new google.maps.Map(document.getElementById('map'), {
+ zoom: 4,
+ center: new google.maps.LatLng(20.385825,79.892578),
+ mapTypeId: google.maps.MapTypeId.ROADMAP
+ });
+
+ codeLocations(locations,map);
+ var infowindow = new google.maps.InfoWindow();
+
+ var marker, i;
+
+ for (i = 0; i < locations.length; i++) {
+ marker = new google.maps.Marker({
+ position: new google.maps.LatLng(locations[i][1], locations[i][2]),
+ map: map
+ });
+
+ google.maps.event.addListener(marker, 'click', (function(marker, i) {
+ return function() {
+ infowindow.setContent(locations[i][0]);
+ infowindow.open(map, marker);
+ }
+ })(marker, i));
+ }
+
+ });
+
+ </script>
+
{% endblock %}
View
@@ -4,4 +4,5 @@
url(r'^$', 'ngoq.views.main', name='main'),
url(r'data$', 'ngoq.views.get_data_json', name='datajson'),
url(r'data/(?P<id>[a-zA-Z0-9_\-\\]+)$', 'ngoq.views.get_record_json', name='recjson'),
+ url(r'locations$', 'ngoq.views.locations', name='locations'),
)
View
@@ -74,6 +74,12 @@ def get_data_json(request):
data = load_data()
return HttpResponse(simplejson.dumps(data))
+def locations(request):
+ data = load_data()
+
+ d = [x["City"] + ",india" for x in data.values()]
+ return HttpResponse(simplejson.dumps(d[1:20]))
+
@lfu_cache()
def load_data():
data = {}

0 comments on commit 1dc93c5

Please sign in to comment.