perf: Add a continuousCloseProximity option to annotations
MODIFY
CHANGELOG.md
CHANGELOG.md
# GeoJS Change Log
+## Version 1.4.1
+
+### Improvements
+
+- Add a continuousCloseProximity option to annotations (#1106)
+
## Version 1.4.0
### Features

MODIFY
src/annotation.js
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;
}
}

MODIFY
src/annotationLayer.js
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

MODIFY
tests/cases/annotation.js
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(),

perf: Add a continuousCloseProximity option to annotations