diff --git a/README.md b/README.md index 0267ba2..271b6fe 100644 --- a/README.md +++ b/README.md @@ -23,6 +23,13 @@ Build a bounding box URL using this page: https://osmlab.github.io/show-me-the-w - https://osmlab.github.io/show-me-the-way/#comment=missingmaps - `comment=missingmaps`, will only show changes where the changeset comment contained missingmaps somewhere +### Filter by feature keys + +- key={string} +- Restrict viewing only edits where the changeset's features include keys equal to a string. + - https://osmlab.github.io/show-me-the-way/#key=building + - `key=building`, will only show changes where the changeset includes features with the key building + ### Change the playback speed - runTime={seconds} diff --git a/js/change.js b/js/change.js index 6e82aa2..6849079 100644 --- a/js/change.js +++ b/js/change.js @@ -84,30 +84,32 @@ class Change { isRelevant() { return new Promise((resolve) => { - let relevant = false; + let commentRelevance = false; + let keyRelevance = false; const mapElement = this.neu || this.old; - if (this.context.comment == "") { + if (this.context.comment === "" && !this.context.key) { return resolve(true); } this.fetchChangesetData(mapElement.changeset) .then((changesetData) => { - relevant = ( - changesetData.comment && - changesetData.comment.toLowerCase() - .indexOf(this.context.comment.toLowerCase()) > -1 - ); - if (!relevant) { + commentRelevance = + this.context.comment !== "" && + changesetData.comment?.toLowerCase() + .includes(this.context.comment.toLowerCase()) || false; + + keyRelevance = Object.keys(mapElement.tags).includes(this.context.key); + + if (!(commentRelevance || keyRelevance)) { console.log( "Skipping map element " + mapElement.id - + " because changeset " + mapElement.changeset - + " didn't match " + this.context.comment + + " because it didn't match filters." ); } - return resolve(relevant); + return resolve(commentRelevance | keyRelevance); }); }); }