Skip to content

Commit

Permalink
Merge pull request #1106 from OpenGeoscience/continuous-close-proximity
Browse files Browse the repository at this point in the history
perf: Add a continuousCloseProximity option to annotations
  • Loading branch information
manthey authored Sep 7, 2021
2 parents ea15150 + e8a7b78 commit ccf2a37
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 3 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# GeoJS Change Log

## Version 1.4.1

### Improvements

- Add a continuousCloseProximity option to annotations (#1106)

## Version 1.4.0

### Features
Expand Down
18 changes: 15 additions & 3 deletions src/annotation.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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 &&
(ccp === 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;
}
}

Expand Down Expand Up @@ -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;
Expand Down
5 changes: 5 additions & 0 deletions src/annotationLayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions tests/cases/annotation.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down

0 comments on commit ccf2a37

Please sign in to comment.