Don't create zero-area rectangles.
MODIFY
src/annotation.js
src/annotation.js
@@ -697,6 +697,11 @@ var rectangleAnnotation = function (args) {
map.displayToGcs({x: evt.upperRight.x, y: evt.upperRight.y}, null),
map.displayToGcs({x: evt.upperRight.x, y: evt.lowerLeft.y}, null)
];
+ /* Don't keep rectangles that have nearly zero area in display pixels */
+ if (layer.displayDistance(corners[0], null, corners[1], null) *
+ layer.displayDistance(corners[0], null, corners[3], null) < 0.01) {
+ return 'remove';
+ }
m_this.options('corners', corners);
m_this.state(annotationState.done);
return 'done';
@@ -854,6 +859,11 @@ var rectangleAnnotation = function (args) {
evt.handled = true;
if (corners.length) {
m_this._setCornersFromMouse(corners, evt);
+ /* Don't keep rectangles that have nearly zero area in display pixels */
+ if (layer.displayDistance(corners[0], null, corners[1], null) *
+ layer.displayDistance(corners[0], null, corners[3], null) < 0.01) {
+ return 'remove';
+ }
m_this.state(annotationState.done);
return 'done';
}

MODIFY
tests/cases/annotation.js
tests/cases/annotation.js
@@ -347,6 +347,16 @@ describe('geo.annotation', function () {
expect(coor[0].y).toBeCloseTo(10.055);
expect(coor[2].x).toBeCloseTo(-20.215);
expect(coor[2].y).toBeCloseTo(15.199);
+ // a zero-area rectangle should be asked to be removed.
+ ann = geo.annotation.rectangleAnnotation({layer: layer, corners: corners});
+ ann.state(geo.annotation.state.create);
+ evt = {
+ event: geo.event.actionselection,
+ state: {action: geo.geo_action.annotation_rectangle},
+ lowerLeft: {x: 10, y: 65},
+ upperRight: {x: 90, y: 65}
+ };
+ expect(ann.processAction(evt)).toBe('remove');
});
it('_coordinates', function () {
var ann = geo.annotation.rectangleAnnotation({corners: corners});
@@ -428,6 +438,22 @@ describe('geo.annotation', function () {
});
expect(ann.options('corners').length).toBe(4);
expect(ann.state()).toBe(geo.annotation.state.done);
+ // a zero-area rectangle should be asked to be removed.
+ ann = geo.annotation.rectangleAnnotation({layer: layer});
+ ann.state(geo.annotation.state.create);
+ expect(ann.mouseClick({
+ buttonsDown: {left: true},
+ time: time,
+ map: corners[0],
+ mapgcs: map.displayToGcs(corners[0], null)
+ })).toBe(true);
+ expect(ann.options('corners').length).toBe(4);
+ expect(ann.mouseClick({
+ buttonsDown: {left: true},
+ time: time,
+ map: corners[1],
+ mapgcs: map.displayToGcs(corners[1], null)
+ })).toBe('remove');
});
});

Don't create zero-area rectangles.