Skip to content

Instantly share code, notes, and snippets.

@DylanCodeCabin
Created November 17, 2022 06:28
Show Gist options
  • Save DylanCodeCabin/1660785f6159557904e4288d2f168b15 to your computer and use it in GitHub Desktop.
Save DylanCodeCabin/1660785f6159557904e4288d2f168b15 to your computer and use it in GitHub Desktop.
/**
* Our default hide until search behaviour still performs an initial "cache" of markers, but the markers are not shown
*
* This really shows weakness at large data set handling (thousands) where the search will fail if the initial cache is not created
*
* This series of overrides will overcome this by only doing the first fetch when the search is performed
*
* It then re-runs the search after the fact, but only if it has not been done already
*
* This can be added in Maps > Settings > Custom Scripts > Custom JavaScript
*
* Full compat with V9 and late V8 builds - Long term, we will resolve this in core.
*/
jQuery(function($){
WPGMZA.Map.prototype.__onInit = WPGMZA.Map.prototype.onInit;
WPGMZA.StoreLocator.prototype.__onSearch = WPGMZA.StoreLocator.prototype.onSearch;
WPGMZA.Map.prototype.__onFeaturesFetched = WPGMZA.Map.prototype.onFeaturesFetched;
WPGMZA.Map.prototype.onInit = function(event){
var self = this;
this.settings.autoFetchFeatures = false;
this._needsFetch = true;
this.__onInit();
}
WPGMZA.StoreLocator.prototype.onSearch = function(event){
if(this.map._needsFetch){
/* We need to fetch markers first */
this.map._needsFetch = false;
this.map._needsResearch = true;
this.map.fetchFeatures();
} else {
this.__onSearch();
}
}
WPGMZA.Map.prototype.onFeaturesFetched = function(data){
this.__onFeaturesFetched(data);
if(this._needsResearch){
this._needsResearch = false;
this.storeLocator.onSearch();
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment