Limit Copy operation by visible extent (close #7603)

This commit is contained in:
Quincy Morgan
2020-05-15 09:51:50 -04:00
parent 834b8b4d6c
commit 21ed04ed65
3 changed files with 22 additions and 4 deletions
+3
View File
@@ -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:
+4
View File
@@ -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": {
+15 -4
View File
@@ -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);
};