bjorn2404 / jQuery-Store-Locator-Plugin

A store locator plugin using Google Maps API version 3
MIT License
493 stars 235 forks source link

auto zoom out in max distance example #228

Open sparkcom opened 6 years ago

sparkcom commented 6 years ago

In this example https://bjornblog.com/storelocator/v2/maxdistance-example.html

when search 'MN 55102' within 10 miles it's fine. but if i increase the max distance to 40 miles, the map should zoom out so that all the search results can be seen in the map window. Is there any way to automatically zoom to increase every result?

mvaneijgen commented 5 years ago

Ever found a solution for this?

Edit: Found something, but isn't that elegant. You'll need to use the callbackFormVals which get you the current distance (bh-sl-maxdistance) set after form submit. You need to set

$("#bh-sl-map-container").storeLocator({
  ...
  callbackFormVals: function(addressInput, searchInput, distance, region) {
    var zoom = 14;
    if(distance == 40) {
      zoom = 6;
    }
    if(distance == 100) {
      zoom = 4;
    }
    setTimeout(() => { this.map.setZoom(zoom); }, 50);
  },
  ...
});

This is not automatic, but it's the closet I can get to set the zoom level based on the distance.