Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf: Add a continuousCloseProximity option to annotations #1106

Merged
merged 2 commits into from
Sep 7, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 &&
(cpp === true || layer.displayDistance(vertices[0], null, evt.mouse.map, 'display') <= cpp)) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be ccp === true ?

Right now, it works but I have to set continuousPointProximity to true as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, my mistake.

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