Skip to content
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
8b60486
feat: add operation for cycling crosswalk tags
RitaDee Oct 20, 2023
8f2a536
refactor: replace highway with crosswalk
RitaDee Oct 21, 2023
b3490a2
refactor: edit operation for cycling crosswalk presets
RitaDee Oct 21, 2023
921dbf4
feat: add the 'cycle_crosswalk_tag' operation with its associated strโ€ฆ
RitaDee Oct 21, 2023
cbc0127
refactor: add crosswalk
RitaDee Oct 23, 2023
9b54bd9
refactor: consolidate annotation for cycle_highway_tag in core.yaml
RitaDee Oct 23, 2023
45bab7c
feat: extend hotkey operation to cycle through crosswalk presets
RitaDee Oct 24, 2023
bf107fb
refactor: separate handling of highway and crosswalk presets
RitaDee Oct 25, 2023
d2ff9ec
feat: add cycle tag functionality for highway and crosswalk
RitaDee Oct 25, 2023
60fdf1e
refactor: implement cycling through preset tags for highway and crossโ€ฆ
RitaDee Oct 25, 2023
b25c368
refactor: improve code structure and logic in operationCycleHighwayTag
RitaDee Oct 26, 2023
b372793
Merge branch 'main' into crosswalk
RitaDee Oct 26, 2023
69351cd
chore: rebase working branch with main
RitaDee Oct 26, 2023
1cb71aa
chore: rebase working branch with main
RitaDee Oct 27, 2023
ebd0a25
Merge branch 'crosswalk' of github.com:RitaDee/Rapid into crosswalk
RitaDee Oct 27, 2023
a6a3a59
refactor: correct the scope of isSameSelection in operationCycleHighwโ€ฆ
RitaDee Oct 27, 2023
d48c707
feat: update operationCycleHighwayTag
RitaDee Oct 30, 2023
a3f170a
refactor: update operationCycleHighwayTag
RitaDee Oct 31, 2023
38775ae
feat: add hotkey for crosswalk
RitaDee Oct 31, 2023
81aa162
refactor: use appropriate translation
RitaDee Oct 31, 2023
4514a6a
Merge branch 'main' into crosswalk
bhousel Nov 8, 2023
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
5 changes: 3 additions & 2 deletions data/core.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -513,8 +513,9 @@ en:
cycle_highway_tag:
title: Cycle Highway Tag
key: C
description: Shortcut to cycle selected highway through several different tags.
annotation: Changed highway tag of selected way.
description: Shortcut to cycle selected highway or crosswalk through several different tags.
highway_annotation: Changed highway tag of selected way.
crosswalk_annotation: Changed crosswalk tag of selected way.
restriction:
controls:
distance: Distance
Expand Down
89 changes: 58 additions & 31 deletions modules/operations/cycle_highway_tag.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,31 +6,62 @@ import { KeyOperationBehavior } from '../behaviors/KeyOperationBehavior';
let _wasSelectedIDs = [];
let _wasPresetIDs = [];


export function operationCycleHighwayTag(context, selectedIDs) {
const editor = context.systems.editor;
const graph = editor.staging.graph;
const l10n = context.systems.l10n;
const presets = context.systems.presets;

// Allow cycling through lines that match these presets
const allowPresetRegex = [
const allowHighwayPresetRegex = [
/^highway\/(motorway|trunk|primary|secondary|tertiary|unclassified|residential|living_street|service|track)/,
/^line$/
Comment thread
Bonkles marked this conversation as resolved.
Outdated
/^line$/,
];

const defaultPresetIDs = [
const defaultHighwayPresetIDs = [
'highway/residential',
'highway/service',
'highway/track',
'highway/unclassified',
'highway/tertiary',
'line'
'line',
];

// Allow cycling through crossings that match these presets
const allowCrossingPresetRegex = [
/^crossing\/(unmarked|marked|marked:zebra|marked:lines|marked:dashes|marked:ladder|marked:dots|marked:ladder:skewed)/,
];

const defaultCrossingPresetIDs = [
'crossing/unmarked;crossing:markings=no',
'crossing/marked;crossing:markings=yes',
'crossing/marked;crossing:markings=zebra',
'crossing/marked;crossing:markings=lines',
'crossing/marked;crossing:markings=ladder',
'crossing/marked;crossing:markings=dashes',
'crossing/marked;crossing:markings=dots',
'crossing/marked;crossing:markings=ladder:skewed',
];

// same selection as before?
const isSameSelection = utilArrayIdentical(selectedIDs, _wasSelectedIDs);
const presetIDs = new Set(isSameSelection ? _wasPresetIDs : defaultPresetIDs);
// Check if selection is highway or crossing
const isCrosswalkSelection = selectedIDs.some((id) => id.includes('crosswalk'));
const isHighwaySelection = selectedIDs.some((id) => id.includes('highway'));

Comment thread
RitaDee marked this conversation as resolved.
Outdated
// Define the preset IDs based on the selection type
let presetIDs;

// Declare isSameSelection here
let isSameSelection = utilArrayIdentical(selectedIDs, _wasSelectedIDs);

if (isCrosswalkSelection) {
presetIDs = defaultCrossingPresetIDs;
} else if (isHighwaySelection) {
presetIDs = isSameSelection ? _wasPresetIDs : defaultHighwayPresetIDs;
} else {
return;
Comment thread
Bonkles marked this conversation as resolved.
Outdated
}

_wasPresetIDs = presetIDs;

// Gather selected entities allowed to be cycled
const entities = selectedIDs
Expand All @@ -39,22 +70,22 @@ export function operationCycleHighwayTag(context, selectedIDs) {
if (entity?.type !== 'way') return false;

const preset = presets.match(entity, graph);
if (allowPresetRegex.some(regex => regex.test(preset.id))) {
if (!presetIDs.has(preset.id)) presetIDs.add(preset.id); // make sure we can cycle back to the original preset
// Check if the preset matches either allowHighwayPresetRegex or allowCrossingPresetRegex
if (
allowHighwayPresetRegex.some(regex => regex.test(preset.id)) ||
allowCrossingPresetRegex.some(regex => regex.test(preset.id))
) {
return true;
} else {
return false;
}
return false;
});

_wasSelectedIDs = selectedIDs.slice(); // copy
_wasPresetIDs = Array.from(presetIDs); // copy

_wasSelectedIDs = selectedIDs.slice(); // copy

let operation = function() {
if (!entities.length) return;

// Pick the next preset..
// Pick the next preset...
const currPresetIDs = Array.from(presetIDs);
const currPreset = presets.match(entities[0], editor.staging.graph);
const index = currPreset ? currPresetIDs.indexOf(currPreset.id) : -1;
Expand All @@ -63,51 +94,47 @@ export function operationCycleHighwayTag(context, selectedIDs) {

editor.beginTransaction();

// Update all selected highways...
// Update all selected highways or crosswalks...
for (const entity of entities) {
const oldPreset = presets.match(entity, editor.staging.graph);
const action = actionChangePreset(entity.id, oldPreset, newPreset, true /* skip field defaults */);
const action = actionChangePreset(entity.id, oldPreset, newPreset, true);
editor.perform(action);
}

// If this is the same selection as before, and the previous edit was also a cycle-tags,
// we can just replace the previous edit with this one.
const annotation = operation.annotation();
// Determine the appropriate annotation based on the selection type
const annotationKey = isCrosswalkSelection ? 'crosswalk_annotation' : 'highway_annotation';
const annotation = l10n.t(`operations.cycle_highway_tag.${annotationKey}`);

const options = { annotation: annotation, selectedIDs: selectedIDs };
if (isSameSelection && editor.getUndoAnnotation() === annotation) {
editor.commitAppend(options); // Replace the previous cycle-tags edit
editor.commitAppend(options);
} else {
editor.commit(options);
}

editor.endTransaction();
context.enter('select-osm', { selection: { osm: selectedIDs }} ); // reselect
context.enter('select-osm', { selection: { osm: selectedIDs } });
};


operation.available = function() {
return entities.length > 0;
};


operation.disabled = function() {
return false;
};


operation.tooltip = function() {
const disabledReason = operation.disabled();
return disabledReason ?
l10n.t(`operations.cycle_highway_tag.${disabledReason}`) :
l10n.t('operations.cycle_highway_tag.description');
return disabledReason
? l10n.t(`operations.cycle_highway_tag.${disabledReason}`)
: l10n.t('operations.cycle_highway_tag.description');
};


operation.annotation = function() {
return l10n.t('operations.cycle_highway_tag.annotation');
};


operation.id = 'cycle_highway_tag';
operation.keys = [ 'โ‡ง' + l10n.t('operations.cycle_highway_tag.key') ];
operation.title = l10n.t('operations.cycle_highway_tag.title');
Expand Down
โšก