Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a button in the mapillary image photo viewer to "add the current image id as field to feature" #10046

Merged
merged 28 commits into from
Jul 16, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
87f0014
Add set button and view button at mapillary field (#9339)
laigyu Dec 20, 2023
a2296cf
fix setButton when imageChange disabled
laigyu Dec 20, 2023
33f4f8e
fix button title
laigyu Dec 21, 2023
5890b79
Add set mapillary id button in the mapillary photo viewer
laigyu Dec 27, 2023
6523ae6
Update icon to '#iD-operation-merge'
laigyu Jan 18, 2024
2b0e0f6
update core.yaml
laigyu Jan 18, 2024
0ef947d
Update set_photo_from_viewer button create/remove logic
laigyu Jan 20, 2024
437ecf9
update open the viewer button logic
laigyu Jan 24, 2024
0ad46e0
Add error message in photoviewer when invalid id
laigyu Jan 27, 2024
cc10898
finish open the viewer button logic
laigyu Jan 29, 2024
b597cc1
refactor the code
laigyu Feb 2, 2024
666bbbf
code style change
laigyu Feb 2, 2024
6b860b7
refactor the code
laigyu Feb 5, 2024
8bb1d0d
Merge remote-tracking branch 'upstream/develop' into add-button-to-ma…
laigyu Apr 5, 2024
94e32a8
revert field button
laigyu Apr 7, 2024
d448b58
revert error handler
laigyu Apr 7, 2024
6b8b41c
tooltip style change
laigyu Apr 8, 2024
2325de4
update butotn logic
laigyu Apr 12, 2024
b1ff86c
tooltip update
laigyu Apr 15, 2024
904c802
Merge branch 'openstreetmap:develop' into add-button-to-mapillary
laigyu Apr 17, 2024
6e9d225
use slightly smaller "plus" icon
tyrasd Jul 12, 2024
2ea9691
slightly tweak tooltip text
tyrasd Jul 12, 2024
b604ef8
make button work on newly created features; refactor code
tyrasd Jul 12, 2024
d9c973b
disable button when photo is too far from selected feature
tyrasd Jul 12, 2024
1d0f9e6
lint
tyrasd Jul 12, 2024
7d65b19
simplify code
tyrasd Jul 12, 2024
daf2c98
add to changelog
tyrasd Jul 12, 2024
d13c202
update "add mapillary tag" button state when tags of the feature change
tyrasd Jul 16, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions css/60_photos.css
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,15 @@
z-index: 50;
}

.photoviewer button.set-mapillary-image-ID-field {
border-radius: 0;
padding: 5px;
position: absolute;
left: 5px;
top: 5px;
z-index: 50;
}

.photoviewer button.resize-handle-xy {
border-radius: 0;
position: absolute;
Expand Down
2 changes: 2 additions & 0 deletions data/core.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -786,6 +786,8 @@ en:
inch: in
max_length_reached: "This string is longer than the maximum length of {maxChars} characters. Anything exceeding that length will be truncated."
set_today: "Sets the value to today."
set_mapillary: "Sets the current ID of mapillary"
show_mapillary_from_field: "Show image on viewer"
laigyu marked this conversation as resolved.
Show resolved Hide resolved
background:
title: Background
description: Background Settings
Expand Down
86 changes: 85 additions & 1 deletion modules/ui/fields/input.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { isColourValid } from '../../osm/tags';
import { uiLengthIndicator } from '..';
import { uiTooltip } from '../tooltip';
import { isEqual } from 'lodash-es';
import { services } from '../../services';

export {
uiFieldText as uiFieldColour,
Expand All @@ -30,6 +31,8 @@ export function uiFieldText(field, context) {
var dispatch = d3_dispatch('change');
var input = d3_select(null);
var outlinkButton = d3_select(null);
var mapillaryViewButton = d3_select(null);
var mapillarySetButton = d3_select(null);
var wrap = d3_select(null);
var _lengthIndicator = uiLengthIndicator(context.maxCharsForTagValue());
var _entityIDs = [];
Expand Down Expand Up @@ -169,8 +172,72 @@ export function uiFieldText(field, context) {
change()();
});
} else if (field.type === 'identifier' && field.urlFormat && field.pattern) {

input.attr('type', 'text');

if (field.id==='mapillary'){
const service = services.mapillary;
// set button
mapillarySetButton = wrap.selectAll('.mapillary-set-current')
.data([0])
.enter()
.append('button')
.attr('class', 'form-field-button mapillary-set-current')
.call(svgIcon('#fas-rotate'))
.attr('title', t('inspector.set_mapillary'))
.on('click', function(d3_event) {
d3_event.preventDefault();
const image = service.getActiveImage();
if (!image) return;
if (image.id===utilGetSetValue(input).trim()) return;
service
.ensureViewerLoaded(context)
.then(function() {
service
.showViewer(context)
.selectImage(context, image.id)
.initViewer(context);
utilGetSetValue(input, image.id);
change()();
});
})
.merge(wrap.selectAll('.mapillary-set-current'))
.classed('disabled', () => {
const image = service.getActiveImage();
if (!image) return true;
if (image.id===utilGetSetValue(input).trim()) return true;
});
service.on('imageChanged', function() {
mapillarySetButton.classed('disabled', () => {
const image = service.getActiveImage();
if (!image) return true;
if (image.id===utilGetSetValue(input).trim()) return true;
return false;
});
});
// view button
mapillaryViewButton = wrap.selectAll('.mapillary-show-view')
.data([0])
.enter()
.append('button')
.attr('class', 'form-field-button mapillary-show-view')
.call(svgIcon('#fas-eye'))
.attr('title', t('inspector.show_mapillary_from_field'))
.on('click', function(d3_event) {
d3_event.preventDefault();
if ( !utilGetSetValue(input).trim()) return;
service
.ensureViewerLoaded(context)
.then(function() {
service
.showViewer(context)
.selectImage(context, utilGetSetValue(input).trim())
.initViewer(context);
});
})
.merge(wrap.selectAll('.mapillary-show-view'))
.classed('disabled', () => !utilGetSetValue(input).trim());
}

outlinkButton = wrap.selectAll('.foreign-id-permalink')
.data([0]);

Expand Down Expand Up @@ -525,6 +592,23 @@ export function uiFieldText(field, context) {
outlinkButton.classed('disabled', disabled);
}

if (mapillaryViewButton && !mapillaryViewButton.empty()) {
mapillaryViewButton.classed('disabled', !utilGetSetValue(input).trim());
}

if (mapillarySetButton && !mapillarySetButton.empty()) {
const service = services.mapillary;
mapillarySetButton.classed('disabled', () => {
const image = service.getActiveImage();
if (!image) return true;
if (image.id===utilGetSetValue(input).trim()) {
return true;
} else {
return false;
}
});
}

if (!isMixed) {
_lengthIndicator.update(tags[field.key]);
}
Expand Down
60 changes: 59 additions & 1 deletion modules/ui/photoviewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { t } from '../core/localizer';
import { dispatch as d3_dispatch } from 'd3-dispatch';
import { svgIcon } from '../svg/icon';
import { utilGetDimensions } from '../util/dimensions';
import { utilRebind } from '../util';
import { utilRebind , utilGetSetValue } from '../util';
import { services } from '../services';

export function uiPhotoviewer(context) {
Expand Down Expand Up @@ -61,6 +61,64 @@ export function uiPhotoviewer(context) {
buildResizeListener(selection, 'resize', dispatch, { resizeOnY: true })
);

if (services.mapillary) {
addMapillayIdButton();
}

// add set-mapillary-button in mapillary viewer
function addMapillayIdButton () {

const service = services.mapillary;
selection
.append('button')
.attr('class', 'set-mapillary-image-ID-field')
.on('click', function(d3_event) {
d3_event.preventDefault();
const editorPane = d3_select('.entity-editor-pane');
const inspector_wrap = d3_select('.inspector-wrap');
const mailallary_image_ID_field = d3_select('.wrap-form-field-mapillary');
const changeEvent = new Event('change');
if (!editorPane) return;

if (!editorPane.classed('hide')&&!inspector_wrap.classed('inspector-hidden')){
// check if mapillary image id field exist
if (!mailallary_image_ID_field.empty()) {
// insert id
const image = service.getActiveImage();
const fieldInput = d3_select('.wrap-form-field-mapillary .identifier');
utilGetSetValue(fieldInput,image.id);

// trigger change at field
fieldInput.node().focus();
fieldInput.node().dispatchEvent(changeEvent);
} else {
// open the Mapillary field
const comboboxInput = d3_select('.value.combobox-input');
const EnterEvent = new KeyboardEvent('keydown',{keyCode : 13});
utilGetSetValue(comboboxInput,'Mapillary Image ID');
comboboxInput.node().focus();
comboboxInput.node().dispatchEvent(EnterEvent);

// insert id
const image = service.getActiveImage();
const fieldInput = d3_select('.wrap-form-field-mapillary .identifier');
utilGetSetValue(fieldInput,image.id);

// trigger change at field
fieldInput.node().focus();
fieldInput.node().dispatchEvent(changeEvent);
}
} else {
/* eslint-disable no-console */
console.log('editorPane hide');
/* eslint-disable no-console */
}
})
.append('div')
.call(svgIcon('#fas-rotate'))
.attr('title', t('inspector.set_mapillary'));
}

function buildResizeListener(target, eventName, dispatch, options) {

var resizeOnX = !!options.resizeOnX;
Expand Down
Loading