|
33 | 33 | zoom : 12,
|
34 | 34 | mapTypeId: google.maps.MapTypeId.ROADMAP
|
35 | 35 | },
|
36 |
| - 'pinColor' : 'fe7569', |
| 36 | + 'pinColor' : 'fe7569', //TODO: New marker settings |
37 | 37 | 'pinTextColor' : '000000',
|
38 | 38 | 'lengthUnit' : 'm',
|
39 | 39 | 'storeLimit' : 26,
|
|
60 | 60 | 'maxDistanceID' : 'maxdistance',
|
61 | 61 | 'fullMapStart' : false,
|
62 | 62 | 'noForm' : false,
|
63 |
| - 'loading' : false, |
| 63 | + 'loading' : false, //TODO: Add loading back |
64 | 64 | 'loadingDiv' : 'bh-storelocator-loading',
|
65 | 65 | 'featuredLocations' : false,
|
66 | 66 | 'pagination' : false,
|
|
74 | 74 | 'infowindowTemplateID' : null,
|
75 | 75 | 'taxonomyFilters' : null,
|
76 | 76 | 'callbackBeforeSend' : null,
|
77 |
| - 'callbackComplete' : null, |
78 | 77 | 'callbackSuccess' : null,
|
79 | 78 | 'callbackModalOpen' : null,
|
80 | 79 | 'callbackModalClose' : null,
|
|
136 | 135 | else {
|
137 | 136 | dataTypeRead = this.settings.dataType;
|
138 | 137 | }
|
139 |
| - |
140 |
| - // Do the initial data request |
141 |
| - originalDataRequest = this.getData(); |
142 |
| - |
143 |
| - // Save separately so we can avoid multiple AJAX requests |
144 |
| - originalDataRequest.done(function (data) { |
145 |
| - originalData = data; |
146 |
| - }); |
147 |
| - |
148 |
| - // Save the original zoom setting so it can be retrieved if taxonomy filtering resets it |
149 |
| - originalZoom = this.settings.mapSettings.zoom; |
150 | 138 |
|
151 | 139 | // Set up the directionsService if it's true
|
152 | 140 | if(this.settings.inlineDirections === true){
|
153 | 141 | directionsDisplay = new google.maps.DirectionsRenderer();
|
154 | 142 | directionsService = new google.maps.DirectionsService();
|
155 | 143 | $(this.settings.listDiv).prepend('<div class="bh-storelocator-directions-panel"></div>');
|
156 | 144 | }
|
| 145 | + |
| 146 | + // Save the original zoom setting so it can be retrieved if taxonomy filtering resets it |
| 147 | + originalZoom = this.settings.mapSettings.zoom; |
157 | 148 |
|
158 | 149 | // Add Handlebars helper for handling URL output
|
159 | 150 | Handlebars.registerHelper('niceURL', function(url) {
|
|
197 | 188 | }
|
198 | 189 | // Handle script tag template method
|
199 | 190 | else if (this.settings.listTemplateID !== null && this.settings.infowindowTemplateID !== null) {
|
200 |
| - //TODO: Test this |
201 | 191 | // Infowindows
|
202 | 192 | infowindowTemplate = Handlebars.compile($(this.settings.infowindowTemplateID).html());
|
203 | 193 |
|
|
232 | 222 | });
|
233 | 223 | }
|
234 | 224 | },
|
| 225 | + |
| 226 | + /** |
| 227 | + * Primary locator function runs after the templates are loaded |
| 228 | + */ |
| 229 | + locator: function () { |
| 230 | + // Do taxonomy filtering if set |
| 231 | + if (this.settings.taxonomyFilters !== null) { |
| 232 | + this.taxonomyFiltering(); |
| 233 | + } |
| 234 | + |
| 235 | + // Add modal window divs if set |
| 236 | + if (this.settings.modalWindow === true) { |
| 237 | + $this.wrap('<div class="' + this.settings.overlayDiv + '"><div class="' + this.settings.modalWindowDiv + '"><div class="' + this.settings.modalContentDiv + '">'); |
| 238 | + $('.' + this.settings.modalWindowDiv).prepend('<div class="' + this.settings.closeIconDiv + '"></div>'); |
| 239 | + $('.' + this.settings.overlayDiv).hide(); |
| 240 | + } |
| 241 | + |
| 242 | + if (this.settings.slideMap === true) { |
| 243 | + // Let's hide the map container to begin |
| 244 | + $this.hide(); |
| 245 | + } |
| 246 | + |
| 247 | + this.start(); |
| 248 | + this.processFormInput(); |
| 249 | + }, |
235 | 250 |
|
236 | 251 | /**
|
237 | 252 | * Reset function
|
|
288 | 303 | },
|
289 | 304 |
|
290 | 305 | /**
|
291 |
| - * Changing AJAX call to this function. TODO: Add old callbacks, maybe switch to when/then |
| 306 | + * AJAX data request |
292 | 307 | */
|
293 |
| - getData: function () { |
| 308 | + getData: function (lat, lng, address) { |
294 | 309 | var d = $.Deferred();
|
| 310 | + |
| 311 | + // Before send callback |
| 312 | + if (this.settings.callbackBeforeSend) { |
| 313 | + this.settings.callbackBeforeSend.call(this); |
| 314 | + } |
295 | 315 |
|
| 316 | + // AJAX request |
296 | 317 | $.ajax({
|
297 | 318 | type : 'GET',
|
298 | 319 | url : this.settings.dataLocation + (this.settings.dataType === 'jsonp' ? (this.settings.dataLocation.match(/\?/) ? '&' : '?') + 'callback=?' : ''),
|
| 320 | + // Passing the lat, lng, and address with the AJAX request so they can optionally be used by back-end languages |
| 321 | + data: { |
| 322 | + 'origLat' : lat, |
| 323 | + 'origLng' : lng, |
| 324 | + 'origAddress': address |
| 325 | + }, |
299 | 326 | dataType : dataTypeRead,
|
300 | 327 | jsonpCallback: (this.settings.dataType === 'jsonp' ? this.settings.jsonpCallback : null)
|
301 | 328 | }).done(function (p) {
|
|
382 | 409 | r.geocode({'latLng': latlng}, function (data) {
|
383 | 410 | if (data !== null) {
|
384 | 411 | var originAddress = data.address;
|
385 |
| - _this.mapping(originalData, _this.settings.defaultLat, _this.settings.defaultLng, originAddress); |
| 412 | + _this.mapping(_this.settings.defaultLat, _this.settings.defaultLng, originAddress); |
386 | 413 | } else {
|
387 | 414 | // Unable to geocode
|
388 |
| - alert(this.settings.addressErrorAlert); |
| 415 | + alert(_this.settings.addressErrorAlert); |
389 | 416 | }
|
390 | 417 | });
|
391 | 418 | }
|
392 | 419 |
|
393 | 420 | // If show full map option is true
|
394 | 421 | if (this.settings.fullMapStart === true) {
|
395 | 422 | // Just do the mapping without an origin
|
396 |
| - this.mapping(originalData); |
| 423 | + this.mapping(); |
397 | 424 | }
|
398 | 425 |
|
399 | 426 | // HTML5 geolocation API option
|
|
569 | 596 | }
|
570 | 597 | },
|
571 | 598 |
|
572 |
| - /** |
573 |
| - * Google distance calculation WIP |
574 |
| - */ |
575 |
| - calcRoute: function (start, end) { |
576 |
| - var unitSystem; |
577 |
| - var directionsService = new google.maps.DirectionsService(); |
578 |
| - |
579 |
| - if (this.settings.lengthUnit === 'm') { |
580 |
| - unitSystem = google.maps.UnitSystem.IMPERIAL; |
581 |
| - } |
582 |
| - else { |
583 |
| - unitSystem = google.maps.UnitSystem.METRIC; |
584 |
| - } |
585 |
| - |
586 |
| - var request = { |
587 |
| - origin : start, |
588 |
| - destination: end, |
589 |
| - travelMode : google.maps.TravelMode.DRIVING, //Make new setting |
590 |
| - unitSystem : unitSystem |
591 |
| - }; |
592 |
| - directionsService.route(request, function (response, status) { |
593 |
| - if (status === google.maps.DirectionsStatus.OK) { |
594 |
| - return(response); |
595 |
| - } |
596 |
| - }); |
597 |
| - }, |
598 |
| - |
599 |
| - /** |
600 |
| - * Google distance matrix request probably not going to use but save for later |
601 |
| - * |
602 |
| - * @param origins {array} origins - in this case, the origin will always be what the user enters |
603 |
| - * @param destinations {array} locations |
604 |
| - */ |
605 |
| - calculateDistances: function (origins, destinations) { |
606 |
| - var service = new google.maps.DistanceMatrixService(); |
607 |
| - var request = { |
608 |
| - origins : origins, |
609 |
| - destinations : destinations, |
610 |
| - travelMode : google.maps.TravelMode.DRIVING, |
611 |
| - unitSystem : google.maps.UnitSystem.IMPERIAL, //TODO: make setting |
612 |
| - avoidHighways: false, |
613 |
| - avoidTolls : false |
614 |
| - }; |
615 |
| - |
616 |
| - service.getDistanceMatrix(request, function (response, status) { |
617 |
| - if (status === google.maps.DistanceMatrixStatus.OK) { |
618 |
| - return(response); |
619 |
| - } |
620 |
| - }); |
621 |
| - }, |
622 |
| - |
623 | 599 | /**
|
624 | 600 | * Map marker setup
|
625 | 601 | *
|
|
632 | 608 | createMarker: function (point, name, address, letter, map) {
|
633 | 609 | var marker;
|
634 | 610 |
|
635 |
| - // Set up pin icon with the Google Charts API for all of our markers |
636 |
| - /*var pinImage = new google.maps.MarkerImage('https://chart.googleapis.com/chart?chst=d_map_pin_letter&chld=' + letter + '|' + this.settings.pinColor + '|' + this.settings.pinTextColor, |
637 |
| - new google.maps.Size(21, 34), |
638 |
| - new google.maps.Point(0, 0), |
639 |
| - new google.maps.Point(10, 34));*/ |
| 611 | + // Letter markers image |
640 | 612 | var pinImage = new google.maps.MarkerImage('http://mt.googleapis.com/vt/icon/name=icons/spotlight/spotlight-waypoint-b.png&text=' + letter + '&psize=16&font=fonts/Roboto-Regular.ttf&color=ff333333&ax=44&ay=48');
|
641 | 613 |
|
642 | 614 | // Create the markers
|
|
648 | 620 | });
|
649 | 621 | }
|
650 | 622 | else {
|
| 623 | + // Default dot marker |
651 | 624 | marker = new google.maps.Marker({
|
652 | 625 | position : point,
|
653 | 626 | map : map,
|
|
705 | 678 | }
|
706 | 679 |
|
707 | 680 | // Define location data
|
708 |
| - var locations = { |
| 681 | + return { |
709 | 682 | location: [$.extend(locationData, {
|
710 | 683 | 'markerid': markerId,
|
711 | 684 | 'marker' : indicator,
|
712 | 685 | 'length' : distLength,
|
713 | 686 | 'origin' : userInput
|
714 | 687 | })]
|
715 | 688 | };
|
716 |
| - |
717 |
| - return locations; |
718 | 689 | },
|
719 | 690 |
|
720 | 691 | /**
|
721 |
| - * Set up the list templates TODO: Maybe rename this function because it's doing more than just handling the clicks |
| 692 | + * Set up the list templates |
722 | 693 | *
|
723 | 694 | * @param marker {object} Google Maps marker
|
724 | 695 | * @param storeStart {number} optional first location on the current page
|
725 | 696 | * @param page {number} optional current page
|
726 | 697 | */
|
727 |
| - listClick: function (marker, storeStart, page) { |
| 698 | + listSetup: function (marker, storeStart, page) { |
728 | 699 | // Define the location data
|
729 | 700 | var locations = this.defineLocationData(marker, storeStart, page);
|
730 | 701 |
|
|
777 | 748 | r.geocode({'latLng': latlng}, function (data) {
|
778 | 749 | if (data !== null) {
|
779 | 750 | var originAddress = data.address;
|
780 |
| - _this.mapping(originalData, position.coords.latitude, position.coords.longitude, originAddress); |
| 751 | + _this.mapping(position.coords.latitude, position.coords.longitude, originAddress); |
781 | 752 | } else {
|
782 | 753 | // Unable to geocode
|
783 | 754 | alert(this.settings.addressErrorAlert);
|
|
808 | 779 | }
|
809 | 780 |
|
810 | 781 | this.reset();
|
811 |
| - this.mapping(originalData, olat, olng, userInput, maxDistance, newPage); |
| 782 | + this.mapping(olat, olng, userInput, maxDistance, newPage); |
812 | 783 | },
|
813 | 784 |
|
814 | 785 | /**
|
|
923 | 894 | if (data !== null) {
|
924 | 895 | olat = data.latitude;
|
925 | 896 | olng = data.longitude;
|
926 |
| - _this.mapping(originalData, olat, olng, userInput, distance); |
| 897 | + |
| 898 | + // Run the mapping function |
| 899 | + _this.mapping(olat, olng, userInput, distance); |
927 | 900 | } else {
|
928 | 901 | // Unable to geocode
|
929 | 902 | alert(this.settings.addressErrorAlert);
|
|
941 | 914 | * @param origin {string} origin address
|
942 | 915 | * @param maxDistance {number} optional maximum distance
|
943 | 916 | */
|
944 |
| - mapping: function (data, orig_lat, orig_lng, origin, maxDistance, page) { |
| 917 | + mapping: function (orig_lat, orig_lng, origin, maxDistance, page) { |
945 | 918 | var _this = this;
|
946 | 919 | var firstRun, marker, bounds, storeStart, storeNumToShow, myOptions;
|
947 | 920 | var i = 0;
|
|
956 | 929 | page = 0;
|
957 | 930 | }
|
958 | 931 |
|
| 932 | + // Do the initial data request - doing this here so the lat/lng and address can be passed over and used if needed |
| 933 | + originalDataRequest = _this.getData(olat, olng, origin); |
| 934 | + |
| 935 | + // Save data separately so we can avoid multiple AJAX requests |
| 936 | + originalDataRequest.done(function (data) { |
| 937 | + // Success callback |
| 938 | + if (_this.settings.callbackSuccess) { |
| 939 | + _this.settings.callbackSuccess.call(this); |
| 940 | + } |
| 941 | + |
| 942 | + originalData = data; |
| 943 | + }); |
| 944 | + |
959 | 945 | /**
|
960 | 946 | * Process the location data
|
961 | 947 | */
|
962 |
| - originalDataRequest.then(function () { |
| 948 | + originalDataRequest.then(function (data) { |
963 | 949 | // Callback
|
964 | 950 | if (_this.settings.callbackSuccess) {
|
965 | 951 | _this.settings.callbackSuccess.call(this);
|
|
1162 | 1148 |
|
1163 | 1149 | // Pop up the modal window
|
1164 | 1150 | $('.' + _this.settings.overlayDiv).fadeIn();
|
1165 |
| - // Close modal when close icon is clicked and when background overlay is clicked TODO: Make sure this works with multiple |
| 1151 | + // Close modal when close icon is clicked and when background overlay is clicked |
1166 | 1152 | $(document).on('click', '.' + _this.settings.closeIconDiv + ', .' + _this.settings.overlayDiv, function () {
|
1167 | 1153 | _this.modalClose();
|
1168 | 1154 | });
|
|
1298 | 1284 | $(markers).each(function (x, marker) {
|
1299 | 1285 | var letter = String.fromCharCode('A'.charCodeAt(0) + x);
|
1300 | 1286 | var currentMarker = markers[x];
|
1301 |
| - _this.listClick(currentMarker, storeStart, page); |
| 1287 | + _this.listSetup(currentMarker, storeStart, page); |
1302 | 1288 | });
|
1303 | 1289 |
|
1304 | 1290 | // Handle clicks from the list
|
|
1376 | 1362 | _this.beginMapping();
|
1377 | 1363 | }
|
1378 | 1364 | else {
|
1379 |
| - _this.mapping(originalData); |
| 1365 | + _this.mapping(); |
1380 | 1366 | }
|
1381 | 1367 | }
|
1382 | 1368 | }
|
|
1397 | 1383 | _this.beginMapping();
|
1398 | 1384 | }
|
1399 | 1385 | else {
|
1400 |
| - _this.mapping(originalData); |
| 1386 | + _this.mapping(); |
1401 | 1387 | }
|
1402 | 1388 | }
|
1403 | 1389 | }
|
|
1424 | 1410 | _this.beginMapping();
|
1425 | 1411 | }
|
1426 | 1412 | else {
|
1427 |
| - _this.mapping(originalData); |
| 1413 | + _this.mapping(); |
1428 | 1414 | }
|
1429 | 1415 | }
|
1430 | 1416 | }
|
|
1440 | 1426 | _this.beginMapping();
|
1441 | 1427 | }
|
1442 | 1428 | else {
|
1443 |
| - _this.mapping(originalData); |
| 1429 | + _this.mapping(); |
1444 | 1430 | }
|
1445 | 1431 | }
|
1446 | 1432 | }
|
1447 | 1433 | });
|
1448 |
| - }, |
1449 |
| - |
1450 |
| - /** |
1451 |
| - * Primary locator function runs after the templates are loaded |
1452 |
| - */ |
1453 |
| - locator: function () { |
1454 |
| - // Do taxonomy filtering if set |
1455 |
| - if (this.settings.taxonomyFilters !== null) { |
1456 |
| - this.taxonomyFiltering(); |
1457 |
| - } |
1458 |
| - |
1459 |
| - // Add modal window divs if set |
1460 |
| - if (this.settings.modalWindow === true) { |
1461 |
| - $this.wrap('<div class="' + this.settings.overlayDiv + '"><div class="' + this.settings.modalWindowDiv + '"><div class="' + this.settings.modalContentDiv + '">'); |
1462 |
| - $('.' + this.settings.modalWindowDiv).prepend('<div class="' + this.settings.closeIconDiv + '"></div>'); |
1463 |
| - $('.' + this.settings.overlayDiv).hide(); |
1464 |
| - } |
1465 |
| - |
1466 |
| - if (this.settings.slideMap === true) { |
1467 |
| - // Let's hide the map container to begin |
1468 |
| - $this.hide(); |
1469 |
| - } |
1470 |
| - |
1471 |
| - this.start(); |
1472 |
| - this.processFormInput(); |
1473 | 1434 | }
|
1474 | 1435 |
|
1475 | 1436 | });
|
|
0 commit comments