metabase icon indicating copy to clipboard operation
metabase copied to clipboard

Fix brush filters for longitudes that lie outside the normal -180 to 180 range

Open appleby opened this issue 1 year ago • 2 comments

Closes #41056

Description

Fix brush filter for LeafletMap.jsx to allow selecting points anywhere on the map.

  1. update Leafletmap.jsx to call LatLng.wrap() to wrap longitudes in filterBounds into the canonical range [-180, 180].
  2. modify update-lat-lon-filter so that if the filter bounds cross the 180th meridian, the filter is split into two parts covering the east and west sides with separate :inside filters that are ORed together.

How to verify

Describe the steps to verify that the changes are working as expected.

  1. New question -> Sample Dataset -> People
  2. Visualize
  3. Change viz type to Pin Map
  4. Scroll east or west a long ways (far enough to cross the 180th meridian)
  5. Click Draw box to filter button
  6. Draw a box
  7. Filter should work
  8. Zoom out
  9. Scroll to the 180th meridian (either direction)
  10. Click Draw box to filter button
  11. Draw a filter box that crosses the 180th meridian.
  12. Unless you modify your sample DB, you won't have any points near the meridian, but if you make your box large enough you can select some points in, e.g., Alaska.
  13. Verify that a two-part filter is added that covers both the eastern and western hemisphere sides of your selection.
  14. Get crazy. Zoom out and select a region > 360º.
  15. Should filter to the range [-180,180].

Demo

Loom demo posted to slack here

https://metaboat.slack.com/archives/C0645JP1W81/p1738960382927599

Checklist

  • [x] Tests have been added/updated to cover changes in this PR

appleby avatar Feb 06 '25 22:02 appleby

Static BadgeStatic BadgeStatic BadgeStatic Badge

View Full Report ↗︎Docs

trunk-io[bot] avatar Feb 07 '25 19:02 trunk-io[bot]

I had to check if [-180, 180] is actually canonical. AFAICT that is the case. There are some shenanigans with the International Date Line and certain time zones, see for example when Samoa moved from UTC-11 to UTC+13 in 2011. But that's a time zone thing only; Samoa is located near 172 degrees W.

bshepherdson avatar Feb 13 '25 15:02 bshepherdson

I had to check if [-180, 180] is actually canonical. AFAICT that is the case. There are some shenanigans with the International Date Line and certain time zones, see for example when Samoa moved from UTC-11 to UTC+13 in 2011. But that's a time zone thing only; Samoa is located near 172 degrees W.

I had the same concern. AFAICT ISO 6709 is the relevant standard and seemingly common enough that assuming [-180,180] will likely fix more people than it breaks, but it's a good call out and worth checking in with @mngr to get his thoughts before merging.

appleby avatar Feb 13 '25 19:02 appleby