var querystringparameters = new Array(); function querystring() { var query = window.location.search.substring(1); var parms = query.split('&'); for (var i=0; i 0) { var key = parms[i].substring(0,pos); var val = parms[i].substring(pos+1); querystringparameters[key] = val; } } } var map = null; var geocoder = null; //Initialize the Map Engine function initialize() { if (GBrowserIsCompatible()) { map = new GMap2(document.getElementById('map_canvas')); map.addMapType(G_PHYSICAL_MAP); map.addControl(new GSmallMapControl(), new GControlPosition(G_ANCHOR_TOP_LEFT, new GSize(5,35))); map.addControl(new GMenuMapTypeControl(), new GControlPosition(G_ANCHOR_TOP_LEFT, new GSize(5,5))); //Set the map center map.setCenter(new GLatLng(40.557605743408, -74.284591674805), 7); //map.setCenter(new GLatLng(34.2501, -118.5255), 4); querystringparameters['address'] = null; querystring(); geocoder = new GClientGeocoder(); if (querystringparameters['address']) { showAddress(querystringparameters['address']); } //Set the map type map.setMapType(G_PHYSICAL_MAP); //Start the MarkerManager var mgr = new MarkerManager(map); //Update the map when it's moved GEvent.addListener(map, 'moveend', function() { updateMap(); }); //Create custom marker var tinyIcon = new GIcon(); tinyIcon.image = 'images/barn_icon.png'; tinyIcon.iconSize = new GSize(30, 30); tinyIcon.iconAnchor = new GPoint(5, 28); tinyIcon.infoWindowAnchor = new GPoint(5, 1); function createMarker(input) { //var div = document.createElement('div'); var marker = new GMarker(input.point, { icon:tinyIcon,title:input.barn_name }); GEvent.addListener(marker, 'click', function() { window.open(input.link, '_blank'); }); GEvent.addListener(marker, 'mouseover', function() { addDivBox(input.barn_name, input.barn_info, input.rev_rating, input.num_reviews); }); //if (input.point.lat() > '34.2501') { GEvent.addListener(marker, 'mouseout', function() { removeDivBoxId('infodiv'); }); //} else { //var div = document.getElementById('infodiv'); //GEvent.addDomListener(div, 'mouseout', function() { removeDivBoxId('infodiv'); }); //} return marker; } //Parse all JSON data function parseJson (doc) { var jsonData = eval('(' + doc + ')'); var marker = []; for (var i = 0; i < jsonData.markers.length; i++) { //JSON returned error if (jsonData.markers[i].errormessage) { var errorshown = true; if (jsonData.markers[i].errormessage=='NothingFound') { var nothingFound = true; } else { var nothingFound = false; } } else { marker.push(createMarker(jsonData.markers[i])); var errorshown = false; } } if (errorshown == false) { if (document.getElementById('diverror')) { removeDivBoxId('diverror'); } mgr.addMarkers(marker, 1); mgr.refresh(); removeDivBoxId('loadingdiv'); } else { removeDivBoxId('loadingdiv'); if (document.getElementById('infodiv')) { removeDivBoxId('infodiv'); } mgr.clearMarkers(); mgr.refresh(); if (nothingFound == false) { showErrorMessage(); } } } function showErrorMessage() { var div = document.createElement('div'); var pos = new GControlPosition(G_ANCHOR_TOP_RIGHT, new GSize(5,5)); div.id = 'diverror'; div.style.border = '1px solid red'; div.style.position = 'absolute'; div.style.backgroundColor = '#ffffff'; div.style.width = '160px'; div.style.height = '62px'; div.style.textAlign = 'center'; div.style.padding = '0px'; div.style.fontSize = '9pt'; div.style.fontWeight = 'bold'; div.style.fontFamily = 'Arial, sans-serif'; div.style.color = '#444444'; div.style.lineHeight = '11pt'; div.innerHTML = '
Over 250 stables found!
Please zoom in or
move the map.
'; pos.apply(div); map.getContainer().appendChild(div); } function showLoadingMessage() { var div = document.createElement('div'); var pos = new GControlPosition(G_ANCHOR_TOP_RIGHT, new GSize(5,5)); div.id = 'loadingdiv'; div.style.border = '1px solid black'; div.style.position = 'absolute'; div.style.backgroundColor = '#ffffff'; div.style.width = '160px'; div.style.height = '32px'; div.style.textAlign = 'center'; div.style.padding = '0px'; div.style.fontSize = '9pt'; div.style.fontWeight = 'bold'; div.style.fontFamily = 'Arial, sans-serif'; div.style.color = '#444444'; div.innerHTML = '
Loading Stables...
'; pos.apply(div); map.getContainer().appendChild(div); } function addDivBox(barn_name, barn_info, rev_rating, num_reviews) { var div = document.createElement('div'); var pos = new GControlPosition(G_ANCHOR_BOTTOM_LEFT, new GSize(0,0)); div.id = 'infodiv'; div.style.borderTop = '1px solid black'; div.style.position = 'absolute'; div.style.backgroundColor = '#f9f9f9'; div.style.width = '600px'; div.style.height = '52px'; div.style.lineHeight = '11pt'; div.style.textAlign = 'left'; div.style.padding = '0px'; div.style.overflow = 'hidden'; div.innerHTML = '
'+barn_name+' ('+num_reviews+')
'+barn_info+'
'+rev_rating+'
'; pos.apply(div); map.getContainer().appendChild(div); } function removeDivBoxId(id) { var div = document.getElementById(id); div.parentNode.removeChild(div); } //function removeDivBox(div) { //var div = document.getElementById(id); //div.parentNode.removeChild(div); //} function updateMap() { if (document.getElementById('diverror')) { removeDivBoxId('diverror'); } if (document.getElementById('loadingdiv')) { removeDivBoxId('loadingdiv'); } if (document.getElementById('infodiv')) { removeDivBoxId('infodiv'); } mgr.clearMarkers(); mgr.refresh(); var bounds = map.getBounds(); var southWest = bounds.getSouthWest(); var northEast = bounds.getNorthEast(); showLoadingMessage(); GDownloadUrl('all_barns_json.php5?sw_lng='+southWest.lng()+'&sw_lat='+southWest.lat()+'&ne_lng='+northEast.lng()+'&ne_lat='+northEast.lat(), function(data, responseCode) { parseJson(data); }); } var bounds = map.getBounds(); var southWest = bounds.getSouthWest(); var northEast = bounds.getNorthEast(); showLoadingMessage(); GDownloadUrl('all_barns_json.php5?sw_lng='+southWest.lng()+'&sw_lat='+southWest.lat()+'&ne_lng='+northEast.lng()+'&ne_lat='+northEast.lat(), function(data, responseCode) { parseJson(data); }); } } function showAddress(address) { if (geocoder) { geocoder.getLatLng( address, function(point) { if (!point) { alert(address + " not found"); } else { map.setCenter(point, 9); } } ); } }