Added org_home_gmap function to the map JS for displaying the mentor-student map.
Patch by: Madhusudan.C.S and Merio Ferraro
Reviewed by: Lennard de Rijk
--- a/app/soc/content/js/map-090420.js Sun Apr 19 22:07:20 2009 +0000
+++ b/app/soc/content/js/map-090420.js Sun Apr 19 22:14:35 2009 +0000
@@ -173,3 +173,121 @@
}
};
+org_home_gmap = new function(){
+ // Global variables
+ var map;
+
+ // HTML div tag where map needs to be inserted
+ var map_div = "org_home_map";
+
+ // Geocoder object for obtaining locations from city/country
+ var geocoder = new GClientGeocoder();
+
+ // Lat/lng pairs stored for drawing polylines.
+ var student_lat = 0;
+ var student_lng = 0;
+ var mentor_lat = 0;
+ var mentor_lng = 0;
+
+ // Setup required icons
+ var base_icon = new GIcon();
+ base_icon.shadow = "http://www.google.com/mapfiles/shadow50.png";
+ base_icon.iconSize = new GSize(20, 34);
+ base_icon.shadowSize = new GSize(37, 34);
+ base_icon.iconAnchor = new GPoint(9, 34);
+ base_icon.infoWindowAnchor = new GPoint(9, 2);
+ base_icon.infoShadowAnchor = new GPoint(18, 25);
+ var student_icon = new GIcon(base_icon);
+ student_icon.image = "http://www.google.com/mapfiles/marker.png";
+ var mentor_icon = new GIcon(base_icon);
+ mentor_icon.image = "/soc/content/images/mentor-marker.png";
+
+ // Mark mentor marker if he has published the location and call
+ // drawStudentMarker function.
+ function drawMarkers(map_elem) {
+ function iterateStudents(students, mentor_name, mentor_published) {
+ for (student in students) {
+ drawStudentMarker(students[student], mentor_name, mentor_published);
+ }
+ }
+ if (map_elem.type == 'mentor') {
+ geocoder.setBaseCountryCode(map_elem.ccTLD);
+ geocoder.getLatLng(
+ map_elem.city,
+ function(point) {
+ if (point) {
+ var marker = new GMarker(point, mentor_icon);
+ mentor_lat = marker.getPoint().lat();
+ mentor_lng = marker.getPoint().lng();
+ var html = "<strong>" + map_elem.name + "</strong><br> Mentor";
+ GEvent.addListener(marker, "click", function() {
+ marker.openInfoWindowHtml(html);
+ });
+ map.addOverlay(marker);
+ } else {
+ mentor_lat = null;
+ mentor_lng = null;
+ }
+ iterateStudents(map_elem.students, map_elem.name, true);
+ }
+ );
+ } else if (map_elem.type == 'none') {
+ drawStudentMarker(map_elem.student, map_elem.name, false);
+ }
+ }
+
+ // Mark student and enable a popup box upon click
+ function drawStudentMarker(student, mname, mentor_published) {
+ geocoder.setBaseCountryCode(student.ccTLD);
+ geocoder.getLatLng(
+ student.city,
+ function(point) {
+ if (point) {
+ var marker = new GMarker(point, student_icon);
+ var html = "<strong>" + student.name + "</strong><br>";
+ html += "<a href='"+ student.url + "'>" + student.summary + "</a><br>";
+ html += "Mentor: " + mname;
+ GEvent.addListener(marker, "click", function() {
+ marker.openInfoWindowHtml(html);
+ });
+ student_lat = marker.getPoint().lat();
+ student_lng = marker.getPoint().lng();
+ map.addOverlay(marker);
+ } else {
+ student_lat = null;
+ student_lng = null;
+ }
+ if (mentor_published) {
+ drawPolyLine();
+ }
+ }
+ );
+ }
+
+ // Draw a polyline between the student and his mentor
+ drawPolyLine = function() {
+ var polyline = new GPolyline([
+ new GLatLng(mentor_lat, mentor_lng),
+ new GLatLng(student_lat, student_lng)
+ ], "#ff0000", 3);
+ map.addOverlay(polyline);
+ }
+
+ // Map load function
+ this.map_load = function(map_data) {
+ // Check if browser is gmap compatible.
+ if (GBrowserIsCompatible()) {
+ // Create the map and add small controls
+ map = new GMap2(document.getElementById(map_div));
+ map.addControl(new GLargeMapControl());
+ map.addControl(new GMapTypeControl());
+
+ // Set map center and initial zoom level
+ map.setCenter(new GLatLng(0, 0), 1);
+
+ for (elem in map_data) {
+ drawMarkers(map_data[elem])
+ }
+ }
+ }
+};