`
});
marker.addListener('gmp-click', (m) => {
// Close the currently open info window if one exists
if (currentInfoWindow) {
currentInfoWindow.close();
}
if (currentInfoWindow == infowindow) {
currentInfoWindow = null; // Clear the reference if it's not the same info window
} else {
map.setZoom(14); // Zoom in on the marker
map.panTo(marker.position);
infowindow.open(map, marker);
// Update the reference to the currently open info window
currentInfoWindow = infowindow;
}
});
// Optional: Close info window when map is clicked (not on a marker)
map.addListener('click', () => {
if (currentInfoWindow) {
currentInfoWindow.close();
currentInfoWindow = null; // Clear the reference
}
});
// Add to sidebar list
const li = document.createElement("div");
li.textContent = store.name;
li.addEventListener("click", () => {
google.maps.event.trigger(marker, 'gmp-click');
(function ($) {
// $('html, body').animate({
// scrollTop: $(".map-container").offset().top
// }, 400);
})(jQuery.noConflict());
});
li.classList = "store-li"
li.setAttribute("data-search", `${store.name} ${store.address} ${store.place_address}`.trim().toLowerCase());
li.setAttribute("data-region", `${store.region}`);
li.setAttribute("data-visible", `show`);
storeList.appendChild(li);
bounds.extend(marker.position); // include this marker in map bounds
});
map.fitBounds(bounds, 0);
setTimeout(() => {
map.setZoom(11.5); // Adjust zoom level after fitting bounds
}, 100);
initMapSearch();
}
function initStoresList() {
(function ($) {
$(`.map-stores-list`).html(`
No outlets found for your current search or filter criteria
`);
Object.keys(stores).forEach(region => {
$(".map-regions-filter").append(``);
});
$(".map-regions-filter").on("change", "input", function (param) {
$(".map-regions-filter input").each(function (k, v) {
if ($(v).prop("checked")) {
$(`.map-stores-list .store-li[data-region="${$(v).val()}"][data-visible="show"]`).show();
} else {
$(`.map-stores-list .store-li[data-region="${$(v).val()}"]`).hide()
};
});
checkStoresList();
});
})(jQuery.noConflict());
}
function initMapSearch() {
(function ($) {
const $input = $('#map-search-input');
const $list = $('#map-stores-list');
const $items = $list.children('div.store-li');
const originalOrder = $items.toArray(); // Save initial DOM order
$input.on('input', function () {
const query = $(this).val().trim().toLowerCase();
const current_filter = [];
$(".map-regions-filter input").each(function (k, v) {
if ($(v).prop("checked")) {
current_filter.push($(v).val());
}
});
if (!query) {
// Reset: show all, restore original order
// $items.show();
$items.each(function () {
const $li = $(this);
$li.attr('data-visible', 'show')
if (current_filter.includes($li.data("region"))) {
$li.show();
} else {
$li.hide();
}
});
$list.append(originalOrder);
checkStoresList();
return;
}
const terms = query.split(/\s+/);
const matches = [];
// special search for query without space
if (query.length > 1 && !query.includes(" ")) {
const queryChars = query.split("");
terms.push(...queryChars);
}
$items.each(function () {
const $li = $(this);
const dataText = $li.data('search').toLowerCase();
const dataTextTerms = dataText.split(/\s+/);
const labelText = $li.text().toLowerCase();
const labelTextTerms = labelText.split(/\s+/);
let count = 0;
terms.forEach(term => {
if (dataText.includes(term)) {
count += 2 * term.length
// extra points for starting char data
dataTextTerms.forEach(dtTerm => {
if (term.charAt(0) == dtTerm.charAt(0)) {
count += 1;
}
});
// extra points for starting char
labelTextTerms.forEach(ltTerm => {
if (term == ltTerm.substring(0, term.length)) {
count += 5 * term.length;
}
});
} else {
count--;
if (query.length > 1 && !query.includes(" ")) {
count -= 3 * terms.length
}
}
// bias for equal start chars
if (term == labelText.substring(0, term.length)) {
count += 5 * term.length;
}
});
if (count > 0) {
// add bias for starting alphabet
if (labelText.charAt(0) == query.charAt(0)) {
count += 10
;
}
$li.attr('data-visible', 'show')
if (current_filter.includes($li.data("region"))) {
matches.push({ el: $li, count });
} else {
$li.hide();
}
// matches.push({ el: $li, count });
} else {
$li.attr('data-visible', 'hide')
$li.hide();
}
});
// Sort and show matches
matches.sort((a, b) => b.count - a.count);
matches.forEach(m => {
$list.append(m.el); // Move in DOM
m.el.show();
});
checkStoresList();
});
})(jQuery.noConflict());
}
function checkStoresList() {
(function ($) {
if (!$(`.map-stores-list .store-li:visible`).length) {
$(`.store-none`).show();
} else {
$(`.store-none`).hide();
};
})(jQuery.noConflict());
}
(function ($) {
$(document).ready(function (e) {
try {
if (!$("body").hasClass("admin-bar")) initMap();
} catch (error) {
}
})
})(jQuery.noConflict());
While our products are now conveniently available at Guardian, we understand that true well-being often benefits from a tailored approach. Our experienced TCM physicians offer comprehensive consultations to evaluate your health and recommend a personalised treatment strategy.