Skip to content

Refactor frontend to use adiffs.osmcha.org; remove changeset-map - #772

Merged
jake-low merged 8 commits into
mainfrom
jlow/refactor
Apr 7, 2025
Merged

jake-low merged 8 commits into
mainfrom
jlow/refactor

Conversation

@jake-low

Copy link
Copy Markdown
Contributor

Background

OSMCha is an application for viewing OpenStreetMap changesets. To do this, OSMCha needs data about everything that was modified: specifically, it needs to know the complete old and new versions of all elements that were affected by the change, directly or indirectly.

Changesets from openstreetmap.org don't contain all of this information "off the shelf". When you download a changeset from openstreetmap.org via the API (example), it only contains the new versions of elements, not the old versions. It also does not contain elements that were modified indirectly (e.g. moving some nodes that are part of a way changes the way's shape, but does not actually generate a new version of that way, so only the nodes would be included in the changeset). These changeset files are optimized to be small in size and easy to compute (they directly match OSM's underlying data model), but because of this they don't contain enough detail for visually presenting the scope of the changes to a human. The changes in the planet.openstreetmap.org replication files have this same limitation.

To get the data we need in order to visualize changesets, OSMCha relies on a backend data pipeline that processes changesets from the OpenStreetMap API and "augments" them with additional context. These "augmented diffs" are computed in advance and then fetched by the osmcha.org website when you view a changeset.

The version of this pipeline that we currently use is based on Overpass, a queryable database system for OSM (and the same technology that powers overpass-turbo.eu). It's possible to use Overpass to query for all of the old and new versions of each element in a changeset. Our backend does this for each new changeset, and stores the results in a S3 bucket called real-changesets.

There are problems with this approach. Overpass is an impressive and flexible tool, but it's not meant for this kind of workload, so building augmented diffs in this way is expensive and fairly slow. The Overpass query we use is also prone to false positive matches if two changesets occur in the same area in a very short time window, which means OSMCha occasionally shows changes that aren't actually part of the changeset you're looking at (#467, #492).

Over the last few months, I've been working on a new pipeline to generate augmented diff data. The code for that pipeline is at osmcha/osmx-adiff-builder and it is running in production at adiffs.osmcha.org. It uses OSMExpress to keep a local mirror of the OpenStreetMap dataset, from which it can build augmented diffs. These diffs are served in the Augmented Diff XML format, which is supported by various OSM software (the real-changesets bucket serves data in a bespoke JSON representation that was less interoperable with other tools).

The new pipeline is faster, cheaper to operate, and does not have the same false-positive problem that our previous approach did. Its goal is to replace the existing real-changesets S3 bucket, and in doing so make the osmcha.org website faster and more dependable.

What's in this PR

This PR switches the osmcha.org web frontend to load augmented diff data from adiffs.osmcha.org (the new service) instead of from the S3 real-changesets bucket (the old service). To do this, a lot of other interrelated changes had to be made as well.

Most significantly, OSMCha now no longer depends on the changeset-map library. changeset-map is one of the original tools for visualizing OSM changesets, and OSMCha was initially built around it, with changeset-map providing the core map visualization UI and OSMCha providing the rest of the UI surrounding it (like the sidebar and changeset metadata panel).

However, this separation created some challenges. changeset-map does its own loading of changeset data (including handling the bespoke real-changesets JSON format). It renders both the changeset map overlay and the underlying basemap (using Mapbox GL JS 1.13). And it also renders some UI elements, like the element info panel you see in the lower right when you click a map element in OSMCha.

To simplify maintenance, these jobs have been moved into the osmcha-frontend, or spun out into separate, single-purpose libraries. Parsing augmented diff XML into a JavaScript object is done by the standalone osm-adiff-parser library. To render augmented diffs on a map, we use MapLibre GL JS and a new maplibre-adiff-viewer plugin, which takes a parsed augmented diff and renders it on top of any basemap you provide. The maplibre-adiff-viewer plugin is UI-agnostic, so it can be used in any project that wishes to render an augmented diff on a MapLibre map (like the new osmcha-cli tool).

In short, this PR means that OSMCha:

  • does not depend on changeset-map, and instead depends on osm-adiff-parser and maplibre-adiff-viewer to parse and render augmented diffs
  • does not depend on Mapbox GL JS or on Mapbox tiles, stylesheets or other map resources, instead depending on MapLibre and on tiles hosted by OpenStreetMap US
  • does not depend on real-changesets, and instead loads augmented diffs from adiffs.osmcha.org

What does it look like?

Mostly the same as before. 🙂 Here's an overall before/after:

Screenshot 2025-03-26 at 11-57-38 OSMCha
Screenshot 2025-03-26 at 11-58-01 OSMCha

The map visualization provided by maplibre-adiff-viewer is slightly tweaked compared to the rendering used by changeset-map.

  • Lines are thinner, with less pronounced halos, to make it easier to see complex geometry changes.
  • Ways are only shown in yellow if their tags changed. Geometry-only changes are shown in gray instead.
  • Relation members are shown by default now (in purple) if the relation was modified

Before/after:

Screenshot 2025-03-26 at 12 02 09 PM Screenshot 2025-03-26 at 12 01 20 PM

Clicking on a map element reveals a new details panel (the old one was part of changeset-map). It contains the same information as before, but the layout has been modified a bit to increase information density. Before/after:

Screenshot 2025-03-26 at 11 55 38 AM Screenshot 2025-03-26 at 11 55 52 AM

Some other minor changes include a tweaked map legend / controls panel:

Screenshot 2025-03-26 at 12 11 31 PM Screenshot 2025-03-26 at 12 12 31 PM

And a reimplemented location filter interface, built with MapLibre and terra-draw. Before/after:

Screenshot 2025-03-26 at 12 25 47 PM Screenshot 2025-03-26 at 12 25 32 PM

Fixes

Some changesets that changeset-map failed to render are correctly handled by maplibre-adiff-viewer

This also fixes a number of issues related to processing or rendering changesets with large bounding boxes.

Previously, there were also problems where OSMCha would incorrectly combine edits from multiple changesets together if they occurred in the same area and within a short time window. The new augmented diff service uses canonical information from the OSM API to determine which edits belong to each changeset, so it is not prone to this mistake.

Miscellaneous other issues that are fixed by this PR:

Known limitations

  • Currently, adiffs.osmcha.org has augmented diffs for all changesets going back to about November 2024. If you try to load a changeset before that, OSMCha will fall back to using the Overpass API (much like it does today if a changeset is not found in the real-changesets bucket). This method is slower and subject to the limitations mentioned above (it will fail if the changeset's bounding box is very large, and may incorrectly combine changesets that happened in the same place at nearly the same time). I am planning to backfill data for older changesets in the near future.
  • The Mapbox Satellite, Mapbox Streets, and Mapbox Dark basemaps are no longer available. Bing aerial imagery is now the default basemap. We are looking into adding additional imagery providers. OpenStreetMap Carto is also still available as a basemap.
  • The Bing aerial imagery layer is just raster imagery; whereas Mapbox Satellite included a vector overlay containing boundaries, city and town names, etc which was helpful for getting your bearings when viewing a changeset. In the future I'm hoping to add an optional overlay similar to this to the Bing imagery layer.

};
layerOptions = [
{
label: 'Mapbox Satellite',

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The Bing aerial imagery layer is just raster imagery; whereas Mapbox Satellite included a vector overlay containing boundaries, city and town names, etc which was helpful for getting your bearings when viewing a changeset. In the future I'm hoping to add an optional overlay similar to this to the Bing imagery layer.

If you end up creating something like this, iD might be able to use it as a replacement for the existing Location Overlay, which is a custom Mapbox tileset that needs to be updated manually once in a while.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good to know, I will keep that in mind. For OSMCha this would probably be a vector tileset and accompanying stylesheet that could be overlaid on top of the raster basemap. It looks like iD's locator overlay is a raster tileset of PNGs with alpha channels. Do you know if iD can render vector tiles? I know it uses a custom SVG-based rendering engine (not MapLibre or Leaflet), just wondering if it already supports parsing and using MVTs.

@jake-low
jake-low merged commit 06485d7 into main Apr 7, 2025
@jake-low
jake-low deleted the jlow/refactor branch April 7, 2025 21:39
@mvexel

mvexel commented Apr 7, 2025

Copy link
Copy Markdown

Congrats @jake-low @willemarcel ! This was a big lift!

@iandees

iandees commented Apr 8, 2025

Copy link
Copy Markdown

+1, this is a big change, well coordinated!

@batpad

batpad commented Apr 8, 2025

Copy link
Copy Markdown

... tears in my eyes seeing those issues close ... thank you so much for your work on this @jake-low !

@nrenner

nrenner commented Apr 8, 2025

Copy link
Copy Markdown

Very excited about this big improvement!

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