Skip to content

Commit caa044e

Browse files
committed
Added visible markers option to only display the location information for the current markers on the map
1 parent f961b13 commit caa044e

File tree

4 files changed

+96
-4
lines changed

4 files changed

+96
-4
lines changed

dist/assets/js/plugins/storeLocator/jquery.storelocator.js

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/*! jQuery Google Maps Store Locator - v2.0.6 - 2015-03-26
1+
/*! jQuery Google Maps Store Locator - v2.0.6 - 2015-03-27
22
* http://www.bjornblog.com/web/jquery-store-locator-plugin
33
* Copyright (c) 2015 Bjorn Holine; Licensed MIT */
44

@@ -68,6 +68,7 @@
6868
'nameSearch' : false,
6969
'searchID' : 'bh-sl-search',
7070
'nameAttribute' : 'name',
71+
'visibleMarkersList' : false,
7172
'infowindowTemplatePath' : 'assets/js/plugins/storeLocator/templates/infowindow-description.html',
7273
'listTemplatePath' : 'assets/js/plugins/storeLocator/templates/location-list-description.html',
7374
'KMLinfowindowTemplatePath': 'assets/js/plugins/storeLocator/templates/kml-infowindow-description.html',
@@ -1442,6 +1443,32 @@
14421443
});
14431444
},
14441445

1446+
/**
1447+
* Updates the location list to reflect the markers that are displayed on the map
1448+
*
1449+
* @param markers {Object} Map markers
1450+
* @param map {Object} Google map
1451+
*/
1452+
checkVisibleMarkers: function(markers, map) {
1453+
var _this = this;
1454+
var locations, listHtml;
1455+
1456+
// Empty the location list
1457+
$('.' + this.settings.locationList + ' ul').empty();
1458+
1459+
// Set up the new list
1460+
$(markers).each(function(x, marker){
1461+
if(map.getBounds().contains(marker.getPosition())) {
1462+
// Define the location data
1463+
_this.listSetup(marker, 0, 0);
1464+
1465+
// Set up the list template with the location data
1466+
listHtml = listTemplate(locations);
1467+
$('.' + _this.settings.locationList + ' ul').append(listHtml);
1468+
}
1469+
});
1470+
},
1471+
14451472
/**
14461473
* The primary mapping function that runs everything
14471474
*
@@ -1916,6 +1943,24 @@
19161943
$('.' + _this.settings.locationList + ' ul li:even').css('background', _this.settings.listColor1);
19171944
$('.' + _this.settings.locationList + ' ul li:odd').css('background', _this.settings.listColor2);
19181945

1946+
// Visible markers list
1947+
if(_this.settings.visibleMarkersList === true) {
1948+
// Add event listener to filter the list when the map is fully loaded
1949+
google.maps.event.addListenerOnce(map, 'idle', function(){
1950+
_this.checkVisibleMarkers(markers, map);
1951+
});
1952+
1953+
// Add event listener for center change
1954+
google.maps.event.addListener(map, 'center_changed', function() {
1955+
_this.checkVisibleMarkers(markers, map);
1956+
});
1957+
1958+
// Add event listener for zoom change
1959+
google.maps.event.addListener(map, 'zoom_changed', function() {
1960+
_this.checkVisibleMarkers(markers, map);
1961+
});
1962+
}
1963+
19191964
// Modal ready callback
19201965
if (_this.settings.modal === true && _this.settings.callbackModalReady) {
19211966
_this.settings.callbackModalReady.call(this);

0 commit comments

Comments
 (0)