Skip to content

Commit 068d1df

Browse files
committed
Improved zooming when maxDistance setting is enabled taking advantage of the fitBounds method
1 parent 1dd4686 commit 068d1df

File tree

4 files changed

+62
-17
lines changed

4 files changed

+62
-17
lines changed

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

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/*! jQuery Google Maps Store Locator - v3.1.5 - 2021-09-26
1+
/*! jQuery Google Maps Store Locator - v3.1.5 - 2021-09-27
22
* http://www.bjornblog.com/web/jquery-store-locator-plugin
33
* Copyright (c) 2021 Bjorn Holine; Licensed MIT */
44

@@ -2899,7 +2899,6 @@
28992899

29002900
// Create array for featured locations
29012901
featuredset = $.grep(locationset, function (val) {
2902-
29032902
if (val.hasOwnProperty('featured')) {
29042903
return val.featured === 'true';
29052904
}
@@ -2910,9 +2909,8 @@
29102909

29112910
// Create array for normal locations
29122911
normalset = $.grep(locationset, function (val) {
2913-
29142912
if (val.hasOwnProperty('featured')) {
2915-
return val.featured !== 'true';
2913+
return val.featured !== 'true';
29162914
}
29172915
});
29182916

@@ -2975,7 +2973,13 @@
29752973
_this.resultsTotalCount(locationset.length);
29762974

29772975
// Google maps settings
2978-
if ((_this.settings.fullMapStart === true && firstRun === true && _this.settings.querystringParams !== true) || (_this.settings.mapSettings.zoom === 0) || (typeof origin === 'undefined') || (distError === true)) {
2976+
if (
2977+
(_this.settings.fullMapStart === true && firstRun === true && _this.settings.querystringParams !== true) ||
2978+
(_this.settings.mapSettings.zoom === 0) ||
2979+
(typeof origin === 'undefined') ||
2980+
(distError === true) ||
2981+
(_this.settings.maxDistance === true && firstRun === false)
2982+
) {
29792983
myOptions = _this.settings.mapSettings;
29802984
bounds = new google.maps.LatLngBounds();
29812985
}
@@ -3061,15 +3065,27 @@
30613065
marker = _this.createMarker(point, locationset[y].name, locationset[y].address, letter, _this.map, locationset[y].category);
30623066
marker.set('id', y);
30633067
markers[y] = marker;
3064-
if ((_this.settings.fullMapStart === true && firstRun === true && _this.settings.querystringParams !== true) || (_this.settings.mapSettings.zoom === 0) || (typeof origin === 'undefined') || (distError === true)) {
3068+
if (
3069+
(_this.settings.fullMapStart === true && firstRun === true && _this.settings.querystringParams !== true) ||
3070+
(_this.settings.mapSettings.zoom === 0) ||
3071+
(typeof origin === 'undefined') ||
3072+
(distError === true) ||
3073+
(_this.settings.maxDistance === true && firstRun === false)
3074+
) {
30653075
bounds.extend(point);
30663076
}
30673077
// Pass variables to the pop-up infowindows
30683078
_this.createInfowindow(marker, null, infowindow, storeStart, page);
30693079
}
30703080

30713081
// Center and zoom if no origin or zoom was provided, or distance of first marker is greater than distanceAlert
3072-
if ((_this.settings.fullMapStart === true && firstRun === true && _this.settings.querystringParams !== true) || (_this.settings.mapSettings.zoom === 0) || (typeof origin === 'undefined') || (distError === true)) {
3082+
if (
3083+
(_this.settings.fullMapStart === true && firstRun === true && _this.settings.querystringParams !== true) ||
3084+
(_this.settings.mapSettings.zoom === 0) ||
3085+
(typeof origin === 'undefined') ||
3086+
(distError === true) ||
3087+
(_this.settings.maxDistance === true && firstRun === false)
3088+
) {
30733089
_this.map.fitBounds(bounds);
30743090

30753091
// Prevent zooming in too far after fitBounds
@@ -3086,7 +3102,13 @@
30863102
locList.empty();
30873103

30883104
// Set up the location list markup
3089-
if (firstRun && _this.settings.fullMapStartListLimit !== false && !isNaN(_this.settings.fullMapStartListLimit) && _this.settings.fullMapStartListLimit !== -1 && markers.length > _this.settings.fullMapStartListLimit) {
3105+
if (
3106+
firstRun &&
3107+
_this.settings.fullMapStartListLimit !== false &&
3108+
!isNaN(_this.settings.fullMapStartListLimit) &&
3109+
_this.settings.fullMapStartListLimit !== -1 &&
3110+
markers.length > _this.settings.fullMapStartListLimit
3111+
) {
30903112
for (var m = 0; m < _this.settings.fullMapStartListLimit; m++) {
30913113
var currentMarker = markers[m];
30923114
_this.listSetup(currentMarker, storeStart, page);

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

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

readme.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ filtering.
3737

3838
### Version 3.1.5
3939
* Added a zoom listener after fitBounds is used to prevent high zoom levels after name search and taxonomy filtering.
40+
* Improved zooming when maxDistance setting is enabled taking advantage of the fitBounds method.
4041

4142
### Version 3.1.4
4243
* Fixed name search filter value not clearing if form input is cleared.

src/js/jquery.storelocator.js

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2895,7 +2895,6 @@
28952895

28962896
// Create array for featured locations
28972897
featuredset = $.grep(locationset, function (val) {
2898-
28992898
if (val.hasOwnProperty('featured')) {
29002899
return val.featured === 'true';
29012900
}
@@ -2906,9 +2905,8 @@
29062905

29072906
// Create array for normal locations
29082907
normalset = $.grep(locationset, function (val) {
2909-
29102908
if (val.hasOwnProperty('featured')) {
2911-
return val.featured !== 'true';
2909+
return val.featured !== 'true';
29122910
}
29132911
});
29142912

@@ -2971,7 +2969,13 @@
29712969
_this.resultsTotalCount(locationset.length);
29722970

29732971
// Google maps settings
2974-
if ((_this.settings.fullMapStart === true && firstRun === true && _this.settings.querystringParams !== true) || (_this.settings.mapSettings.zoom === 0) || (typeof origin === 'undefined') || (distError === true)) {
2972+
if (
2973+
(_this.settings.fullMapStart === true && firstRun === true && _this.settings.querystringParams !== true) ||
2974+
(_this.settings.mapSettings.zoom === 0) ||
2975+
(typeof origin === 'undefined') ||
2976+
(distError === true) ||
2977+
(_this.settings.maxDistance === true && firstRun === false)
2978+
) {
29752979
myOptions = _this.settings.mapSettings;
29762980
bounds = new google.maps.LatLngBounds();
29772981
}
@@ -3057,15 +3061,27 @@
30573061
marker = _this.createMarker(point, locationset[y].name, locationset[y].address, letter, _this.map, locationset[y].category);
30583062
marker.set('id', y);
30593063
markers[y] = marker;
3060-
if ((_this.settings.fullMapStart === true && firstRun === true && _this.settings.querystringParams !== true) || (_this.settings.mapSettings.zoom === 0) || (typeof origin === 'undefined') || (distError === true)) {
3064+
if (
3065+
(_this.settings.fullMapStart === true && firstRun === true && _this.settings.querystringParams !== true) ||
3066+
(_this.settings.mapSettings.zoom === 0) ||
3067+
(typeof origin === 'undefined') ||
3068+
(distError === true) ||
3069+
(_this.settings.maxDistance === true && firstRun === false)
3070+
) {
30613071
bounds.extend(point);
30623072
}
30633073
// Pass variables to the pop-up infowindows
30643074
_this.createInfowindow(marker, null, infowindow, storeStart, page);
30653075
}
30663076

30673077
// Center and zoom if no origin or zoom was provided, or distance of first marker is greater than distanceAlert
3068-
if ((_this.settings.fullMapStart === true && firstRun === true && _this.settings.querystringParams !== true) || (_this.settings.mapSettings.zoom === 0) || (typeof origin === 'undefined') || (distError === true)) {
3078+
if (
3079+
(_this.settings.fullMapStart === true && firstRun === true && _this.settings.querystringParams !== true) ||
3080+
(_this.settings.mapSettings.zoom === 0) ||
3081+
(typeof origin === 'undefined') ||
3082+
(distError === true) ||
3083+
(_this.settings.maxDistance === true && firstRun === false)
3084+
) {
30693085
_this.map.fitBounds(bounds);
30703086

30713087
// Prevent zooming in too far after fitBounds
@@ -3082,7 +3098,13 @@
30823098
locList.empty();
30833099

30843100
// Set up the location list markup
3085-
if (firstRun && _this.settings.fullMapStartListLimit !== false && !isNaN(_this.settings.fullMapStartListLimit) && _this.settings.fullMapStartListLimit !== -1 && markers.length > _this.settings.fullMapStartListLimit) {
3101+
if (
3102+
firstRun &&
3103+
_this.settings.fullMapStartListLimit !== false &&
3104+
!isNaN(_this.settings.fullMapStartListLimit) &&
3105+
_this.settings.fullMapStartListLimit !== -1 &&
3106+
markers.length > _this.settings.fullMapStartListLimit
3107+
) {
30863108
for (var m = 0; m < _this.settings.fullMapStartListLimit; m++) {
30873109
var currentMarker = markers[m];
30883110
_this.listSetup(currentMarker, storeStart, page);

0 commit comments

Comments
 (0)