feat: date and username filtering for photo overlay layers

This commit is contained in:
Nikola Plesa
2020-07-23 13:28:19 +02:00
parent bd9d4bce74
commit 22bc5121a4
10 changed files with 337 additions and 3 deletions
+43
View File
@@ -9,6 +9,10 @@ export function rendererPhotos(context) {
var _layerIDs = ['streetside', 'mapillary', 'mapillary-map-features', 'mapillary-signs', 'openstreetcam'];
var _allPhotoTypes = ['flat', 'panoramic'];
var _shownPhotoTypes = _allPhotoTypes.slice(); // shallow copy
var _dateFilters = ['fromDate', 'toDate'];
var _fromDate;
var _toDate;
var _username;
function photos() {}
@@ -37,16 +41,43 @@ export function rendererPhotos(context) {
return _allPhotoTypes;
};
photos.dateFilters = function() {
return _dateFilters;
};
photos.dateFilterValue = function(val) {
return val === _dateFilters[0] ? _fromDate : _toDate;
};
photos.setDateFilter = function(type, val) {
if (type === _dateFilters[0]) _fromDate = val;
if (type === _dateFilters[1]) _toDate = val;
dispatch.call('change', this);
};
photos.setUsernameFilter = function(val) {
_username = val;
dispatch.call('change', this);
};
function showsLayer(id) {
var layer = context.layers().layer(id);
return layer && layer.supported() && layer.enabled();
}
photos.shouldFilterByDate = function() {
return showsLayer('mapillary') || showsLayer('openstreetcam') || showsLayer('streetside');
};
photos.shouldFilterByPhotoType = function() {
return showsLayer('mapillary') ||
(showsLayer('streetside') && showsLayer('openstreetcam'));
};
photos.shouldFilterByUsername = function() {
return showsLayer('mapillary') || showsLayer('openstreetcam');
};
photos.showsPhotoType = function(val) {
if (!photos.shouldFilterByPhotoType()) return true;
@@ -61,6 +92,14 @@ export function rendererPhotos(context) {
return photos.showsPhotoType('panoramic');
};
photos.fromDate = function() {
return _fromDate;
};
photos.toDate = function() {
return _toDate;
};
photos.togglePhotoType = function(val) {
var index = _shownPhotoTypes.indexOf(val);
if (index !== -1) {
@@ -72,6 +111,10 @@ export function rendererPhotos(context) {
return photos;
};
photos.username = function() {
return _username;
};
photos.init = function() {
var hash = utilStringQs(window.location.hash);
if (hash.photo_overlay) {