[openstreetmap/openstreetmap-website] Filter changesets in History by bounding box area (#3242)
kallejre
notifications at github.com
Thu Jan 6 16:06:29 UTC 2022
I had similar issue today where after holiday season i wanted to catch up with changes made in local area over the past few weeks, but sadly there was recently very large undiscussed import, which was promptly followed by series revertions from DWG. So, how about adding option to OSM website's history (osm.org/history) view to hide changesets that don't fit into current bounding box? Luckily there's already this issue, so i won't create a duplicate one.
>From technical viewpoint, this seems to be relatively simple change, adding around 10-15 lines of code in [backend](https://github.com/openstreetmap/openstreetmap-website/blob/f1c6a87aa137c11d0aff5a4b0e563ac2c2a8f82d/app/controllers/api/changesets_controller.rb#L258-L261) for how changesets are filtered (just additional nested if-statement and support for two new parameters on ln162), 15-20 lines for [adding checkbox to frontend UI](https://github.com/openstreetmap/openstreetmap-website/blob/d02b8d9f1ed9b99651cdffae69b8c70e533d5517/app/views/changesets/history.html.erb#L15) and passing checkbox and slider value to API in [update() function](https://github.com/openstreetmap/openstreetmap-website/blob/70d7d8d850148f714b70a3297c02a8203214dec6/app/assets/javascripts/index/history.js#L62). I think I'm missing here something from what receives response from API and converts it into pretty html.
Here's quick UI prototype for filtering. Slider could disappear when checkbox is unchecked. Some users might prefer numeric entry for determining how large bounding boxes should be selected, but i felt that having to type some value into the field would feel unnatural and inconsistent with rest of website's mouse-oriented UI. For same reason checkbox and slider don't have "Submit" button, if anyone wonders.
<details>
<summary>HTML code for the UI prototype below</summary>
```html
<div class="add-meaningful-name">
<input type="checkbox" id="hide-cs" name="hide-cs" onchange="update()">
<label for="hide-cs">Hide very large changesets</label><br>
<span class="add-name-for-collapsible-class">
Select size sensitivity:<br>
Smaller <input type="range" min="1" max="5" value="2" class="chset-bbox-slider" onchange="update()"> Larger
</span>
</div>
```
</details>

Another portion is so-called "business decisions" for determining the actual behaviour of the slider. I don't think that hiding a large changeset could hide many relevant changesets mostly due to probability of how changed elements are distributed around changeset area. The larger the changeset area, the less likely it is to contain modifications in currently viewed area. Obviously this should be optional feature deselected by default, but looking at large changesets, here in Estonia they are usually irrelevant changes often focusing on Russia or Norway.
Questionable part is deciding where goes the borderline for selection of the changeset. Initial idea was to show only changesets which fit fully in the viewport. Another suggestion involved calculating area of bounding box and comparing it against area of viewport, but I'm afraid performing such calculations might be too demanding for the server. Also, said area can't be a constant due to map having multiple zoom levels. Perhaps ignore changesets, where current viewport area is less than X% of the changeset area? X is determined by the slider.
Finally, we are talking here about spatial database queries done on server infra possibly millions times per second, meaning the more refined changeset filtering algorithm is selected, more significant performance impact it would have. Computationally least expensive could be following filter (based on [existing method](https://github.com/openstreetmap/openstreetmap-website/blob/f1c6a87aa137c11d0aff5a4b0e563ac2c2a8f82d/app/controllers/api/changesets_controller.rb#L258-L261)):
```ruby
changesets.where("min_lon < ? and max_lon > ? and min_lat < ? and max_lat > ?",
bbox.min_lon.to_i, bbox.max_lon.to_i,
bbox.min_lat.to_i, bbox.max_lat.to_i)
```
PS. Probably I don't know how Ruby works because i have never used it, but shouldn't API [`changesets` endpoint](https://github.com/openstreetmap/openstreetmap-website/blob/f1c6a87aa137c11d0aff5a4b0e563ac2c2a8f82d/app/controllers/api/changesets_controller.rb#L347) also support URL parameters `open/closed=false`, currently it seems to only check if parameter is present, not it's value. Therefore code from that part is probably not reusable for the changeset filtering methods.
--
Reply to this email directly or view it on GitHub:
https://github.com/openstreetmap/openstreetmap-website/issues/3242#issuecomment-1006709194
You are receiving this because you are subscribed to this thread.
Message ID: <openstreetmap/openstreetmap-website/issues/3242/1006709194 at github.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openstreetmap.org/pipermail/rails-dev/attachments/20220106/f77dfc79/attachment-0001.htm>
More information about the rails-dev
mailing list