Skip to content

Conversation

@carolpettirossi
Copy link
Contributor

@carolpettirossi carolpettirossi commented Aug 22, 2025

Fix(LeafletJS): Ensure distance filter handles empty values correctly

Resolves: #92

Summary of Changes:

This pull request addresses a bug in the LeafletJS map implementation where an empty value in the distance filter would cause unexpected behavior, preventing the map from displaying any locations.

The key changes in this patch are:

  1. Improved Type Coercion in apply_distance_limit: The distance value from the input is now explicitly parsed as a float using parseFloat(). If the result is not a finite number (as determined by Number.isFinite()), the distance filter in the state is set to an empty string. This ensures that non-numeric or empty inputs are handled gracefully.
  2. Robust Filtering Logic in apply_distance_filters: The distance filtering logic now checks if the distance value is a finite number before attempting to filter locations. If the distance is not a valid number (i.e., it's an empty string), the filter is skipped, and the original, unfiltered list of locations is returned.
  3. Refined Geocoding Behavior: When a search result from the Nominatim API does not include a boundingbox, the map now centers on the point with a default zoom level (setView(point, 13)) instead of trying to fit non-existent bounds. This prevents the map from zooming out unexpectedly.
  4. Minor Code Refinements:
    • Replaced .map() with .forEach() for iterating over locations during marker initialization, as a new array is not required.
    • Removed a hardcoded check that was incorrectly removing the "Rochester YMCA" location from the map.
    • Corrected a typo where this.maps was used instead of this.map when removing a marker.

These changes ensure that the distance filter is more robust and user-friendly, providing a more stable and predictable experience when interacting with the LeafletJS map.

@froboy
Copy link
Contributor

froboy commented Aug 22, 2025

@carolpettirossi could you please update the description to note what's fixed?

Copy link
Contributor

@froboy froboy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@carolpettirossi there are some changes here that look like cleanup (spacing changes, var/const declarations, etc). Could you please put Github comments on any of the code changes that are actually getting to the root cause, just so reviewers can understand what's going on? Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Near locations are not displayed after user searches for a Zip Code

3 participants