var shouldbehash = ""; var currenthash = window.location.hash; if (currenthash){ var initzoom = 11; } else { var initzoom = 3; } var ib = null; var marker = new Array(); var sites = [ ]; var sites2fltr = sites; var boxText = document.createElement("div"); boxText.style.cssText = "border: 1px solid black; margin-top: 8px; background: yellow; padding: 5px;"; boxText.innerHTML = "Empty"; var boxOptions = { alignBottom: true ,content: boxText ,disableAutoPan: false ,maxWidth: 0 ,pixelOffset: new google.maps.Size(-135, -35) ,zIndex: null ,boxStyle: { background: "#fff", width: "231px", height: "auto", padding: "19px 20px", } ,closeBoxMargin: "0px 0px 0px 0px" ,closeBoxURL: "/css/img/close.png" ,infoBoxClearance: 100 ,isHidden: false ,pane: "floatPane" ,enableEventPropagation: false }; var ib = new InfoBox(boxOptions); $(document).ready(function () { if ($("#map_canvas").length > 0) { initialize(); } $(".markerjump").on('click', function(){ $("body, html").animate({ scrollTop: 0 }, 400); $(".markerjump").not(this).removeClass("selected"); $(this).addClass("selected"); var marker_id = $(this).attr("href").replace("#",""); moveAndInfo(marker_id); }); if(currenthash != "" && currenthash != shouldbehash) { var marker_id = currenthash.replace("#",""); moveAndInfo(marker_id); } $("body").on("click", ".button a", function(e){ e.preventDefault(); var tl = $(this); var tbutton = tl.closest(".button"); var fltrparent = tbutton.find(".fltrparent"); var tfltrtype, fltrtype1, fltrtype2, ftlr1, fltr2, fltrel1, fltrel2; initzoom = 3; if (tl.hasClass("fmap")) { var tfltr = tl.classData("f"); //get clicked filter type if (tl.hasClass("fyear")) { tfltrtype = 6; //define remaining filter elements fltrel1 = $(".fprize.selected"); fltrel2 = $(".fstatus.selected"); //define remaining filter types fltrtype1 = 7; fltrtype2 = 8; } else if (tl.hasClass("fprize")) { tfltrtype = 7; fltrel1 = $(".fyear.selected"); fltrel2 = $(".fstatus.selected"); fltrtype1 = 6; fltrtype2 = 8; } else if (tl.hasClass("fstatus")) { tfltrtype = 8; fltrel1 = $(".fyear.selected"); fltrel2 = $(".fprize.selected"); fltrtype1 = 6; fltrtype2 = 7; } //filter out pins sites = $.grep(sites2fltr, function(loc) { if (fltrel1.length && fltrel2.length) { fltr1 = fltrel1.classData("f"); fltr2 = fltrel2.classData("f"); return loc[tfltrtype] == tfltr && loc[fltrtype1] == fltr1 && loc[fltrtype2] == fltr2; } else if (fltrel1.length && !fltrel2.length) { fltr1 = fltrel1.classData("f"); return loc[tfltrtype] == tfltr && loc[fltrtype1] == fltr1; } else if (!fltrel1.length && fltrel2.length) { fltr2 = fltrel2.classData("f"); return loc[tfltrtype] == tfltr && loc[fltrtype2] == fltr2; } else { return loc[tfltrtype] == tfltr; } }); fltrparent.addClass("selected"); tl.addClass("selected"); tbutton.find(".fmap").not(tl).removeClass("selected"); $(".markerjump").removeClass("selected"); } else if (tl.hasClass("fltrparent")) { var selectedftlr = tbutton.find(".fmap.selected"); if (tl.hasClass("selected")) { tl.removeClass("selected"); selectedftlr.removeClass("selected"); //get clicked filter type if (selectedftlr.hasClass("fyear")) { //define remaining filter elements fltrel1 = $(".fprize.selected"); fltrel2 = $(".fstatus.selected"); //define remaining filter types fltrtype1 = 7; fltrtype2 = 8; } else if (selectedftlr.hasClass("fprize")) { fltrel1 = $(".fyear.selected"); fltrel2 = $(".fstatus.selected"); fltrtype1 = 6; fltrtype2 = 8; } else if (selectedftlr.hasClass("fstatus")) { fltrel1 = $(".fyear.selected"); fltrel2 = $(".fprize.selected"); fltrtype1 = 6; fltrtype2 = 7; } //filter out pins sites = $.grep(sites2fltr, function(loc) { if (fltrel1 && fltrel2) { if (fltrel1.length && fltrel2.length) { fltr1 = fltrel1.classData("f"); fltr2 = fltrel2.classData("f"); return loc[fltrtype1] == fltr1 && loc[fltrtype2] == fltr2; } else if (fltrel1.length && !fltrel2.length) { fltr1 = fltrel1.classData("f"); return loc[fltrtype1] == fltr1; } else if (!fltrel1.length && fltrel2.length) { fltr2 = fltrel2.classData("f"); return loc[fltrtype2] == fltr2; } else { return sites; } } else { return sites; } }); } //$(".dropdown a").not(tl).removeClass("selected"); //$(".fltrparent").not(fltrparent).removeClass("selected"); } //reinitialise initialize(); }); }); function moveAndInfo(marker_id){ var row = find(marker_id, sites); var loc = new google.maps.LatLng(sites[row][1], sites[row][2]); map.setCenter(loc); ib.setContent(sites[row][4]); ib.open(map, marker[row]); var thishash = "#"+sites[row][5]; $(".markerjump").removeClass("selected"); $(".markerjump[href='"+thishash+"']").addClass("selected"); } function find(thing, theArray) { var results, col, row, subArray; results = []; // Empty array for (row = 0; row < theArray.length; ++row) { subArray = theArray[row]; for (col = 0; col < subArray.length; ++col) { value = subArray[col]; if (value == thing) { // or whatever your criterion //results.push({row: row, col: col}); return row; } } } return results; } function initialize() { var centerMap = new google.maps.LatLng(12.865416, -85.207229); var myOptions = { zoom: initzoom ,center: centerMap ,mapTypeId: google.maps.MapTypeId.ROADMAP ,disableDefaultUI: true ,zoomControl: true ,zoomControlOptions: { style: google.maps.ZoomControlStyle.SMALL } } var styleOptions = { name: "Dummy Style" }; var MAP_STYLE = [ { stylers: [ { "saturation": -100 } ] } ]; map = new google.maps.Map(document.getElementById("map_canvas"), myOptions); setMarkers(map, sites); var mapType = new google.maps.StyledMapType(MAP_STYLE, styleOptions); map.mapTypes.set("Dummy Style", mapType); map.setMapTypeId("Dummy Style"); } function map_recenter(latlng,offsetx,offsety) { var point1 = map.getProjection().fromLatLngToPoint( (latlng instanceof google.maps.LatLng) ? latlng : map.getCenter() ); var point2 = new google.maps.Point( ( (typeof(offsetx) == 'number' ? offsetx : 0) / Math.pow(15, map.getZoom()) ) || 0, ( (typeof(offsety) == 'number' ? offsety : 0) / Math.pow(15, map.getZoom()) ) || 0 ); map.panTo(map.getProjection().fromPointToLatLng(new google.maps.Point( point1.x - point2.x, point1.y + point2.y ))); } function setMarkers(map, markers) { var defaultpin = new google.maps.MarkerImage("/css/img/pin-mchap.png", new google.maps.Size(18.0, 16.0), new google.maps.Point(0, 0), new google.maps.Point(9, 8) ); var hash = ""; for (var i = 0; i < markers.length; i++) { var sites = markers[i]; var siteLatLng = new google.maps.LatLng(sites[1], sites[2]); marker[i] = new google.maps.Marker({ position: siteLatLng, map: map, icon: defaultpin, title: sites[0], zIndex: sites[3], html: sites[4], hash: sites[5] }); var contentString = "Some content"; google.maps.event.addListener(marker[i], "click", function () { ib.setContent(this.html); ib.open(map, this); map_recenter(this.getPosition(),50,-150); var thishash = "#"+this.hash; $(".markerjump").removeClass("selected"); $(".markerjump[href='"+thishash+"']").addClass("selected"); window.location.hash = thishash; }); } }