Skip to content

Commit 706097a

Browse files
committed
Added dragSearch setting, added geocodeID setting, updated Bower file, options, package, readme,
1 parent feb4ecc commit 706097a

File tree

8 files changed

+192
-61
lines changed

8 files changed

+192
-61
lines changed

bower.json

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "jquery-storelocator-plugin",
3-
"version": "2.4.2",
3+
"version": "2.5.0",
44
"description": "This jQuery plugin takes advantage of Google Maps API version 3 to create an easy to implement store locator. No back-end programming is required, you just need to feed it KML, XML, or JSON data with all the location information.",
55
"repository": {
66
"type": "git",
@@ -16,7 +16,11 @@
1616
"handlebars": ">=1.0"
1717
},
1818
"main" : [
19+
"dist/assets/js/plugins/storeLocator/jquery.storelocator.js",
1920
"dist/assets/js/plugins/storeLocator/jquery.storelocator.min.js",
21+
"dist/assets/js/plugins/storeLocator/templates/infowindow-description.html",
22+
"dist/assets/js/plugins/storeLocator/templates/location-list-description.html",
23+
"dist/assets/css/storelocator.css",
2024
"dist/assets/css/storelocator.min.css"
2125
],
2226
"devDependencies": {

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

+86-28
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/*! jQuery Google Maps Store Locator - v2.4.2 - 2016-02-28
1+
/*! jQuery Google Maps Store Locator - v2.5.0 - 2016-03-06
22
* http://www.bjornblog.com/web/jquery-store-locator-plugin
33
* Copyright (c) 2016 Bjorn Holine; Licensed MIT */
44

@@ -58,6 +58,7 @@
5858
'defaultLng' : null,
5959
'autoComplete' : false,
6060
'autoGeocode' : false,
61+
'geocodeID' : null,
6162
'maxDistance' : false,
6263
'maxDistanceID' : 'bh-sl-maxdistance',
6364
'fullMapStart' : false,
@@ -74,6 +75,7 @@
7475
'searchID' : 'bh-sl-search',
7576
'nameAttribute' : 'name',
7677
'visibleMarkersList' : false,
78+
'dragSearch' : false,
7779
'infowindowTemplatePath' : 'assets/js/plugins/storeLocator/templates/infowindow-description.html',
7880
'listTemplatePath' : 'assets/js/plugins/storeLocator/templates/location-list-description.html',
7981
'KMLinfowindowTemplatePath': 'assets/js/plugins/storeLocator/templates/kml-infowindow-description.html',
@@ -559,39 +561,58 @@
559561
}
560562
}
561563

562-
// HTML5 geolocation API option
564+
// HTML5 auto geolocation API option
563565
if (this.settings.autoGeocode === true && doAutoGeo === true) {
564566
_this.writeDebug('Auto Geo');
565-
// Saved geo location (saves around 3-5 seconds)
566-
if (_this.settings.sessionStorage === true && window.sessionStorage && window.sessionStorage.getItem('myGeo')){
567-
_this.writeDebug('Using Session Saved Values for GEO');
568-
_this.autoGeocodeQuery(JSON.parse(window.sessionStorage.getItem('myGeo')));
569-
return false;
570-
}
571-
else if (navigator.geolocation) {
572-
navigator.geolocation.getCurrentPosition(function(position){
573-
_this.writeDebug('Current Position Result');
574-
// To not break autoGeocodeQuery then we create the obj to match the geolocation format
575-
var pos = {
576-
coords: {
577-
latitude : position.coords.latitude,
578-
longitude: position.coords.longitude,
579-
accuracy : position.coords.accuracy
580-
}
581-
};
582-
// Have to do this to get around scope issues
583-
if (_this.settings.sessionStorage === true && window.sessionStorage) {
584-
window.sessionStorage.setItem('myGeo',JSON.stringify(pos));
585-
}
586-
_this.autoGeocodeQuery(pos);
587-
}, function(error){
588-
_this._autoGeocodeError(error);
589-
});
590-
}
567+
568+
_this.htmlGeocode();
569+
}
570+
571+
// HTML5 geolocation API button option
572+
if (this.settings.autoGeocode !== null) {
573+
_this.writeDebug('Button Geo');
574+
575+
$(document).on('click.'+pluginName, '#' + this.settings.geocodeID, function () {
576+
_this.htmlGeocode();
577+
});
591578
}
592579
}
593580
},
594581

582+
/**
583+
* Geocode function used for auto geocode setting and geocodeID button
584+
*/
585+
htmlGeocode: function() {
586+
this.writeDebug('htmlGeocode',arguments);
587+
var _this = this;
588+
589+
if (this.settings.sessionStorage === true && window.sessionStorage && window.sessionStorage.getItem('myGeo')){
590+
this.writeDebug('Using Session Saved Values for GEO');
591+
this.autoGeocodeQuery(JSON.parse(window.sessionStorage.getItem('myGeo')));
592+
return false;
593+
}
594+
else if (navigator.geolocation) {
595+
navigator.geolocation.getCurrentPosition(function(position){
596+
_this.writeDebug('Current Position Result');
597+
// To not break autoGeocodeQuery then we create the obj to match the geolocation format
598+
var pos = {
599+
coords: {
600+
latitude : position.coords.latitude,
601+
longitude: position.coords.longitude,
602+
accuracy : position.coords.accuracy
603+
}
604+
};
605+
// Have to do this to get around scope issues
606+
if (_this.settings.sessionStorage === true && window.sessionStorage) {
607+
window.sessionStorage.setItem('myGeo',JSON.stringify(pos));
608+
}
609+
_this.autoGeocodeQuery(pos);
610+
}, function(error){
611+
_this._autoGeocodeError(error);
612+
});
613+
}
614+
},
615+
595616
/**
596617
* Geocode function used to geocode the origin (entered location)
597618
*/
@@ -1692,6 +1713,35 @@
16921713
});
16931714
},
16941715

1716+
/**
1717+
* Performs a new search when the map is dragged to a new position
1718+
*
1719+
* @param map {Object} Google map
1720+
*/
1721+
dragSearch: function(map) {
1722+
this.writeDebug('dragSearch',arguments);
1723+
var newCenter = map.getCenter(),
1724+
newCenterCoords,
1725+
_this = this;
1726+
1727+
mappingObj = {};
1728+
olat = mappingObj.lat = newCenter.lat();
1729+
olng = mappingObj.lng = newCenter.lng();
1730+
1731+
// Determine the new origin addresss
1732+
var newAddress = new this.reverseGoogleGeocode(this);
1733+
newCenterCoords = new google.maps.LatLng(mappingObj.lat, mappingObj.lng);
1734+
newAddress.geocode({'latLng': newCenterCoords}, function (data) {
1735+
if (data !== null) {
1736+
mappingObj.origin = data.address;
1737+
_this.mapping(mappingObj);
1738+
} else {
1739+
// Unable to geocode
1740+
_this.notify(_this.settings.addressErrorAlert);
1741+
}
1742+
});
1743+
},
1744+
16951745
/**
16961746
* The primary mapping function that runs everything
16971747
*
@@ -2027,6 +2077,14 @@
20272077
map.setCenter(center);
20282078
});
20292079

2080+
2081+
// Add map drag listener if setting is enabled and re-search on drag end
2082+
if (_this.settings.dragSearch === true ) {
2083+
map.addListener('dragend', function() {
2084+
_this.dragSearch(map);
2085+
});
2086+
}
2087+
20302088
// Load the map
20312089
$this.data(_this.settings.mapID.replace('#', ''), map);
20322090

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

+3-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

options.md

+2
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
| defaultLng | null | If using defaultLoc, set this to the default location longitude. |
3737
| autoComplete | false | Set to true to enable Google Places autocomplete. Note the slight markup differences in the example file. |
3838
| autoGeocode | false | Set to true if you want to use the HTML5 geolocation API (good for mobile) to geocode the user's location. |
39+
| geocodeID | null | Set to the ID of an element to connect the HTML5 geolocation API to a button instead of firing automatically. |
3940
| maxDistance | false | Set to true if you want to give users an option to limit the distance from their location to the markers. |
4041
| maxDistanceID | 'bh-sl-maxdistance' | ID of the select element for the maximum distance options. |
4142
| fullMapStart | false | Set to true if you want to immediately show a map of all locations. The map will center and zoom automatically. |
@@ -52,6 +53,7 @@
5253
| searchID | 'bh-sl-search' | ID of the search input form field for location name searching. |
5354
| nameAttribute | 'name' | If using nameSearch, the data attribute used for the location name in the data file. |
5455
| visibleMarkersList | false | Set to true to have the location list only show data from markers that are visible on the map. |
56+
| dragSearch | false | Set to true to perform a new search after the map is dragged. |
5557
| infowindowTemplatePath | 'assets/js/plugins/storeLocator/templates/infowindow-description.html' | Path to the default infowindow template. |
5658
| listTemplatePath | 'assets/js/plugins/storeLocator/templates/location-list-description.html' | Path to the default list template. |
5759
| KMLinfowindowTemplatePath | 'assets/js/plugins/storeLocator/templates/kml-infowindow-description.html' | Path to the KML infowindow template – used if dataType is set to kml. |

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "jquery-storelocator-plugin",
3-
"version": "2.4.2",
3+
"version": "2.5.0",
44
"description": "This jQuery plugin takes advantage of Google Maps API version 3 to create an easy to implement store locator. No back-end programming is required, you just need to feed it KML, XML, or JSON data with all the location information.",
55
"repository": {
66
"type": "git",

readme.md

+9
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,15 @@ filtering.
3535

3636
## Changelog
3737

38+
### Version 2.5.0
39+
40+
* Added new dragSearch setting which peforms a new search when the map is dragged when enabled.
41+
* Added new geocodeID setting so that the HTML geocoding API can be triggered by a button instead of firing automatically.
42+
* Fixed issues with no results where clicking the marker would display data from the previous result and clicking the location list item would throw an error.
43+
* Merged in pull request from [hawkmeister](https://github.com/hawkmeister) with update to bower.json file with main property.
44+
* Merged in pull request from [hyperTwitch](https://github.com/hyperTwitch) with fixes for using fullMapStartListLimit in combination with a different store limit.
45+
* Updated jQuery references to the latest version.
46+
3847
### Version 2.4.2
3948

4049
* Fixed issue with new full map start location list limit where clicking on a marker that didn't have a list item

src/js/jquery.storelocator.js

+85-27
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
'defaultLng' : null,
5656
'autoComplete' : false,
5757
'autoGeocode' : false,
58+
'geocodeID' : null,
5859
'maxDistance' : false,
5960
'maxDistanceID' : 'bh-sl-maxdistance',
6061
'fullMapStart' : false,
@@ -71,6 +72,7 @@
7172
'searchID' : 'bh-sl-search',
7273
'nameAttribute' : 'name',
7374
'visibleMarkersList' : false,
75+
'dragSearch' : false,
7476
'infowindowTemplatePath' : 'assets/js/plugins/storeLocator/templates/infowindow-description.html',
7577
'listTemplatePath' : 'assets/js/plugins/storeLocator/templates/location-list-description.html',
7678
'KMLinfowindowTemplatePath': 'assets/js/plugins/storeLocator/templates/kml-infowindow-description.html',
@@ -556,39 +558,58 @@
556558
}
557559
}
558560

559-
// HTML5 geolocation API option
561+
// HTML5 auto geolocation API option
560562
if (this.settings.autoGeocode === true && doAutoGeo === true) {
561563
_this.writeDebug('Auto Geo');
562-
// Saved geo location (saves around 3-5 seconds)
563-
if (_this.settings.sessionStorage === true && window.sessionStorage && window.sessionStorage.getItem('myGeo')){
564-
_this.writeDebug('Using Session Saved Values for GEO');
565-
_this.autoGeocodeQuery(JSON.parse(window.sessionStorage.getItem('myGeo')));
566-
return false;
567-
}
568-
else if (navigator.geolocation) {
569-
navigator.geolocation.getCurrentPosition(function(position){
570-
_this.writeDebug('Current Position Result');
571-
// To not break autoGeocodeQuery then we create the obj to match the geolocation format
572-
var pos = {
573-
coords: {
574-
latitude : position.coords.latitude,
575-
longitude: position.coords.longitude,
576-
accuracy : position.coords.accuracy
577-
}
578-
};
579-
// Have to do this to get around scope issues
580-
if (_this.settings.sessionStorage === true && window.sessionStorage) {
581-
window.sessionStorage.setItem('myGeo',JSON.stringify(pos));
582-
}
583-
_this.autoGeocodeQuery(pos);
584-
}, function(error){
585-
_this._autoGeocodeError(error);
586-
});
587-
}
564+
565+
_this.htmlGeocode();
566+
}
567+
568+
// HTML5 geolocation API button option
569+
if (this.settings.autoGeocode !== null) {
570+
_this.writeDebug('Button Geo');
571+
572+
$(document).on('click.'+pluginName, '#' + this.settings.geocodeID, function () {
573+
_this.htmlGeocode();
574+
});
588575
}
589576
}
590577
},
591578

579+
/**
580+
* Geocode function used for auto geocode setting and geocodeID button
581+
*/
582+
htmlGeocode: function() {
583+
this.writeDebug('htmlGeocode',arguments);
584+
var _this = this;
585+
586+
if (this.settings.sessionStorage === true && window.sessionStorage && window.sessionStorage.getItem('myGeo')){
587+
this.writeDebug('Using Session Saved Values for GEO');
588+
this.autoGeocodeQuery(JSON.parse(window.sessionStorage.getItem('myGeo')));
589+
return false;
590+
}
591+
else if (navigator.geolocation) {
592+
navigator.geolocation.getCurrentPosition(function(position){
593+
_this.writeDebug('Current Position Result');
594+
// To not break autoGeocodeQuery then we create the obj to match the geolocation format
595+
var pos = {
596+
coords: {
597+
latitude : position.coords.latitude,
598+
longitude: position.coords.longitude,
599+
accuracy : position.coords.accuracy
600+
}
601+
};
602+
// Have to do this to get around scope issues
603+
if (_this.settings.sessionStorage === true && window.sessionStorage) {
604+
window.sessionStorage.setItem('myGeo',JSON.stringify(pos));
605+
}
606+
_this.autoGeocodeQuery(pos);
607+
}, function(error){
608+
_this._autoGeocodeError(error);
609+
});
610+
}
611+
},
612+
592613
/**
593614
* Geocode function used to geocode the origin (entered location)
594615
*/
@@ -1689,6 +1710,35 @@
16891710
});
16901711
},
16911712

1713+
/**
1714+
* Performs a new search when the map is dragged to a new position
1715+
*
1716+
* @param map {Object} Google map
1717+
*/
1718+
dragSearch: function(map) {
1719+
this.writeDebug('dragSearch',arguments);
1720+
var newCenter = map.getCenter(),
1721+
newCenterCoords,
1722+
_this = this;
1723+
1724+
mappingObj = {};
1725+
olat = mappingObj.lat = newCenter.lat();
1726+
olng = mappingObj.lng = newCenter.lng();
1727+
1728+
// Determine the new origin addresss
1729+
var newAddress = new this.reverseGoogleGeocode(this);
1730+
newCenterCoords = new google.maps.LatLng(mappingObj.lat, mappingObj.lng);
1731+
newAddress.geocode({'latLng': newCenterCoords}, function (data) {
1732+
if (data !== null) {
1733+
mappingObj.origin = data.address;
1734+
_this.mapping(mappingObj);
1735+
} else {
1736+
// Unable to geocode
1737+
_this.notify(_this.settings.addressErrorAlert);
1738+
}
1739+
});
1740+
},
1741+
16921742
/**
16931743
* The primary mapping function that runs everything
16941744
*
@@ -2024,6 +2074,14 @@
20242074
map.setCenter(center);
20252075
});
20262076

2077+
2078+
// Add map drag listener if setting is enabled and re-search on drag end
2079+
if (_this.settings.dragSearch === true ) {
2080+
map.addListener('dragend', function() {
2081+
_this.dragSearch(map);
2082+
});
2083+
}
2084+
20272085
// Load the map
20282086
$this.data(_this.settings.mapID.replace('#', ''), map);
20292087

storelocator.jquery.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"title": "jQuery Google Maps Store Locator",
44
"description": "This jQuery plugin takes advantage of Google Maps API version 3 to create an easy to implement store locator. No back-end programming is required, you just need to feed it KML, XML, or JSON data with all the location information.",
55
"keywords": ["jquery","locator","store", "location", "locations", "maps", "map", "stores", "find"],
6-
"version": "2.4.2",
6+
"version": "2.5.0",
77
"author": {
88
"name": "Bjorn Holine",
99
"url": "http://www.bjornblog.com/"

0 commit comments

Comments
 (0)