username filter wip

This commit is contained in:
mattiapezzotti
2024-06-23 14:05:06 +02:00
parent 8b68f07799
commit 44baa63ed5
3 changed files with 68 additions and 9 deletions
+1 -1
View File
@@ -128,7 +128,7 @@ export function rendererPhotos(context) {
};
photos.shouldFilterByUsername = function() {
return !showsLayer('mapillary') && showsLayer('kartaview') && !showsLayer('streetside');
return !showsLayer('mapillary') && showsLayer('kartaview') && !showsLayer('streetside') || showsLayer('panoramax');
};
photos.showsPhotoType = function(val) {
+47 -5
View File
@@ -14,6 +14,8 @@ const apiUrl = 'https://panoramax.openstreetmap.fr/';
const tileUrl = apiUrl + 'api/map/{z}/{x}/{y}.pbf';
const imageBlobUrl = apiUrl + 'api/pictures/{pictureID}/{definition}.jpg';
const imageDataUrl = apiUrl + 'api/collections/{collectionId}/items/{itemId}';
const userIdUrl = apiUrl + 'api/users/search?q={username}'
const usernameURL = apiUrl + '/api/users/{userId}'
const highDefinition = "hd";
const standardDefinition = "sd";
@@ -133,8 +135,6 @@ function loadTileDataToCache(data, tile) {
i,
feature,
loc,
locX,
locY,
d;
if (vectorTile.layers.hasOwnProperty(pictureLayer)) {
@@ -154,6 +154,7 @@ function loadTileDataToCache(data, tile) {
sequence_id: feature.properties.sequences.split("\"")[1],
heading: feature.properties.heading,
image_path: "",
captured_by: "",
resolution: feature.properties.resolution,
isPano: feature.properties.type == "equirectangular",
model: feature.properties.model,
@@ -204,6 +205,28 @@ async function getImageData(collection_id, image_id){
return data;
}
async function getUserId(username){
const requestUrl = userIdUrl.replace('{username}', username);
const response = await fetch(requestUrl, { method: 'GET' });
if (!response.ok) {
throw new Error(response.status + ' ' + response.statusText);
}
const data = await response.json();
return data.features[0].id;
}
async function getUsername(user_id){
const requestUrl = usernameURL.replace('{userId}', user_id);
const response = await fetch(requestUrl, { method: 'GET' });
if (!response.ok) {
throw new Error(response.status + ' ' + response.statusText);
}
const data = await response.json();
return data.name;
}
export default {
init: function() {
if (!_cache) {
@@ -339,6 +362,11 @@ export default {
}
},
getUserIdFromName: async function(username){
const id = await getUserId(username)
return id;
},
selectImage: function (context, id) {
let that = this;
@@ -370,9 +398,9 @@ export default {
const hdDomId = utilUniqueDomId('panoramax-hd');
let label = line1
.append('label')
.attr('for', hdDomId)
.attr('class', 'panoramax-hd');
.append('label')
.attr('for', hdDomId)
.attr('class', 'panoramax-hd');
label
.append('input')
@@ -458,6 +486,20 @@ export default {
if (isNaN(d.getTime())) return null;
return d.toLocaleDateString(localizer.localeCode(), options);
}
if (d.account_id) {
let line2 = attribution
.append('div')
.attr('class', 'attribution-row');
getUsername(d.account_id).then(function(username){
line2
.append('span')
.attr('class', 'captured_by')
.text('Captured by: ' + username);
d.captured_by = username;
});
}
return this;
},
+20 -3
View File
@@ -41,6 +41,9 @@ export function svgPanoramaxImages(projection, context, dispatch) {
const showsFlat = context.photos().showsFlat();
const fromDate = context.photos().fromDate();
const toDate = context.photos().toDate();
const username = context.photos().usernames();
const service = getService();
if (!showsPano || !showsFlat) {
images = images.filter(function(image) {
@@ -58,6 +61,14 @@ export function svgPanoramaxImages(projection, context, dispatch) {
return new Date(image.capture_time).getTime() <= new Date(toDate).getTime();
});
}
if (username && service) {
service.getUserIdFromName(username).then(function(id){
images = images.filter(function(image) {
return id == image.account_id ;
});
})
}
return images;
}
@@ -67,21 +78,27 @@ export function svgPanoramaxImages(projection, context, dispatch) {
const showsFlat = context.photos().showsFlat();
const fromDate = context.photos().fromDate();
const toDate = context.photos().toDate();
const usernames = context.photos().usernames();
if (!showsPano || !showsFlat) {
sequences = sequences.filter(function(sequence) {
if (sequence.properties.type === "equirectangular") return showsPano;
if (sequence.type === "equirectangular") return showsPano;
return showsFlat;
});
}
if (fromDate) {
sequences = sequences.filter(function(sequence) {
return new Date(sequence.properties.date).getTime() >= new Date(fromDate).getTime().toString();
return new Date(sequence.date).getTime() >= new Date(fromDate).getTime().toString();
});
}
if (toDate) {
sequences = sequences.filter(function(sequence) {
return new Date(sequence.properties.date).getTime() <= new Date(toDate).getTime().toString();
return new Date(sequence.date).getTime() <= new Date(toDate).getTime().toString();
});
}
if (usernames) {
sequences = sequences.filter(function(sequence) {
return usernames.indexOf(sequence.account_id) !== -1;
});
}