Exit full screenEnter full screen
For the best experience, please view in landscape
';var infoWindow = new google.maps.InfoWindow({content: defaultInfoWindowContent,maxWidth: 230});google.maps.event.addListener(infoWindow, 'domready', function(){$('.gm-style-iw + div').empty().append("
");});function initMap() {let mapOptions = {center: { lat: 57.1451807, lng: -4.4494629},zoom: 7,mapTypeControl: false,fullscreenControl: false,// Move controls to the rightzoomControlOptions: { position: google.maps.ControlPosition.RIGHT_CENTER },panControlOptions: { position: google.maps.ControlPosition.RIGHT_CENTER }};window.map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions);window.map.controls[google.maps.ControlPosition.LEFT_BOTTOM].push(document.getElementById('legend'));setZoom();plotMarkers(jsonResults, true);}function setZoom(bounds) {//now fit the map to the newly inclusive bounds unless a specific zoom level is provided let zoom = 0;let lat = undefined;let lng = undefined;let change = false;if (zoom > 0) {window.map.setZoom(zoom);change = true;}if (lat !== undefined && lng !== undefined) {window.map.setCenter(new google.maps.LatLng(lat, lng));change = true;}return change;}function submitFacets(e) {return false;}function toggleTextFilter() {// If any of the facets are selectedlet toggle = false;$('.facetlistform__checkbox').each(function() {if ($(this).prop("checked") === true) {toggle = true;}});if (toggle) {// Show the text filter$(".mapsearchwrapper").show();} else {// Hide and clear the input$(".mapsearchwrapper").hide();$("input#mapsearch").val('');}}toggleTextFilter();var requestCount = 0;function groupUpdateMap(facetid) {let $group = $('#' + facetid);if ($group) {// Prevent clicking until async has finished$group.prop("disabled", true);// Parse all facets from the child facet listlet facetIds = [];// Ensure all the group items get ticked/unticked immediately as per parent$group.parent().children("ul.subfacets").find(".facetlistform__checkbox").each(function () {facetIds.push($(this).attr('id').replace('f', ''));$(this).prop("disabled", true);});// Update URLs for all facets to include the group$('.facetlistform__checkbox').each(function() {for (let i = 0; i < facetIds.length; i++) {// Add back in if it doesn't already exist (once)$(this).attr('data-newurl', removeParam($(this).attr('data-newurl'), 'f', facetIds[i]));if ($group.prop("checked") && ("f" + facetIds[i]) !== $(this).attr('id')) {$(this).attr('data-newurl', addParam($(this).attr('data-newurl'), 'f', facetIds[i]));} else if (!$group.prop("checked") && ("f" + facetIds[i]) === $(this).attr('id')) {// Add back in if we're unchecking the group, and this is the current facet, effectively reversing first line$(this).attr('data-newurl', addParam($(this).attr('data-newurl'), 'f', facetIds[i]));}}});// Update the current URLwindow.history.replaceState('', 'Filtering by ' + $group.text(), $group.attr('data-newurl'));// Make request for updated contentlet url = addParam($group.attr('data-newurl'), 'ajax', 'json');requestCount++;let thisRequest = requestCount;$.ajax(url, {success: function (data) {jsonResults = data;// filter data if search field has a valuelet $mapSearch = $("#mapsearch");var data = ($mapSearch.val() !== '')? filter(jsonResults, $mapSearch.val()) : data;if (thisRequest >= requestCount) {// Plot new dataplotMarkers(data, false);$group.prop("checked", !$group.prop("checked"));$group.parent().children("ul.subfacets").find(".facetlistform__checkbox").each(function () {$(this).prop("checked", $group.prop("checked"));});}},error: function () {if (thisRequest >= requestCount) {// Reverse attempt to load these facets$('.facetlistform__checkbox').each(function () {for (let i = 0; i < facetIds.length; i++) {// Add back in if it doesn't already exist (once)$(this).attr('data-newurl', removeParam($(this).attr('data-newurl'), 'f', facetIds[i]));if ($group.prop("checked") && ("f" + facetIds[i]) !== $(this).attr('id')) {$(this).attr('data-newurl', addParam($(this).attr('data-newurl'), 'f', facetIds[i]));} else if (!$group.prop("checked") && ("f" + facetIds[i]) === $(this).attr('id')) {// Add back in if we're unchecking the group, and this is the current facet, effectively reversing first line$(this).attr('data-newurl', addParam($(this).attr('data-newurl'), 'f', facetIds[i]));}}});}},complete: function () {if (thisRequest >= requestCount) {// Always re-enable checkboxes on final load of async requests$('.facetlistform__checkbox').prop("disabled", false);// Final check?updateGroupChecks();toggleTextFilter();}}});}}function updateMap(facetid) {var $facet = $('#' + facetid);if ($facet) {// Disable individual facet while it loads$facet.prop("disabled", true);// Increment tracking of requests/save the current state for laterrequestCount++;let thisRequest = requestCount;let thisFacets = getParamValues($facet.attr('data-newurl'), "f");// Update the current URLwindow.history.replaceState('', 'Filtering by ' + $facet.text(), $facet.attr('data-newurl'));// Make request for updated contentlet url = addParam($facet.attr('data-newurl'), 'ajax', 'json');$.ajax(url, {success: function (data) {jsonResults = data;// filter data if search field has a valuelet $mapSearch = $("#mapsearch");var data = ($mapSearch.val() !== '')? filter(jsonResults, $mapSearch.val()) : data;if (thisRequest >= requestCount) {// Plot (latest) new dataplotMarkers(data, false);// Check/uncheck accordingly$('.facetlistform__checkbox').prop("checked", false);for (let facet of thisFacets) {$("#f" + facet).prop("checked", true);}}},error: function () {if (thisRequest >= requestCount) {// Reverse attempt to load these facetsupdateFacetUrls(facetid, $facet.prop("checked"));}},complete: function () {if (thisRequest >= requestCount) {// Always re-enable checkboxes on final load of async requests$('.facetlistform__checkbox').prop("disabled", false);updateGroupChecks();toggleTextFilter();}}});// Update all other URLs in meantime, so the user can continue faceting:updateFacetUrls(facetid, $facet.prop("checked"));}}function updateFacetUrls(facetid, addFacet) {$('.facetlistform__checkbox').each(function() {let oldHref = $(this).attr('data-newurl');// If it's the current facetif ($(this).attr('id') === facetid) {// If it's checkedif (addFacet) {$(this).attr('data-newurl', removeParam(oldHref, 'f', facetid.replace('f', '')));} else {$(this).attr('data-newurl', addParam(oldHref, 'f', facetid.replace('f', '')));}}// If it's a different facetelse {// Add the current facet to the href if it was checkedif (addFacet) {$(this).attr('data-newurl', addParam(oldHref, 'f', facetid.replace('f', '')));}// Otherwise remove it from the hrefelse {$(this).attr('data-newurl', removeParam(oldHref, 'f', facetid.replace('f', '')));}}});$('.facetlistform__checkbox--group').each(function() {let $parent = $(this);let facetIsMemberOfgroup = false;let allGroupFacetsSelected = true;let facetIds = [];// Loop over any children, adding the IDs to the list and detect whether they are all selected too$(this).parent().children("ul.subfacets").find(".facetlistform__checkbox").each(function() {facetIds.push($(this).attr('id').replace('f', ''));if(!$(this).prop("checked")) {allGroupFacetsSelected = false;}if ($(this).attr('id') === facetid) {facetIsMemberOfgroup = true;}});// If the current facet is not a member of this group, update the group URL accordinglyif (!facetIsMemberOfgroup) {// Add the current facet to the href if it was checkedif (addFacet) {$parent.attr('data-newurl', addParam($parent.attr('data-newurl'), 'f', facetid.replace('f', '')));}// Otherwise remove it from the hrefelse {$parent.attr('data-newurl', removeParam($parent.attr('data-newurl'), 'f', facetid.replace('f', '')));}} else {// Choose whether to remove or add all group IDs from URLfor (let i = 0; i < facetIds.length; i++) {if (allGroupFacetsSelected) {$parent.attr('data-newurl', removeParam($parent.attr('data-newurl'), 'f', facetIds[i]));} else {// Add back in if it doesn't already exist (once)$parent.attr('data-newurl', addParam($parent.attr('data-newurl'), 'f', facetIds[i]));}}}});}function updateGroupChecks() {$('.facetlistform__checkbox--group').each(function() {let $parent = $(this);let allGroupFacetsSelected = true;$(this).parent().children("ul.subfacets").find(".facetlistform__checkbox").each(function () {if (!$(this).prop("checked")) {allGroupFacetsSelected = false;}});$parent.prop("checked", allGroupFacetsSelected);});}function addParam(url, paramName, paramValue) {// Prevent duplications by removing any existing matches first:let newUrl = removeParam(url, paramName, paramValue);return newUrl + (newUrl.indexOf('?') === -1 ? '?' : '&') + paramName + '=' + paramValue;}function removeParam(url, paramName, paramValue) {let newUrl = url.replace(new RegExp('&?' + paramName + '=' + paramValue), '');// Remove the trailing '?' if it's all that's leftif (newUrl.match(/\?$/i)) {newUrl = newUrl.substring(0, newUrl.indexOf('?'));}return newUrl;}function getParamValues(url, paramName) {let facetIds = [];let facetMatches = url.matchAll('[?&]' + paramName + '=([^]*)');for (const match of facetMatches) {facetIds.push(match[1]);}return facetIds;}function plotMarkers(items, reset) {// Remove existing markers from the mapfor (let i=0; i