Combine fromDate and toDate parameters into single photo_dates parameter

Rename `username` parameter to `photo_username`
Add API documentation of photo filter parameters
This commit is contained in:
Quincy Morgan
2020-10-19 15:43:25 -04:00
parent fb0ea5ce41
commit 893629da4f
2 changed files with 22 additions and 12 deletions

4
API.md
View File

@@ -43,6 +43,10 @@ of iD (e.g. `https://ideditor-release.netlify.app`), the following parameters ar
* __`photo_overlay`__ - The street-level photo overlay layers to enable.<br/>
_Example:_ `photo_overlay=streetside,mapillary,openstreetcam`<br/>
_Available values:_ `streetside` (Microsoft Bing), `mapillary`, `mapillary-signs`, `mapillary-map-features`, `openstreetcam`
* __`photo_dates`__ - The range of capture dates by which to filter street-level photos. Dates are given in YYYY-MM-DD format and separated by `_`. One-sided ranges are supported.<br/>
_Example:_ `photo_dates=2019-01-01_2020-12-31`, `photo_dates=2019-01-01_`, `photo_dates=_2020-12-31`<br/>
* __`photo_username`__ - The Mapillary or OpenStreetCam username by which to filter street-level photos.<br/>
_Example:_ `photo_user=quincylvania`<br/>
* __`photo`__ - The service and ID of the street-level photo to show.<br/>
_Example:_ `photo=streetside/718514589`<br/>
_Available prefixes:_ `streetside/`, `mapillary/`, `openstreetcam/`

View File

@@ -72,7 +72,11 @@ export function rendererPhotos(context) {
}
dispatch.call('change', this);
if (updateUrl) {
setUrlFilterValue(type, val);
var rangeString;
if (_fromDate || _toDate) {
rangeString = (_fromDate || '') + '_' + (_toDate || '');
}
setUrlFilterValue('photo_dates', rangeString);
}
};
@@ -80,17 +84,19 @@ export function rendererPhotos(context) {
_username = val;
dispatch.call('change', this);
if (updateUrl) {
setUrlFilterValue('username', val);
setUrlFilterValue('photo_username', val);
}
};
function setUrlFilterValue(type, val) {
function setUrlFilterValue(property, val) {
if (!window.mocha) {
var hash = utilStringQs(window.location.hash);
if (val) {
hash[type] = val;
if (hash[property] === val) return;
hash[property] = val;
} else {
delete hash[type];
if (!(property in hash)) return;
delete hash[property];
}
window.location.replace('#' + utilQsString(hash, true));
}
@@ -153,14 +159,14 @@ export function rendererPhotos(context) {
photos.init = function() {
var hash = utilStringQs(window.location.hash);
if (hash.fromDate) {
this.setDateFilter('fromDate', hash.fromDate, false);
if (hash.photo_dates) {
// expect format like `photo_dates=2019-01-01_2020-12-31`, but allow a few different separators
var parts = /^(.*)[\/_+:](.*)$/g.exec(hash.photo_dates.trim());
this.setDateFilter('fromDate', parts && parts.length >= 2 && parts[1], false);
this.setDateFilter('toDate', parts && parts.length >= 3 && parts[2], false);
}
if (hash.toDate) {
this.setDateFilter('toDate', hash.toDate, false);
}
if (hash.username) {
this.setUsernameFilter(hash.username, false);
if (hash.photo_username) {
this.setUsernameFilter(hash.photo_username, false);
}
if (hash.photo_overlay) {
// support enabling photo layers by default via a URL parameter, e.g. `photo_overlay=openstreetcam;mapillary;streetside`