app/soc/content/js/map-090420.js
author Lennard de Rijk <ljvderijk@gmail.com>
Fri, 24 Jul 2009 20:57:53 +0200
changeset 2677 7df4d0fcbb80
parent 2390 723dfa4811e8
child 2695 9c7d31b8247c
permissions -rw-r--r--
Use proper in-line import in Request helper.
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
  
2390
723dfa4811e8 Partial fix for displaying mentors and students on Organization home page.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2253
diff changeset
   183
  // Geo Data to be displayed on Google Maps
723dfa4811e8 Partial fix for displaying mentors and students on Organization home page.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2253
diff changeset
   184
  var geo_data = null;
723dfa4811e8 Partial fix for displaying mentors and students on Organization home page.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2253
diff changeset
   185
  var geo_data_keys = [];
723dfa4811e8 Partial fix for displaying mentors and students on Organization home page.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2253
diff changeset
   186
  
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
   187
  // 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
   188
  var geocoder = new GClientGeocoder();
2390
723dfa4811e8 Partial fix for displaying mentors and students on Organization home page.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2253
diff changeset
   189
  var numGeocoded = 0;
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
   190
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
  // 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
   192
  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
   193
  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
   194
  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
   195
  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
   196
  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
   197
  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
   198
  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
   199
  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
   200
  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
   201
  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
   202
  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
   203
2390
723dfa4811e8 Partial fix for displaying mentors and students on Organization home page.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2253
diff changeset
   204
  Object.prototype.keys = function ()
723dfa4811e8 Partial fix for displaying mentors and students on Organization home page.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2253
diff changeset
   205
  {
723dfa4811e8 Partial fix for displaying mentors and students on Organization home page.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2253
diff changeset
   206
    var keys = [];
723dfa4811e8 Partial fix for displaying mentors and students on Organization home page.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2253
diff changeset
   207
    for(i in this) if (this.hasOwnProperty(i))
723dfa4811e8 Partial fix for displaying mentors and students on Organization home page.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2253
diff changeset
   208
    {
723dfa4811e8 Partial fix for displaying mentors and students on Organization home page.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2253
diff changeset
   209
      keys.push(i);
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
   210
    }
2390
723dfa4811e8 Partial fix for displaying mentors and students on Organization home page.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2253
diff changeset
   211
    return keys;
723dfa4811e8 Partial fix for displaying mentors and students on Organization home page.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2253
diff changeset
   212
  }
723dfa4811e8 Partial fix for displaying mentors and students on Organization home page.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2253
diff changeset
   213
  
723dfa4811e8 Partial fix for displaying mentors and students on Organization home page.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2253
diff changeset
   214
  
723dfa4811e8 Partial fix for displaying mentors and students on Organization home page.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2253
diff changeset
   215
  // Mark student and enable a popup box upon click
723dfa4811e8 Partial fix for displaying mentors and students on Organization home page.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2253
diff changeset
   216
  function drawMarker(person) {
723dfa4811e8 Partial fix for displaying mentors and students on Organization home page.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2253
diff changeset
   217
    geocoder.setBaseCountryCode(person.ccTLD);
723dfa4811e8 Partial fix for displaying mentors and students on Organization home page.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2253
diff changeset
   218
    geocoder.getLocations(
723dfa4811e8 Partial fix for displaying mentors and students on Organization home page.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2253
diff changeset
   219
      person.city,
723dfa4811e8 Partial fix for displaying mentors and students on Organization home page.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2253
diff changeset
   220
      function(response) {
723dfa4811e8 Partial fix for displaying mentors and students on Organization home page.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2253
diff changeset
   221
        var delay = 0;
723dfa4811e8 Partial fix for displaying mentors and students on Organization home page.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2253
diff changeset
   222
        if (response.Status.code == 620) {
723dfa4811e8 Partial fix for displaying mentors and students on Organization home page.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2253
diff changeset
   223
          // Too fast, try again, with a small pause
723dfa4811e8 Partial fix for displaying mentors and students on Organization home page.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2253
diff changeset
   224
          delay = 100;
723dfa4811e8 Partial fix for displaying mentors and students on Organization home page.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2253
diff changeset
   225
        } else {
723dfa4811e8 Partial fix for displaying mentors and students on Organization home page.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2253
diff changeset
   226
          if (response.Status.code == 200) {
723dfa4811e8 Partial fix for displaying mentors and students on Organization home page.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2253
diff changeset
   227
            // Success; do something with the address.
723dfa4811e8 Partial fix for displaying mentors and students on Organization home page.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2253
diff changeset
   228
            var html = "";
723dfa4811e8 Partial fix for displaying mentors and students on Organization home page.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2253
diff changeset
   229
            var marker = null;
723dfa4811e8 Partial fix for displaying mentors and students on Organization home page.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2253
diff changeset
   230
            
723dfa4811e8 Partial fix for displaying mentors and students on Organization home page.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2253
diff changeset
   231
            place = response.Placemark[0];
723dfa4811e8 Partial fix for displaying mentors and students on Organization home page.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2253
diff changeset
   232
            point = new GLatLng(place.Point.coordinates[1],
723dfa4811e8 Partial fix for displaying mentors and students on Organization home page.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2253
diff changeset
   233
                                place.Point.coordinates[0]);
723dfa4811e8 Partial fix for displaying mentors and students on Organization home page.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2253
diff changeset
   234
            if (person.type == 'mentor') {
723dfa4811e8 Partial fix for displaying mentors and students on Organization home page.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2253
diff changeset
   235
              marker = new GMarker(point, mentor_icon);
723dfa4811e8 Partial fix for displaying mentors and students on Organization home page.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2253
diff changeset
   236
              html = "<strong>" + person.name + "</strong><br> Mentor";
723dfa4811e8 Partial fix for displaying mentors and students on Organization home page.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2253
diff changeset
   237
            } else if (person.type == 'student') {
723dfa4811e8 Partial fix for displaying mentors and students on Organization home page.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2253
diff changeset
   238
              marker = new GMarker(point, student_icon);
723dfa4811e8 Partial fix for displaying mentors and students on Organization home page.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2253
diff changeset
   239
              html = "<strong>" + person.name + "</strong><br>";
723dfa4811e8 Partial fix for displaying mentors and students on Organization home page.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2253
diff changeset
   240
              html += "<a href='"+ person.url + "'>" + person.summary + "</a><br>";
723dfa4811e8 Partial fix for displaying mentors and students on Organization home page.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2253
diff changeset
   241
              html += "Mentor: " + person.mentor;
723dfa4811e8 Partial fix for displaying mentors and students on Organization home page.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2253
diff changeset
   242
            }
723dfa4811e8 Partial fix for displaying mentors and students on Organization home page.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2253
diff changeset
   243
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
   244
            GEvent.addListener(marker, "click", function() {
2390
723dfa4811e8 Partial fix for displaying mentors and students on Organization home page.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2253
diff changeset
   245
              marker.openInfoWindowHtml(html);
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
   246
            });
2390
723dfa4811e8 Partial fix for displaying mentors and students on Organization home page.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2253
diff changeset
   247
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
   248
            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
   249
          }
2390
723dfa4811e8 Partial fix for displaying mentors and students on Organization home page.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2253
diff changeset
   250
          
723dfa4811e8 Partial fix for displaying mentors and students on Organization home page.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2253
diff changeset
   251
          // Move onto the next address; this skips bad addresses, too.
723dfa4811e8 Partial fix for displaying mentors and students on Organization home page.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2253
diff changeset
   252
          numGeocoded += 1;
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
   253
        }
2390
723dfa4811e8 Partial fix for displaying mentors and students on Organization home page.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2253
diff changeset
   254
        
723dfa4811e8 Partial fix for displaying mentors and students on Organization home page.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2253
diff changeset
   255
        window.setTimeout(geocodeAll, delay);
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
   256
      }
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
    );
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
  }
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
2390
723dfa4811e8 Partial fix for displaying mentors and students on Organization home page.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2253
diff changeset
   260
  // Draw a polyline between two points
723dfa4811e8 Partial fix for displaying mentors and students on Organization home page.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2253
diff changeset
   261
  drawPolyLine = function(from, to) {
723dfa4811e8 Partial fix for displaying mentors and students on Organization home page.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2253
diff changeset
   262
    var polyline = new GPolyline([from, to], "#ff0000", 3);
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
   263
    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
   264
  }
2390
723dfa4811e8 Partial fix for displaying mentors and students on Organization home page.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2253
diff changeset
   265
723dfa4811e8 Partial fix for displaying mentors and students on Organization home page.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2253
diff changeset
   266
  function geocodeAll() {
723dfa4811e8 Partial fix for displaying mentors and students on Organization home page.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2253
diff changeset
   267
    if (numGeocoded < geo_data_keys.length) {
723dfa4811e8 Partial fix for displaying mentors and students on Organization home page.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2253
diff changeset
   268
      drawMarker(geo_data[geo_data_keys[numGeocoded]])
723dfa4811e8 Partial fix for displaying mentors and students on Organization home page.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2253
diff changeset
   269
    }
723dfa4811e8 Partial fix for displaying mentors and students on Organization home page.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2253
diff changeset
   270
  }
723dfa4811e8 Partial fix for displaying mentors and students on Organization home page.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2253
diff changeset
   271
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
   272
  // 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
   273
  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
   274
    // 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
   275
    if (GBrowserIsCompatible()) {
2390
723dfa4811e8 Partial fix for displaying mentors and students on Organization home page.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2253
diff changeset
   276
      geo_data = map_data;
723dfa4811e8 Partial fix for displaying mentors and students on Organization home page.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2253
diff changeset
   277
      
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
   278
      // 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
   279
      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
   280
      map.addControl(new GLargeMapControl());
2390
723dfa4811e8 Partial fix for displaying mentors and students on Organization home page.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2253
diff changeset
   281
      map.addControl(new GMapTypeControl());
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
   282
      
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
      // 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
   284
      map.setCenter(new GLatLng(0, 0), 1);
2390
723dfa4811e8 Partial fix for displaying mentors and students on Organization home page.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2253
diff changeset
   285
      geocoder.setCache(null);
723dfa4811e8 Partial fix for displaying mentors and students on Organization home page.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2253
diff changeset
   286
      geo_data_keys = geo_data.keys()
723dfa4811e8 Partial fix for displaying mentors and students on Organization home page.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2253
diff changeset
   287
      window.setTimeout(geocodeAll, 50);
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
   288
      
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
    }
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
};