From d9c973b7453841e5543a8ef1a88c9b4844f9cbab Mon Sep 17 00:00:00 2001 From: Martin Raifer Date: Fri, 12 Jul 2024 17:49:34 +0200 Subject: [PATCH] disable button when photo is too far from selected feature --- data/core.yaml | 4 +++- modules/ui/photoviewer.js | 25 ++++++++++++++++++------- 2 files changed, 21 insertions(+), 8 deletions(-) diff --git a/data/core.yaml b/data/core.yaml index 6861f5568..d81519189 100644 --- a/data/core.yaml +++ b/data/core.yaml @@ -790,7 +790,9 @@ en: set_today: "Sets the value to today." set_photo_from_viewer: enable: "Tag this photo id on the currently selected map feature" - disable: "This image is already tagged on this feature" + disable: + already_set: "This photo is already tagged on the selected map feature" + too_far: "This photo is too far away from the selected map feature" background: title: Background description: Background Settings diff --git a/modules/ui/photoviewer.js b/modules/ui/photoviewer.js index d80194111..ee4b032a7 100644 --- a/modules/ui/photoviewer.js +++ b/modules/ui/photoviewer.js @@ -10,6 +10,7 @@ import { utilRebind, utilGetSetValue, utilStringQs } from '../util'; import { services } from '../services'; import { uiTooltip } from './tooltip'; import { actionChangeTags } from '../actions'; +import { geoSphericalDistance } from '../geo'; export function uiPhotoviewer(context) { @@ -82,7 +83,7 @@ export function uiPhotoviewer(context) { e.preventDefault(); e.stopPropagation(); setMapillaryPhotoId(); - buttonDisable(true); + buttonDisable('already_set'); }); } buttonShowHide(); @@ -144,23 +145,33 @@ export function uiPhotoviewer(context) { } function buttonShowHide() { - let activeImageId = services.mapillary.getActiveImage()?.id; + const activeImage = services.mapillary.getActiveImage(); + const activeImageId = activeImage?.id; const graph = context.graph(); + const entities = context.selectedIDs() + .map(id => graph.entity(id)); - buttonDisable(context.selectedIDs() - .map(entityID => graph.entity(entityID).tags.mapillary) - .every(value => value === activeImageId)); + if (entities.map(entity => entity.tags.mapillary) + .every(value => value === activeImage?.id)) { + buttonDisable('already_set'); + } else if (activeImage && entities.map(entity => entity.extent().center()) + .every(loc => geoSphericalDistance(loc, activeImage.loc) > 100)) { + buttonDisable('too_far'); + } else { + buttonDisable(false); + } } - function buttonDisable(disabled) { + function buttonDisable(reason) { + const disabled = reason !== false; const button = selection.selectAll('.set-photo-from-viewer').data([0]); button.attr('disabled', disabled ? 'true' : null); button.classed('disabled', disabled); button.call(uiTooltip().destroyAny); if (disabled) { button.call(uiTooltip() - .title(() => t.append('inspector.set_photo_from_viewer.disable')) + .title(() => t.append(`inspector.set_photo_from_viewer.disable.${reason}`)) .placement('right') ); } else {