client/locations-list-map.js
/**
 * Responsible for initializing the search field and links below the search field (e.g. use
 * location, reset map, etc).
 */
Responsible for initializing the search field and links below the search field .
Responsible for initializing the search field and links below the search field .
function initMapSearch(data, filters) {
  if (!gShowMapSearch) {
    $('.map-search-wrap').hide();
    return;
  }
  const $search = $('#map-search');
  const searchEl = $search[0];
  gAutocomplete = new google.maps.places.Autocomplete(
    searchEl,
    { types: ['geocode'] }
  );
  const { q } = searchParams;
  if (q) {
    $search.val(q);
    attemptGeocode(q);
  }
  gAutocomplete.setFields(['geometry']);
  gAutocomplete.addListener('place_changed', () => {
    const place = gAutocomplete.getPlace();
    if (place.geometry) {
      sendEvent('map', 'autocomplete', $search.val());
      const { viewport } = place.geometry;
      if (viewport) {
        fitMapToMarkersNearBounds(viewport);
      } else {
        sendEvent('map', 'autocomplete-fail', $search.val());
      }
    } else {
      sendEvent('map', 'search', $search.val());
      attemptGeocode($search.val());
    }
  });
  $('#use-location').on('click', (e) => {
    e.preventDefault();
    sendEvent('map', 'center', 'user-location');
    centerMapToMarkersNearUser();
  });
  $('#reset-map').on('click', (e) => {
    e.preventDefault();
    resetMap(data, filters);
    $search.val('');
    for (const element of document.getElementById('filter-container').children) {
      element.selectrReference.clear();
    }
    sendEvent('map', 'reset', 'default-location');
    $('.dataset-toggle').prop('checked', false);
  });
}
function initMapSearch ( data , filters ) { if ( ! gShowMapSearch ) { $ ( '.map-search-wrap' ) . hide ( ) ; return ; } const $search = $ ( '#map-search' ) ; const searchEl = $search [ 0 ] ; gAutocomplete = new google . maps . places . Autocomplete ( searchEl , { types : [ 'geocode' ] } ) ; const { q } = searchParams ; if ( q ) { $search . val ( q ) ; attemptGeocode ( q ) ; } gAutocomplete . setFields ( [ 'geometry' ] ) ; gAutocomplete . addListener ( 'place_changed' , ( ) => { const place = gAutocomplete . getPlace ( ) ; if ( place . geometry ) { sendEvent ( 'map' , 'autocomplete' , $search . val ( ) ) ; const { viewport } = place . geometry ; if ( viewport ) { fitMapToMarkersNearBounds ( viewport ) ; } else { sendEvent ( 'map' , 'autocomplete-fail' , $search . val ( ) ) ; } } else { sendEvent ( 'map' , 'search' , $search . val ( ) ) ; attemptGeocode ( $search . val ( ) ) ; } } ) ; $ ( '#use-location' ) . on ( 'click' , ( e ) => { e . preventDefault ( ) ; sendEvent ( 'map' , 'center' , 'user-location' ) ; centerMapToMarkersNearUser ( ) ; } ) ; $ ( '#reset-map' ) . on ( 'click' , ( e ) => { e . preventDefault ( ) ; resetMap ( data , filters ) ; $search . val ( '' ) ; for ( const element of document . getElementById ( 'filter-container' ) . children ) { element . selectrReference . clear ( ) ; } sendEvent ( 'map' , 'reset' , 'default-location' ) ; $ ( '.dataset-toggle' ) . prop ( 'checked' , false ) ; } ) ; }
Responsible for initializing the search field and links below the search field (e.g.
Responsible for initializing the search field and links below the search field ( e . g .
// If disabled, hide the search fields and don't bother attaching any functionality to them. // Search element (jquery + html element for autocompleter) // Initialize the map search autocompleter. // initialize map search with query param `q` if it's set // Avoid paying for data that you don't need by restricting the set of place fields that are // returned to just the address components. // When the user selects an address from the drop-down, populate the address fields in the form. // Get the location object that we can map.setCenter() on // Setup event listeners for map action links.