app/soc/content/js/map-090420.js
author Pawel Solyga <Pawel.Solyga@gmail.com>
Tue, 28 Apr 2009 12:47:06 +0200
changeset 2282 47a7eb2704c2
parent 2253 ab216123bee7
child 2390 723dfa4811e8
permissions -rw-r--r--
Remove E1103 and E1101 errors from ignore list in pylintrc file. We are going to use "# pylint disable-msg=E1103" comments in the source file itself to ignore false-positives. Patch by: Pawel Solyga Reviewed by: to-be-reviewed
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1152
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
     1
role_profile_gmap = new function(){
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
     2
  // Create global variables
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
     3
  var map;
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
     4
  var marker;
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
     5
  var geocoder;
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
     6
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
     7
  // The following strings can be customized to reflect ids in the page. 
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
     8
  // You can also add or remove fields used for GMap Geocoding in 
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
     9
  // the JSON address object
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    10
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    11
  var current_lat = 0;
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    12
  var current_lng = 0;
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    13
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    14
  // Two different levels for zoom: Starting one and an inner that 
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    15
  // is used when showing the map if lat and lon page fields are set
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    16
  var world_zoom = 0;
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    17
  var country_zoom = 4;
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    18
  var state_zoom = 6;
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    19
  var city_zoom = 10;
1759
94b64c07f7ce Revert r2376 since it's not needed as discussed in Issue 188.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 1720
diff changeset
    20
  var address_zoom = 13;
1152
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    21
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    22
  // Do not add a starting # as this JQuery selector seems 
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    23
  // incompatible with GMap API
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    24
  var map_div = "role_profile_map";
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    25
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    26
  var field_lat = "#id_latitude";
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    27
  var field_lng = "#id_longitude";
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    28
  // Need to save old values to avoid unwanted updating 
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    29
  // of lat and lot if marker dragged and blur another time an address field
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    30
  var address = {
1759
94b64c07f7ce Revert r2376 since it's not needed as discussed in Issue 188.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 1720
diff changeset
    31
    street: {
94b64c07f7ce Revert r2376 since it's not needed as discussed in Issue 188.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 1720
diff changeset
    32
      id: "#id_res_street",
94b64c07f7ce Revert r2376 since it's not needed as discussed in Issue 188.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 1720
diff changeset
    33
      old_value: ""
94b64c07f7ce Revert r2376 since it's not needed as discussed in Issue 188.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 1720
diff changeset
    34
    },
1152
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    35
    city: {
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    36
      id: "#id_res_city",
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    37
      old_value: ""
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    38
    },
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    39
    state: {
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    40
      id: "#id_res_state",
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    41
      old_value: ""
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    42
    },
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    43
    country: {
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    44
      id: "#id_res_country",
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    45
      old_value: ""
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    46
    },
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    47
    postalcode: {
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    48
      id: "#id_res_postalcode",
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    49
      old_value: ""
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    50
    }
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    51
  }
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    52
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    53
  // Save current address fields in the JSON Object
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    54
  function saveOldAddress() {
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    55
    for (var a in address) {
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    56
      address[a].old_value = $(address[a].id).val();
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    57
    }
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    58
  }
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    59
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    60
  // Return true if the user has edited address fields
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    61
  function isNewAddress() {
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    62
    for (var a in address) {
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    63
      if ($(address[a].id).val() != address[a].old_value) return true;
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    64
    }
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    65
    return false;
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    66
  }
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    67
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    68
  // Write saved lat and lng values to page fields
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    69
  function setLatLngFields() {
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    70
    $(field_lat).val(current_lat);
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    71
    $(field_lng).val(current_lng);
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    72
  }
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    73
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    74
  // Read lat and lng fields and store them
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    75
  function readLatLngFields() {
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    76
    current_lat = $(field_lat).val();
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    77
    current_lng = $(field_lng).val();
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    78
  }
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    79
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    80
  // This function reads address fields, merge them and uses 
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    81
  // GMap API geocoding to find the first hit
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    82
  // Using geocoding http://code.google.com/intl/it-IT/apis/maps/documentation/services.html#Geocoding
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    83
  function calculateAddress() {
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    84
    // If the user has really edited address fields...
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    85
    if (isNewAddress()) {
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    86
      // Merge address fields
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    87
      var address_string = "";
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    88
      for (var a in address) {
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    89
        address_string+=$(address[a].id).val();
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    90
        if (a!=address.length-1) {address_string+=","};
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    91
      }
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    92
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    93
      // Ask GMap API for geocoding
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    94
      geocoder.getLatLng(
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    95
        address_string,
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    96
        function(point) {
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    97
          // If a point is found
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    98
          if (point) {
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    99
            // Save the current address in the JSON object
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   100
            saveOldAddress();
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   101
            // Set the new zoom, map center and marker coords
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   102
            var zoom_set = world_zoom;
1759
94b64c07f7ce Revert r2376 since it's not needed as discussed in Issue 188.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 1720
diff changeset
   103
            if ($(address.street.id).val()!="") zoom_set = address_zoom;
1152
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   104
            else if ($(address.city.id).val()!="") zoom_set = city_zoom;
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   105
            else if ($(address.state.id).val()!="") zoom_set = state_zoom;
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   106
            else if ($(address.country.id).val()!="") zoom_set = country_zoom;
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   107
            map.setCenter(point, zoom_set);
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   108
            marker.setPoint(point);
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   109
            map.clearOverlays();
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   110
            map.addOverlay(marker);
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   111
            // Save point coords in local variables and then update 
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   112
            // the page lat/lng fields
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   113
            current_lat = point.lat();
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   114
            current_lng = point.lng();
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   115
            setLatLngFields();
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   116
          }
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   117
        }
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   118
      );
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   119
    }
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   120
  }
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   121
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   122
  // Public function to load the map
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   123
  this.map_load = function() {
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   124
    // All can happen only if there is gmap compatible browser.
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   125
    // TODO: Fallback in case the browser is not compatible
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   126
    if (GBrowserIsCompatible()) {
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   127
      // Save the address fields. This is useful if the page is being edited 
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   128
      // to not update blindly the lat/lng fields with GMap geocoding if 
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   129
      // blurring an address field
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   130
      saveOldAddress();
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   131
      var starting_point;
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   132
      var zoom_selected = world_zoom;
1719
328db0964f86 Show the marker for the Google maps plug in by default.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1152
diff changeset
   133
      var show_marker = true;
1152
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   134
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   135
      // Create the map and add small controls
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   136
      map = new GMap2(document.getElementById(map_div));
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   137
      map.addControl(new GSmallMapControl());
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   138
      map.addControl(new GMapTypeControl());
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   139
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   140
      // Instantiate a global geocoder for future use
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   141
      geocoder = new GClientGeocoder();
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   142
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   143
      // If lat and lng fields are not void (the page is being edited) then 
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   144
      // update the starting coords, modify the zoom level and tells following 
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   145
      // code to show the marker
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   146
      if ($(field_lat).val()!="" && $(field_lng).val()!="") {
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   147
        readLatLngFields();
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   148
        zoom_selected = address_zoom;
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   149
        show_marker = true;
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   150
      }
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   151
      
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   152
      // Set map center, marker coords and show it if this is an editing
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   153
      starting_point = new GLatLng(current_lat,current_lng);
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   154
      map.setCenter(starting_point, zoom_selected);
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   155
      marker = new GMarker(starting_point, {draggable:true});
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   156
      if (show_marker) map.addOverlay(marker);
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   157
      
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   158
      // Adds a new event listener to geocode the address when an address 
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   159
      // field is blurred
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   160
      for (var a in address) {
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   161
        $(address[a].id).blur(calculateAddress);
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   162
      }
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   163
      
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   164
      // Adds a new event listener: if the marker has been dragged around...
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   165
      GEvent.addListener(marker, "dragend", function() {
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   166
        // Update internal variables with current marker coords...
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   167
        current_lat = marker.getPoint().lat();
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   168
        current_lng = marker.getPoint().lng();
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   169
        // ...and set page fields accordingly
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   170
        setLatLngFields();
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   171
      });
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   172
    }
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   173
  }
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   174
};
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   175
2253
ab216123bee7 Added org_home_gmap function to the map JS for displaying the mentor-student map.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2251
diff changeset
   176
org_home_gmap = new function(){
ab216123bee7 Added org_home_gmap function to the map JS for displaying the mentor-student map.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2251
diff changeset
   177
  // Global variables
ab216123bee7 Added org_home_gmap function to the map JS for displaying the mentor-student map.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2251
diff changeset
   178
  var map;
ab216123bee7 Added org_home_gmap function to the map JS for displaying the mentor-student map.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2251
diff changeset
   179
ab216123bee7 Added org_home_gmap function to the map JS for displaying the mentor-student map.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2251
diff changeset
   180
  // HTML div tag where map needs to be inserted
ab216123bee7 Added org_home_gmap function to the map JS for displaying the mentor-student map.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2251
diff changeset
   181
  var map_div = "org_home_map";
ab216123bee7 Added org_home_gmap function to the map JS for displaying the mentor-student map.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2251
diff changeset
   182
  
ab216123bee7 Added org_home_gmap function to the map JS for displaying the mentor-student map.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2251
diff changeset
   183
  // Geocoder object for obtaining locations from city/country
ab216123bee7 Added org_home_gmap function to the map JS for displaying the mentor-student map.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2251
diff changeset
   184
  var geocoder = new GClientGeocoder();
ab216123bee7 Added org_home_gmap function to the map JS for displaying the mentor-student map.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2251
diff changeset
   185
  
ab216123bee7 Added org_home_gmap function to the map JS for displaying the mentor-student map.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2251
diff changeset
   186
  // Lat/lng pairs stored for drawing polylines.
ab216123bee7 Added org_home_gmap function to the map JS for displaying the mentor-student map.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2251
diff changeset
   187
  var student_lat = 0;
ab216123bee7 Added org_home_gmap function to the map JS for displaying the mentor-student map.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2251
diff changeset
   188
  var student_lng = 0;
ab216123bee7 Added org_home_gmap function to the map JS for displaying the mentor-student map.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2251
diff changeset
   189
  var mentor_lat = 0;
ab216123bee7 Added org_home_gmap function to the map JS for displaying the mentor-student map.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2251
diff changeset
   190
  var mentor_lng = 0;
ab216123bee7 Added org_home_gmap function to the map JS for displaying the mentor-student map.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2251
diff changeset
   191
ab216123bee7 Added org_home_gmap function to the map JS for displaying the mentor-student map.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2251
diff changeset
   192
  // Setup required icons
ab216123bee7 Added org_home_gmap function to the map JS for displaying the mentor-student map.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2251
diff changeset
   193
  var base_icon = new GIcon();
ab216123bee7 Added org_home_gmap function to the map JS for displaying the mentor-student map.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2251
diff changeset
   194
  base_icon.shadow = "http://www.google.com/mapfiles/shadow50.png";
ab216123bee7 Added org_home_gmap function to the map JS for displaying the mentor-student map.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2251
diff changeset
   195
  base_icon.iconSize = new GSize(20, 34);
ab216123bee7 Added org_home_gmap function to the map JS for displaying the mentor-student map.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2251
diff changeset
   196
  base_icon.shadowSize = new GSize(37, 34);
ab216123bee7 Added org_home_gmap function to the map JS for displaying the mentor-student map.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2251
diff changeset
   197
  base_icon.iconAnchor = new GPoint(9, 34);
ab216123bee7 Added org_home_gmap function to the map JS for displaying the mentor-student map.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2251
diff changeset
   198
  base_icon.infoWindowAnchor = new GPoint(9, 2);
ab216123bee7 Added org_home_gmap function to the map JS for displaying the mentor-student map.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2251
diff changeset
   199
  base_icon.infoShadowAnchor = new GPoint(18, 25);
ab216123bee7 Added org_home_gmap function to the map JS for displaying the mentor-student map.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2251
diff changeset
   200
  var student_icon = new GIcon(base_icon);
ab216123bee7 Added org_home_gmap function to the map JS for displaying the mentor-student map.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2251
diff changeset
   201
  student_icon.image = "http://www.google.com/mapfiles/marker.png";
ab216123bee7 Added org_home_gmap function to the map JS for displaying the mentor-student map.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2251
diff changeset
   202
  var mentor_icon = new GIcon(base_icon);
ab216123bee7 Added org_home_gmap function to the map JS for displaying the mentor-student map.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2251
diff changeset
   203
  mentor_icon.image = "/soc/content/images/mentor-marker.png";
ab216123bee7 Added org_home_gmap function to the map JS for displaying the mentor-student map.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2251
diff changeset
   204
ab216123bee7 Added org_home_gmap function to the map JS for displaying the mentor-student map.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2251
diff changeset
   205
  // Mark mentor marker if he has published the location and call 
ab216123bee7 Added org_home_gmap function to the map JS for displaying the mentor-student map.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2251
diff changeset
   206
  // drawStudentMarker function.
ab216123bee7 Added org_home_gmap function to the map JS for displaying the mentor-student map.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2251
diff changeset
   207
  function drawMarkers(map_elem) {
ab216123bee7 Added org_home_gmap function to the map JS for displaying the mentor-student map.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2251
diff changeset
   208
    function iterateStudents(students, mentor_name, mentor_published) {
ab216123bee7 Added org_home_gmap function to the map JS for displaying the mentor-student map.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2251
diff changeset
   209
      for (student in students) {
ab216123bee7 Added org_home_gmap function to the map JS for displaying the mentor-student map.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2251
diff changeset
   210
        drawStudentMarker(students[student], mentor_name, mentor_published);
ab216123bee7 Added org_home_gmap function to the map JS for displaying the mentor-student map.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2251
diff changeset
   211
      }
ab216123bee7 Added org_home_gmap function to the map JS for displaying the mentor-student map.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2251
diff changeset
   212
    }
ab216123bee7 Added org_home_gmap function to the map JS for displaying the mentor-student map.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2251
diff changeset
   213
    if (map_elem.type == 'mentor') {
ab216123bee7 Added org_home_gmap function to the map JS for displaying the mentor-student map.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2251
diff changeset
   214
      geocoder.setBaseCountryCode(map_elem.ccTLD);
ab216123bee7 Added org_home_gmap function to the map JS for displaying the mentor-student map.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2251
diff changeset
   215
      geocoder.getLatLng(
ab216123bee7 Added org_home_gmap function to the map JS for displaying the mentor-student map.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2251
diff changeset
   216
        map_elem.city,
ab216123bee7 Added org_home_gmap function to the map JS for displaying the mentor-student map.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2251
diff changeset
   217
        function(point) {
ab216123bee7 Added org_home_gmap function to the map JS for displaying the mentor-student map.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2251
diff changeset
   218
          if (point) {
ab216123bee7 Added org_home_gmap function to the map JS for displaying the mentor-student map.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2251
diff changeset
   219
            var marker = new GMarker(point, mentor_icon);
ab216123bee7 Added org_home_gmap function to the map JS for displaying the mentor-student map.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2251
diff changeset
   220
            mentor_lat = marker.getPoint().lat();
ab216123bee7 Added org_home_gmap function to the map JS for displaying the mentor-student map.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2251
diff changeset
   221
            mentor_lng = marker.getPoint().lng();
ab216123bee7 Added org_home_gmap function to the map JS for displaying the mentor-student map.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2251
diff changeset
   222
            var html = "<strong>" + map_elem.name + "</strong><br> Mentor";
ab216123bee7 Added org_home_gmap function to the map JS for displaying the mentor-student map.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2251
diff changeset
   223
            GEvent.addListener(marker, "click", function() {
ab216123bee7 Added org_home_gmap function to the map JS for displaying the mentor-student map.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2251
diff changeset
   224
                 marker.openInfoWindowHtml(html);
ab216123bee7 Added org_home_gmap function to the map JS for displaying the mentor-student map.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2251
diff changeset
   225
            });
ab216123bee7 Added org_home_gmap function to the map JS for displaying the mentor-student map.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2251
diff changeset
   226
            map.addOverlay(marker);
ab216123bee7 Added org_home_gmap function to the map JS for displaying the mentor-student map.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2251
diff changeset
   227
          } else {
ab216123bee7 Added org_home_gmap function to the map JS for displaying the mentor-student map.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2251
diff changeset
   228
            mentor_lat = null;
ab216123bee7 Added org_home_gmap function to the map JS for displaying the mentor-student map.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2251
diff changeset
   229
            mentor_lng = null;
ab216123bee7 Added org_home_gmap function to the map JS for displaying the mentor-student map.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2251
diff changeset
   230
          }
ab216123bee7 Added org_home_gmap function to the map JS for displaying the mentor-student map.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2251
diff changeset
   231
          iterateStudents(map_elem.students, map_elem.name, true);
ab216123bee7 Added org_home_gmap function to the map JS for displaying the mentor-student map.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2251
diff changeset
   232
        }
ab216123bee7 Added org_home_gmap function to the map JS for displaying the mentor-student map.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2251
diff changeset
   233
      );
ab216123bee7 Added org_home_gmap function to the map JS for displaying the mentor-student map.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2251
diff changeset
   234
    } else if (map_elem.type == 'none') {
ab216123bee7 Added org_home_gmap function to the map JS for displaying the mentor-student map.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2251
diff changeset
   235
      drawStudentMarker(map_elem.student, map_elem.name, false);
ab216123bee7 Added org_home_gmap function to the map JS for displaying the mentor-student map.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2251
diff changeset
   236
    }
ab216123bee7 Added org_home_gmap function to the map JS for displaying the mentor-student map.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2251
diff changeset
   237
  }
ab216123bee7 Added org_home_gmap function to the map JS for displaying the mentor-student map.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2251
diff changeset
   238
ab216123bee7 Added org_home_gmap function to the map JS for displaying the mentor-student map.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2251
diff changeset
   239
  // Mark student and enable a popup box upon click
ab216123bee7 Added org_home_gmap function to the map JS for displaying the mentor-student map.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2251
diff changeset
   240
  function drawStudentMarker(student, mname, mentor_published) {
ab216123bee7 Added org_home_gmap function to the map JS for displaying the mentor-student map.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2251
diff changeset
   241
    geocoder.setBaseCountryCode(student.ccTLD);
ab216123bee7 Added org_home_gmap function to the map JS for displaying the mentor-student map.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2251
diff changeset
   242
    geocoder.getLatLng(
ab216123bee7 Added org_home_gmap function to the map JS for displaying the mentor-student map.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2251
diff changeset
   243
      student.city,
ab216123bee7 Added org_home_gmap function to the map JS for displaying the mentor-student map.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2251
diff changeset
   244
      function(point) {
ab216123bee7 Added org_home_gmap function to the map JS for displaying the mentor-student map.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2251
diff changeset
   245
        if (point) {
ab216123bee7 Added org_home_gmap function to the map JS for displaying the mentor-student map.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2251
diff changeset
   246
          var marker = new GMarker(point, student_icon);
ab216123bee7 Added org_home_gmap function to the map JS for displaying the mentor-student map.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2251
diff changeset
   247
          var html = "<strong>" + student.name + "</strong><br>";
ab216123bee7 Added org_home_gmap function to the map JS for displaying the mentor-student map.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2251
diff changeset
   248
          html += "<a href='"+ student.url + "'>" + student.summary + "</a><br>";
ab216123bee7 Added org_home_gmap function to the map JS for displaying the mentor-student map.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2251
diff changeset
   249
          html += "Mentor: " + mname;
ab216123bee7 Added org_home_gmap function to the map JS for displaying the mentor-student map.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2251
diff changeset
   250
          GEvent.addListener(marker, "click", function() {
ab216123bee7 Added org_home_gmap function to the map JS for displaying the mentor-student map.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2251
diff changeset
   251
            marker.openInfoWindowHtml(html);
ab216123bee7 Added org_home_gmap function to the map JS for displaying the mentor-student map.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2251
diff changeset
   252
          });
ab216123bee7 Added org_home_gmap function to the map JS for displaying the mentor-student map.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2251
diff changeset
   253
          student_lat = marker.getPoint().lat();
ab216123bee7 Added org_home_gmap function to the map JS for displaying the mentor-student map.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2251
diff changeset
   254
          student_lng = marker.getPoint().lng();
ab216123bee7 Added org_home_gmap function to the map JS for displaying the mentor-student map.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2251
diff changeset
   255
          map.addOverlay(marker);
ab216123bee7 Added org_home_gmap function to the map JS for displaying the mentor-student map.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2251
diff changeset
   256
        } else {
ab216123bee7 Added org_home_gmap function to the map JS for displaying the mentor-student map.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2251
diff changeset
   257
          student_lat = null;
ab216123bee7 Added org_home_gmap function to the map JS for displaying the mentor-student map.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2251
diff changeset
   258
          student_lng = null;
ab216123bee7 Added org_home_gmap function to the map JS for displaying the mentor-student map.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2251
diff changeset
   259
        }
ab216123bee7 Added org_home_gmap function to the map JS for displaying the mentor-student map.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2251
diff changeset
   260
        if (mentor_published) {
ab216123bee7 Added org_home_gmap function to the map JS for displaying the mentor-student map.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2251
diff changeset
   261
          drawPolyLine();
ab216123bee7 Added org_home_gmap function to the map JS for displaying the mentor-student map.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2251
diff changeset
   262
        }
ab216123bee7 Added org_home_gmap function to the map JS for displaying the mentor-student map.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2251
diff changeset
   263
      }
ab216123bee7 Added org_home_gmap function to the map JS for displaying the mentor-student map.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2251
diff changeset
   264
    );
ab216123bee7 Added org_home_gmap function to the map JS for displaying the mentor-student map.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2251
diff changeset
   265
  }
ab216123bee7 Added org_home_gmap function to the map JS for displaying the mentor-student map.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2251
diff changeset
   266
ab216123bee7 Added org_home_gmap function to the map JS for displaying the mentor-student map.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2251
diff changeset
   267
  // Draw a polyline between the student and his mentor
ab216123bee7 Added org_home_gmap function to the map JS for displaying the mentor-student map.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2251
diff changeset
   268
  drawPolyLine = function() {
ab216123bee7 Added org_home_gmap function to the map JS for displaying the mentor-student map.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2251
diff changeset
   269
    var polyline = new GPolyline([
ab216123bee7 Added org_home_gmap function to the map JS for displaying the mentor-student map.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2251
diff changeset
   270
      new GLatLng(mentor_lat, mentor_lng),
ab216123bee7 Added org_home_gmap function to the map JS for displaying the mentor-student map.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2251
diff changeset
   271
      new GLatLng(student_lat, student_lng)
ab216123bee7 Added org_home_gmap function to the map JS for displaying the mentor-student map.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2251
diff changeset
   272
      ], "#ff0000", 3);
ab216123bee7 Added org_home_gmap function to the map JS for displaying the mentor-student map.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2251
diff changeset
   273
    map.addOverlay(polyline);
ab216123bee7 Added org_home_gmap function to the map JS for displaying the mentor-student map.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2251
diff changeset
   274
  }
ab216123bee7 Added org_home_gmap function to the map JS for displaying the mentor-student map.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2251
diff changeset
   275
    
ab216123bee7 Added org_home_gmap function to the map JS for displaying the mentor-student map.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2251
diff changeset
   276
  // Map load function
ab216123bee7 Added org_home_gmap function to the map JS for displaying the mentor-student map.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2251
diff changeset
   277
  this.map_load = function(map_data) {
ab216123bee7 Added org_home_gmap function to the map JS for displaying the mentor-student map.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2251
diff changeset
   278
    // Check if browser is gmap compatible.
ab216123bee7 Added org_home_gmap function to the map JS for displaying the mentor-student map.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2251
diff changeset
   279
    if (GBrowserIsCompatible()) {
ab216123bee7 Added org_home_gmap function to the map JS for displaying the mentor-student map.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2251
diff changeset
   280
      // Create the map and add small controls
ab216123bee7 Added org_home_gmap function to the map JS for displaying the mentor-student map.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2251
diff changeset
   281
      map = new GMap2(document.getElementById(map_div));
ab216123bee7 Added org_home_gmap function to the map JS for displaying the mentor-student map.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2251
diff changeset
   282
      map.addControl(new GLargeMapControl());
ab216123bee7 Added org_home_gmap function to the map JS for displaying the mentor-student map.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2251
diff changeset
   283
        map.addControl(new GMapTypeControl());
ab216123bee7 Added org_home_gmap function to the map JS for displaying the mentor-student map.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2251
diff changeset
   284
      
ab216123bee7 Added org_home_gmap function to the map JS for displaying the mentor-student map.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2251
diff changeset
   285
      // Set map center and initial zoom level
ab216123bee7 Added org_home_gmap function to the map JS for displaying the mentor-student map.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2251
diff changeset
   286
      map.setCenter(new GLatLng(0, 0), 1);
ab216123bee7 Added org_home_gmap function to the map JS for displaying the mentor-student map.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2251
diff changeset
   287
      
ab216123bee7 Added org_home_gmap function to the map JS for displaying the mentor-student map.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2251
diff changeset
   288
      for (elem in map_data) {
ab216123bee7 Added org_home_gmap function to the map JS for displaying the mentor-student map.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2251
diff changeset
   289
        drawMarkers(map_data[elem])
ab216123bee7 Added org_home_gmap function to the map JS for displaying the mentor-student map.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2251
diff changeset
   290
      }
ab216123bee7 Added org_home_gmap function to the map JS for displaying the mentor-student map.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2251
diff changeset
   291
    }
ab216123bee7 Added org_home_gmap function to the map JS for displaying the mentor-student map.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2251
diff changeset
   292
  }
ab216123bee7 Added org_home_gmap function to the map JS for displaying the mentor-student map.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2251
diff changeset
   293
};