mirror of
https://github.com/FoggedLens/iD.git
synced 2026-05-15 05:30:35 +02:00
Limit Copy operation by visible extent (close #7603)
This commit is contained in:
@@ -88,6 +88,9 @@ en:
|
||||
annotation:
|
||||
single: Copied a feature.
|
||||
multiple: "Copied {n} features."
|
||||
too_large:
|
||||
single: This can't be copied because not enough of it is currently visible.
|
||||
multiple: These can't be copied because not enough of them are currently visible.
|
||||
paste:
|
||||
title: Paste
|
||||
description:
|
||||
|
||||
Vendored
+4
@@ -112,6 +112,10 @@
|
||||
"annotation": {
|
||||
"single": "Copied a feature.",
|
||||
"multiple": "Copied {n} features."
|
||||
},
|
||||
"too_large": {
|
||||
"single": "This can't be copied because not enough of it is currently visible.",
|
||||
"multiple": "These can't be copied because not enough of them are currently visible."
|
||||
}
|
||||
},
|
||||
"paste": {
|
||||
|
||||
@@ -3,10 +3,13 @@ import { event as d3_event } from 'd3-selection';
|
||||
import { t } from '../core/localizer';
|
||||
import { behaviorOperation } from '../behavior/operation';
|
||||
import { uiCmd } from '../ui/cmd';
|
||||
import { utilArrayGroupBy } from '../util';
|
||||
import { geoExtent } from '../geo';
|
||||
import { utilArrayGroupBy, utilGetAllNodes } from '../util';
|
||||
|
||||
export function operationCopy(context, selectedIDs) {
|
||||
|
||||
var _multi = selectedIDs.length === 1 ? 'single' : 'multiple';
|
||||
|
||||
function getFilteredIdsToCopy() {
|
||||
return selectedIDs.filter(function(selectedID) {
|
||||
var entity = context.graph().hasEntity(selectedID);
|
||||
@@ -98,14 +101,22 @@ export function operationCopy(context, selectedIDs) {
|
||||
|
||||
|
||||
operation.disabled = function() {
|
||||
var nodes = utilGetAllNodes(getFilteredIdsToCopy(), context.graph());
|
||||
var extent = nodes.reduce(function(extent, node) {
|
||||
return extent.extend(node.extent(context.graph()));
|
||||
}, geoExtent());
|
||||
if (extent.area() && extent.percentContainedIn(context.map().extent()) < 0.8) {
|
||||
return 'too_large';
|
||||
}
|
||||
return false;
|
||||
};
|
||||
|
||||
|
||||
operation.tooltip = function() {
|
||||
return selectedIDs.length === 1 ?
|
||||
t('operations.copy.description.single') :
|
||||
t('operations.copy.description.multiple');
|
||||
var disable = operation.disabled();
|
||||
return disable ?
|
||||
t('operations.copy.' + disable + '.' + _multi) :
|
||||
t('operations.copy.description' + '.' + _multi);
|
||||
};
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user