diff --git a/modules/renderer/photos.js b/modules/renderer/photos.js index f2a8de21c..b28fd9b2f 100644 --- a/modules/renderer/photos.js +++ b/modules/renderer/photos.js @@ -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) { diff --git a/modules/services/panoramax.js b/modules/services/panoramax.js index 919387205..bf90444c5 100644 --- a/modules/services/panoramax.js +++ b/modules/services/panoramax.js @@ -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; }, diff --git a/modules/svg/panoramax_images.js b/modules/svg/panoramax_images.js index 39617ccb3..cc223175a 100644 --- a/modules/svg/panoramax_images.js +++ b/modules/svg/panoramax_images.js @@ -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; }); }