From 2e707fe5cb32e8081542066818604f3c7a35feb3 Mon Sep 17 00:00:00 2001 From: Jacques Letesson Date: Wed, 25 Sep 2013 11:04:20 +0200 Subject: [PATCH] Display only the store on the map A new paramater "storeOnMap" which is false by default. If true, two event listeners are added and the the list will be refreshed to display only the store of which the marker is on the map. --- js/jquery.storelocator.js | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/js/jquery.storelocator.js b/js/jquery.storelocator.js index 3f00106..6c62940 100644 --- a/js/jquery.storelocator.js +++ b/js/jquery.storelocator.js @@ -19,6 +19,7 @@ $.fn.storeLocator = function(options) { 'pinTextColor': '000000', 'lengthUnit': 'm', 'storeLimit': 26, + 'storeOnMap': false, 'distanceAlert': 60, 'dataType': 'xml', 'dataLocation': 'locations.xml', @@ -795,6 +796,33 @@ $.fn.storeLocator = function(options) { } + if(settings.storeOnMap === 'true'){ + // Add event listener for center change + google.maps.event.addListener(map, 'center_changed', function() { + checkVisibleMarker(); + }); + + // Add event listener for zoom change + google.maps.event.addListener(map, 'zoom_changed', function() { + checkVisibleMarker(); + }); + + function checkVisibleMarker(){ + $("#" + settings.listDiv + ' ul').empty(); + $(markers).each(function(x, marker){ + if(map.getBounds().contains(marker.getPosition())) + { + //Define the location data + locations = define_location_data(marker); + //Set up the list template with the location data + listHtml = listTemplate(locations); + //console.log(listHtml); + $('#' + settings.listDiv + ' ul').append(listHtml); + } + }) + } + } + }); } });