mirror of
https://github.com/FoggedLens/iD.git
synced 2026-02-13 09:12:52 +00:00
Merge pull request #8077 from mapillary/photo-filtering-url
Persist photo layer filters in the URL
This commit is contained in:
@@ -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`
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user