MyListing Club

Set Explore Default Map Zoom to the Middle of the United States

Building better MyListing websites. One code snippet at a time.

Overview

The Set Explore Default Map Zoom to the Middle of the United States code snippet allows for greater control of how maps are presented within a MyListing website.

While this snippet uses the coordinates that correspond to the middle of the US, you can easily replace the coordinates with the location of your choice.

Implementation

  1. Grab the code snippet.
  2. Follow the provided instructions.
  3. Save your changes.
				
					//// INSTRUCTIONS: 
//// Copy and paste the code snippet below into Theme Tools > Theme Options > Custom Code > JavaScript.

--------------------------- CODE SNIPPET IS BELOW THIS LINE --------------------------- 

// SET EXPLORE PAGE DEFAULT MAP ZOOM TO THE MIDDLE OF THE UNITED STATES
jQuery(document).ready(function ($) {
  if ($(".location-field-wrapper .c27-map").length) {
    var mapZoom = setInterval(function () {
      if (MyListing.Maps.instances.length) {
        MyListing.Maps.instances.forEach((instance) => {
          instance.map.setCenter(["-97.922211", "39.381266"]); // starting position [long, lat]
          instance.map.setZoom(03);
        });
        clearInterval(mapZoom);
      }
    }, 500);
  }
});