/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // Debugging arguments /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// var verbose; var args; if (args == null) { args = new Array(); all_args = document.URL.split("?"); if(all_args[1]) { arg_vals = all_args[1].split("&"); for(var x=0; x 0) { verbose = args["verbose"]; } /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // Global Variables /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// var gotdirections = 0; var mycenter; var sbthold = 17; // zoom level to start showing bars on the map in the side bar default = 15 var map; var gdir; var zl = 12; var outzl = 12; // the start value var refresh = true; var lastswlat = 0; var lastswlong = 0; var lastnelat = 0; var lastnelong = 0; /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // These arrays are cleared when the getpoints function runs, otherwise // they hold the values for the driving directions and side bar /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// var i = 0; var counter; var side_bar_html = ""; var gmarkers = []; var points = []; // added cause IE was crippling output and fixing that output caused the functions to break so we are refrencing the name by array value var names = []; var tooltip = document.createElement("div"); /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // Icons and cluster icon array /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// var SmallPin = new GIcon(); SmallPin.image = "http://www.barsmart.com/gfx/pngs/red_small.png"; SmallPin.shadow = "http://www.barsmart.com/gfx/pngs/shadow_small.png"; SmallPin.iconSize = new GSize(12, 20); SmallPin.shadowSize = new GSize(22, 20); SmallPin.iconAnchor = new GPoint(6, 20); SmallPin.infoWindowAnchor = new GPoint(5, 1); var CThisIcon = []; for (icons = 0; icons <= 51; icons++) { CThisIcon[icons] = new GIcon(); CThisIcon[icons].image = "http://www.barsmart.com/gfx/pngs/cluster_pin_"+icons+".png"; CThisIcon[icons].iconSize=new GSize(44,44); CThisIcon[icons].iconAnchor=new GPoint(22,22); CThisIcon[icons].infoWindowAnchor=new GPoint(22,22); if (icons == 51) { CThisIcon[icons] = new GIcon(); CThisIcon[icons].image = "http://www.barsmart.com/gfx/pngs/cluster_pin_50p.png"; CThisIcon[icons].iconSize=new GSize(44,44); CThisIcon[icons].iconAnchor=new GPoint(22,22); CThisIcon[icons].infoWindowAnchor=new GPoint(22,22); } } /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // failure codes for driving directions /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// var causes=[]; causes[G_GEO_BAD_KEY] = "The given key is either invalid or does not match the domain for which it was given."; causes[G_GEO_TOO_MANY_QUERIES] = "The given key has gone over the requests limit in the 24 hour period."; causes[G_GEO_MISSING_ADDRESS] = "Missing Address: The address was either missing, had no value, or could not be successfully parsed."; causes[G_GEO_UNKNOWN_ADDRESS] = "No corresponding geographic location could be found for the specified address. This may be due to the fact that the address is relatively new, or it may be incorrect."; causes[G_GEO_SERVER_ERROR] = "A geocoding or directions request could not be successfully processed, yet the exact reason for the failure is not known."; causes[G_GEO_BAD_REQUEST] = "A directions request could not be successfully parsed."; causes[G_GEO_MISSING_QUERY] = "The HTTP q parameter was either missing or had no value. For geocoding requests, this means that an empty address was specified as input. For directions requests, this means that no query was specified in the input."; causes[G_GEO_UNKNOWN_DIRECTIONS] = "The GDirections object could not compute directions between the points mentioned in the query. This is usually because there is no route available between the two points, or because we do not have data for routing in that region."; causes[G_GEO_UNAVAILABLE_ADDRESS] = "The geocode for the given address or the route for the given directions query cannot be returned due to legal or contractual reasons."; causes[G_GEO_SUCCESS] = "Success"; /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // // BEGIN: function createTabbedMarker(marker point,html text, bar name) // creates a tabbed marker with info, reviews and driving direction tabs // /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// function createTabbedMarker(point,text,name) { var bar_info; var tabs; var marker = new GMarker(point,SmallPin); gmarkers[i] = marker; points[i] = marker.getPoint(); //duplicate these funcs for listener marker.tooltip = '
 '+name.replace(/ /g, " ")+' 
'; GEvent.addListener(marker,"click", function() { DataURL = "http://www.barsmart.com/getbubble?id="+text; // Debugging if (verbose > 2) { GLog.writeHtml(""+DataURL+""); } points[i] = marker.getPoint(); GDownloadUrl(DataURL, function(data, responseCode) { names[i] = name; var jscript = data; var bars; eval(jscript); for (j in bars) { // Since we don't have info on all these pins lets only show the icons for the ones we reviewed var bar_icons ="
"; if (bars[j].rating == 1) { if (bars[j].web.length > 3) { bar_icons += "\"web"; } else { bar_icons += ""; } if (bars[j].darts == 1) { bar_icons += "\"Darts\""; } else { bar_icons += ""; } if (bars[j].dancing == 1) { bar_icons += "\"Dancing\""; } else { bar_icons += ""; } if (bars[j].pool == 1) { bar_icons += "\"Pool"; } else { bar_icons += ""; } if (bars[j].smoke == 0) { bar_icons += "\"Smoking\""; } else { bar_icons += "\"Smoke-Free\""; } } // We got most of the non smoking bars so if a bar IS non smoking and NOT rated we can show this extra here. else { if (bars[j].smoke == 1) { bar_icons += "\"Smoking\""; } } bar_icons += "
"; if (bars[j].pic == 1) { var picsrc = ""; } else { var picsrc = ""; } bar_info = picsrc+""+names[i]+"
"+bars[j].address+"
"+bars[j].city+", "+bars[j].state+" "+bars[j].zip+"
"+bars[j].phone+""+"
Is this wrong?"; } // To here and from here links html = "
Address:
"+bars[j].address+"
"+bars[j].city+", "+bars[j].state+" "+bars[j].zip+"
Get Directions:
To here   or   from here.
"; var tabstart = '
'; var tabend = '
'; var tabs = [ new GInfoWindowTab("General", tabstart+bar_info+bar_icons+tabend), new GInfoWindowTab("Directions",tabstart+html+tabend) ]; marker.openInfoWindowTabsHtml(tabs); }); }); GEvent.addListener(marker,"mouseover", function() { showTooltip(marker); }); GEvent.addListener(marker,"mouseout", function() { tooltip.style.visibility="hidden" }); if (map.getZoom() == sbthold) { if ((i % 2) == 0) { side_bar_html += ''; } else { side_bar_html += '
' + name + '
'; } } i++; return marker; } /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // // BEGIN: function createClusterMarker(markerpoint,ammount in marker text) // creates cluster markers with custom icon // /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// function createClusterMarker(point,text) { if (text < 50){ var marker = new GMarker(point,CThisIcon[text]); } else { var marker = new GMarker(point,CThisIcon[51]); } points[i] = marker.getPoint(); gmarkers[i] = marker; marker.tooltip = '
 '+text+' bars in this general area 
'; var htmltext = ""+text+" bars in or near this general area.
Click here to zoom in."; GEvent.addListener(marker,"click", function() { marker.openInfoWindow(htmltext); }); GEvent.addListener(marker,"mouseover", function() { showTooltip(marker); }); GEvent.addListener(marker,"mouseout", function() { tooltip.style.visibility="hidden" }); i++; return marker; } /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // // BEGIN: function load() // loads the map // /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// function load() { if (GBrowserIsCompatible()) { map = new GMap2(document.getElementById("map")); map.addControl(new GLargeMapControl()); map.addControl(new GScaleControl()); map.addControl(new GMapTypeControl(1)); //map.addControl(new GOverviewMapControl(new GSize(150,150))); // currently set to the point of the point ;) map.setCenter(new GLatLng(40.44177859358136, -80.01291275024414), 13); map.enableDoubleClickZoom(); //map.enableScrollWheelZoom(); //map.enableContinuousZoom(); map.getPane(G_MAP_FLOAT_PANE).appendChild(tooltip); gdir = new GDirections(map, document.getElementById("driving")); tooltip.style.visibility="hidden"; GEvent.addListener(gdir, "error", function() { var code = gdir.getStatus().code; var cause="Code "+code; if (causes[code]) { cause = causes[code] } alert("Failed to obtain directions, "+cause); }); GEvent.addListener(map, "zoomend", function() { if (map.getZoom() > outzl){ refresh = true; } getPoints(map); if (map.getZoom() >= sbthold) { showSidebar('side_bar'); if (gotdirections == 1){ showSidebar('driving'); } hideSidebar('side_info_bar'); } else { hideSidebar('side_bar'); if (gotdirections == 0) { showSidebar('side_info_bar'); } if (gotdirections == 1) { showSidebar('driving'); } } }); GEvent.addListener(map, "moveend", function() { var iw = map.getInfoWindow(); // prevents reloading the map if an info balloon window is open if (!iw.isHidden()) { // Don't refresh or get points at all } else { getPoints(map); } }); getPoints(map); } else { alert("Sorry, the Google Maps API is not compatible with this browser"); } } /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // // BEGIN: function getDirections() // send request to google to get mapping directions // /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// function getDirections() { gotdirections = 1; showSidebar('driving'); hideSidebar('side_info_bar'); var saddr = document.getElementById("saddr").value var daddr = document.getElementById("daddr").value map.clearOverlays(); gdir.load("from: "+saddr+" to: "+daddr); } /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // // BEGIN: function ClearDirections() // clear the directions object, hide the window, and refresh the map // /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// function ClearDirections() { gdir.clear(); gotdirections = 0; hideSidebar('driving'); if (zl != 17) { showSidebar('side_info_bar'); } refresh = true; getPoints(map); } /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // // BEGIN: function sbClick() // opens info windows of items clicked on in side bar // /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// function sbClick(i) { GEvent.trigger(gmarkers[i], "click"); } /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // // BEGIN: function directions(tohere/fromhere,points array position,place name) // rewrites the 'directionfromto' div with appropriate direction form // /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// function directions(direction,i,name) { var d_html = ""; switch(direction) { // To here directions form case "tohere" : d_html += "
Directions: 
"; d_html += "
"; d_html += "
"; d_html += ""; d_html += ""; d_html += ""; d_html += "
"; d_html += "
"; d_html += "
"; break; // From here directions form case "fromhere" : d_html += "
Directions: 
"; d_html += "
"; d_html += "
"; d_html += ""; d_html += ""; d_html += ""; d_html += "
"; d_html += "
"; d_html += "
"; break; } // set the inner html to the appropriate form to here or from here document.getElementById('directionfromto').innerHTML = d_html; } /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // // BEGIN: function showHide(object id) // flip the loading box on/off // /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// function showHide(obj) { var objID = document.getElementById(obj); objID.style.display = (objID.style.display == "none")?"":"none"; } /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // // BEGIN: function showTooltip(marker) // shows the tooltips for the bar names // /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// function showTooltip(marker) { tooltip.innerHTML = marker.tooltip; var point=map.getCurrentMapType().getProjection().fromLatLngToPixel(map.fromDivPixelToLatLng(new GPoint(0,0),true),map.getZoom()); var offset=map.getCurrentMapType().getProjection().fromLatLngToPixel(marker.getPoint(),map.getZoom()); var anchor=marker.getIcon().iconAnchor; var width=marker.getIcon().iconSize.width; var height=tooltip.clientHeight; var pos = new GControlPosition(G_ANCHOR_TOP_LEFT, new GSize(offset.x - point.x - anchor.x + width, offset.y - point.y -anchor.y -height)); pos.apply(tooltip); tooltip.style.visibility="visible"; } /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // // BEGIN: function hideSidebar() // hides the sidebar when we are in clusters and pins mode /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// function hideSidebar(obj) { var objID = document.getElementById(obj); objID.style.display = "none"; } /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // // BEGIN: function showSidebar() // shows the sidebar when we are not in clusters and pins mode /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// function showSidebar(obj) { var objID = document.getElementById(obj); objID.style.display = "block"; if (obj != "side_info_bar") { if (gotdirections == 0 && map.getZoom() == 17) { objID.style.height = "395px"; } else if (gotdirections == 1 && map.getZoom() != 17) { objID.style.height = "395px"; } else { objID.style.height = "160px"; } } } /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // // BEGIN: function clusterZoom() // provides an animated zoom to a clusters x,y location // /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// function clusterZoom(i) { map.closeInfoWindow(); map.zoomIn(points[i],true,true); } /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // // BEGIN: function ClearAllMarkers() // clears all of the markers from the map and resets our arrays between point loads // /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// function ClearAllMarkers() { for (var i in gmarkers) { if (gmarkers[i]) map.removeOverlay(gmarkers[i]); if (verbose > 2) { GLog.writeHtml("Removing Marker: "+i+"."); } } // These arrays are cleared when we refresh the data on the page // they hold the values for the driving directions and side bar etc.. i = 0; counter = 0; side_bar_html = ""; gmarkers = []; points = []; names = []; } /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // // BEGIN: function getPoints() // Gets points from xml file if page is refreshed or the map is moved significantly // /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// function getPoints(map) { var center = map.getCenter(); var bounds = map.getBounds(); outzl = zl; zl = map.getZoom(); var mapsw = bounds.getSouthWest(); var mapne = bounds.getNorthEast(); var mapswlat = mapsw.lat(); var mapswlong = mapsw.lng(); var mapnelat = mapne.lat(); var mapnelong = mapne.lng(); var dataswlat = mapswlat - (mapnelat-mapswlat)/2; var dataswlong = mapswlong - (mapnelong-mapswlong)/2; var datanelat = mapnelat + (mapnelat-mapswlat)/2; var datanelong = mapnelong + (mapnelong-mapswlong)/2; if ((refresh || mapswlat < lastswlat || mapswlong < lastswlong || mapnelat > lastnelat || mapnelong > lastnelong)) { lastswlat = dataswlat; lastswlong = dataswlong; lastnelat = datanelat; lastnelong = datanelong; //map.clearOverlays(); ClearAllMarkers(); // loading message document.getElementById("loading_status_content").innerHTML = "Loading points data..."; showHide('loading_status'); PointsURL = "http://www.barsmart.com/getpoints?swlat="+dataswlat+"&swlng="+dataswlong+"&nelat="+datanelat+"&nelng="+datanelong+"&zl="+zl+"&page=1"; // Debugging if (verbose > 2) { GLog.writeHtml(""+PointsURL+""); } GDownloadUrl(PointsURL, function(data, responseCode) { var jscript = data; var bars; var barsLength; eval(jscript); // create points for (i in bars) { counter++; var thisLat = parseFloat(bars[i].lat); var thisLon = parseFloat(bars[i].lon); var MarkType = bars[i].type; // get the point type var bar = new GLatLng(thisLat,thisLon); var bar_name = bars[i].n; if (MarkType == 'm') { var bar_ID = bars[i].id; map.addOverlay(createTabbedMarker(bar, bar_ID,bar_name)); document.getElementById("loading_status_content").innerHTML = "Adding point " + counter + " of " + barsLength + " points."; // Debugging if (verbose > 2) { GLog.writeHtml(counter+" "+bar_name+" "+bar); } } else { var num_bars = bars[i].c; map.addOverlay(createClusterMarker(bar, num_bars)); document.getElementById("loading_status_content").innerHTML = "Adding point " + counter + " of " + barsLength + " points."; // Debugging if (verbose > 2) { GLog.writeHtml(counter+" "+num_bars+" "+bar); } } // marktype } window.setTimeout("showHide('loading_status')",300); if (map.getZoom() == sbthold) { document.getElementById("side_bar").innerHTML = side_bar_html; } }); refresh = false; } }