mirror of
https://github.com/FoggedLens/iD.git
synced 2026-05-15 21:48:20 +02:00
Prefix file variables in operations/orthogonalize.js with underscores
Simplify multiple disabled reasons code for circularize and orthogonalize operaitons
This commit is contained in:
@@ -56,22 +56,17 @@ export function operationCircularize(selectedIDs, context) {
|
||||
operation.disabled = function() {
|
||||
if (!_actions.length) return '';
|
||||
|
||||
var actionDisabled;
|
||||
var actionDisableds = {};
|
||||
var actionDisableds = _actions.map(function(action) {
|
||||
return action.disabled(context.graph());
|
||||
}).filter(Boolean);
|
||||
|
||||
if (_actions.every(function(action) {
|
||||
var disabled = action.disabled(context.graph());
|
||||
if (disabled) actionDisableds[disabled] = true;
|
||||
return disabled;
|
||||
})) {
|
||||
actionDisabled = _actions[0].disabled(context.graph());
|
||||
}
|
||||
if (actionDisableds.length === _actions.length) {
|
||||
// none of the features can be circularized
|
||||
|
||||
if (actionDisabled) {
|
||||
if (Object.keys(actionDisableds).length > 1) {
|
||||
if (new Set(actionDisableds).size > 1) {
|
||||
return 'multiple_blockers';
|
||||
}
|
||||
return actionDisabled;
|
||||
return actionDisableds[0];
|
||||
} else if (_extent.percentContainedIn(context.extent()) < 0.8) {
|
||||
return 'too_large';
|
||||
} else if (someMissing()) {
|
||||
|
||||
@@ -6,11 +6,11 @@ import { utilGetAllNodes } from '../util';
|
||||
|
||||
export function operationOrthogonalize(selectedIDs, context) {
|
||||
var _extent;
|
||||
var type;
|
||||
var actions = selectedIDs.map(chooseAction).filter(Boolean);
|
||||
var amount = actions.length === 1 ? 'single' : 'multiple';
|
||||
var nodes = utilGetAllNodes(selectedIDs, context.graph());
|
||||
var coords = nodes.map(function(n) { return n.loc; });
|
||||
var _type;
|
||||
var _actions = selectedIDs.map(chooseAction).filter(Boolean);
|
||||
var _amount = _actions.length === 1 ? 'single' : 'multiple';
|
||||
var _coords = utilGetAllNodes(selectedIDs, context.graph())
|
||||
.map(function(n) { return n.loc; });
|
||||
|
||||
|
||||
function chooseAction(entityID) {
|
||||
@@ -26,14 +26,14 @@ export function operationOrthogonalize(selectedIDs, context) {
|
||||
|
||||
// square a line/area
|
||||
if (entity.type === 'way' && new Set(entity.nodes).size > 2 ) {
|
||||
if (type && type !== 'feature') return null;
|
||||
type = 'feature';
|
||||
if (_type && _type !== 'feature') return null;
|
||||
_type = 'feature';
|
||||
return actionOrthogonalize(entityID, context.projection);
|
||||
|
||||
// square a single vertex
|
||||
} else if (geometry === 'vertex') {
|
||||
if (type && type !== 'corner') return null;
|
||||
type = 'corner';
|
||||
if (_type && _type !== 'corner') return null;
|
||||
_type = 'corner';
|
||||
var graph = context.graph();
|
||||
var parents = graph.parentWays(entity);
|
||||
if (parents.length === 1) {
|
||||
@@ -49,10 +49,10 @@ export function operationOrthogonalize(selectedIDs, context) {
|
||||
|
||||
|
||||
var operation = function() {
|
||||
if (!actions.length) return;
|
||||
if (!_actions.length) return;
|
||||
|
||||
var combinedAction = function(graph, t) {
|
||||
actions.forEach(function(action) {
|
||||
_actions.forEach(function(action) {
|
||||
if (!action.disabled(graph)) {
|
||||
graph = action(graph, t);
|
||||
}
|
||||
@@ -70,32 +70,26 @@ export function operationOrthogonalize(selectedIDs, context) {
|
||||
|
||||
|
||||
operation.available = function() {
|
||||
return actions.length && selectedIDs.length === actions.length;
|
||||
return _actions.length && selectedIDs.length === _actions.length;
|
||||
};
|
||||
|
||||
|
||||
// don't cache this because the visible extent could change
|
||||
operation.disabled = function() {
|
||||
if (!actions.length) return '';
|
||||
if (!_actions.length) return '';
|
||||
|
||||
var actionDisabled;
|
||||
var actionDisableds = _actions.map(function(action) {
|
||||
return action.disabled(context.graph());
|
||||
}).filter(Boolean);
|
||||
|
||||
var actionDisableds = {};
|
||||
if (actionDisableds.length === _actions.length) {
|
||||
// none of the features can be squared
|
||||
|
||||
if (actions.every(function(action) {
|
||||
var disabled = action.disabled(context.graph());
|
||||
if (disabled) actionDisableds[disabled] = true;
|
||||
return disabled;
|
||||
})) {
|
||||
actionDisabled = actions[0].disabled(context.graph());
|
||||
}
|
||||
|
||||
if (actionDisabled) {
|
||||
if (Object.keys(actionDisableds).length > 1) {
|
||||
if (new Set(actionDisableds).size > 1) {
|
||||
return 'multiple_blockers';
|
||||
}
|
||||
return actionDisabled;
|
||||
} else if (type !== 'corner' &&
|
||||
return actionDisableds[0];
|
||||
} else if (_type !== 'corner' &&
|
||||
_extent.percentContainedIn(context.extent()) < 0.8) {
|
||||
return 'too_large';
|
||||
} else if (someMissing()) {
|
||||
@@ -111,7 +105,7 @@ export function operationOrthogonalize(selectedIDs, context) {
|
||||
if (context.inIntro()) return false;
|
||||
var osm = context.connection();
|
||||
if (osm) {
|
||||
var missing = coords.filter(function(loc) { return !osm.isDataLoaded(loc); });
|
||||
var missing = _coords.filter(function(loc) { return !osm.isDataLoaded(loc); });
|
||||
if (missing.length) {
|
||||
missing.forEach(function(loc) { context.loadTileAtLoc(loc); });
|
||||
return true;
|
||||
@@ -125,13 +119,13 @@ export function operationOrthogonalize(selectedIDs, context) {
|
||||
operation.tooltip = function() {
|
||||
var disable = operation.disabled();
|
||||
return disable ?
|
||||
t('operations.orthogonalize.' + disable + '.' + amount) :
|
||||
t('operations.orthogonalize.description.' + type + '.' + amount);
|
||||
t('operations.orthogonalize.' + disable + '.' + _amount) :
|
||||
t('operations.orthogonalize.description.' + _type + '.' + _amount);
|
||||
};
|
||||
|
||||
|
||||
operation.annotation = function() {
|
||||
return t('operations.orthogonalize.annotation.' + type + '.' + amount);
|
||||
return t('operations.orthogonalize.annotation.' + _type + '.' + _amount);
|
||||
};
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user