﻿

function LoadGMap(area) {
  var map = new GMap2(document.getElementById("map_canvas"));
  map.setMapType(G_SATELLITE_MAP);
  map.addControl(new GLargeMapControl3D());
  //map.addControl(new GSmallZoomControl());
  map.addControl(new GScaleControl());
  //map.setUIToDefault();

  //coordinates of interesting sites
  var airportLatLng = new GLatLng(4.190632775021203, 73.5289192199707);
  var bodLatLng = new GLatLng(4.430107599912046, 73.38438034057617);
  var kudLatLng = new GLatLng(4.416929047775391, 73.38034629821777);
  var biyLatLng = new GLatLng(3.9214572273785624, 73.45647811889648);
  var makLatLng = new GLatLng(4.542800230362131, 73.40553760528564);
  var dnkLatLng = new GLatLng(5.039988874499243, 72.88166999816895);


  /*
  GEvent.addListener(map, "click", function(overlay, latlng) {
    if (latlng) {
      var myHtml = "<span style='font-size:90%;'>" + latlng + "<br />Zoom: " + map.getZoom() + "<br />C: " + map.getCenter() + "</span>";
      map.openInfoWindow(latlng, myHtml);
    }
  });
  */
  
  //center map
  switch (area) {
    case "bod":
      {
        map.setCenter(new GLatLng(4.369689721257184, 73.46832275390625), 10);
        break;
      }
    case "mak":
      {
        map.setCenter(new GLatLng(4.421721275679643, 73.487548828125), 10);
        break;
      }
    case "biy":
      {
        map.setCenter(new GLatLng(4.013589705718849, 73.46145629882812), 10);
        break;
      }
    case "dnk":
      {
        //map.setCenter(new GLatLng(4.680454682128591, 73.1689453125), 9);
        map.setCenter(new GLatLng(5.039988874499243, 72.88166999816895), 9);
        break;
      }
  }

  // Create Airport marker icon using GChart API
  var airIcon = new GIcon();
  airIcon.image = "http://chart.apis.google.com/chart?chst=d_map_pin_icon&chld=airport|87D4FF";
  airIcon.shadow = "http://chart.apis.google.com/chart?chst=d_map_pin_shadow";
  airIcon.iconSize = new GSize(24, 40);
  airIcon.shadowSize = new GSize(44, 40);
  airIcon.iconAnchor = new GPoint(12, 40);
  airIcon.infoWindowAnchor = new GPoint(12, 5);

  // Create custom icon marker
  var custIcon = new GIcon();
  custIcon.image = "http://www.dive-ocean.com/img/GIconDVOMarker.png";
  custIcon.shadow = "http://chart.apis.google.com/chart?chst=d_map_pin_shadow";
  custIcon.iconSize = new GSize(32, 32);
  custIcon.shadowSize = new GSize(44, 32);
  custIcon.iconAnchor = new GPoint(16, 31);
  custIcon.infoWindowAnchor = new GPoint(16, 2);

  // Create custom icon marker
  var custIcon2 = new GIcon();
  custIcon2.image = "http://www.dive-ocean.com/img/GIconDVOMarker2.png";
  custIcon2.shadow = "http://chart.apis.google.com/chart?chst=d_map_pin_shadow";
  custIcon2.iconSize = new GSize(32, 32);
  custIcon2.shadowSize = new GSize(44, 32);
  custIcon2.iconAnchor = new GPoint(16, 31);
  custIcon2.infoWindowAnchor = new GPoint(16, 2);

  //Create Airport marker
  markerOptions = { icon: airIcon };
  var markerAirport = new GMarker(airportLatLng, markerOptions);
  GEvent.addListener(markerAirport, "click", function() {
    this.openInfoWindowHtml("<span style='font-size:12px;'><b>Malè</b><br />International Airport</span>");
  });
  map.addOverlay(markerAirport);

  //Create Resort markers
  markerOptions = { icon: custIcon };
  /*
  markerResort = new GMarker(kudLatLng, markerOptions);
  GEvent.addListener(markerResort, "click", function() {
    this.openInfoWindowHtml("<span style='font-size:12px;'>Coco Palm Kuda Hithi</span>");
  });
  map.addOverlay(markerResort);
  */
  if (area == 'bod') { markerOptions = { icon: custIcon2} }
  var markerResort = new GMarker(bodLatLng, markerOptions);
  GEvent.addListener(markerResort, "click", function() {
    this.openInfoWindowHtml("<span style='font-size:12px;'>Coco Palm Bodu Hithi<br />Coco Palm Kuda Hithi</span>");
  });
  map.addOverlay(markerResort);

  markerOptions = { icon: custIcon };
  if (area == 'mak') { markerOptions = { icon: custIcon2} }
  markerResort = new GMarker(makLatLng, markerOptions);
  GEvent.addListener(markerResort, "click", function() {
    this.openInfoWindowHtml("<span style='font-size:12px;'>Makunudu</span>");
  });
  map.addOverlay(markerResort);

  markerOptions = { icon: custIcon };
  if (area == 'biy') { markerOptions = { icon: custIcon2} }
  markerResort = new GMarker(biyLatLng, markerOptions);
  GEvent.addListener(markerResort, "click", function() {
    this.openInfoWindowHtml("<span style='font-size:12px;'>Biyadhoo</span>");
  });
  map.addOverlay(markerResort);

  markerOptions = { icon: custIcon };
  if (area == 'dnk') { markerOptions = { icon: custIcon2} }
  markerResort = new GMarker(dnkLatLng, markerOptions);
  GEvent.addListener(markerResort, "click", function() {
    this.openInfoWindowHtml("<span style='font-size:12px;'>Coco Palm Dhuni Kolhu</span>");
  });
  map.addOverlay(markerResort);

}

