|
1 |
| -/*! jQuery Google Maps Store Locator - v1.4.9 - 2014-09-21 |
| 1 | +/*! jQuery Google Maps Store Locator - v1.4.9 - 2014-10-05 |
2 | 2 | * http://www.bjornblog.com/web/jquery-store-locator-plugin
|
3 | 3 | * Copyright (c) 2014 Bjorn Holine; Licensed MIT */
|
4 | 4 |
|
|
19 | 19 | var featuredset = [], locationset = [], normalset = [], markers = [];
|
20 | 20 | var filters = {}, locationData = {}, GeoCodeCalc = {}, mappingObj = {};
|
21 | 21 |
|
22 |
| - // Create the defaults once. Do not change these settings in this file - settings should be overridden in the plugin call |
| 22 | + // Create the defaults once. DO NOT change these settings in this file - settings should be overridden in the plugin call |
23 | 23 | var defaults = {
|
24 | 24 | 'mapID' : 'bh-sl-map',
|
25 | 25 | 'locationList' : 'bh-sl-loc-list',
|
|
33 | 33 | },
|
34 | 34 | 'markerImg' : null,
|
35 | 35 | 'markerDim' : null,
|
| 36 | + 'catMarkers' : null, |
36 | 37 | 'lengthUnit' : 'm',
|
37 | 38 | 'storeLimit' : 26,
|
38 | 39 | 'distanceAlert' : 60,
|
|
59 | 60 | 'maxDistanceID' : 'bh-sl-maxdistance',
|
60 | 61 | 'fullMapStart' : false,
|
61 | 62 | 'noForm' : false,
|
62 |
| - 'loading' : false, //TODO: Add loading back |
| 63 | + 'loading' : false, |
63 | 64 | 'loadingContainer' : 'bh-sl-loading',
|
64 | 65 | 'featuredLocations' : false,
|
65 | 66 | 'pagination' : false,
|
|
354 | 355 |
|
355 | 356 | /**
|
356 | 357 | * AJAX data request
|
| 358 | + * |
| 359 | + * @param lat (number) |
| 360 | + * @param lng (number) |
| 361 | + * @param address (string) |
| 362 | + * @returns {*} |
357 | 363 | */
|
358 | 364 | getData: function (lat, lng, address) {
|
| 365 | + var _this = this; |
359 | 366 | var d = $.Deferred();
|
360 | 367 |
|
361 | 368 | // Before send callback
|
362 | 369 | if (this.settings.callbackBeforeSend) {
|
363 | 370 | this.settings.callbackBeforeSend.call(this);
|
364 | 371 | }
|
365 | 372 |
|
| 373 | + //Loading |
| 374 | + if(this.settings.loading === true){ |
| 375 | + $('.' + this.settings.formContainer).append('<div class="' + this.settings.loadingContainer +'"><\/div>'); |
| 376 | + } |
| 377 | + |
366 | 378 | // AJAX request
|
367 | 379 | $.ajax({
|
368 | 380 | type : 'GET',
|
|
377 | 389 | jsonpCallback: (this.settings.dataType === 'jsonp' ? this.settings.jsonpCallback : null)
|
378 | 390 | }).done(function (p) {
|
379 | 391 | d.resolve(p);
|
| 392 | + |
| 393 | + //Loading remove |
| 394 | + if(_this.settings.loading === true){ |
| 395 | + $('.' + _this.settings.formContainer + ' .' + _this.settings.loadingContainer).remove(); |
| 396 | + } |
380 | 397 | }).fail(d.reject);
|
381 | 398 | return d.promise();
|
382 | 399 | },
|
|
705 | 722 | $('.bh-sl-pagination-container .bh-sl-pagination').append(pagesOutput);
|
706 | 723 | },
|
707 | 724 |
|
| 725 | + /** |
| 726 | + * Marker image setup |
| 727 | + * |
| 728 | + * @param markerUrl (string) path to marker image |
| 729 | + * @param markerWidth (number} width of mearker |
| 730 | + * @param markerHeight (number) height of marker |
| 731 | + * @returns {object} Google Maps icon object |
| 732 | + */ |
| 733 | + markerImage: function (markerUrl, markerWidth, markerHeight) { |
| 734 | + var markerImg; |
| 735 | + |
| 736 | + // User defined marker dimensions |
| 737 | + if(typeof markerWidth !== 'undefined' && typeof markerHeight !== 'undefined') { |
| 738 | + markerImg = { |
| 739 | + url: markerUrl, |
| 740 | + size: new google.maps.Size(markerWidth, markerHeight) |
| 741 | + }; |
| 742 | + } |
| 743 | + // Default marker dimensions: 32px x 32px |
| 744 | + else { |
| 745 | + markerImg = { |
| 746 | + url: markerUrl, |
| 747 | + size: new google.maps.Size(32, 32) |
| 748 | + }; |
| 749 | + } |
| 750 | + |
| 751 | + return markerImg; |
| 752 | + }, |
| 753 | + |
708 | 754 | /**
|
709 | 755 | * Map marker setup
|
710 | 756 | *
|
711 |
| - * @param point |
712 |
| - * @param name |
713 |
| - * @param address |
714 |
| - * @param letter |
| 757 | + * @param point {object} LatLng of current location |
| 758 | + * @param name (string) location name |
| 759 | + * @param address (string) location address |
| 760 | + * @param letter (string) optional letter used for front-end identification and correlation between list and points |
| 761 | + * @param category (string) location category/categories |
715 | 762 | * @returns {google.maps.Marker}
|
716 | 763 | */
|
717 |
| - createMarker: function (point, name, address, letter, map) { |
| 764 | + createMarker: function (point, name, address, letter, map, category) { |
718 | 765 | var marker, markerImg, letterMarkerImg;
|
719 |
| - |
720 |
| - if(this.settings.markerImg !== null) { |
721 |
| - if(this.settings.markerDim !== null) { |
722 |
| - markerImg = new google.maps.MarkerImage(this.settings.markerImg, null, null, null, new google.maps.Size(this.settings.markerDim.width,this.settings.markerDim.height)); |
| 766 | + var categories = []; |
| 767 | + |
| 768 | + // Remove any spaces from category value |
| 769 | + if(category.length) { |
| 770 | + category = category.replace(/\s+/g, ''); |
| 771 | + } |
| 772 | + |
| 773 | + // Custom multi-marker image override (different markers for different categories |
| 774 | + if(this.settings.catMarkers !== null) { |
| 775 | + // Multiple categories |
| 776 | + if(category.indexOf(',') !== -1) { |
| 777 | + // Break the category variable into an array if there are multiple categories for the location |
| 778 | + categories = category.split(','); |
| 779 | + // With multiple categories the color will be determined by the last matched category in the data |
| 780 | + for(var i = 0; i < categories.length; i++) { |
| 781 | + if(categories[i] in this.settings.catMarkers) { |
| 782 | + markerImg = this.markerImage(this.settings.catMarkers[categories[i]][0], this.settings.catMarkers[categories[i]][1], this.settings.catMarkers[categories[i]][2]); |
| 783 | + } |
| 784 | + } |
723 | 785 | }
|
| 786 | + // Single category |
724 | 787 | else {
|
725 |
| - markerImg = new google.maps.MarkerImage(this.settings.markerImg, null, null, null, new google.maps.Size(32,32)); |
| 788 | + if(category in this.settings.catMarkers) { |
| 789 | + markerImg = this.markerImage(this.settings.catMarkers[category][0], this.settings.catMarkers[category][1], this.settings.catMarkers[category][2]); |
| 790 | + } |
726 | 791 | }
|
727 | 792 | }
|
| 793 | + |
| 794 | + // Custom single marker image override |
| 795 | + if(this.settings.markerImg !== null) { |
| 796 | + markerImg = this.markerImage(this.settings.markerImg, this.settings.markerDim.width, this.settings.markerDim.height); |
| 797 | + } |
728 | 798 |
|
729 | 799 | // Create the default markers
|
730 |
| - if (this.settings.storeLimit === -1 || this.settings.storeLimit > 26) { |
| 800 | + if (this.settings.storeLimit === -1 || this.settings.storeLimit > 26 || this.settings.catMarkers !== null) { |
731 | 801 | marker = new google.maps.Marker({
|
732 | 802 | position : point,
|
733 | 803 | map : map,
|
|
737 | 807 | }
|
738 | 808 | else {
|
739 | 809 | // Letter markers image
|
740 |
| - letterMarkerImg = new google.maps.MarkerImage('https://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'); |
| 810 | + letterMarkerImg = { |
| 811 | + url: 'https://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' |
| 812 | + }; |
741 | 813 |
|
742 | 814 | // Letter markers
|
743 | 815 | marker = new google.maps.Marker({
|
|
755 | 827 | * Define the location data for the templates
|
756 | 828 | *
|
757 | 829 | * @param currentMarker {object} Google Maps marker
|
758 |
| - * @param storeStart {number} optional first location on the current page |
759 |
| - * @param page {number} optional current page |
| 830 | + * @param storeStart (number) optional first location on the current page |
| 831 | + * @param page (number) optional current page |
760 | 832 | * @returns {{location: *[]}}
|
761 | 833 | */
|
762 | 834 | defineLocationData: function (currentMarker, storeStart, page) {
|
|
1423 | 1495 | }
|
1424 | 1496 | else{
|
1425 | 1497 | if(_this.settings.originMarkerImg !== null) {
|
1426 |
| - if(_this.settings.originMarkerDim !== null) { |
1427 |
| - originImg = new google.maps.MarkerImage(_this.settings.originMarkerImg, null, null, null, new google.maps.Size(_this.settings.originMarkerDim.width,_this.settings.originMarkerDim.height)); |
1428 |
| - } |
1429 |
| - else { |
1430 |
| - originImg = new google.maps.MarkerImage(_this.settings.originMarkerImg); |
1431 |
| - } |
| 1498 | + originImg = this.markerImage(_this.settings.originMarkerImg, _this.settings.originMarkerDim.width, _this.settings.originMarkerDim.height); |
1432 | 1499 | }
|
1433 | 1500 | else {
|
1434 |
| - originImg = new google.maps.MarkerImage('https://mt.googleapis.com/vt/icon/name=icons/spotlight/spotlight-waypoint-a.png'); |
| 1501 | + originImg = { |
| 1502 | + url: 'https://mt.googleapis.com/vt/icon/name=icons/spotlight/spotlight-waypoint-a.png' |
| 1503 | + }; |
1435 | 1504 | }
|
1436 | 1505 |
|
1437 | 1506 | marker = new google.maps.Marker({
|
|
1475 | 1544 | letter = String.fromCharCode('A'.charCodeAt(0) + y);
|
1476 | 1545 | }
|
1477 | 1546 |
|
| 1547 | + |
1478 | 1548 | var point = new google.maps.LatLng(locationset[y].lat, locationset[y].lng);
|
1479 |
| - marker = _this.createMarker(point, locationset[y].name, locationset[y].address, letter, map); |
| 1549 | + marker = _this.createMarker(point, locationset[y].name, locationset[y].address, letter, map, locationset[y].category); |
1480 | 1550 | marker.set('id', y);
|
1481 | 1551 | markers[y] = marker;
|
1482 | 1552 | if ((_this.settings.fullMapStart === true && firstRun === true) || (_this.settings.mapSettings.zoom === 0) || (typeof origin === 'undefined')) {
|
|
0 commit comments