Merge pull request #8077 from mapillary/photo-filtering-url

Persist photo layer filters in the URL
This commit is contained in:
Quincy Morgan
2020-10-15 13:39:46 -04:00
committed by GitHub
2 changed files with 31 additions and 4 deletions

View File

@@ -50,17 +50,35 @@ export function rendererPhotos(context) {
return val === _dateFilters[0] ? _fromDate : _toDate;
};
photos.setDateFilter = function(type, val) {
photos.setDateFilter = function(type, val, updateUrl) {
if (type === _dateFilters[0]) _fromDate = val;
if (type === _dateFilters[1]) _toDate = val;
dispatch.call('change', this);
if (updateUrl) {
setUrlFilterValue(type, val);
}
};
photos.setUsernameFilter = function(val) {
photos.setUsernameFilter = function(val, updateUrl) {
_username = val;
dispatch.call('change', this);
if (updateUrl) {
setUrlFilterValue('username', val);
}
};
function setUrlFilterValue(type, val) {
if (!window.mocha) {
var hash = utilStringQs(window.location.hash);
if (val) {
hash[type] = val;
} else {
delete hash[type];
}
window.location.replace('#' + utilQsString(hash, true));
}
}
function showsLayer(id) {
var layer = context.layers().layer(id);
return layer && layer.supported() && layer.enabled();
@@ -127,6 +145,15 @@ export function rendererPhotos(context) {
if (layer && !layer.enabled()) layer.enabled(true);
});
}
if (hash.fromDate) {
this.setDateFilter('fromDate', hash.fromDate, false);
}
if (hash.toDate) {
this.setDateFilter('toDate', hash.toDate, false);
}
if (hash.username) {
this.setUsernameFilter(hash.username, false);
}
if (hash.photo) {
// support opening a photo via a URL parameter, e.g. `photo=mapillary-fztgSDtLpa08ohPZFZjeRQ`

View File

@@ -220,7 +220,7 @@ export function uiSectionPhotoOverlays(context) {
})
.on('change', function(d) {
var value = d3_select(this).property('value');
context.photos().setDateFilter(d, value);
context.photos().setDateFilter(d, value, true);
});
li
@@ -275,7 +275,7 @@ export function uiSectionPhotoOverlays(context) {
.property('value', context.photos().username())
.on('change', function() {
var value = d3_select(this).property('value');
context.photos().setUsernameFilter(value);
context.photos().setUsernameFilter(value, true);
});
li