client/locations-list-map.js
/**
 * Changes the markers currently rendered on the map based strictly on filters or lack thereof. This will reset the
 * 'markers' module variable as well.
 */
Changes the markers currently rendered on the map based strictly on filters or lack thereof. This will reset the
'markers' module variable as well.
Changes the markers currently rendered on the map based strictly on filters or lack thereof . This will reset the ' markers ' module variable as well .
function showMarkers(data, filters, recenterMap = true) {
  if (!gMap || !gPrimaryCluster) {
    return;
  }
  const bounds = new google.maps.LatLngBounds();
  const applied = filters.applied || {};
  const hasFilters = Object.keys(applied).length > 0;
  const markers = getMarkers(data, applied, hasFilters && bounds, {
    icon: getIcon(gDatasetMarkers[gDataset].standard),
    datasetKey: gDataset,
  });
  if (hasFilters) {
    gPrimaryMarkers = markers.inFilters;
    gSecondaryMarkers = markers.outOfFilters;
    Object.keys(datasetData).forEach((secondDataKey) => {
      const secondaryData = datasetData[secondDataKey].formattedDataset;
      datasetData[secondDataKey].markers = getMarkers(secondaryData, applied, hasFilters && bounds, {
        icon: getIcon(gDatasetMarkers[gDataset].standard),
        datasetKey: gDataset,
      }).inFilters;
      gSecondaryMarkers.push(
        ...datasetData[secondDataKey].markers
      );
    });
  } else {
    gPrimaryMarkers = markers.outOfFilters;
    gSecondaryMarkers = [];
    Object.keys(datasetData).forEach((secondDataKey) => {
      const secondaryData = datasetData[secondDataKey].formattedDataset;
      datasetData[secondDataKey].markers = getMarkers(secondaryData, applied, hasFilters && bounds, {
        icon: getIcon(gDatasetMarkers[gDataset].standard),
        datasetKey: gDataset,
      }).outOfFilters;
      gSecondaryMarkers.push(
        ...datasetData[secondDataKey].markers
      );
    });
  }
  if (gPrimaryCluster) {
    gPrimaryCluster.clearMarkers();
  }
  if (gSecondaryCluster) {
    gSecondaryCluster.clearMarkers();
  }
  for (const marker of gPrimaryMarkers) {
    marker.setOptions({
      icon: getIcon(gDatasetMarkers[gDataset].standard),
      ...PRIMARY_MARKER_OPTIONS,
    });
  }
  for (const marker of gSecondaryMarkers) {
    marker.setOptions({
      icon: getIcon(gDatasetMarkers[gDataset].standard),
      ...SECONDARY_MARKER_OPTIONS,
    });
  }
  updateClusters(gPrimaryCluster, gSecondaryCluster);
  updateStats(); 
  if (recenterMap) {
    setTimeout(() => {
      centerMapToBounds(gMap, bounds, 9);
    }, 0);
  }
}
function showMarkers ( data , filters , recenterMap = true ) { if ( ! gMap || ! gPrimaryCluster ) { return ; } const bounds = new google . maps . LatLngBounds ( ) ; const applied = filters . applied || { } ; const hasFilters = Object . keys ( applied ) . length > 0 ; const markers = getMarkers ( data , applied , hasFilters && bounds , { icon : getIcon ( gDatasetMarkers [ gDataset ] . standard ) , datasetKey : gDataset , } ) ; if ( hasFilters ) { gPrimaryMarkers = markers . inFilters ; gSecondaryMarkers = markers . outOfFilters ; Object . keys ( datasetData ) . forEach ( ( secondDataKey ) => { const secondaryData = datasetData [ secondDataKey ] . formattedDataset ; datasetData [ secondDataKey ] . markers = getMarkers ( secondaryData , applied , hasFilters && bounds , { icon : getIcon ( gDatasetMarkers [ gDataset ] . standard ) , datasetKey : gDataset , } ) . inFilters ; gSecondaryMarkers . push ( ... datasetData [ secondDataKey ] . markers ) ; } ) ; } else { gPrimaryMarkers = markers . outOfFilters ; gSecondaryMarkers = [ ] ; Object . keys ( datasetData ) . forEach ( ( secondDataKey ) => { const secondaryData = datasetData [ secondDataKey ] . formattedDataset ; datasetData [ secondDataKey ] . markers = getMarkers ( secondaryData , applied , hasFilters && bounds , { icon : getIcon ( gDatasetMarkers [ gDataset ] . standard ) , datasetKey : gDataset , } ) . outOfFilters ; gSecondaryMarkers . push ( ... datasetData [ secondDataKey ] . markers ) ; } ) ; } if ( gPrimaryCluster ) { gPrimaryCluster . clearMarkers ( ) ; } if ( gSecondaryCluster ) { gSecondaryCluster . clearMarkers ( ) ; } for ( const marker of gPrimaryMarkers ) { marker . setOptions ( { icon : getIcon ( gDatasetMarkers [ gDataset ] . standard ) , ... PRIMARY_MARKER_OPTIONS , } ) ; } for ( const marker of gSecondaryMarkers ) { marker . setOptions ( { icon : getIcon ( gDatasetMarkers [ gDataset ] . standard ) , ... SECONDARY_MARKER_OPTIONS , } ) ; } updateClusters ( gPrimaryCluster , gSecondaryCluster ) ; updateStats ( ) ; if ( recenterMap ) { setTimeout ( ( ) => { centerMapToBounds ( gMap , bounds , 9 ) ; } , 0 ) ; } }
Changes the markers currently rendered on the map based strictly on filters or lack thereof.
Changes the markers currently rendered on the map based strictly on filters or lack thereof .
// filters have possibly changed // HACK. On some browsers, the markercluster freaks out if it gets a bunch of new markers // immediately followed by a map view change. Making the view change async works around // this bug.