Advertisement
Guest User

Untitled

a guest
Oct 11th, 2012
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.     // initialize variables
  2.     var infowindow = null;
  3.     var directionDisplay;
  4.     var directionsService = new google.maps.DirectionsService();
  5.     var gmarkers = [];
  6.  
  7.     $(document).ready(function () { initialize(); });
  8.  
  9.     function initialize() {
  10.  
  11.         // directions
  12.         directionsDisplay = new google.maps.DirectionsRenderer();
  13.  
  14.         var centerMap = new google.maps.LatLng(busipress_map_vars.center_lat , busipress_map_vars.center_long);
  15.  
  16.         var myOptions = {
  17.             zoom: 4,
  18.             center: centerMap,
  19.             mapTypeId: google.maps.MapTypeId.TERRAIN
  20.         }
  21.  
  22.         var map = new google.maps.Map(document.getElementById("map-canvas"), myOptions);
  23.  
  24.         setMarkers(map, sites);
  25.         infowindow = new google.maps.InfoWindow({
  26.                 content: "loading..."
  27.             });
  28.  
  29.         var start = busipress_map_vars.path_start;
  30.         var end = busipress_map_vars.path_end;
  31.         var request = {
  32.             origin:start,
  33.             destination:end,
  34.             travelMode: google.maps.DirectionsTravelMode.DRIVING
  35.         };
  36.         directionsService.route(request, function(response, status) {
  37.             if (status == google.maps.DirectionsStatus.OK) {
  38.                 directionsDisplay.setDirections(response);
  39.             }
  40.         });
  41.  
  42.         directionsDisplay.setMap(map);
  43.     }
  44.  
  45.     /**
  46.      * show locations
  47.      */
  48.     var sites = busipress_map_vars.locations;
  49.  
  50.     /**
  51.      * set markers on map
  52.      */
  53.     function setMarkers(map, markers) {
  54.  
  55.         for (var i = 0; i < markers.length; i++) {
  56.             var sites = markers[i];
  57.  
  58.             // default icon
  59.             var defaultIcon = new google.maps.MarkerImage(sites[4][0],
  60.                 // This marker is 32 pixels wide by 32 pixels tall.
  61.                 new google.maps.Size(sites[4][1], sites[4][2]),
  62.                 // The origin for this image is 0,0.
  63.                 new google.maps.Point(0,0),
  64.                 // The anchor for this image is the base of the flagpole at 0,32.
  65.                 new google.maps.Point((sites[4][1] / 2), sites[4][2]));
  66.  
  67.             // default shadow
  68.             var shadow = new google.maps.MarkerImage(sites[6][0],
  69.                 // The shadow image is larger in the horizontal dimension
  70.                 // while the position and offset are the same as for the main image.
  71.                 new google.maps.Size(sites[6][1], sites[6][2]),
  72.                 new google.maps.Point(0,0),
  73.                 new google.maps.Point((sites[6][1] / 2), sites[6][2]));
  74.  
  75.             // active icion
  76.             var activeIcon = new google.maps.MarkerImage(sites[5][0],
  77.                 // This marker is 20 pixels wide by 32 pixels tall.
  78.                 new google.maps.Size(sites[5][1], sites[5][2]),
  79.                 // The origin for this image is 0,0.
  80.                 new google.maps.Point(0,0),
  81.                 // The anchor for this image is the base of the flagpole at 0,32.
  82.                 new google.maps.Point((sites[5][1] / 2), sites[5][2]));
  83.             var shape = {
  84.                 coord: [9,0,6,1,4,2,2,4,0,8,0,12,1,14,2,16,5,19,7,23,8,26,9,30,9,34,11,34,11,30,12,26,13,24,14,21,16,18,18,16,20,12,20,8,18,4,16,2,15,1,13,0],
  85.                 type: 'poly'
  86.             };
  87.  
  88.             var siteLatLng = new google.maps.LatLng(sites[1], sites[2]);
  89.             var marker = new google.maps.Marker({
  90.                 position: siteLatLng,
  91.                 map: map,
  92.                 title: sites[0],
  93.                 icon: defaultIcon,
  94.                 shadow: shadow,
  95.                 zIndex: 1,
  96.                 html: sites[3],
  97.                 myDefaultIcon: defaultIcon,
  98.                 myActiveIcon: activeIcon
  99.             });
  100.  
  101.             google.maps.event.addListener(marker, "click", function () {
  102.                 for (var i = 0; i < gmarkers.length; i++) {
  103.                    gmarkers[i].setIcon(gmarkers[i].myDefaultIcon);
  104.                 }
  105.                 this.setIcon(marker[i].myActiveIcon);
  106.  
  107.                 infowindow.setContent(this.html);
  108.                 infowindow.open(map, this);
  109.             });
  110.             gmarkers.push(marker);
  111.         }
  112.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement