|
1 |
| -/*! jQuery Google Maps Store Locator - v2.2.2 - 2015-11-30 |
| 1 | +/*! jQuery Google Maps Store Locator - v2.2.2 - 2015-12-09 |
2 | 2 | * http://www.bjornblog.com/web/jquery-store-locator-plugin
|
3 | 3 | * Copyright (c) 2015 Bjorn Holine; Licensed MIT */
|
4 | 4 |
|
|
58 | 58 | 'maxDistance' : false,
|
59 | 59 | 'maxDistanceID' : 'bh-sl-maxdistance',
|
60 | 60 | 'fullMapStart' : false,
|
| 61 | + 'fullMapStartBlank' : false, |
61 | 62 | 'noForm' : false,
|
62 | 63 | 'loading' : false,
|
63 | 64 | 'loadingContainer' : 'bh-sl-loading',
|
|
482 | 483 | _start: function () {
|
483 | 484 | this.writeDebug('_start');
|
484 | 485 | var _this = this,
|
485 |
| - doAutoGeo = this.settings.autoGeocode; |
486 |
| - // If a default location is set |
487 |
| - if (this.settings.defaultLoc === true) { |
488 |
| - // The address needs to be determined for the directions link |
489 |
| - var r = new this.reverseGoogleGeocode(this); |
490 |
| - var latlng = new google.maps.LatLng(this.settings.defaultLat, this.settings.defaultLng); |
491 |
| - r.geocode({'latLng': latlng}, function (data) { |
492 |
| - if (data !== null) { |
493 |
| - var originAddress = data.address; |
494 |
| - mappingObj.lat = _this.settings.defaultLat; |
495 |
| - mappingObj.lng = _this.settings.defaultLng; |
496 |
| - mappingObj.origin = originAddress; |
497 |
| - _this.mapping(mappingObj); |
498 |
| - } else { |
499 |
| - // Unable to geocode |
500 |
| - _this.notify(_this.settings.addressErrorAlert); |
501 |
| - } |
502 |
| - }); |
503 |
| - } |
| 486 | + doAutoGeo = this.settings.autoGeocode, |
| 487 | + latlng; |
| 488 | + |
| 489 | + // Full map blank start |
| 490 | + if (_this.settings.fullMapStartBlank !== false) { |
| 491 | + var $mapDiv = $('#' + _this.settings.mapID); |
| 492 | + $mapDiv.addClass('bh-sl-map-open'); |
| 493 | + var myOptions = _this.settings.mapSettings; |
| 494 | + myOptions.zoom = _this.settings.fullMapStartBlank; |
| 495 | + |
| 496 | + latlng = new google.maps.LatLng(this.settings.defaultLat, this.settings.defaultLng); |
| 497 | + myOptions.center = latlng; |
504 | 498 |
|
| 499 | + // Create the map |
| 500 | + var map = new google.maps.Map(document.getElementById(_this.settings.mapID), myOptions); |
505 | 501 |
|
506 |
| - // If there is already have a value in the address bar |
507 |
| - if ( $('#' + this.settings.addressID).val().trim() !== ''){ |
508 |
| - _this.writeDebug('Using Address Field'); |
509 |
| - _this.processForm(null); |
510 |
| - doAutoGeo = false; // No need for additional processing |
| 502 | + // Re-center the map when the browser is re-sized |
| 503 | + google.maps.event.addDomListener(window, 'resize', function() { |
| 504 | + var center = map.getCenter(); |
| 505 | + google.maps.event.trigger(map, 'resize'); |
| 506 | + map.setCenter(center); |
| 507 | + }); |
| 508 | + |
| 509 | + // Only do this once |
| 510 | + _this.settings.fullMapStartBlank = false; |
| 511 | + myOptions.zoom = originalZoom; |
511 | 512 | }
|
512 |
| - // If show full map option is true |
513 |
| - else if (this.settings.fullMapStart === true) { |
514 |
| - if((this.settings.querystringParams === true && this.getQueryString(this.settings.addressID)) || (this.settings.querystringParams === true && this.getQueryString(this.settings.searchID)) || (this.settings.querystringParams === true && this.getQueryString(this.settings.maxDistanceID))) { |
515 |
| - _this.writeDebug('Using Query String'); |
516 |
| - this.processForm(null); |
| 513 | + else { |
| 514 | + // If a default location is set |
| 515 | + if (this.settings.defaultLoc === true) { |
| 516 | + // The address needs to be determined for the directions link |
| 517 | + var r = new this.reverseGoogleGeocode(this); |
| 518 | + latlng = new google.maps.LatLng(this.settings.defaultLat, this.settings.defaultLng); |
| 519 | + r.geocode({'latLng': latlng}, function (data) { |
| 520 | + if (data !== null) { |
| 521 | + var originAddress = data.address; |
| 522 | + mappingObj.lat = _this.settings.defaultLat; |
| 523 | + mappingObj.lng = _this.settings.defaultLng; |
| 524 | + mappingObj.origin = originAddress; |
| 525 | + _this.mapping(mappingObj); |
| 526 | + } else { |
| 527 | + // Unable to geocode |
| 528 | + _this.notify(_this.settings.addressErrorAlert); |
| 529 | + } |
| 530 | + }); |
| 531 | + } |
| 532 | + |
| 533 | + // If there is already have a value in the address bar |
| 534 | + if ( $('#' + this.settings.addressID).val().trim() !== ''){ |
| 535 | + _this.writeDebug('Using Address Field'); |
| 536 | + _this.processForm(null); |
517 | 537 | doAutoGeo = false; // No need for additional processing
|
518 | 538 | }
|
519 |
| - else { |
520 |
| - this.mapping(null); |
| 539 | + // If show full map option is true |
| 540 | + else if (this.settings.fullMapStart === true) { |
| 541 | + if((this.settings.querystringParams === true && this.getQueryString(this.settings.addressID)) || (this.settings.querystringParams === true && this.getQueryString(this.settings.searchID)) || (this.settings.querystringParams === true && this.getQueryString(this.settings.maxDistanceID))) { |
| 542 | + _this.writeDebug('Using Query String'); |
| 543 | + this.processForm(null); |
| 544 | + doAutoGeo = false; // No need for additional processing |
| 545 | + } |
| 546 | + else { |
| 547 | + this.mapping(null); |
| 548 | + } |
521 | 549 | }
|
522 |
| - } |
523 | 550 |
|
524 |
| - // HTML5 geolocation API option |
525 |
| - if (this.settings.autoGeocode === true && doAutoGeo === true) { |
526 |
| - _this.writeDebug('Auto Geo'); |
527 |
| - // Saved geo location (saves around 3-5 seconds) |
528 |
| - if (_this.settings.sessionStorage === true && window.sessionStorage && window.sessionStorage.getItem('myGeo')){ |
529 |
| - _this.writeDebug('Using Session Saved Values for GEO'); |
530 |
| - _this.autoGeocodeQuery(JSON.parse(window.sessionStorage.getItem('myGeo'))); |
531 |
| - return false; |
532 |
| - } |
533 |
| - else if (navigator.geolocation) { |
534 |
| - navigator.geolocation.getCurrentPosition(function(position){ |
535 |
| - _this.writeDebug('Current Position Result'); |
536 |
| - // To not break autoGeocodeQuery then we create the obj to match the geolocation format |
537 |
| - var pos = { |
538 |
| - coords: { |
539 |
| - latitude : position.coords.latitude, |
540 |
| - longitude: position.coords.longitude, |
541 |
| - accuracy : position.coords.accuracy |
| 551 | + // HTML5 geolocation API option |
| 552 | + if (this.settings.autoGeocode === true && doAutoGeo === true) { |
| 553 | + _this.writeDebug('Auto Geo'); |
| 554 | + // Saved geo location (saves around 3-5 seconds) |
| 555 | + if (_this.settings.sessionStorage === true && window.sessionStorage && window.sessionStorage.getItem('myGeo')){ |
| 556 | + _this.writeDebug('Using Session Saved Values for GEO'); |
| 557 | + _this.autoGeocodeQuery(JSON.parse(window.sessionStorage.getItem('myGeo'))); |
| 558 | + return false; |
| 559 | + } |
| 560 | + else if (navigator.geolocation) { |
| 561 | + navigator.geolocation.getCurrentPosition(function(position){ |
| 562 | + _this.writeDebug('Current Position Result'); |
| 563 | + // To not break autoGeocodeQuery then we create the obj to match the geolocation format |
| 564 | + var pos = { |
| 565 | + coords: { |
| 566 | + latitude : position.coords.latitude, |
| 567 | + longitude: position.coords.longitude, |
| 568 | + accuracy : position.coords.accuracy |
| 569 | + } |
| 570 | + }; |
| 571 | + // Have to do this to get around scope issues |
| 572 | + if (_this.settings.sessionStorage === true && window.sessionStorage) { |
| 573 | + window.sessionStorage.setItem('myGeo',JSON.stringify(pos)); |
542 | 574 | }
|
543 |
| - }; |
544 |
| - // Have to do this to get around scope issues |
545 |
| - if (_this.settings.sessionStorage === true && window.sessionStorage) { |
546 |
| - window.sessionStorage.setItem('myGeo',JSON.stringify(pos)); |
547 |
| - } |
548 |
| - _this.autoGeocodeQuery(pos); |
549 |
| - }, function(error){ |
550 |
| - _this._autoGeocodeError(error); |
551 |
| - }); |
| 575 | + _this.autoGeocodeQuery(pos); |
| 576 | + }, function(error){ |
| 577 | + _this._autoGeocodeError(error); |
| 578 | + }); |
| 579 | + } |
552 | 580 | }
|
553 | 581 | }
|
554 | 582 | },
|
|
1633 | 1661 | origin = mappingObject.origin;
|
1634 | 1662 | page = mappingObject.page;
|
1635 | 1663 | }
|
1636 |
| - |
| 1664 | + |
1637 | 1665 | // Set the initial page to zero if not set
|
1638 | 1666 | if ( _this.settings.pagination === true ) {
|
1639 | 1667 | if (typeof page === 'undefined' || originalOrigin !== addressInput ) {
|
|
1664 | 1692 | if(_this.settings.taxonomyFilters !== null && _this.hasEmptyObjectVals(filters)) {
|
1665 | 1693 | _this.checkFilters();
|
1666 | 1694 | }
|
1667 |
| - |
1668 | 1695 | /**
|
1669 | 1696 | * Process the location data
|
1670 | 1697 | */
|
|
0 commit comments