From d9eb72e88b7f18d1b77628fc5776ddbe4b76a3c3 Mon Sep 17 00:00:00 2001 From: David Manthey Date: Tue, 7 Sep 2021 10:12:31 -0400 Subject: [PATCH 1/2] perf: Add a continuousCloseProximity option to annotations --- CHANGELOG.md | 6 ++++++ src/annotation.js | 18 +++++++++++++++--- src/annotationLayer.js | 5 +++++ tests/cases/annotation.js | 10 ++++++++++ 4 files changed, 36 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0a43c8b3bc..f3ae6ce7d5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # GeoJS Change Log +## Version 1.4.1 + +### Improvements + +- Add a continuousCloseProximity option to annotations (#1106) + ## Version 1.4.0 ### Features diff --git a/src/annotation.js b/src/annotation.js index f8e537014e..dc70faae89 100644 --- a/src/annotation.js +++ b/src/annotation.js @@ -1129,8 +1129,10 @@ function continuousVerticesProcessAction(m_this, evt, name) { } var cpp = layer.options('continuousPointProximity'); var cpc = layer.options('continuousPointColinearity'); + var ccp = layer.options('continuousCloseProximity'); if (cpp || cpp === 0) { var vertices = m_this.options('vertices'); + var update = false; if (!vertices.length) { vertices.push(evt.mouse.mapgcs); vertices.push(evt.mouse.mapgcs); @@ -1152,8 +1154,18 @@ function continuousVerticesProcessAction(m_this, evt, name) { } vertices[vertices.length - 1] = evt.mouse.mapgcs; vertices.push(evt.mouse.mapgcs); - return true; + update = true; } + if ((ccp || ccp === 0) && evt.event === geo_event.actionup && + (cpp === true || layer.displayDistance(vertices[0], null, evt.mouse.map, 'display') <= cpp)) { + if (vertices.length < 3 + (name === 'polygon' ? 1 : 0)) { + return 'remove'; + } + vertices.pop(); + m_this.state(annotationState.done); + return 'done'; + } + return update; } } @@ -1731,8 +1743,8 @@ var polygonAnnotation = function (args) { end = true; } } else if (vertices.length >= 2 && layer.displayDistance( - vertices[0], null, evt.map, 'display') <= - layer.options('finalPointProximity')) { + vertices[0], null, evt.map, 'display') <= + layer.options('finalPointProximity')) { end = true; } else { vertices[vertices.length - 1] = evt.mapgcs; diff --git a/src/annotationLayer.js b/src/annotationLayer.js index 1e24a2de62..42a519473d 100644 --- a/src/annotationLayer.js +++ b/src/annotationLayer.js @@ -24,6 +24,10 @@ var textFeature = require('./textFeature'); * @property {number} [continuousPointColinearity=1.0deg] The minimum angle * between a series of three points when dragging to not interpret them as * colinear. Only applies if `continuousPointProximity` is not `false`. + * @property {number} [continuousCloseProximity=10] The minimum distance in + * display coordinates (pixels) to close a polygon or end drawing a line when + * dragging to create an annotation. `false` never closes at the end of a + * drag. `true` is effectively infinite. * @property {number} [finalPointProximity=10] The maximum distance in display * coordinates (pixels) between the starting point and the mouse coordinates * to signal closing a polygon. A value of 0 requires an exact match. A @@ -133,6 +137,7 @@ var annotationLayer = function (arg) { // in radians, minimum angle between continuous points to interpret them as // being coliner continuousPointColinearity: 1.0 * Math.PI / 180, + continuousCloseProximity: 10, // in pixels, 0 is exact finalPointProximity: 10, // in pixels, 0 is exact showLabels: true, clickToEdit: false diff --git a/tests/cases/annotation.js b/tests/cases/annotation.js index 2831cf534a..db03a5a357 100644 --- a/tests/cases/annotation.js +++ b/tests/cases/annotation.js @@ -1367,6 +1367,16 @@ describe('geo.annotation', function () { // the same point count expect(ann.processAction(evt)).toBe(true); expect(ann.options('vertices').length).toBe(4); + // test up near the end of the line + var evt = { + state: {action: geo.geo_action.annotation_line}, + mouse: { + map: vertices[0], + mapgcs: map.displayToGcs(vertices[0], null) + }, + event: geo.event.actionup + }; + expect(ann.processAction(evt)).toBe('done'); }); it('processEditAction', function () { var map = createMap(), From e8a7b78ad612b5ab4e4e2221d04f0555db97b109 Mon Sep 17 00:00:00 2001 From: David Manthey Date: Tue, 7 Sep 2021 12:48:33 -0400 Subject: [PATCH 2/2] Fix a wrong variable name. --- src/annotation.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/annotation.js b/src/annotation.js index dc70faae89..745149cb3e 100644 --- a/src/annotation.js +++ b/src/annotation.js @@ -1157,7 +1157,7 @@ function continuousVerticesProcessAction(m_this, evt, name) { update = true; } if ((ccp || ccp === 0) && evt.event === geo_event.actionup && - (cpp === true || layer.displayDistance(vertices[0], null, evt.mouse.map, 'display') <= cpp)) { + (ccp === true || layer.displayDistance(vertices[0], null, evt.mouse.map, 'display') <= cpp)) { if (vertices.length < 3 + (name === 'polygon' ? 1 : 0)) { return 'remove'; }