// // This JS file sets up the Gmap and shows all of the locations in a specific region. Its // used by the maps app for the home page. // if (GBrowserIsCompatible()) { var gmarkers = []; // // Function linked to "Map It!" button to open marker windows given a location ID. // function map_it_click(location_id) { GEvent.trigger(gmarkers[location_id], "click"); window.location.hash="map"; } // // custom icon to use on the map // var icon = new GIcon(); icon.image = "http://labs.google.com/ridefinder/images/mm_20_red.png"; icon.shadow = "http://labs.google.com/ridefinder/images/mm_20_shadow.png"; icon.iconSize = new GSize(12, 20); icon.shadowSize = new GSize(22, 20); icon.iconAnchor = new GPoint(6, 20); icon.infoWindowAnchor = new GPoint(5, 1); // // create the map and center it on the napa valley // var map = new GMap2(document.getElementById("map")); map.addControl(new GLargeMapControl()); map.setCenter(new GLatLng(38.4,-122.45), 10); // // setup the ad unit on the map // var publisher_id = "pub-4573498472547028"; adsManagerOptions = { maxAdsOnMap : 2, style: 'adunit', channel: '6137780196' }; adsManager = new GAdsManager(map, publisher_id, adsManagerOptions); adsManager.enable(); // // Generate a "click" listener given a location ID. // var generate_listener = function(location_id){ return function(){ var marker = gmarkers[location_id]; if (marker.retrieved == true){ marker.openInfoWindowHtml('
'+marker.content+'
'); } else { // Load the location info and store it in the marker object. $.getJSON('/api/location/id/'+marker.location_id, function(json){ marker.content = json.content; marker.retrieved = true; marker.openInfoWindowHtml('
'+marker.content+'
'); }); } }; }; // // Setup all marks. // // Array of location data needed for marks. The html for the windows is loaded async when "click" action is // triggered. All location data is in a giant array to save space. var locations = [[38.540364, -122.508401, 139],[38.302337, -122.279286, 140],[38.256294, -122.349793, 141],[38.577643, -122.579402, 142],[38.3963, -122.3692, 143],[38.507548, -122.470042, 144],[38.578901, -122.580081, 145],]; // Add a marker for for each location in locations array. for(key in locations){ var marker = new GMarker(new GLatLng(locations[key][0], locations[key][1]), icon); marker.location_id = locations[key][2]; marker.retrieved = false; GEvent.addListener(marker, "click", generate_listener(marker.location_id)); gmarkers[marker.location_id] = marker; map.addOverlay(marker); } }