Skip to content

Commit 29c7b6f

Browse files
authored
Merge pull request bjorn2404#159 from ollea/patch-4
Update jquery.storelocator.js
2 parents dc137e2 + a28fcd6 commit 29c7b6f

File tree

1 file changed

+33
-24
lines changed

1 file changed

+33
-24
lines changed

src/js/jquery.storelocator.js

Lines changed: 33 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
}
1111

1212
// Variables used across multiple methods
13-
var $this, listTemplate, infowindowTemplate, dataTypeRead, originalOrigin, originalData, originalZoom, dataRequest, searchInput, addressInput, olat, olng, storeNum, directionsDisplay, directionsService, prevSelectedMarkerBefore, prevSelectedMarkerAfter, firstRun;
13+
var $this, map, listTemplate, infowindowTemplate, dataTypeRead, originalOrigin, originalData, originalZoom, dataRequest, searchInput, addressInput, olat, olng, storeNum, directionsDisplay, directionsService, prevSelectedMarkerBefore, prevSelectedMarkerAfter, firstRun;
1414
var featuredset = [], locationset = [], normalset = [], markers = [];
1515
var filters = {}, locationData = {}, GeoCodeCalc = {}, mappingObj = {};
1616

@@ -376,6 +376,15 @@
376376
}
377377
},
378378

379+
/**
380+
* Get google.maps.Map instance
381+
*
382+
* @returns {Object} google.maps.Map instance
383+
*/
384+
getMap: function() {
385+
return this.map;
386+
},
387+
379388
/**
380389
* Load templates via Handlebars templates in /templates or inline via IDs - private
381390
*/
@@ -599,13 +608,13 @@
599608
myOptions.center = latlng;
600609

601610
// Create the map
602-
var map = new google.maps.Map(document.getElementById(_this.settings.mapID), myOptions);
611+
_this.map = new google.maps.Map(document.getElementById(_this.settings.mapID), myOptions);
603612

604613
// Re-center the map when the browser is re-sized
605614
google.maps.event.addDomListener(window, 'resize', function() {
606-
var center = map.getCenter();
607-
google.maps.event.trigger(map, 'resize');
608-
map.setCenter(center);
615+
var center = _this.map.getCenter();
616+
google.maps.event.trigger(_this.map, 'resize');
617+
_this.map.setCenter(center);
609618
});
610619

611620
// Only do this once
@@ -1957,11 +1966,11 @@
19571966
noResults;
19581967

19591968
// Create the map
1960-
var map = new google.maps.Map(document.getElementById(this.settings.mapID), myOptions);
1969+
this.map = new google.maps.Map(document.getElementById(this.settings.mapID), myOptions);
19611970

19621971
// Callback
19631972
if (this.settings.callbackNoResults) {
1964-
this.settings.callbackNoResults.call(this, map, myOptions);
1973+
this.settings.callbackNoResults.call(this, this.map, myOptions);
19651974
}
19661975

19671976
// Empty the location list
@@ -1978,10 +1987,10 @@
19781987
center = new google.maps.LatLng(0, 0);
19791988
}
19801989

1981-
map.setCenter(center);
1990+
this.map.setCenter(center);
19821991

19831992
if (originalZoom) {
1984-
map.setZoom(originalZoom);
1993+
this.map.setZoom(originalZoom);
19851994
}
19861995
},
19871996

@@ -2499,35 +2508,35 @@
24992508
}
25002509

25012510
// Create the map
2502-
var map = new google.maps.Map(document.getElementById(_this.settings.mapID), myOptions);
2511+
_this.map = new google.maps.Map(document.getElementById(_this.settings.mapID), myOptions);
25032512

25042513
// Re-center the map when the browser is re-sized
25052514
google.maps.event.addDomListener(window, 'resize', function() {
2506-
var center = map.getCenter();
2507-
google.maps.event.trigger(map, 'resize');
2508-
map.setCenter(center);
2515+
var center = _this.map.getCenter();
2516+
google.maps.event.trigger(_this.map, 'resize');
2517+
_this.map.setCenter(center);
25092518
});
25102519

25112520

25122521
// Add map drag listener if setting is enabled and re-search on drag end
25132522
if (_this.settings.dragSearch === true ) {
2514-
map.addListener('dragend', function() {
2523+
_this.map.addListener('dragend', function() {
25152524
_this.dragSearch(map);
25162525
});
25172526
}
25182527

25192528
// Load the map
2520-
$this.data(_this.settings.mapID.replace('#', ''), map);
2529+
$this.data(_this.settings.mapID.replace('#', ''), _this.map);
25212530

25222531
// Map set callback.
25232532
if (_this.settings.callbackMapSet) {
2524-
_this.settings.callbackMapSet.call(this, map, originPoint, originalZoom, myOptions);
2533+
_this.settings.callbackMapSet.call(this, _this.map, originPoint, originalZoom, myOptions);
25252534
}
25262535

25272536
// Initialize the infowondow
25282537
if ( typeof InfoBubble !== 'undefined' && _this.settings.infoBubble !== null ) {
25292538
var infoBubbleSettings = _this.settings.infoBubble;
2530-
infoBubbleSettings.map = map;
2539+
infoBubbleSettings.map = _this.map;
25312540

25322541
infowindow = new InfoBubble(infoBubbleSettings);
25332542
} else {
@@ -2536,7 +2545,7 @@
25362545

25372546

25382547
// Add origin marker if the setting is set
2539-
_this.originMarker(origin,originPoint,map);
2548+
_this.originMarker(origin,originPoint,_this.map);
25402549

25412550
// Handle pagination
25422551
$(document).on('click.'+pluginName, '.bh-sl-pagination li', function (e) {
@@ -2546,7 +2555,7 @@
25462555
});
25472556

25482557
// Inline directions
2549-
_this.inlineDirections(map, origin);
2558+
_this.inlineDirections(_this.map, origin);
25502559

25512560
// Add markers and infowindows loop
25522561
for (var y = 0; y <= storeNumToShow - 1; y++) {
@@ -2560,7 +2569,7 @@
25602569
}
25612570

25622571
var point = new google.maps.LatLng(locationset[y].lat, locationset[y].lng);
2563-
marker = _this.createMarker(point, locationset[y].name, locationset[y].address, letter, map, locationset[y].category);
2572+
marker = _this.createMarker(point, locationset[y].name, locationset[y].address, letter, _this.map, locationset[y].category);
25642573
marker.set('id', y);
25652574
markers[y] = marker;
25662575
if ((_this.settings.fullMapStart === true && firstRun === true) || (_this.settings.mapSettings.zoom === 0) || (typeof origin === 'undefined') || (distError === true)) {
@@ -2572,7 +2581,7 @@
25722581

25732582
// Center and zoom if no origin or zoom was provided, or distance of first marker is greater than distanceAlert
25742583
if ((_this.settings.fullMapStart === true && firstRun === true) || (_this.settings.mapSettings.zoom === 0) || (typeof origin === 'undefined') || (distError === true)) {
2575-
map.fitBounds(bounds);
2584+
_this.map.fitBounds(bounds);
25762585
}
25772586

25782587
// Create the links that focus on the related marker
@@ -2594,18 +2603,18 @@
25942603

25952604
// MarkerClusterer setup
25962605
if ( typeof MarkerClusterer !== 'undefined' && _this.settings.markerCluster !== null ) {
2597-
var markerCluster = new MarkerClusterer(map, markers, _this.settings.markerCluster);
2606+
var markerCluster = new MarkerClusterer(_this.map, markers, _this.settings.markerCluster);
25982607
}
25992608

26002609
// Handle clicks from the list
2601-
_this.listClick(map, infowindow, storeStart, page);
2610+
_this.listClick(_this.map, infowindow, storeStart, page);
26022611

26032612
// Add the list li background colors - this wil be dropped in a future version in favor of CSS
26042613
$('.' + _this.settings.locationList + ' ul > li:even').css('background', _this.settings.listColor1);
26052614
$('.' + _this.settings.locationList + ' ul > li:odd').css('background', _this.settings.listColor2);
26062615

26072616
// Visible markers list
2608-
_this.visibleMarkersList(map, markers);
2617+
_this.visibleMarkersList(_this.map, markers);
26092618

26102619
// Modal ready callback
26112620
if (_this.settings.modal === true && _this.settings.callbackModalReady) {

0 commit comments

Comments
 (0)