Skip to content

Update jquery.storelocator.js #159

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 28, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 33 additions & 24 deletions src/js/jquery.storelocator.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
}

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

Expand Down Expand Up @@ -376,6 +376,15 @@
}
},

/**
* Get google.maps.Map instance
*
* @returns {Object} google.maps.Map instance
*/
getMap: function() {
return this.map;
},

/**
* Load templates via Handlebars templates in /templates or inline via IDs - private
*/
Expand Down Expand Up @@ -599,13 +608,13 @@
myOptions.center = latlng;

// Create the map
var map = new google.maps.Map(document.getElementById(_this.settings.mapID), myOptions);
_this.map = new google.maps.Map(document.getElementById(_this.settings.mapID), myOptions);

// Re-center the map when the browser is re-sized
google.maps.event.addDomListener(window, 'resize', function() {
var center = map.getCenter();
google.maps.event.trigger(map, 'resize');
map.setCenter(center);
var center = _this.map.getCenter();
google.maps.event.trigger(_this.map, 'resize');
_this.map.setCenter(center);
});

// Only do this once
Expand Down Expand Up @@ -1957,11 +1966,11 @@
noResults;

// Create the map
var map = new google.maps.Map(document.getElementById(this.settings.mapID), myOptions);
this.map = new google.maps.Map(document.getElementById(this.settings.mapID), myOptions);

// Callback
if (this.settings.callbackNoResults) {
this.settings.callbackNoResults.call(this, map, myOptions);
this.settings.callbackNoResults.call(this, this.map, myOptions);
}

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

map.setCenter(center);
this.map.setCenter(center);

if (originalZoom) {
map.setZoom(originalZoom);
this.map.setZoom(originalZoom);
}
},

Expand Down Expand Up @@ -2499,35 +2508,35 @@
}

// Create the map
var map = new google.maps.Map(document.getElementById(_this.settings.mapID), myOptions);
_this.map = new google.maps.Map(document.getElementById(_this.settings.mapID), myOptions);

// Re-center the map when the browser is re-sized
google.maps.event.addDomListener(window, 'resize', function() {
var center = map.getCenter();
google.maps.event.trigger(map, 'resize');
map.setCenter(center);
var center = _this.map.getCenter();
google.maps.event.trigger(_this.map, 'resize');
_this.map.setCenter(center);
});


// Add map drag listener if setting is enabled and re-search on drag end
if (_this.settings.dragSearch === true ) {
map.addListener('dragend', function() {
_this.map.addListener('dragend', function() {
_this.dragSearch(map);
});
}

// Load the map
$this.data(_this.settings.mapID.replace('#', ''), map);
$this.data(_this.settings.mapID.replace('#', ''), _this.map);

// Map set callback.
if (_this.settings.callbackMapSet) {
_this.settings.callbackMapSet.call(this, map, originPoint, originalZoom, myOptions);
_this.settings.callbackMapSet.call(this, _this.map, originPoint, originalZoom, myOptions);
}

// Initialize the infowondow
if ( typeof InfoBubble !== 'undefined' && _this.settings.infoBubble !== null ) {
var infoBubbleSettings = _this.settings.infoBubble;
infoBubbleSettings.map = map;
infoBubbleSettings.map = _this.map;

infowindow = new InfoBubble(infoBubbleSettings);
} else {
Expand All @@ -2536,7 +2545,7 @@


// Add origin marker if the setting is set
_this.originMarker(origin,originPoint,map);
_this.originMarker(origin,originPoint,_this.map);

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

// Inline directions
_this.inlineDirections(map, origin);
_this.inlineDirections(_this.map, origin);

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

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

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

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

// MarkerClusterer setup
if ( typeof MarkerClusterer !== 'undefined' && _this.settings.markerCluster !== null ) {
var markerCluster = new MarkerClusterer(map, markers, _this.settings.markerCluster);
var markerCluster = new MarkerClusterer(_this.map, markers, _this.settings.markerCluster);
}

// Handle clicks from the list
_this.listClick(map, infowindow, storeStart, page);
_this.listClick(_this.map, infowindow, storeStart, page);

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

// Visible markers list
_this.visibleMarkersList(map, markers);
_this.visibleMarkersList(_this.map, markers);

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