in packages/geofire/src/GeoQuery.ts [231:268]
public updateCriteria(newQueryCriteria: QueryCriteria): void {
// Validate and save the new query criteria
validateCriteria(newQueryCriteria);
this._center = newQueryCriteria.center || this._center;
this._radius = newQueryCriteria.radius || this._radius;
// Loop through all of the locations in the query, update their distance from the center of the
// query, and fire any appropriate events
const keys: string[] = Object.keys(this._locationsTracked);
for (const key of keys) {
// If the query was cancelled while going through this loop, stop updating locations and stop
// firing events
if (this._cancelled === true) {
break;
}
// Get the cached information for this location
const locationDict = this._locationsTracked[key];
// Save if the location was already in the query
const wasAlreadyInQuery = locationDict.isInQuery;
// Update the location's distance to the new query center
locationDict.distanceFromCenter = distanceBetween(locationDict.location, this._center);
// Determine if the location is now in this query
locationDict.isInQuery = (locationDict.distanceFromCenter <= this._radius);
// If the location just left the query, fire the 'key_exited' callbacks
// Else if the location just entered the query, fire the 'key_entered' callbacks
if (wasAlreadyInQuery && !locationDict.isInQuery) {
this._fireCallbacksForKey('key_exited', key, locationDict.location, locationDict.distanceFromCenter);
} else if (!wasAlreadyInQuery && locationDict.isInQuery) {
this._fireCallbacksForKey('key_entered', key, locationDict.location, locationDict.distanceFromCenter);
}
}
// Reset the variables which control when the 'ready' event fires
this._valueEventFired = false;
// Listen for new geohashes being added to GeoFire and fire the appropriate events
this._listenForNewGeohashes();
}